From 57320c0c25c0d91c7ede0d173629aa51cc59919b Mon Sep 17 00:00:00 2001 From: mittorn Date: Sat, 16 Mar 2019 11:58:44 +0700 Subject: [PATCH] ref: get rid of vidState, add GL_SwapBuffers to engine exports --- engine/client/ref_common.c | 2 ++ engine/client/vid_common.c | 13 ++++++------- engine/client/vid_common.h | 10 +--------- engine/platform/sdl/vid_sdl.c | 23 +++++++++++++++++------ engine/ref_api.h | 1 + ref_gl/gl_rmain.c | 7 +------ 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index d460bbb5..fa5da53e 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -3,6 +3,7 @@ #include "library.h" #include "cl_tent.h" #include "platform/platform.h" +#include "vid_common.h" struct ref_state_s ref; ref_globals_t refState; @@ -352,6 +353,7 @@ static ref_api_t gEngfuncs = GL_SetAttribute, GL_GetAttribute, GL_GetProcAddress, + GL_SwapBuffers, BuildGammaTable, LightToTexGamma, diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index d3d37fdd..6bc654fb 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -27,7 +27,6 @@ convar_t *vid_brightness; convar_t *vid_gamma; convar_t *vid_highdpi; -vidstate_t vidState; glwstate_t glw_state; convar_t *window_xpos; @@ -54,8 +53,8 @@ void VID_InitDefaultResolution( void ) { // we need to have something valid here // until video subsystem initialized - vidState.width = 640; - vidState.height = 480; + refState.width = 640; + refState.height = 480; } /* @@ -65,8 +64,8 @@ R_SaveVideoMode */ void R_SaveVideoMode( int w, int h ) { - vidState.width = w; - vidState.height = h; + refState.width = w; + refState.height = h; host.window_center_x = w / 2; host.window_center_y = h / 2; @@ -76,8 +75,8 @@ void R_SaveVideoMode( int w, int h ) // check for 4:3 or 5:4 if( w * 3 != h * 4 && w * 4 != h * 5 ) - vidState.wideScreen = true; - else vidState.wideScreen = false; + refState.wideScreen = true; + else refState.wideScreen = false; } /* diff --git a/engine/client/vid_common.h b/engine/client/vid_common.h index a113286f..eaf473c6 100644 --- a/engine/client/vid_common.h +++ b/engine/client/vid_common.h @@ -28,15 +28,6 @@ typedef struct } glwstate_t; -typedef struct vidstate_s -{ - int width, height; - int prev_width, prev_height; - qboolean fullScreen; - qboolean wideScreen; -} vidstate_t; - -extern vidstate_t vidState; extern glwstate_t glw_state; #define VID_MIN_HEIGHT 200 @@ -50,5 +41,6 @@ void R_SaveVideoMode( int w, int h ); void VID_CheckChanges( void ); const char *VID_GetModeString( int vid_mode ); void VID_StartupGamma( void ); +void GL_SwapBuffers(); #endif // VID_COMMON diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 1356833b..8c025c20 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -24,6 +24,10 @@ GNU General Public License for more details. static vidmode_t *vidmodes = NULL; static int num_vidmodes = 0; static void GL_SetupAttributes( void ); +struct +{ + int prev_width, prev_height; +} sdlState; int R_MaxVideoModes( void ) { @@ -470,9 +474,9 @@ void VID_DestroyWindow( void ) host.hWnd = NULL; } - if( vidState.fullScreen ) + if( refState.fullScreen ) { - vidState.fullScreen = false; + refState.fullScreen = false; } } @@ -488,6 +492,13 @@ static void GL_SetupAttributes( void ) ref.dllFuncs.GL_SetupAttributes( glw_state.safe ); } + +void GL_SwapBuffers() +{ + SDL_GL_SwapWindow( host.hWnd ); +} + + int GL_SetAttribute( int attr, int val ) { return SDL_GL_SetAttribute( (SDL_GLattr)attr, val ); @@ -568,7 +579,7 @@ rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) glw_state.desktopWidth = displayMode.w; glw_state.desktopHeight = displayMode.h; - vidState.fullScreen = fullscreen; + refState.fullScreen = fullscreen; if( !host.hWnd ) { @@ -640,8 +651,8 @@ qboolean VID_SetMode( void ) if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, fullscreen )) == rserr_ok ) { - vidState.prev_width = iScreenWidth; - vidState.prev_height = iScreenHeight; + sdlState.prev_width = iScreenWidth; + sdlState.prev_height = iScreenHeight; } else { @@ -660,7 +671,7 @@ qboolean VID_SetMode( void ) } // try setting it back to something safe - if(( err = R_ChangeDisplaySettings( vidState.prev_width, vidState.prev_height, false )) != rserr_ok ) + if(( err = R_ChangeDisplaySettings( sdlState.prev_width, sdlState.prev_height, false )) != rserr_ok ) { Con_Reportf( S_ERROR "VID_SetMode: could not revert to safe mode\n" ); Sys_Warn("could not revert to safe mode!"); diff --git a/engine/ref_api.h b/engine/ref_api.h index 6ed3abfa..0654628a 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -383,6 +383,7 @@ typedef struct ref_api_s int (*GL_SetAttribute)( int attr, int value ); int (*GL_GetAttribute)( int attr, int *value ); void *(*GL_GetProcAddress)( const char *name ); + void (*GL_SwapBuffers)(); // gamma void (*BuildGammaTable)( float lightgamma, float brightness ); diff --git a/ref_gl/gl_rmain.c b/ref_gl/gl_rmain.c index bcea5b4b..a1d96e51 100644 --- a/ref_gl/gl_rmain.c +++ b/ref_gl/gl_rmain.c @@ -1138,12 +1138,7 @@ void R_EndFrame( void ) { // flush any remaining 2D bits R_Set2DMode( false ); - -#ifdef XASH_SDL - SDL_GL_SwapWindow( host.hWnd ); -#elif defined __ANDROID__ // For direct android backend - Android_SwapBuffers(); -#endif + gEngfuncs.GL_SwapBuffers(); } /*