简体   繁体   中英

Rendering to the mipmap level of a texture

I want to write to a particular texture mipmap level. The problem is that OpenGL says "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT​" and "Framebuffer is not completed" if I don't generate the mipmaps before(glGenerateMipmap(GL_TEXTURE_2D);).

Generating the mipmaps before writing to them works, but it is an stupid performance cost since the automatically generated mipmap levels would never be used.

Is it possible to avoid this?

Note: I know that not writing directly to the levels and calling glGenerateMipmaps is faster, but I need to do this.

It seems like you simply did not create the storage for the mipmap level you tried to render to, glTexImage[n]D() does not do that - it only creates a storage for one single mipmap level. You need to separately creaet each mipmap level separately. glGenerateMipmaps does this implicitely. However, you only actually need a tiny bit of what it does, so it is better to avoid it here. Your best option is to create the mipmap chain from level 0 to the level you need manually.

With really modern GL, I would recommend you use immutable texures from GL_ARB_texture_storage . The glTexStorage() function allows creating the storage for all required mipmap levels in a single call. With immutable textures, you can still change the content any time, the only thing you can't is creating new data storage (with potentially different formats or sizes), so you can't repeatedly call glTexImage[n]D() on such texture object. However, you still can delete the whole object and create a new one, if the need arises.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM