From eb22ff53c4ea4b363dccd088cfeb6ccd31b51b7d Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 29 Jun 2019 20:40:23 +0300 Subject: [PATCH] sdl: vid: fix washed out screen on Windows and probably other platforms(#50) --- engine/platform/sdl/vid_sdl.c | 62 ++++++++++++++++++++++++++++++----- engine/ref_api.h | 14 ++------ 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 427a3e8e..67320c97 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -712,27 +712,73 @@ void GL_SwapBuffers() SDL_GL_SwapWindow( host.hWnd ); } - int GL_SetAttribute( int attr, int val ) { switch( attr ) { +#define MAP_REF_API_ATTRIBUTE_TO_SDL( name ) case REF_##name: return SDL_GL_SetAttribute( SDL_##name, val ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_RED_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_GREEN_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_BLUE_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_ALPHA_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_DOUBLEBUFFER ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_DEPTH_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_STENCIL_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLEBUFFERS ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLESAMPLES ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_ACCELERATED_VISUAL ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MAJOR_VERSION ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MINOR_VERSION ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_EGL ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_FLAGS ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_SHARE_WITH_CURRENT_CONTEXT ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_FRAMEBUFFER_SRGB_CAPABLE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RELEASE_BEHAVIOR ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RESET_NOTIFICATION ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_NO_ERROR ); case REF_GL_CONTEXT_PROFILE_MASK: #ifdef SDL_HINT_OPENGL_ES_DRIVER - if( val == REF_GL_CONTEXT_PROFILE_ES ) - SDL_SetHint( SDL_HINT_OPENGL_ES_DRIVER, "1" ); + if (val == REF_GL_CONTEXT_PROFILE_ES) + SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "1"); #endif // SDL_HINT_OPENGL_ES_DRIVER - break; - default: - break; + return SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, val ); +#undef MAP_REF_API_ATTRIBUTE_TO_SDL } - return SDL_GL_SetAttribute( (SDL_GLattr)attr, val ); + ASSERT( 0 ); + return -1; } int GL_GetAttribute( int attr, int *val ) { - return SDL_GL_GetAttribute( (SDL_GLattr)attr, val ); + switch( attr ) + { +#define MAP_REF_API_ATTRIBUTE_TO_SDL( name ) case REF_##name: return SDL_GL_GetAttribute( SDL_##name, val ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_RED_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_GREEN_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_BLUE_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_ALPHA_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_DOUBLEBUFFER ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_DEPTH_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_STENCIL_SIZE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLEBUFFERS ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_MULTISAMPLESAMPLES ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_ACCELERATED_VISUAL ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MAJOR_VERSION ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_MINOR_VERSION ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_EGL ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_FLAGS ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_SHARE_WITH_CURRENT_CONTEXT ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_FRAMEBUFFER_SRGB_CAPABLE ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RELEASE_BEHAVIOR ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_RESET_NOTIFICATION ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_NO_ERROR ); + MAP_REF_API_ATTRIBUTE_TO_SDL( GL_CONTEXT_PROFILE_MASK ); +#undef MAP_REF_API_ATTRIBUTE_TO_SDL + } + + ASSERT( 0 ); + return 0; } #ifndef EGL_LIB diff --git a/engine/ref_api.h b/engine/ref_api.h index de6f057f..c429a5c2 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -169,27 +169,19 @@ typedef enum SAFE_DONTCARE // ignore everything, let SDL/EGL decide } ref_safegl_context_t; -// binary compatible with SDL2 enum // OpenGL configuration attributes { REF_GL_RED_SIZE, REF_GL_GREEN_SIZE, REF_GL_BLUE_SIZE, REF_GL_ALPHA_SIZE, - // UNUSED_REF_GL_BUFFER_SIZE, - REF_GL_DOUBLEBUFFER = REF_GL_ALPHA_SIZE + 1, + REF_GL_DOUBLEBUFFER, REF_GL_DEPTH_SIZE, REF_GL_STENCIL_SIZE, - // UNUSED_REF_GL_ACCUM_RED_SIZE, - // UNUSED_REF_GL_ACCUM_GREEN_SIZE, - // UNUSED_REF_GL_ACCUM_BLUE_SIZE, - // UNUSED_REF_GL_ACCUM_ALPHA_SIZE, - // UNUSED_REF_GL_STEREO, - REF_GL_MULTISAMPLEBUFFERS = REF_GL_STENCIL_SIZE + 5, + REF_GL_MULTISAMPLEBUFFERS, REF_GL_MULTISAMPLESAMPLES, REF_GL_ACCELERATED_VISUAL, - // UNUSED_REF_GL_RETAINED_BACKING, - REF_GL_CONTEXT_MAJOR_VERSION = REF_GL_ACCELERATED_VISUAL + 1, + REF_GL_CONTEXT_MAJOR_VERSION, REF_GL_CONTEXT_MINOR_VERSION, REF_GL_CONTEXT_EGL, REF_GL_CONTEXT_FLAGS,