Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of the textarget parameter for glFramebufferTexture?

Tags:

opengl

According to http://www.opengl.org/sdk/docs/man/xhtml/glFramebufferTexture.xml, a call to glFramebufferTexture should look similar to:

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0);

If the API already knows the textureId why does it need to know the target (GL_TEXTURE_2D) too? Does this mean that the texture should be bound before this call? i.e. do I need to call:

glBindTexture(GL_TEXTURE_2D, textureId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureId, 0);
glBindTexture(GL_TEXTURE_2D, 0);

Or will glFramebufferTexture2D handle everything?

like image 924
Mark Ingram Avatar asked Jun 13 '13 16:06

Mark Ingram


1 Answers

It's there because of stupidity.

See, the way you attach a face of a cubemap to an FBO is to use one of the cubemap face texture targets. So if you want to attach the +X face of a cubemap, you use the GL_TEXTURE_CUBE_MAP_POSITIVE_X​ target. The texture's bind target (if you were binding it) would be GL_TEXTURE_CUBE_MAP, but that's not what you pass to textarget when you want to attach a face to an FBO.

This is stupid because OpenGL also provides the glFramebufferTextureLayer function, which doesn't take a textarget parameter. It correctly identifies the texture's type from just the object. It works on 3D texture, 1D and 2D arrays, and even cubemap array textures. But it does not work on non-array cubemaps; you still have to use the silly glFramebufferTexture2D with it's silly textarget parameter.

By all rights, the only functions you should use are glFramebufferTextureLayer and glFramebufferTexture. But because of how glFramebufferTextureLayer doesn't work on non-array cubemap faces, you have to use glFramebufferTexture2D for faces of a non-array cubemap.


Thanks to ARB_direct_state_access (and therefore OpenGL 4.5), this idiocy no longer applies. glFramebufferTextureLayer may now be used on non-array cubemap faces, so now there is no point to any of the dimension-based FramebufferTexture functions. And therefore, no point to textarget.

like image 58
Nicol Bolas Avatar answered Oct 31 '22 05:10

Nicol Bolas