From 30971e75717f3d7b826714fbbb1171dfaf9164cf Mon Sep 17 00:00:00 2001 From: "John F. Fay" Date: Mon, 12 Nov 2007 04:06:19 +0000 Subject: [PATCH] Implementing Jocelyn Frechot's changes -- see e-mail of Thursday, 11/8/2007 9:12 AM. git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@735 7f0cb862-5218-0410-a997-914c9d46530a --- include/GL/freeglut_ext.h | 4 ++ src/freeglut_ext.c | 1 + src/freeglut_init.c | 6 ++- src/freeglut_internal.h | 3 ++ src/freeglut_state.c | 118 +++++++++++++++++++++++++++++++++++++++++++++ src/freeglut_structure.c | 6 --- src/freeglut_window.c | 29 +++++------ 7 files changed, 145 insertions(+), 22 deletions(-) diff --git a/include/GL/freeglut_ext.h b/include/GL/freeglut_ext.h index 5e4ad2c..384bfa1 100644 --- a/include/GL/freeglut_ext.h +++ b/include/GL/freeglut_ext.h @@ -73,11 +73,14 @@ * Only one GLUT_AUXn bit may be used at a time. * Value 0x0400 is defined in OpenGLUT. */ +#define GLUT_AUX 0x1000 + #define GLUT_AUX1 0x1000 #define GLUT_AUX2 0x2000 #define GLUT_AUX3 0x4000 #define GLUT_AUX4 0x8000 + /* * Process loop function, see freeglut_main.c */ @@ -98,6 +101,7 @@ FGAPI void FGAPIENTRY glutMenuDestroyFunc( void (* callback)( void ) ); * State setting and retrieval functions, see freeglut_state.c */ FGAPI void FGAPIENTRY glutSetOption ( GLenum option_flag, int value ); +FGAPI int * FGAPIENTRY glutGetModeValues(GLenum mode, int * size); /* A.Donev: User-data manipulation */ FGAPI void* FGAPIENTRY glutGetWindowData( void ); FGAPI void FGAPIENTRY glutSetWindowData(void* data); diff --git a/src/freeglut_ext.c b/src/freeglut_ext.c index a1d6f59..b920e30 100644 --- a/src/freeglut_ext.c +++ b/src/freeglut_ext.c @@ -161,6 +161,7 @@ static GLUTproc fghGetProcAddress( const char* procName ) CHECK_NAME(glutWMCloseFunc); CHECK_NAME(glutMenuDestroyFunc); CHECK_NAME(glutSetOption); + CHECK_NAME(glutGetModeValues); CHECK_NAME(glutSetWindowData); CHECK_NAME(glutGetWindowData); CHECK_NAME(glutSetMenuData); diff --git a/src/freeglut_init.c b/src/freeglut_init.c index 83c02ab..054285e 100644 --- a/src/freeglut_init.c +++ b/src/freeglut_init.c @@ -79,7 +79,9 @@ SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */ GLUT_EXEC_STATE_INIT, /* ExecState */ NULL, /* ProgramName */ GL_FALSE, /* JoysticksInitialised */ - GL_FALSE /* InputDevsInitialised */ + GL_FALSE, /* InputDevsInitialised */ + 0, /* AuxiliaryBufferNumber */ + 0 /* SampleNumber */ }; @@ -893,7 +895,7 @@ void FGAPIENTRY glutInitDisplayString( const char* displayMode ) break ; case 36 : /* "aux": some number of aux buffers */ - glut_state_flag |= GLUT_AUX1; + glut_state_flag |= GLUT_AUX; break ; case 37 : /* Unrecognized */ diff --git a/src/freeglut_internal.h b/src/freeglut_internal.h index 1cda9e6..770e908 100644 --- a/src/freeglut_internal.h +++ b/src/freeglut_internal.h @@ -302,6 +302,9 @@ struct tagSFG_State char *ProgramName; /* Name of the invoking program */ GLboolean JoysticksInitialised; /* Only initialize if application calls for them */ GLboolean InputDevsInitialised; /* Only initialize if application calls for them */ + + int AuxiliaryBufferNumber; /* Number of auxiliary buffers */ + int SampleNumber; /* Number of samples per pixel */ }; /* The structure used by display initialization in freeglut_init.c */ diff --git a/src/freeglut_state.c b/src/freeglut_state.c index 07539b0..cca7b92 100644 --- a/src/freeglut_state.c +++ b/src/freeglut_state.c @@ -116,6 +116,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; @@ -720,4 +728,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 ***/ diff --git a/src/freeglut_structure.c b/src/freeglut_structure.c index 1d064b6..c1b9145 100644 --- a/src/freeglut_structure.c +++ b/src/freeglut_structure.c @@ -219,12 +219,6 @@ void fgDestroyWindow( SFG_Window* window ) fghClearCallBacks( window ); fgCloseWindow( window ); -#if TARGET_HOST_UNIX_X11 - if (window->Window.FBConfig != NULL) - { - XFree( window->Window.FBConfig ); - } -#endif free( window ); if( fgStructure.CurrentWindow == window ) fgStructure.CurrentWindow = NULL; diff --git a/src/freeglut_window.c b/src/freeglut_window.c index c12075e..f6da23e 100644 --- a/src/freeglut_window.c +++ b/src/freeglut_window.c @@ -128,19 +128,20 @@ GLXFBConfig* fgChooseFBConfig( void ) ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 ); } - if( fgState.DisplayMode & GLUT_AUX1 ) - ATTRIB_VAL( GLX_AUX_BUFFERS, 1 ); - if( fgState.DisplayMode & GLUT_AUX2 ) - ATTRIB_VAL( GLX_AUX_BUFFERS, 2 ); - if( fgState.DisplayMode & GLUT_AUX3 ) - ATTRIB_VAL( GLX_AUX_BUFFERS, 3 ); - if( fgState.DisplayMode & GLUT_AUX4 ) - ATTRIB_VAL( GLX_AUX_BUFFERS, 4 ); - if ( fgState.DisplayMode & GLUT_MULTISAMPLE ) - { - ATTRIB_VAL( GLX_SAMPLE_BUFFERS, 1 ); - } - + if ((fgState.DisplayMode & GLUT_AUX) + || (fgState.DisplayMode & GLUT_AUX1) + || (fgState.DisplayMode & GLUT_AUX2) + || (fgState.DisplayMode & GLUT_AUX3) + || (fgState.DisplayMode & GLUT_AUX4)) + { + ATTRIB_VAL(GLX_AUX_BUFFERS, fgState.AuxiliaryBufferNumber) + } + + if (fgState.DisplayMode & GLUT_MULTISAMPLE) + { + ATTRIB_VAL(GLX_SAMPLE_BUFFERS, 1) + ATTRIB_VAL(GLX_SAMPLES, fgState.SampleNumber) + } /* Push a null at the end of the list */ ATTRIB( None ); @@ -896,7 +897,7 @@ void fgCloseWindow( SFG_Window* window ) glXDestroyContext( fgDisplay.Display, window->Window.Context ); XFree( window->Window.FBConfig ); XDestroyWindow( fgDisplay.Display, window->Window.Handle ); - XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ + /* XFlush( fgDisplay.Display ); */ /* XXX Shouldn't need this */ #elif TARGET_HOST_MS_WINDOWS -- 1.7.10.4