Browse Source

glgsg: add gl-forward-compatible config variable

This is meant to be used alongside gl-version to request a "forward compatible" OpenGL 3.0 or 3.1 context, which removes support for deprecated features such as the fixed-function pipeline.
rdb 6 years ago
parent
commit
475bd55bb1

+ 5 - 0
panda/src/glstuff/glmisc_src.cxx

@@ -17,6 +17,11 @@ ConfigVariableInt gl_version
   ("gl-version", "",
    PRC_DESC("Set this to get an OpenGL context with a specific version."));
 
+ConfigVariableBool gl_forward_compatible
+  ("gl-forward-compatible", false,
+   PRC_DESC("Setting this to true will request a forward-compatible OpenGL "
+            "context, which will not support the fixed-function pipeline."));
+
 ConfigVariableBool gl_support_fbo
   ("gl-support-fbo", true,
    PRC_DESC("Configure this false if your GL's implementation of "

+ 1 - 0
panda/src/glstuff/glmisc_src.h

@@ -41,6 +41,7 @@
 // #define GSG_VERBOSE 1
 
 extern EXPCL_GL ConfigVariableInt gl_version;
+extern EXPCL_GL ConfigVariableBool gl_forward_compatible;
 extern EXPCL_GL ConfigVariableBool gl_support_fbo;
 extern ConfigVariableBool gl_cheap_textures;
 extern ConfigVariableBool gl_ignore_clamp;

+ 12 - 1
panda/src/glxdisplay/glxGraphicsStateGuardian.cxx

@@ -352,9 +352,20 @@ choose_pixel_format(const FrameBufferProperties &properties,
           attrib_list[n++] = gl_version[1];
         }
       }
+      int flags = 0;
       if (gl_debug) {
+        flags |= GLX_CONTEXT_DEBUG_BIT_ARB;
+      }
+      if (gl_forward_compatible) {
+        flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
+        if (gl_version.get_num_words() == 0 || gl_version[0] < 2) {
+          glxdisplay_cat.error()
+            << "gl-forward-compatible requires gl-version >= 3 0\n";
+        }
+      }
+      if (flags != 0) {
         attrib_list[n++] = GLX_CONTEXT_FLAGS_ARB;
-        attrib_list[n++] = GLX_CONTEXT_DEBUG_BIT_ARB;
+        attrib_list[n++] = flags;
       }
       attrib_list[n] = None;
       _context = _glXCreateContextAttribs(_display, _fbconfig, _share_context,

+ 12 - 1
panda/src/wgldisplay/wglGraphicsStateGuardian.cxx

@@ -609,9 +609,20 @@ make_context(HDC hdc) {
         attrib_list[n++] = gl_version[1];
       }
     }
+    int flags = 0;
     if (gl_debug) {
+      flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
+    }
+    if (gl_forward_compatible) {
+      flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
+      if (gl_version.get_num_words() == 0 || gl_version[0] < 2) {
+        wgldisplay_cat.error()
+          << "gl-forward-compatible requires gl-version >= 3 0\n";
+      }
+    }
+    if (flags != 0) {
       attrib_list[n++] = WGL_CONTEXT_FLAGS_ARB;
-      attrib_list[n++] = WGL_CONTEXT_DEBUG_BIT_ARB;
+      attrib_list[n++] = flags;
     }
 #ifndef SUPPORT_FIXED_FUNCTION
     attrib_list[n++] = WGL_CONTEXT_PROFILE_MASK_ARB;