sokol icon indicating copy to clipboard operation
sokol copied to clipboard

sokol_gfx.h: missing validation check in for number of mipmaps when creating image

Open ilar81 opened this issue 6 years ago • 1 comments

I've found out some difference with generating MIP maps in OpenGL and Direct3D backends of Sokol. In OpenGl backend all MIP maps to 1 pixel resolution are needed otherwise black texture is appeared. In Direct3D backend it works fine with any number of MIP maps. Is this trait of OpenGL or Sokol? May be doing some assert or warning about this trait in OpenGL backend is good idea....

ilar81 avatar Mar 06 '19 14:03 ilar81

Hmm, true, looks like this is a missing validation check in sokol-gfx. The intent is that you either provide no mipmaps (only the highest level surface), so sg_image_desc.num_mipmaps =1, or the full mipmap chain down to 1x1, with num_mipmaps = log2((w > h) ? w : h) + 1;.

I'll need to look around in the GL, D3D11 and Metal docs what's the behaviour when the user restricts access to mipmaps (via sg_image_desc.min_lod and max_lod), but this is not allowed in GLES2/WebGL anyway, so I think it's best to use the rule "either no mipmaps, or all".

I'll rename the ticket and keep it open, and thanks for writing the bug report :)

floooh avatar Mar 06 '19 15:03 floooh

This has been fixed in the meantime by dropping the GLES2 backend, and generally setting GL_TEXTURE_MAX_LEVEL when creating GL textures.

floooh avatar Jan 27 '24 15:01 floooh