-1

我正在尝试在 OpenGL 中创建一个稀疏纹理数组,据我所知,我的值还可以。请参阅实际调用上方的注释以获取来自调试器的值。

    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);
4

1 回答 1

1

结果我错过了规范中纹理存储大小(w,h,d)必须是虚拟页面大小的倍数的部分。

我很好奇将纹理拟合到这种约束的最佳方法是什么。

于 2015-02-20T18:45:46.640 回答