Moving the platform-specific FBConfig and device context variables into platform-specific parts of the code

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1014 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
fayjf 2012-01-29 03:15:41 +00:00
parent 9d8d27aa4f
commit d918fca3c0
9 changed files with 40 additions and 32 deletions

View File

@ -255,6 +255,12 @@ struct tagSFG_PlatformDisplay
*/ */
typedef Window SFG_WindowHandleType ; typedef Window SFG_WindowHandleType ;
typedef GLXContext SFG_WindowContextType ; typedef GLXContext SFG_WindowContextType ;
typedef struct tagSFG_PlatformContext SFG_PlatformContext;
struct tagSFG_PlatformContext
{
GLXFBConfig* FBConfig; /* The window's FBConfig */
};
#endif #endif
@ -438,11 +444,7 @@ struct tagSFG_Context
SFG_WindowHandleType Handle; /* The window's handle */ SFG_WindowHandleType Handle; /* The window's handle */
SFG_WindowContextType Context; /* The window's OpenGL/WGL context */ SFG_WindowContextType Context; /* The window's OpenGL/WGL context */
#if TARGET_HOST_POSIX_X11 SFG_PlatformContext pContext; /* The window's FBConfig (X11) or device context (Windows) */
GLXFBConfig* FBConfig; /* The window's FBConfig */
#elif TARGET_HOST_MS_WINDOWS
HDC Device; /* The window's device context */
#endif
int DoubleBuffered; /* Treat the window as double-buffered */ int DoubleBuffered; /* Treat the window as double-buffered */
}; };

View File

@ -66,7 +66,7 @@ static int fghGetConfig( int attribute )
if( fgStructure.CurrentWindow ) if( fgStructure.CurrentWindow )
result = glXGetFBConfigAttrib( fgDisplay.Display, result = glXGetFBConfigAttrib( fgDisplay.Display,
*(fgStructure.CurrentWindow->Window.FBConfig), *(fgStructure.CurrentWindow->Window.pContext.FBConfig),
attribute, attribute,
&returnValue ); &returnValue );
@ -125,7 +125,7 @@ int fgPlatformGlutGet ( GLenum eWhat )
else else
{ {
const GLXFBConfig * fbconfig = const GLXFBConfig * fbconfig =
fgStructure.CurrentWindow->Window.FBConfig; fgStructure.CurrentWindow->Window.pContext.FBConfig;
XVisualInfo * visualInfo = XVisualInfo * visualInfo =
glXGetVisualFromFBConfig( fgDisplay.Display, *fbconfig ); glXGetVisualFromFBConfig( fgDisplay.Display, *fbconfig );

View File

@ -63,7 +63,7 @@ static void fghClearCallBacks( SFG_Window *window )
#if TARGET_HOST_POSIX_X11 #if TARGET_HOST_POSIX_X11
void fgPlatformCreateWindow ( SFG_Window *window ) void fgPlatformCreateWindow ( SFG_Window *window )
{ {
window->Window.FBConfig = NULL; window->Window.pContext.FBConfig = NULL;
window->State.OldHeight = window->State.OldWidth = -1; window->State.OldHeight = window->State.OldWidth = -1;
} }

View File

@ -398,7 +398,7 @@ static GLXContext fghCreateNewContext( SFG_Window* window )
/* "classic" context creation */ /* "classic" context creation */
Display *dpy = fgDisplay.Display; Display *dpy = fgDisplay.Display;
GLXFBConfig config = *(window->Window.FBConfig); GLXFBConfig config = *(window->Window.pContext.FBConfig);
int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE; int render_type = ( !menu && index_mode ) ? GLX_COLOR_INDEX_TYPE : GLX_RGBA_TYPE;
GLXContext share_list = NULL; GLXContext share_list = NULL;
Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT ); Bool direct = ( fgState.DirectContext != GLUT_FORCE_INDIRECT_CONTEXT );
@ -548,12 +548,12 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
if( window->IsMenu && ( ! fgStructure.MenuContext ) ) if( window->IsMenu && ( ! fgStructure.MenuContext ) )
fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ; fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ;
window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); window->Window.pContext.FBConfig = fgChooseFBConfig( &num_FBConfigs );
if( window->IsMenu && ( ! fgStructure.MenuContext ) ) if( window->IsMenu && ( ! fgStructure.MenuContext ) )
fgState.DisplayMode = current_DisplayMode ; fgState.DisplayMode = current_DisplayMode ;
if( ! window->Window.FBConfig ) if( ! window->Window.pContext.FBConfig )
{ {
/* /*
* The "fgChooseFBConfig" returned a null meaning that the visual * The "fgChooseFBConfig" returned a null meaning that the visual
@ -563,25 +563,25 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
if( !( fgState.DisplayMode & GLUT_DOUBLE ) ) if( !( fgState.DisplayMode & GLUT_DOUBLE ) )
{ {
fgState.DisplayMode |= GLUT_DOUBLE ; fgState.DisplayMode |= GLUT_DOUBLE ;
window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); window->Window.pContext.FBConfig = fgChooseFBConfig( &num_FBConfigs );
fgState.DisplayMode &= ~GLUT_DOUBLE; fgState.DisplayMode &= ~GLUT_DOUBLE;
} }
if( fgState.DisplayMode & GLUT_MULTISAMPLE ) if( fgState.DisplayMode & GLUT_MULTISAMPLE )
{ {
fgState.DisplayMode &= ~GLUT_MULTISAMPLE ; fgState.DisplayMode &= ~GLUT_MULTISAMPLE ;
window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); window->Window.pContext.FBConfig = fgChooseFBConfig( &num_FBConfigs );
fgState.DisplayMode |= GLUT_MULTISAMPLE; fgState.DisplayMode |= GLUT_MULTISAMPLE;
} }
} }
FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL, FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.pContext.FBConfig != NULL,
"FBConfig with necessary capabilities not found", "fgOpenWindow" ); "FBConfig with necessary capabilities not found", "fgOpenWindow" );
/* Get the X visual. */ /* Get the X visual. */
for (i = 0; i < num_FBConfigs; i++) { for (i = 0; i < num_FBConfigs; i++) {
visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display, visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display,
window->Window.FBConfig[i] ); window->Window.pContext.FBConfig[i] );
if (visualInfo) if (visualInfo)
break; break;
} }
@ -750,7 +750,7 @@ void fgPlatformCloseWindow( SFG_Window* window )
{ {
if( window->Window.Context ) if( window->Window.Context )
glXDestroyContext( fgDisplay.Display, window->Window.Context ); glXDestroyContext( fgDisplay.Display, window->Window.Context );
XFree( window->Window.FBConfig ); XFree( window->Window.pContext.FBConfig );
if( window->Window.Handle ) { if( window->Window.Handle ) {
XDestroyWindow( fgDisplay.Display, window->Window.Handle ); XDestroyWindow( fgDisplay.Display, window->Window.Handle );

View File

@ -33,5 +33,5 @@
void fgPlatformGlutSwapBuffers( SFG_PlatformDisplay *pDisplayPtr, SFG_Window* CurrentWindow ) void fgPlatformGlutSwapBuffers( SFG_PlatformDisplay *pDisplayPtr, SFG_Window* CurrentWindow )
{ {
SwapBuffers( CurrentWindow->Window.Device ); SwapBuffers( CurrentWindow->Window.pContext.Device );
} }

View File

@ -42,6 +42,12 @@ struct tagSFG_PlatformDisplay
*/ */
typedef HWND SFG_WindowHandleType ; typedef HWND SFG_WindowHandleType ;
typedef HGLRC SFG_WindowContextType ; typedef HGLRC SFG_WindowContextType ;
typedef struct tagSFG_PlatformContext SFG_PlatformContext;
struct tagSFG_PlatformContext
{
HDC Device; /* The window's device context */
};

View File

@ -329,7 +329,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
"fgPlatformWindowProc" ); "fgPlatformWindowProc" );
window->Window.Handle = hWnd; window->Window.Handle = hWnd;
window->Window.Device = GetDC( hWnd ); window->Window.pContext.Device = GetDC( hWnd );
if( window->IsMenu ) if( window->IsMenu )
{ {
unsigned int current_DisplayMode = fgState.DisplayMode; unsigned int current_DisplayMode = fgState.DisplayMode;
@ -340,7 +340,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
fgState.DisplayMode = current_DisplayMode; fgState.DisplayMode = current_DisplayMode;
if( fgStructure.MenuContext ) if( fgStructure.MenuContext )
wglMakeCurrent( window->Window.Device, wglMakeCurrent( window->Window.pContext.Device,
fgStructure.MenuContext->MContext fgStructure.MenuContext->MContext
); );
else else
@ -348,11 +348,11 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
fgStructure.MenuContext = fgStructure.MenuContext =
(SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) ); (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
fgStructure.MenuContext->MContext = fgStructure.MenuContext->MContext =
wglCreateContext( window->Window.Device ); wglCreateContext( window->Window.pContext.Device );
} }
/* window->Window.Context = wglGetCurrentContext (); */ /* window->Window.Context = wglGetCurrentContext (); */
window->Window.Context = wglCreateContext( window->Window.Device ); window->Window.Context = wglCreateContext( window->Window.pContext.Device );
} }
else else
{ {
@ -362,13 +362,13 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
if( ! fgState.UseCurrentContext ) if( ! fgState.UseCurrentContext )
window->Window.Context = window->Window.Context =
wglCreateContext( window->Window.Device ); wglCreateContext( window->Window.pContext.Device );
else else
{ {
window->Window.Context = wglGetCurrentContext( ); window->Window.Context = wglGetCurrentContext( );
if( ! window->Window.Context ) if( ! window->Window.Context )
window->Window.Context = window->Window.Context =
wglCreateContext( window->Window.Device ); wglCreateContext( window->Window.pContext.Device );
} }
#if !defined(_WIN32_WCE) #if !defined(_WIN32_WCE)
@ -391,7 +391,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
fgSetWindow( current_window ); fgSetWindow( current_window );
} }
ReleaseDC( window->Window.Handle, window->Window.Device ); ReleaseDC( window->Window.Handle, window->Window.pContext.Device );
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
/* Take over button handling */ /* Take over button handling */

View File

@ -229,7 +229,7 @@ int fgPlatformGlutGet ( GLenum eWhat )
case GLUT_WINDOW_FORMAT_ID: case GLUT_WINDOW_FORMAT_ID:
#if !defined(_WIN32_WCE) #if !defined(_WIN32_WCE)
if( fgStructure.CurrentWindow != NULL ) if( fgStructure.CurrentWindow != NULL )
return GetPixelFormat( fgStructure.CurrentWindow->Window.Device ); return GetPixelFormat( fgStructure.CurrentWindow->Window.pContext.Device );
#endif /* defined(_WIN32_WCE) */ #endif /* defined(_WIN32_WCE) */
return 0; return 0;

View File

@ -169,9 +169,9 @@ void fgNewWGLCreateContext( SFG_Window* window )
return; return;
} }
wglMakeCurrent( window->Window.Device, window->Window.Context ); wglMakeCurrent( window->Window.pContext.Device, window->Window.Context );
if ( !fghIsExtensionSupported( window->Window.Device, "WGL_ARB_create_context" ) ) if ( !fghIsExtensionSupported( window->Window.pContext.Device, "WGL_ARB_create_context" ) )
{ {
return; return;
} }
@ -185,7 +185,7 @@ void fgNewWGLCreateContext( SFG_Window* window )
fgError( "wglCreateContextAttribsARB not found" ); fgError( "wglCreateContextAttribsARB not found" );
} }
context = wglCreateContextAttribsARB( window->Window.Device, 0, attributes ); context = wglCreateContextAttribsARB( window->Window.pContext.Device, 0, attributes );
if ( context == NULL ) if ( context == NULL )
{ {
fghContextCreationError(); fghContextCreationError();
@ -296,7 +296,7 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
if (checkOnly) if (checkOnly)
current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL); current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL);
else else
current_hDC = window->Window.Device; current_hDC = window->Window.pContext.Device;
fghFillPFD( ppfd, current_hDC, layer_type ); fghFillPFD( ppfd, current_hDC, layer_type );
pixelformat = ChoosePixelFormat( current_hDC, ppfd ); pixelformat = ChoosePixelFormat( current_hDC, ppfd );
@ -370,13 +370,13 @@ void fgPlatformSetWindow ( SFG_Window *window )
{ {
if( fgStructure.CurrentWindow ) if( fgStructure.CurrentWindow )
ReleaseDC( fgStructure.CurrentWindow->Window.Handle, ReleaseDC( fgStructure.CurrentWindow->Window.Handle,
fgStructure.CurrentWindow->Window.Device ); fgStructure.CurrentWindow->Window.pContext.Device );
if ( window ) if ( window )
{ {
window->Window.Device = GetDC( window->Window.Handle ); window->Window.pContext.Device = GetDC( window->Window.Handle );
wglMakeCurrent( wglMakeCurrent(
window->Window.Device, window->Window.pContext.Device,
window->Window.Context window->Window.Context
); );
} }