Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: glTexImage2DMultisample with GL_DEPTH_COMPONENT24

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207

    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 ?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Here is my code:

    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\n");                        break;
    			case 0x8CDB:                                        tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER\n");          break;
    			case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:          tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n");           break;
    			case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:  tdkPrintf("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n");   break;        
    			case GL_FRAMEBUFFER_UNSUPPORTED:                    tdkPrintf("GL_FRAMEBUFFER_UNSUPPORTED\n");                     break;  
    			default:                                            tdkPrintf("Unknown issue (%X).\n",status);                     break;
    		}
    		glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
     
    render();

    fragment shader:
    Code :
    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.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    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.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by Alfonse Reinheart View Post
    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.
    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.
    Click image for larger version. 

Name:	Multisampling_500018.png 
Views:	55 
Size:	6.8 KB 
ID:	977
    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.
    Last edited by debonair; 02-11-2013 at 03:24 AM.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    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..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •