Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong mipmap level calculation #952

Open
bylee20 opened this issue May 17, 2020 · 0 comments
Open

Wrong mipmap level calculation #952

bylee20 opened this issue May 17, 2020 · 0 comments

Comments

@bylee20
Copy link

bylee20 commented May 17, 2020

In osg::Texture::computeRequiredTextureDimensions(), the number of mipmap levels is miscalculated with NPOT texture.

numMipmapLevels = 1;
for(int s=1; s<width || s<height; s <<= 1, ++numMipmapLevels) {}

Suppose width = height = 100 here.
The for loop will be executed 7 times for s = 1 -> 2 -> 4 -> 8 -> 16 -> 32 -> 64.
Therefore, the computed numMipmapLevels is 8.

This value will be handed over to glTexStorage3D() here:

extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, osg::maximum(_numMipmapLevels,1), texStorageSizedInternalFormat, _textureWidth, _textureHeight, textureDepth);

Now, the OpenGL specification says:

GL_INVALID_OPERATION is generated if target is GL_TEXTURE_2D_ARRAY, GL_PROXY_TEXTURE_2D_ARRAY, GL_TEXURE_CUBE_MAP_ARRAY, or GL_PROXY_TEXTURE_CUBE_MAP_ARRAY and levels is greater than ⌊log2(max(width, height))⌋+1.

Since width = height = 100, log2(max(width, height))=6.xxx and ⌊log2(max(width, height))⌋+1=7 which is smaller than computed numMipmapLevels.
This results into GL_INVALID_OPERATION error.

I am not familiar with mimap concept, so I cannot say nothing about the calculation math.
However, at least, I can tell the computed value does not satisfy the OpenGL requirement here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant