rsp1984
rsp1984

Reputation: 1947

Result of glReadPixels() right after glFramebufferTexture2D()

I successfully use FBOs as a rendering destination in my code. It is not clear to me however what results I can expect when I do:

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                       GL_TEXTURE_2D, someRgbaTexture, 0);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, *someRgbaBuffer);

in OpenGL ES 2.0 (assuming that the FBO is GL_FRAMEBUFFER_COMPLETE).

My goal is to get the content of the texture referenced by someRgbaTexture. Desktop OpenGL has the glGetTexImage() function for that purpose but it doesn't exist in ES.

Setting someRgbaTexture as read-texture, then doing a screen-filling textured quad into another FBO target, then reading back would sure do the trick, but I want to avoid that extra pass.

Therefore: Are the contents of the framebuffer equal to the contents of the texture after a call to glFramebufferTexture2D() or does that call just mean that any future render operation will target the specified texture?
If it's the latter: what would happen if my render operation just writes a single pixel or nothing at all? What would be the guarantees on the content in someRgbaTexture then?

Upvotes: 3

Views: 835

Answers (1)

Reto Koradi
Reto Koradi

Reputation: 54652

This looks completely legal, and should give you the content of the texture as the result of glReadPixels().

On page 114 of the ES 2.0 spec, in the explanation of glFramebufferTexture2D(), the description includes:

No change is made to the state of the texture object

This means that if the texture previously had a well defined content, it still has that content after glFramebufferTexture2D(). And since it's now the color buffer of the current framebuffer, its content will be read by glReadPixels().

Upvotes: 2

Related Questions