From 9486b7d6a3bf0d00cc00ab98380e99810250aa84 Mon Sep 17 00:00:00 2001 From: "John F. Fay" Date: Sun, 29 Jan 2012 03:15:41 +0000 Subject: [PATCH] Moving the platform-specific FBConfig and device context variables into platform-specific parts of the code git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1014 7f0cb862-5218-0410-a997-914c9d46530a --- src/Common/freeglut_internal.h | 12 +++++++----- src/Common/freeglut_state.c | 4 ++-- src/Common/freeglut_structure.c | 2 +- src/Common/freeglut_window.c | 16 ++++++++-------- src/mswin/freeglut_display_mswin.c | 2 +- src/mswin/freeglut_internal_mswin.h | 6 ++++++ src/mswin/freeglut_main_mswin.c | 14 +++++++------- src/mswin/freeglut_state_mswin.c | 2 +- src/mswin/freeglut_window_mswin.c | 14 +++++++------- 9 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/Common/freeglut_internal.h b/src/Common/freeglut_internal.h index 815d13e..f4fc756 100644 --- a/src/Common/freeglut_internal.h +++ b/src/Common/freeglut_internal.h @@ -255,6 +255,12 @@ struct tagSFG_PlatformDisplay */ typedef Window SFG_WindowHandleType ; typedef GLXContext SFG_WindowContextType ; +typedef struct tagSFG_PlatformContext SFG_PlatformContext; +struct tagSFG_PlatformContext +{ + GLXFBConfig* FBConfig; /* The window's FBConfig */ +}; + #endif @@ -438,11 +444,7 @@ struct tagSFG_Context SFG_WindowHandleType Handle; /* The window's handle */ SFG_WindowContextType Context; /* The window's OpenGL/WGL context */ -#if TARGET_HOST_POSIX_X11 - GLXFBConfig* FBConfig; /* The window's FBConfig */ -#elif TARGET_HOST_MS_WINDOWS - HDC Device; /* The window's device context */ -#endif + SFG_PlatformContext pContext; /* The window's FBConfig (X11) or device context (Windows) */ int DoubleBuffered; /* Treat the window as double-buffered */ }; diff --git a/src/Common/freeglut_state.c b/src/Common/freeglut_state.c index 434b41f..6630b6d 100644 --- a/src/Common/freeglut_state.c +++ b/src/Common/freeglut_state.c @@ -66,7 +66,7 @@ static int fghGetConfig( int attribute ) if( fgStructure.CurrentWindow ) result = glXGetFBConfigAttrib( fgDisplay.Display, - *(fgStructure.CurrentWindow->Window.FBConfig), + *(fgStructure.CurrentWindow->Window.pContext.FBConfig), attribute, &returnValue ); @@ -125,7 +125,7 @@ int fgPlatformGlutGet ( GLenum eWhat ) else { const GLXFBConfig * fbconfig = - fgStructure.CurrentWindow->Window.FBConfig; + fgStructure.CurrentWindow->Window.pContext.FBConfig; XVisualInfo * visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display, *fbconfig ); diff --git a/src/Common/freeglut_structure.c b/src/Common/freeglut_structure.c index f8d748f..56798f1 100644 --- a/src/Common/freeglut_structure.c +++ b/src/Common/freeglut_structure.c @@ -63,7 +63,7 @@ static void fghClearCallBacks( SFG_Window *window ) #if TARGET_HOST_POSIX_X11 void fgPlatformCreateWindow ( SFG_Window *window ) { - window->Window.FBConfig = NULL; + window->Window.pContext.FBConfig = NULL; window->State.OldHeight = window->State.OldWidth = -1; } diff --git a/src/Common/freeglut_window.c b/src/Common/freeglut_window.c index 8a44d1a..1468627 100644 --- a/src/Common/freeglut_window.c +++ b/src/Common/freeglut_window.c @@ -398,7 +398,7 @@ static GLXContext fghCreateNewContext( SFG_Window* window ) /* "classic" context creation */ 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; GLXContext share_list = NULL; 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 ) ) fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ; - window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); + window->Window.pContext.FBConfig = fgChooseFBConfig( &num_FBConfigs ); if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = current_DisplayMode ; - if( ! window->Window.FBConfig ) + if( ! window->Window.pContext.FBConfig ) { /* * 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 ) ) { fgState.DisplayMode |= GLUT_DOUBLE ; - window->Window.FBConfig = fgChooseFBConfig( &num_FBConfigs ); + window->Window.pContext.FBConfig = fgChooseFBConfig( &num_FBConfigs ); fgState.DisplayMode &= ~GLUT_DOUBLE; } if( 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; } } - FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.FBConfig != NULL, + FREEGLUT_INTERNAL_ERROR_EXIT( window->Window.pContext.FBConfig != NULL, "FBConfig with necessary capabilities not found", "fgOpenWindow" ); /* Get the X visual. */ for (i = 0; i < num_FBConfigs; i++) { visualInfo = glXGetVisualFromFBConfig( fgDisplay.Display, - window->Window.FBConfig[i] ); + window->Window.pContext.FBConfig[i] ); if (visualInfo) break; } @@ -750,7 +750,7 @@ void fgPlatformCloseWindow( SFG_Window* window ) { if( window->Window.Context ) glXDestroyContext( fgDisplay.Display, window->Window.Context ); - XFree( window->Window.FBConfig ); + XFree( window->Window.pContext.FBConfig ); if( window->Window.Handle ) { XDestroyWindow( fgDisplay.Display, window->Window.Handle ); diff --git a/src/mswin/freeglut_display_mswin.c b/src/mswin/freeglut_display_mswin.c index 9437382..d93675c 100644 --- a/src/mswin/freeglut_display_mswin.c +++ b/src/mswin/freeglut_display_mswin.c @@ -33,5 +33,5 @@ void fgPlatformGlutSwapBuffers( SFG_PlatformDisplay *pDisplayPtr, SFG_Window* CurrentWindow ) { - SwapBuffers( CurrentWindow->Window.Device ); + SwapBuffers( CurrentWindow->Window.pContext.Device ); } diff --git a/src/mswin/freeglut_internal_mswin.h b/src/mswin/freeglut_internal_mswin.h index bd392f0..628c06d 100644 --- a/src/mswin/freeglut_internal_mswin.h +++ b/src/mswin/freeglut_internal_mswin.h @@ -42,6 +42,12 @@ struct tagSFG_PlatformDisplay */ typedef HWND SFG_WindowHandleType ; typedef HGLRC SFG_WindowContextType ; +typedef struct tagSFG_PlatformContext SFG_PlatformContext; +struct tagSFG_PlatformContext +{ + HDC Device; /* The window's device context */ +}; + diff --git a/src/mswin/freeglut_main_mswin.c b/src/mswin/freeglut_main_mswin.c index b4d1bc9..b04e9e0 100644 --- a/src/mswin/freeglut_main_mswin.c +++ b/src/mswin/freeglut_main_mswin.c @@ -329,7 +329,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, "fgPlatformWindowProc" ); window->Window.Handle = hWnd; - window->Window.Device = GetDC( hWnd ); + window->Window.pContext.Device = GetDC( hWnd ); if( window->IsMenu ) { unsigned int current_DisplayMode = fgState.DisplayMode; @@ -340,7 +340,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, fgState.DisplayMode = current_DisplayMode; if( fgStructure.MenuContext ) - wglMakeCurrent( window->Window.Device, + wglMakeCurrent( window->Window.pContext.Device, fgStructure.MenuContext->MContext ); else @@ -348,11 +348,11 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, fgStructure.MenuContext = (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) ); fgStructure.MenuContext->MContext = - wglCreateContext( window->Window.Device ); + wglCreateContext( window->Window.pContext.Device ); } /* window->Window.Context = wglGetCurrentContext (); */ - window->Window.Context = wglCreateContext( window->Window.Device ); + window->Window.Context = wglCreateContext( window->Window.pContext.Device ); } else { @@ -362,13 +362,13 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, if( ! fgState.UseCurrentContext ) window->Window.Context = - wglCreateContext( window->Window.Device ); + wglCreateContext( window->Window.pContext.Device ); else { window->Window.Context = wglGetCurrentContext( ); if( ! window->Window.Context ) window->Window.Context = - wglCreateContext( window->Window.Device ); + wglCreateContext( window->Window.pContext.Device ); } #if !defined(_WIN32_WCE) @@ -391,7 +391,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, fgSetWindow( current_window ); } - ReleaseDC( window->Window.Handle, window->Window.Device ); + ReleaseDC( window->Window.Handle, window->Window.pContext.Device ); #if defined(_WIN32_WCE) /* Take over button handling */ diff --git a/src/mswin/freeglut_state_mswin.c b/src/mswin/freeglut_state_mswin.c index ed1f57e..1f9966b 100644 --- a/src/mswin/freeglut_state_mswin.c +++ b/src/mswin/freeglut_state_mswin.c @@ -229,7 +229,7 @@ int fgPlatformGlutGet ( GLenum eWhat ) case GLUT_WINDOW_FORMAT_ID: #if !defined(_WIN32_WCE) if( fgStructure.CurrentWindow != NULL ) - return GetPixelFormat( fgStructure.CurrentWindow->Window.Device ); + return GetPixelFormat( fgStructure.CurrentWindow->Window.pContext.Device ); #endif /* defined(_WIN32_WCE) */ return 0; diff --git a/src/mswin/freeglut_window_mswin.c b/src/mswin/freeglut_window_mswin.c index bf4ef04..583d5f7 100644 --- a/src/mswin/freeglut_window_mswin.c +++ b/src/mswin/freeglut_window_mswin.c @@ -169,9 +169,9 @@ void fgNewWGLCreateContext( SFG_Window* window ) 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; } @@ -185,7 +185,7 @@ void fgNewWGLCreateContext( SFG_Window* window ) fgError( "wglCreateContextAttribsARB not found" ); } - context = wglCreateContextAttribsARB( window->Window.Device, 0, attributes ); + context = wglCreateContextAttribsARB( window->Window.pContext.Device, 0, attributes ); if ( context == NULL ) { fghContextCreationError(); @@ -296,7 +296,7 @@ GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly, if (checkOnly) current_hDC = CreateDC(TEXT("DISPLAY"), NULL ,NULL ,NULL); else - current_hDC = window->Window.Device; + current_hDC = window->Window.pContext.Device; fghFillPFD( ppfd, current_hDC, layer_type ); pixelformat = ChoosePixelFormat( current_hDC, ppfd ); @@ -370,13 +370,13 @@ void fgPlatformSetWindow ( SFG_Window *window ) { if( fgStructure.CurrentWindow ) ReleaseDC( fgStructure.CurrentWindow->Window.Handle, - fgStructure.CurrentWindow->Window.Device ); + fgStructure.CurrentWindow->Window.pContext.Device ); if ( window ) { - window->Window.Device = GetDC( window->Window.Handle ); + window->Window.pContext.Device = GetDC( window->Window.Handle ); wglMakeCurrent( - window->Window.Device, + window->Window.pContext.Device, window->Window.Context ); } -- 1.7.10.4