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 4 of 4

Thread: Converting OpenGL 3.1 code for Multi-sampled Framebuffers to be OpenGL 2.1 compatable

  1. #1
    Intern Contributor
    Join Date
    Apr 2014
    Posts
    55

    Converting OpenGL 3.1 code for Multi-sampled Framebuffers to be OpenGL 2.1 compatable

    Hello,

    I have the following code which works well for creating multi-sampled framebuffers for anti-aliasing.

    It works great for OpenGL 3+

    What can I change to get a multi-sampled framebuffer object for OpenGL 2.1?

    Specifically I know I need to use extensions but I couldn't find what extensions I need to use for "glTexImage2DMultisample" as an example that would work on most systems that use OpenGL 2.1.

    Thank you for your time.

    Code :
    	glGetIntegerv(GL_MAX_SAMPLES, &NumOfSamples);
     
    	glGenTextures(1, &g_MultiSampleTexture_ID);
    	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, g_MultiSampleTexture_ID);
    	glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, NumOfSamples, GL_RGBA, l_TextureSize.w, l_TextureSize.h, false);
    	glGenFramebuffers(1, &g_MultiSampleFrameBufferObject_ID);
    	glBindFramebuffer(GL_FRAMEBUFFER, g_MultiSampleFrameBufferObject_ID);
    	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, g_MultiSampleTexture_ID, 0);
    	glGenRenderbuffers(1, &g_MultiSampleColorRenderBufferObject_ID);
    	glBindRenderbuffer(GL_RENDERBUFFER, g_MultiSampleColorRenderBufferObject_ID);
    	glRenderbufferStorageMultisample(GL_RENDERBUFFER, NumOfSamples, GL_RGBA, l_TextureSize.w, l_TextureSize.h);
    	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, g_MultiSampleColorRenderBufferObject_ID);
    	glGenRenderbuffers(1, &g_MultiSampleDepthBufferObject_ID);
    	glBindRenderbuffer(GL_RENDERBUFFER, g_MultiSampleDepthBufferObject_ID);
    	glRenderbufferStorageMultisample(GL_RENDERBUFFER, NumOfSamples, GL_DEPTH24_STENCIL8, l_TextureSize.w, l_TextureSize.h);
    	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, g_MultiSampleDepthBufferObject_ID);
    	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, g_MultiSampleDepthBufferObject_ID);
    	g_DrawBufferStatusCheck_ENUM = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
     
    	if (g_DrawBufferStatusCheck_ENUM != GL_FRAMEBUFFER_COMPLETE) {
    		switch (g_DrawBufferStatusCheck_ENUM)
    		{
    		case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
    			break;
    		case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
    			break;
    		case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
    			break;
    		case GL_FRAMEBUFFER_UNSUPPORTED:
    			break;
    		default:
    			break;
    		}
     
    		glBindRenderbuffer(GL_RENDERBUFFER, NULL);
    		glBindTexture(GL_TEXTURE_2D, NULL);
    		glBindFramebuffer(GL_FRAMEBUFFER, NULL);
    		return false;
    	}

  2. #2
    Intern Contributor
    Join Date
    May 2013
    Posts
    67
    There is GL_EXT_framebuffer_multisample which builds on GL_EXT_framebuffer_object.
    I don't know the exact difference from this EXT versions to the newer ARB versions. But according to the specs they build on GL 1.5 and GL 1.1

  3. #3
    Intern Contributor
    Join Date
    Apr 2014
    Posts
    55
    Quote Originally Posted by Osbios View Post
    There is GL_EXT_framebuffer_multisample which builds on GL_EXT_framebuffer_object.
    I don't know the exact difference from this EXT versions to the newer ARB versions. But according to the specs they build on GL 1.5 and GL 1.1
    Thanks so much; I will try this out.

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,170
    OpenGL 2.1 does not include any framebuffer objects as part of the core spec; this was added as a EXT and later ARB extension. Similarly, framebuffer multisample textures and renderbuffers were added via an EXT. The difference between the EXT and ARB is usually minor, but in the case of framebuffer objects it allows more flexible texture attachments (sizes and formats). The point of what I am saying is that to add features beyond core OpenGL 2.1, you must explicitly check for the presence of the ARB_XXXX extension (and possibly fall back to EXT_XXXX if no ARB equivalents exist) - but you must check for each and every extension.
    In your case you can't guarantee that the extension is supported on every target platform, so you might have to accept that you just can't add this feature on certain code paths.

Posting Permissions

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