Hi all!
I am trying to use the NV_explicit_multisample extension with GLSL. But i can’t figure out how to use the renderbuffer texture in my fragment shader.
What I do is rendering my scene to the multisample renderbuffer in the first pass. In a second pass I want to read from the generated renderbuffer texture to get each sample for a fragment.
First pass works fine, if i blit the framebuffer object and have it displayed its working. But how can i set up the uniform samplerRenderbuffer to use the texelFetchRenderbuffer function in my fragment shader?
This is how i set up my framebuffer object for rendering the renderbuffer texture (i skipped the depth buffer here):
glGenTextures(1, &multisampleDepthPeels);
glBindTexture(GL_TEXTURE_RENDERBUFFER_NV, multisampleDepthPeels);
glGenRenderbuffersEXT(1, &rbDP);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbDP);
glRenderbufferStorageMultisampleCoverageNV( GL_RENDERBUFFER_EXT, 16, 4, GL_RGBA32F_ARB, _resx, _resy);
glTexRenderbufferNV(GL_TEXTURE_RENDERBUFFER_NV, rbDP);
glGenFramebuffersEXT(1, &fbDP);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbDP);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rbDP);
And after rendering my scene i try this to use the renderbuffer texture:
glActiveTexture(GL_TEXTURE1)
glBindTexture(GL_TEXTURE_RENDERBUFFER_NV, multisampleDepthPeels);
glUseProgram(techTestProgram);
glUniform1i(glGetUniformLocation(techTestProgram, "resx"), _resx);
glUniform1i(glGetUniformLocation(techTestProgram, "resy"), _resy);
glUniform1i(glGetUniformLocation(techTestProgram,"multisampler"), 1);
////render to FrameBufferObject
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glDrawBuffers(1, sRT);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textures[0], 0);
with this fragment shader:
#version 120
#extension GL_EXT_gpu_shader4 : enable
#extension GL_NV_explicit_multisample : enable
uniform int resx, resy;
uniform samplerRenderbuffer multisampler;
void main(void)
{
ivec2 curr_pos = textureSizeRenderbuffer(multisampler) - ivec2(resx,resy);
gl_FragData[0] = texelFetchRenderbuffer(multisampler, curr_pos, 0);
}
which doesnt work.
If i use
glBindFramebufferEXT( GL_READ_FRAMEBUFFER_EXT, fbDP);
glBindFramebufferEXT( GL_DRAW_FRAMEBUFFER_EXT, fb);
glBlitFramebufferEXT( 0, 0, _resx, _resy, 0, 0, _resx, _resy, GL_COLOR_BUFFER_BIT, GL_NEAREST);
and render a quad with the 2d texture bound to fb it works, but of course i have no access to each individual sample anymore.
Maybe someone tried to use NV_explicit_multisample and can give me a hint or point me towards a code example/ documentation thats a little more descriptive other than the extension specification. Any help is much appreciated!