2
votes

I'm converting some OpenGL ES 2.0 code to run on standard desktop hardware which does not support OpenGL ES 2.0, but only standard OpenGL.

The code uses the extension GL_EXT_shader_framebuffer_fetch (previously known as GL_APPLE_shader_framebuffer_fetch), which allows the fragment shader to read the 'previous' fragment color through:

mediump vec4 lastFragColor = gl_LastFragData[0];

This can be used to do custom (i.e. programmable) blending.

Is there an equivalent for this in OpenGL?

If not, I would have to render to a framebuffer texture and attach this texture to the same fragment shader that is rendering to it.

1
What do you need this for, specifically? There might be other ways around the problem you're trying to solve on desktop OpenGL. For example, I was using this extension to write out per-fragment depth values, but you can do that directly in OpenGL so I was able to rework my shaders using that.Brad Larson♦
Yes that's the reason I needed it initially, and I was able to work around it the same way as you did, after I had asked this question. Thanks anyway!cheesus
"If not, I would have to render to a framebuffer texture and attach this texture to the same fragment shader that is rendering to it." - This won't work, though.Christian Rau

1 Answers

2
votes

While not being a direct equivalent, glTextureBarrier() on desktop OpenGL (core in 4.5, or through ARB_texture_barrier/GL_NV_texture_barrier) allows (with some restrictions) to read from the same texture that is attached to the currently bound fbo, while rendering to it.

so, while GL_EXT_shader_framebuffer_fetch allows you to do something like

gl_FragColor = 0.5 * gl_LastFragData[0];

glTextureBarrier allows you to do something like

gl_FragColor = 0.5 * texelFetch(current_color_attachment, ivec2(gl_FragCoord.xy), 0)​;

Both methods read the current fragment color, modify it and then write it back.