-1

I am trying to create a sparse texture array in OpenGL and as far as i can tell my values are okay. See the comment above the actual call for the values from debugger.

    glGenTextures(1, &mTexId);
    glBindTexture(GL_TEXTURE_2D_ARRAY, mTexId);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SPARSE_ARB, GL_TRUE);

    // TODO: This could be done once per internal format. For now, just do it every time.
    GLint indexCount = 0,
            xSize = 0,
            ySize = 0,
            zSize = 0;
    GLint bestIndex = -1,
            bestXSize = 0,
            bestYSize = 0;
    glGetInternalformativ(GL_TEXTURE_2D_ARRAY, internalformat, GL_NUM_VIRTUAL_PAGE_SIZES_ARB, 1, &indexCount);
    if(indexCount == 0) {
        fprintf(stdout, "No Virtual Page Sizes for given format");
        fflush(stdout);
    }
    _check_gl_error();
    for (GLint i = 0; i < indexCount; ++i) {
        glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_VIRTUAL_PAGE_SIZE_INDEX_ARB, i);
        glGetInternalformativ(GL_TEXTURE_2D_ARRAY, internalformat, GL_VIRTUAL_PAGE_SIZE_X_ARB, 1, &xSize);
        glGetInternalformativ(GL_TEXTURE_2D_ARRAY, internalformat, GL_VIRTUAL_PAGE_SIZE_Y_ARB, 1, &ySize);
        glGetInternalformativ(GL_TEXTURE_2D_ARRAY, internalformat, GL_VIRTUAL_PAGE_SIZE_Z_ARB, 1, &zSize);
        // For our purposes, the "best" format is the one that winds up with Z=1 and the largest x and y sizes.
        if (zSize == 1) {
            if (xSize >= bestXSize && ySize >= bestYSize) {
                bestIndex = i;
                bestXSize = xSize;
                bestYSize = ySize;
            }
        }
    }
    _check_gl_error();

    mXTileSize = bestXSize;
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_VIRTUAL_PAGE_SIZE_INDEX_ARB, bestIndex);
    _check_gl_error();

    // We've set all the necessary parameters, now it's time to create the sparse texture.
    //1, GL_TEXTURE_2D_ARRAY, 5, 32856 aka GL_RGBA8, 500, 331, 5
    glTextureStorage3DEXT(mTexId, GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, slices);
genpfault
  • 51,148
  • 11
  • 85
  • 139
Joe
  • 454
  • 1
  • 6
  • 20

1 Answers1

1

Turns out I missed the part in the spec where the texture storage size (w,h,d) has to be a multiple of the Virtual Page Size.

I'm curious what the best approach is to fitting a texture to such a constraint.

Joe
  • 454
  • 1
  • 6
  • 20