Jonas Sourlier
Jonas Sourlier

Reputation: 14435

OpenGL equivalent of OpenGL ES 2.0's extension GL_EXT_shader_framebuffer_fetch

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.

Upvotes: 2

Views: 2265

Answers (1)

matthias_buehlmann
matthias_buehlmann

Reputation: 5061

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.

Upvotes: 3

Related Questions