Hi,
I’m having some troubles in resolving integer multisampled textures.
I have a simple questions which although, don’t seem to get strong answers so far.
I already know that I can define integer multisample textures, I can attach them to a FBO and I can draw on them from a fragment shader. The question is, can they be resolved coherently? The problem occurs when I try to resolve the integer draw buffer onto a singlesample FBO, because the texture data I get is filled with zeroes.
So, I’m using a multiple render target framebuffer, on which, the first color attachment is a color texture (RGBA8), while the second draw buffer (color attachment 1) is an index texture (R32UI).
gl::BindTexture(gl::TEXTURE_2D_MULTISAMPLE, m_Textures[eTEXTURE_COLORBUFFER]);
gl::TexParameteri(gl::TEXTURE_2D_MULTISAMPLE, gl::TEXTURE_BASE_LEVEL, 0);
gl::TexParameteri(gl::TEXTURE_2D_MULTISAMPLE, gl::TEXTURE_MAX_LEVEL, 0);
gl::TexImage2DMultisample(gl::TEXTURE_2D_MULTISAMPLE, m_Multisample,gl::RGBA8,width,height,gl::FALSE_);
gl::BindTexture(gl::TEXTURE_2D_MULTISAMPLE, m_Textures[eTEXTURE_CLASSBUFFER]);
gl::TexParameteri(gl::TEXTURE_2D_MULTISAMPLE, gl::TEXTURE_BASE_LEVEL, 0);
gl::TexParameteri(gl::TEXTURE_2D_MULTISAMPLE, gl::TEXTURE_MAX_LEVEL, 0);
gl::TexImage2DMultisample(gl::TEXTURE_2D_MULTISAMPLE, m_Multisample,gl::R32UI,width,height,gl::FALSE_);
Both textures are multisampled, and I would like to download them on CPU once the render has been completed.
The code I use to download the image is listed down here.
uint32_t* tex_data = new uint32_t[query.m_FrameDims*query.m_FrameDims];
memset(tex_data,0,sizeof(uint32_t)*query.m_FrameDims*query.m_FrameDims);
gl::BindTexture(gl::TEXTURE_2D,query.m_DestColorTexture);
{
// Copy color texture
gl::ReadBuffer(gl::COLOR_ATTACHMENT0);
gl::ReadPixels(0,0,query.m_FrameDims,query.m_FrameDims,
gl::RGBA,gl::UNSIGNED_BYTE,tex_data);
gl::TexSubImage2D(gl::TEXTURE_2D,0,0,0,query.m_FrameDims,query.m_FrameDims,
gl::RGBA,gl::UNSIGNED_BYTE,tex_data);
}
gl::BindTexture(gl::TEXTURE_2D,query.m_DestClassTexture);
{
// Copy class texture
gl::ReadBuffer(gl::COLOR_ATTACHMENT1);
gl::ReadPixels(0,0,query.m_FrameDims,query.m_FrameDims,
gl::RED_INTEGER,gl::UNSIGNED_INT,tex_data);
gl::TexSubImage2D(gl::TEXTURE_2D,0,0,0,query.m_FrameDims,query.m_FrameDims,
gl::RED_INTEGER,gl::UNSIGNED_INT,tex_data);
}
delete[] tex_data;
With no multisampling everything works fine, and the integer texture is filled with correct data, but as soon as I call the glBlitFramebuffer() function the second color attachment (the integer texture) is zeroed.
I don’t see any docs that says that integer texture can note be multisampled, but even though, I’m not sure they make sense at all.
Hope someone can shed some light on it.