glTexImage2DMultisample with GL_DEPTH_COMPONENT24

Hi,
I know how to use multisample texture with color render-able formats but i am not getting how to use it with depth formats.
Also, with this API there is no filtering so how to set modes for depth textures?
if i want color output can i use render buffer for color attachment and texture for depth attachment? In this case what will be my fragment shader ?

I know how to use multisample texture with color render-able formats but i am not getting how to use it with depth formats.

What aren’t you getting about it?

Also, with this API there is no filtering so how to set modes for depth textures?

You don’t; if you need filtering, you do it in the shader.

if i want color output can i use render buffer for color attachment and texture for depth attachment? In this case what will be my fragment shader ?

Your fragment shader doesn’t know or care if you’re rendering to a renderbuffer or a texture. Shaders can only read from a texture, so if you’re rendering to something you need to read from later, that should be a texture.

Here is my code:


	glGenTextures(1, &id1);


	glBindTexture(*target11, id1);


	glGenFramebuffers(1, &Fboid);

	GLint framebuffer;

	glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&framebuffer);

	glGenRenderbuffers(1, &depth);

glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, *samples ,GL_DEPTH_COMPONENT, width1, height1,true);	

glBindFramebuffer(GL_FRAMEBUFFER, Fboid);
			
glBindRenderbuffer(GL_RENDERBUFFER, depth);
	
glRenderbufferStorageMultisample(GL_RENDERBUFFER,*samples, GL_COLOR_ATTACHMENT0, width1, height1);
					
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, depth);
			
			
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,*target11,id1,0);
						
glEnable(GL_MULTISAMPLE);
		draw_cube(0);
	
		glDisable(GL_MULTISAMPLE);	
		

		status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
		switch(status)
		{
			case GL_FRAMEBUFFER_COMPLETE:                       tdkPrintf("GL_FRAMEBUFFER_COMPLETE
");                        break;
			case 0x8CDB:                                        tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
");          break;
			case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:          tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
");           break;
			case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:  tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
");   break;        
			case GL_FRAMEBUFFER_UNSUPPORTED:                    tdkPrintf("GL_FRAMEBUFFER_UNSUPPORTED
");                     break;  
			default:                                            tdkPrintf("Unknown issue (%X).
",status);                     break;
		}
		glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
	
render();

fragment shader:


uniform sampler2DMS tk_diffuseMap;
in vec3 ps_texCoord;
out vec4 fragColor;
uniform int samples;
 
void main(void)
{

	vec2 iTmp = textureSize(tk_diffuseMap);
	vec2 tmp =floor(iTmp * ps_texCoord.xy);
 
	vec4 color;
	for(int i = 0; i < samples; ++i)
	{
		color = color + texelFetch(tk_diffuseMap, ivec2(tmp), i);
	}
 
	fragColor = vec4(color/samples);
}


I am creating 2 attachments, color attachment with renderbuffer and depth attachment textures. So now i am getting error at
glBindRenderbuffer(GL_RENDERBUFFER, depth);
FAILED: It was expecting: GL_NO_ERROR but OpenGL returned GL_INVALID_ENUM
also
GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
and it renders black cube with no texturing.

Now, when i reverse the attachments i.e. when i use color attachment texture and render buffer with depth attachment code works fine with expected output.
Is it possible to use depth texture without shadow mapping here? also if i want to use shadow mapping how can i set modes of filtering as there is no filtering with texelFetch(). What will be fragment shader in that case? Any sort of psuedocode will help.

Your code is acutely schizophrenic. You have a renderbuffer called depth, which seems wrong if it’s intended to be used as a color buffer. You then use glRenderbufferStorageMultisample, but don’t actually pass an image format; you use GL_COLOR_ATTACHMENT0 instead, which is not allowed.

In short, your code doesn’t do what you say it’s trying to do.

Also, though this is more stylistic, I’m not sure why you’re passing target11 and samples around as pointers to GLuints instead of just GLuints. You’re not modifying them, so there’s no much point to that.

[QUOTE=Alfonse Reinheart;1248166]Your code is acutely schizophrenic. You have a renderbuffer called depth, which seems wrong if it’s intended to be used as a color buffer. You then use glRenderbufferStorageMultisample, but don’t actually pass an image format; you use GL_COLOR_ATTACHMENT0 instead, which is not allowed.
[/QUOTE]
Now, i replaced that with GL_RGBA
glRenderbufferStorageMultisample(GL_RENDERBUFFER,*samples, GL_RGBA, width1, height1);
and at-least i am getting some white output looks like color values are not being rendered.
[ATTACH=CONFIG]376[/ATTACH]

In short, your code doesn’t do what you say it’s trying to do.

can you please tell me how to use renderbuffer for storing color values in above program?

Also, though this is more stylistic, I’m not sure why you’re passing target11 and samples around as pointers to GLuints instead of just GLuints. You’re not modifying them, so there’s no much point to that.

target11 and samples are just enum and integer pointers they are set to GL_TEXTURE_2D_MULTISAMPLE and “4” respectively and they are being modified in the program.

When i comment code for render buffer i get black cube only.
Here i am applying texture of rotated cube to each face of the rotated cube.

Can anyone tell me how to use renderbuffer as color and texture as depth attachment to FBO? I am not sure whether i am doing correct in above code or not…