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.


	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;
	}

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

[QUOTE=Osbios;1260395]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[/QUOTE]

Thanks so much; I will try this out.

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.