Added support for sRGB framebuffers via the GLX_ARB_framebuffer_sRGB /
[freeglut] / src / freeglut_state.c
index 962cb55..5dab8c5 100644 (file)
 static int fghGetConfig( int attribute )
 {
   int returnValue = 0;
+  int result;  /*  Not checked  */
 
   if( fgStructure.CurrentWindow )
-      glXGetConfig( fgDisplay.Display, fgStructure.CurrentWindow->Window.VisualInfo,
-                    attribute, &returnValue );
+      result = glXGetFBConfigAttrib( fgDisplay.Display,
+                                     *(fgStructure.CurrentWindow->Window.FBConfig),
+                                     attribute,
+                                     &returnValue );
 
   return returnValue;
 }
 #endif
 
+/* Check if the window is in full screen state. */
+static int fghCheckFullScreen(void)
+{
+#if TARGET_HOST_POSIX_X11
+
+  int result;
+
+  result = 0;
+  if (fgDisplay.StateFullScreen != None)
+    {
+      result = fgHintPresent(fgStructure.CurrentWindow->Window.Handle,
+                            fgDisplay.State,
+                            fgDisplay.StateFullScreen);
+    }
+
+  return result;
+
+#else
+
+  return 0;
+
+#endif
+}
+
 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
 
 /*
@@ -113,6 +140,14 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
             fgStructure.CurrentWindow->State.Cursor = value;
         break;
 
+    case GLUT_AUX:
+      fgState.AuxiliaryBufferNumber = value;
+      break;
+
+    case GLUT_MULTISAMPLE:
+      fgState.SampleNumber = value;
+      break;
+
     default:
         fgWarning( "glutSetOption(): missing enum handle %d", eWhat );
         break;
@@ -120,7 +155,6 @@ void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
 }
 
 #if TARGET_HOST_MS_WINDOWS
-/* WRONG-- FIXME */
 /* The following include file is available from SGI but is not standard:
  *   #include <GL/wglext.h>
  * So we copy the necessary parts out of it to support the multisampling query
@@ -160,11 +194,19 @@ int FGAPIENTRY glutGet( GLenum eWhat )
     case GLUT_SCREEN_HEIGHT:        return fgDisplay.ScreenHeight  ;
     case GLUT_SCREEN_WIDTH_MM:      return fgDisplay.ScreenWidthMM ;
     case GLUT_SCREEN_HEIGHT_MM:     return fgDisplay.ScreenHeightMM;
-    case GLUT_INIT_WINDOW_X:        return fgState.Position.X      ;
-    case GLUT_INIT_WINDOW_Y:        return fgState.Position.Y      ;
-    case GLUT_INIT_WINDOW_WIDTH:    return fgState.Size.X          ;
-    case GLUT_INIT_WINDOW_HEIGHT:   return fgState.Size.Y          ;
+    case GLUT_INIT_WINDOW_X:        return fgState.Position.Use ?
+                                           fgState.Position.X : -1 ;
+    case GLUT_INIT_WINDOW_Y:        return fgState.Position.Use ?
+                                           fgState.Position.Y : -1 ;
+    case GLUT_INIT_WINDOW_WIDTH:    return fgState.Size.Use ?
+                                           fgState.Size.X : -1     ;
+    case GLUT_INIT_WINDOW_HEIGHT:   return fgState.Size.Use ?
+                                           fgState.Size.Y : -1     ;
     case GLUT_INIT_DISPLAY_MODE:    return fgState.DisplayMode     ;
+    case GLUT_INIT_MAJOR_VERSION:   return fgState.MajorVersion    ;
+    case GLUT_INIT_MINOR_VERSION:   return fgState.MinorVersion    ;
+    case GLUT_INIT_FLAGS:           return fgState.ContextFlags    ;
+    case GLUT_INIT_PROFILE:         return fgState.ContextProfile  ;
 
 #if TARGET_HOST_POSIX_X11
     /*
@@ -210,7 +252,20 @@ int FGAPIENTRY glutGet( GLenum eWhat )
              */
             return 0;
         }
-        return fgStructure.CurrentWindow->Window.VisualInfo->visual->map_entries;
+        else
+        {
+          const GLXFBConfig * fbconfig =
+                fgStructure.CurrentWindow->Window.FBConfig;
+
+          XVisualInfo * visualInfo =
+                glXGetVisualFromFBConfig( fgDisplay.Display, *fbconfig );
+
+          const int result = visualInfo->visual->map_entries;
+
+          XFree(visualInfo);
+
+          return result;
+        }
 
     /*
      * Those calls are somewhat similiar, as they use XGetWindowAttributes()
@@ -275,13 +330,23 @@ int FGAPIENTRY glutGet( GLenum eWhat )
     /* I do not know yet if there will be a fgChooseVisual() function for Win32 */
     case GLUT_DISPLAY_MODE_POSSIBLE:
     {
-        XVisualInfo* visualInfo = fgChooseVisual();
-        if ( visualInfo == NULL ) {
-            return 0;
-        } else {
-            XFree( visualInfo );
-            return 1;
+        /*  We should not have to call fgChooseFBConfig again here.  */
+        GLXFBConfig * fbconfig;
+        int isPossible;
+
+        fbconfig = fgChooseFBConfig();
+
+        if (fbconfig == NULL)
+        {
+            isPossible = 0;
         }
+        else
+        {
+            isPossible = 1;
+            XFree(fbconfig);
+        }
+
+        return isPossible;
     }
 
     /* This is system-dependant */
@@ -289,7 +354,7 @@ int FGAPIENTRY glutGet( GLenum eWhat )
         if( fgStructure.CurrentWindow == NULL )
             return 0;
 
-        return fgStructure.CurrentWindow->Window.VisualInfo->visualid;
+        return fghGetConfig( GLX_VISUAL_ID );
 
 #elif TARGET_HOST_MS_WINDOWS
 
@@ -473,7 +538,15 @@ int FGAPIENTRY glutGet( GLenum eWhat )
 
     case GLUT_DIRECT_RENDERING:
         return fgState.DirectContext;
-        break;
+
+    case GLUT_FULL_SCREEN:
+        return fghCheckFullScreen();
+
+    case GLUT_AUX:
+      return fgState.AuxiliaryBufferNumber;
+
+    case GLUT_MULTISAMPLE:
+      return fgState.SampleNumber;
 
     default:
         fgWarning( "glutGet(): missing enum handle %d", eWhat );
@@ -493,7 +566,6 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat )
     switch( eWhat )
     {
     case GLUT_HAS_KEYBOARD:
-    case GLUT_HAS_KEYBOARD:
         /*
          * Win32 is assumed a keyboard, and this cannot be queried,
          * except for WindowsCE.
@@ -504,7 +576,10 @@ int FGAPIENTRY glutDeviceGet( GLenum eWhat )
          */
 #if defined(_WIN32_CE)
         return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0;
-#    pragma comment (lib,"Kbdui.lib")
+#   if FREEGLUT_LIB_PRAGMAS
+#       pragma comment (lib,"Kbdui.lib")
+#   endif
+
 #else
         return 1;
 #endif
@@ -689,4 +764,114 @@ int FGAPIENTRY glutLayerGet( GLenum eWhat )
     return -1;
 }
 
+int * FGAPIENTRY glutGetModeValues(GLenum eWhat, int * size)
+{
+  int * array;
+
+#if TARGET_HOST_POSIX_X11
+  int attributes[9];
+  GLXFBConfig * fbconfigArray;  /*  Array of FBConfigs  */
+  int fbconfigArraySize;        /*  Number of FBConfigs in the array  */
+  int attribute_name = 0;
+#endif
+
+  FREEGLUT_EXIT_IF_NOT_INITIALISED("glutGetModeValues");
+
+  array = NULL;
+  *size = 0;
+
+  switch (eWhat)
+    {
+#if TARGET_HOST_POSIX_X11
+    case GLUT_AUX:
+    case GLUT_MULTISAMPLE:
+
+      attributes[0] = GLX_BUFFER_SIZE;
+      attributes[1] = GLX_DONT_CARE;
+
+      switch (eWhat)
+        {
+        case GLUT_AUX:
+          /*
+            FBConfigs are now sorted by increasing number of auxiliary
+            buffers.  We want at least one buffer.
+          */
+          attributes[2] = GLX_AUX_BUFFERS;
+          attributes[3] = 1;
+          attributes[4] = None;
+
+          attribute_name = GLX_AUX_BUFFERS;
+
+          break;
+
+
+        case GLUT_MULTISAMPLE:
+          attributes[2] = GLX_AUX_BUFFERS;
+          attributes[3] = GLX_DONT_CARE;
+          attributes[4] = GLX_SAMPLE_BUFFERS;
+          attributes[5] = 1;
+          /*
+            FBConfigs are now sorted by increasing number of samples per
+            pixel.  We want at least one sample.
+          */
+          attributes[6] = GLX_SAMPLES;
+          attributes[7] = 1;
+          attributes[8] = None;
+
+          attribute_name = GLX_SAMPLES;
+
+          break;
+        }
+
+      fbconfigArray = glXChooseFBConfig(fgDisplay.Display,
+                                        fgDisplay.Screen,
+                                        attributes,
+                                        &fbconfigArraySize);
+
+      if (fbconfigArray != NULL)
+        {
+          int * temp_array;
+          int result;   /*  Returned by glXGetFBConfigAttrib. Not checked.  */
+          int previous_value;
+          int i;
+
+          temp_array = malloc(sizeof(int) * fbconfigArraySize);
+          previous_value = 0;
+
+          for (i = 0; i < fbconfigArraySize; i++)
+            {
+              int value;
+
+              result = glXGetFBConfigAttrib(fgDisplay.Display,
+                                            fbconfigArray[i],
+                                            attribute_name,
+                                            &value);
+              if (value > previous_value)
+                {
+                  temp_array[*size] = value;
+                  previous_value = value;
+                  (*size)++;
+                }
+            }
+
+          array = malloc(sizeof(int) * (*size));
+          for (i = 0; i < *size; i++)
+            {
+              array[i] = temp_array[i];
+            }
+
+          free(temp_array);
+          XFree(fbconfigArray);
+        }
+
+      break;
+#endif      
+
+    default:
+      break;
+    }
+
+  return array;
+}
+
 /*** END OF FILE ***/