Jump to content
Eternal Lands Official Forums
Sign in to follow this  
Xaphier

SDL-1.2.15 patch for OpenGL 3.3 debug context

Recommended Posts

I made a small patch for SDL-1.2.15 so it creates and OpenGL 3.3 debug context (or a normal OpenGL context if it fails with the other one). The debug context is useful, because you can use GL_ARB_debug_output (the el 2 client use it) to get much better OpenGL errors.

 

diff -dur src-orig/video/x11/SDL_x11gl.c src/video/x11/SDL_x11gl.c
--- src-orig/video/x11/SDL_x11gl.c 2012-01-19 07:30:06.000000000 +0100
+++ src/video/x11/SDL_x11gl.c 2012-06-07 22:11:20.942600730 +0200
@@ -264,10 +264,52 @@
#if SDL_VIDEO_OPENGL_GLX

 /* We do this to create a clean separation between X and GLX errors. */
- XSync( SDL_Display, False );
- glx_context = this->gl_data->glXCreateContext(GFX_Display,
-		 glx_visualinfo, NULL, True);
- XSync( GFX_Display, False );
+ XSync(SDL_Display, False);
+
+ GLXContext temp_context = this->gl_data->glXCreateContext(GFX_Display, glx_visualinfo, NULL, True);
+
+ if (!temp_context)
+ {
+  SDL_SetError("Could not create GL context");
+  return(-1);
+ }
+ else
+ {
+  int attribs[] = {
+   GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+   GLX_CONTEXT_MINOR_VERSION_ARB, 3,
+   GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
+   GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
+   0
+  };
+
+  //Get a pointer to the context creation function for GL 3.0
+  PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB");
+  if (!glXCreateContextAttribs)
+  {
+   SDL_SetError("GL 3.x is not supported");
+   glx_context = temp_context;
+  }
+  else
+  {
+   //Create a GL 3.0 context
+   GLXFBConfig *framebuffer_config = NULL;
+   int fbcount = 0;
+   framebuffer_config = glXChooseFBConfig(GFX_Display, DefaultScreen(GFX_Display), NULL, &fbcount);
+   if (!framebuffer_config)
+   {
+	SDL_SetError("No good framebuffers found. GL 3.0 disabled");
+	glx_context = temp_context;
+   }
+   else
+   {
+	glx_context = glXCreateContextAttribs(GFX_Display, framebuffer_config[0], NULL, True, attribs);
+	glXDestroyContext(GFX_Display, temp_context);
+   }
+  }
+ }
+
+ XSync(SDL_Display, False);

 if ( glx_context == NULL ) {
  SDL_SetError("Could not create GL context");

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×