PDA

View Full Version : how to unbind a texture which is attach to framebuffer as a rendertarget.



sczybt
03-03-2014, 04:02 AM
in directx, if i set a rendertarget which is still bind as a shader resource texture, it will cause a render error.
so, if we want to use that surface as a rendertarget, we must unbind this texture, like directx api:
DX9->SetTexture(i, NULL);

i want to know, is there any same question in opengl, if i create a texture2d and attach to a framebuffer, and then render something on it.
next step i use this texture as a normal texture, if it is still bind when the next frame, is it cause any errors? may be cause glClear failure by Invalid Operation?

Agent D
03-03-2014, 10:13 AM
if i create a texture2d and attach to a framebuffer, and then render something on it.
next step i use this texture as a normal texture, if it is still bind when the next frame, is it cause any errors?
If you try to use a texture that is attached to the framebuffer object you are rendering to, you will get undefined behaviour (i.e. depends on your implementation).
It might work as expected, it might not.

If you want to unbind the texture in order to render to it, call glBindTexture( <binding>, 0 )


may be cause glClear failure by Invalid Operation?
The 3.x/4.x man pages don't indicate an invalid operation error for glClear, however if you are using compatibillity profile or an older GL version and calling glClear within a begin/end block, GL_INVALID_OPERATION is generated.

sczybt
03-04-2014, 02:50 AM
If you try to use a texture that is attached to the framebuffer object you are rendering to, you will get undefined behaviour (i.e. depends on your implementation).
It might work as expected, it might not.

If you want to unbind the texture in order to render to it, call glBindTexture( <binding>, 0 )


The 3.x/4.x man pages don't indicate an invalid operation error for glClear, however if you are using compatibillity profile or an older GL version and calling glClear within a begin/end block, GL_INVALID_OPERATION is generated.

thank you very much.