From 2e94c32d597f8514a778d67ba9ee223f7e75b50c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 23 Dec 2011 08:20:54 +0000 Subject: [PATCH] - added ability to check if compiler supports SSE and if not fallback to X87 for streflop. - added ability for clients to specify gamma override value for drivers which support it --- mk/cmake/Modules/SpecialMacros.cmake | 19 ++++++++------ source/glest_game/main/main.cpp | 25 ++++++++++++++++++- source/glest_game/main/program.cpp | 14 +++++++++-- source/shared_lib/CMakeLists.txt | 6 ++--- source/shared_lib/include/graphics/context.h | 3 +++ .../shared_lib/include/platform/sdl/gl_wrap.h | 4 ++- .../include/platform/sdl/platform_main.h | 17 ++++++++++++- .../include/platform/sdl/window_gl.h | 4 ++- .../shared_lib/sources/graphics/context.cpp | 2 +- .../sources/graphics/gl/context_gl.cpp | 5 +++- .../platform/common/platform_common.cpp | 5 ++++ .../sources/platform/sdl/gl_wrap.cpp | 14 +++++++++-- .../sources/platform/sdl/window_gl.cpp | 5 +++- .../sources/streflop/CMakeLists.txt | 2 +- 14 files changed, 103 insertions(+), 22 deletions(-) diff --git a/mk/cmake/Modules/SpecialMacros.cmake b/mk/cmake/Modules/SpecialMacros.cmake index 988306611..4003e506d 100644 --- a/mk/cmake/Modules/SpecialMacros.cmake +++ b/mk/cmake/Modules/SpecialMacros.cmake @@ -3,13 +3,13 @@ include(CheckFunctionExists) include(AddFileDependencies) -macro(special_add_library lib) - if (WIN32) - add_library(${lib} STATIC ${ARGN}) - else (WIN32) - add_library(${lib} SHARED ${ARGN}) - endif (WIN32) -endmacro(special_add_library) +#macro(special_add_library lib) +# if (WIN32) +# add_library(${lib} STATIC ${ARGN}) +# else (WIN32) +# add_library(${lib} SHARED ${ARGN}) +# endif (WIN32) +#endmacro(special_add_library) macro(special_check_for_sse _max_sse_level_desired) set(${_max_sse_level_desired}) @@ -78,6 +78,9 @@ macro(special_check_for_sse _max_sse_level_desired) set(SSE_FLAGS "-msse -mfpmath=sse") message(STATUS "Found SSE extensions, using flags: ${SSE_FLAGS}") endif() + + add_definitions(${SSE_FLAGS}) + elseif(MSVC) check_cxx_source_runs(" #include @@ -96,6 +99,8 @@ macro(special_check_for_sse _max_sse_level_desired) message(STATUS "Found SSE2 extensions") set(SSE_FLAGS "/arch:SSE2 /fp:fast -D__SSE__ -D__SSE2__" ) endif() + + add_definitions(${SSE_FLAGS}) endif() endmacro(special_check_for_sse) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 346b5b5f5..2d5936ff6 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -212,7 +212,7 @@ void fatal(const char *s, ...) // failure exit if(SDL_WasInit(SDL_INIT_VIDEO)) { SDL_ShowCursor(1); SDL_WM_GrabInput(SDL_GRAB_OFF); - SDL_SetGamma(1, 1, 1); + //SDL_SetGamma(1, 1, 1); } #ifdef WIN32 LPWSTR wstr = Ansi2WideString(errText.c_str()); @@ -2802,6 +2802,29 @@ int glestMain(int argc, char** argv) { } } + if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SET_GAMMA]) == true) { + int foundParamIndIndex = -1; + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SET_GAMMA]) + string("="),&foundParamIndIndex); + if(foundParamIndIndex < 0) { + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SET_GAMMA]),&foundParamIndIndex); + } + string paramValue = argv[foundParamIndIndex]; + vector paramPartTokens; + Tokenize(paramValue,paramPartTokens,"="); + if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) { + string settings = paramPartTokens[1]; + printf("Forcing gamma [%s]\n",settings.c_str()); + + float newGammaValue = strToFloat(settings); + config.setFloat("GammaValue",newGammaValue); + } + else { + printf("\nInvalid missing gamma setting specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); + //printParameterHelp(argv[0],false); + return -1; + } + } + // Set some statics based on ini entries SystemFlags::ENABLE_THREADED_LOGGING = config.getBool("ThreadedLogging","true"); FontGl::setDefault_fontType(config.getString("DefaultFont",FontGl::getDefault_fontType().c_str())); diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index 278fff339..6bf6b07f8 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -609,7 +609,12 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - window->initGl(config.getInt("ColorBits"), config.getInt("DepthBits"), config.getInt("StencilBits"),config.getBool("HardwareAcceleration","false"),config.getBool("FullScreenAntiAliasing","false")); + window->initGl(config.getInt("ColorBits"), + config.getInt("DepthBits"), + config.getInt("StencilBits"), + config.getBool("HardwareAcceleration","false"), + config.getBool("FullScreenAntiAliasing","false"), + config.getFloat("GammaValue","0.0")); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -742,7 +747,12 @@ void Program::resetSoundSystem() { void Program::reInitGl() { if(window != NULL) { Config &config= Config::getInstance(); - window->initGl(config.getInt("ColorBits"), config.getInt("DepthBits"), config.getInt("StencilBits"),config.getBool("HardwareAcceleration","false"),config.getBool("FullScreenAntiAliasing","false")); + window->initGl(config.getInt("ColorBits"), + config.getInt("DepthBits"), + config.getInt("StencilBits"), + config.getBool("HardwareAcceleration","false"), + config.getBool("FullScreenAntiAliasing","false"), + config.getFloat("GammaValue","0.0")); } } diff --git a/source/shared_lib/CMakeLists.txt b/source/shared_lib/CMakeLists.txt index e0924c051..455a77bbc 100644 --- a/source/shared_lib/CMakeLists.txt +++ b/source/shared_lib/CMakeLists.txt @@ -348,9 +348,9 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST ENDIF() # FIXME: hackish... - IF(WANT_STREFLOP) - SET(STREFLOP_PROPERTIES "-DSTREFLOP_SSE -DLIBM_COMPILING_FLT32") - ENDIF() +# IF(WANT_STREFLOP) +# SET(STREFLOP_PROPERTIES "-DSTREFLOP_SSE -DLIBM_COMPILING_FLT32") +# ENDIF() SET_SOURCE_FILES_PROPERTIES(${MG_SOURCE_FILES} PROPERTIES COMPILE_FLAGS "${PLATFORM_SPECIFIC_DEFINES} ${STREFLOP_PROPERTIES} ${CXXFLAGS}") diff --git a/source/shared_lib/include/graphics/context.h b/source/shared_lib/include/graphics/context.h index 951bdcd51..962ec36de 100644 --- a/source/shared_lib/include/graphics/context.h +++ b/source/shared_lib/include/graphics/context.h @@ -31,6 +31,7 @@ protected: uint32 stencilBits; int8 hardware_acceleration; int8 fullscreen_anti_aliasing; + float gammaValue; public: Context(); @@ -41,12 +42,14 @@ public: uint32 getStencilBits() const {return stencilBits;} int8 getHardware_acceleration() const { return hardware_acceleration; } int8 getFullscreen_anti_aliasing() const { return fullscreen_anti_aliasing; } + float getGammaValue() const { return gammaValue; } void setColorBits(uint32 colorBits) {this->colorBits= colorBits;} void setDepthBits(uint32 depthBits) {this->depthBits= depthBits;} void setStencilBits(uint32 stencilBits) {this->stencilBits= stencilBits;} void setHardware_acceleration(int8 value) { hardware_acceleration = value; } void setFullscreen_anti_aliasing(int8 value) { fullscreen_anti_aliasing = value; } + void setGammaValue(float value) { gammaValue = value; } virtual void init()= 0; virtual void end()= 0; diff --git a/source/shared_lib/include/platform/sdl/gl_wrap.h b/source/shared_lib/include/platform/sdl/gl_wrap.h index 2ffac49aa..b54f5da34 100644 --- a/source/shared_lib/include/platform/sdl/gl_wrap.h +++ b/source/shared_lib/include/platform/sdl/gl_wrap.h @@ -51,7 +51,9 @@ public: PlatformContextGl(); virtual ~PlatformContextGl(); - virtual void init(int colorBits, int depthBits, int stencilBits,bool hardware_acceleration, bool fullscreen_anti_aliasing); + virtual void init(int colorBits, int depthBits, int stencilBits, + bool hardware_acceleration, bool fullscreen_anti_aliasing, + float gammaValue); virtual void end(); virtual void makeCurrent(); diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index b332c8ff4..587281f64 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -64,6 +64,7 @@ const char *GAME_ARGS[] = { "--colorbits", "--depthbits", "--fullscreen", + "--set-gamma", "--use-font", "--font-basesize", @@ -115,10 +116,13 @@ enum GAME_ARG_TYPE { GAME_ARG_USE_COLORBITS, GAME_ARG_USE_DEPTHBITS, GAME_ARG_USE_FULLSCREEN, + GAME_ARG_SET_GAMMA, GAME_ARG_USE_FONT, GAME_ARG_FONT_BASESIZE, - GAME_ARG_VERBOSE_MODE + GAME_ARG_VERBOSE_MODE, + + GAME_ARG_END }; void printParameterHelp(const char *argv0, bool foundInvalidArgs) { @@ -323,6 +327,10 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\tWhere x either true or false"); printf("\n \t\texample: %s %s=true",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_USE_FULLSCREEN]); + printf("\n%s=x\t\t\toverride the video gamma (contrast) value.",GAME_ARGS[GAME_ARG_SET_GAMMA]); + printf("\n \t\tWhere x a floating point value"); + printf("\n \t\texample: %s %s=1.5",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_SET_GAMMA]); + printf("\n%s=x\t\t\toverride the font to use.",GAME_ARGS[GAME_ARG_USE_FONT]); printf("\n \t\tWhere x is the path and name of a font file supported"); printf("\n \t\t by freetype2."); @@ -365,6 +373,13 @@ bool hasCommandArgument(int argc, char** argv,const string argName, int *foundIn int mainSetup(int argc, char **argv) { bool haveSpecialOutputCommandLineOption = false; + const int knownArgCount = sizeof(GAME_ARGS) / sizeof(GAME_ARGS[0]); + if(knownArgCount != GAME_ARG_END) { + char szBuf[1024]=""; + sprintf(szBuf,"Internal arg count mismatch knownArgCount = %d, GAME_ARG_END = %d",knownArgCount,GAME_ARG_END); + throw runtime_error(""); + } + if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_OPENGL_INFO]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SDL_INFO]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LUA_INFO]) == true || diff --git a/source/shared_lib/include/platform/sdl/window_gl.h b/source/shared_lib/include/platform/sdl/window_gl.h index b9dc2a80b..28597846f 100644 --- a/source/shared_lib/include/platform/sdl/window_gl.h +++ b/source/shared_lib/include/platform/sdl/window_gl.h @@ -29,7 +29,9 @@ private: ContextGl context; public: - void initGl(int colorBits, int depthBits, int stencilBits,bool hardware_acceleration, bool fullscreen_anti_aliasing); + void initGl(int colorBits, int depthBits, int stencilBits, + bool hardware_acceleration, bool fullscreen_anti_aliasing, + float gammaValue); void makeCurrentGl(); void swapBuffersGl(); }; diff --git a/source/shared_lib/sources/graphics/context.cpp b/source/shared_lib/sources/graphics/context.cpp index f1d059162..096d8878a 100644 --- a/source/shared_lib/sources/graphics/context.cpp +++ b/source/shared_lib/sources/graphics/context.cpp @@ -25,7 +25,7 @@ Context::Context() { stencilBits= 0; hardware_acceleration=0; fullscreen_anti_aliasing=0; - + gammaValue=0; } }}//end namespace diff --git a/source/shared_lib/sources/graphics/gl/context_gl.cpp b/source/shared_lib/sources/graphics/gl/context_gl.cpp index 0bace788f..cbb7d3283 100644 --- a/source/shared_lib/sources/graphics/gl/context_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/context_gl.cpp @@ -32,7 +32,10 @@ ContextGl::ContextGl() : Context() { } void ContextGl::init() { - pcgl.init(colorBits, depthBits, stencilBits, (hardware_acceleration != 0), (fullscreen_anti_aliasing != 0)); + + pcgl.init(colorBits, depthBits, stencilBits, + (hardware_acceleration != 0), (fullscreen_anti_aliasing != 0), + gammaValue); } ContextGl::~ContextGl() { diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 9ed0f029f..967180107 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -1587,6 +1587,11 @@ bool changeVideoMode(int resW, int resH, int colorBits, int ) { void restoreVideoMode(bool exitingApp) { //SDL_Quit(); + if(exitingApp == true && SDL_WasInit(SDL_INIT_VIDEO)) { + SDL_ShowCursor(1); + SDL_WM_GrabInput(SDL_GRAB_OFF); + SDL_SetGamma(1, 1, 1); + } } int getScreenW() { diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index 692d0655b..e9ac71083 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -50,7 +50,9 @@ PlatformContextGl::~PlatformContextGl() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } -void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool hardware_acceleration, bool fullscreen_anti_aliasing) { +void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits, + bool hardware_acceleration, + bool fullscreen_anti_aliasing, float gammaValue) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -209,7 +211,15 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool //fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); int bufferSize = (resW * resH * BaseColorPickEntity::COLOR_COMPONENTS); - BaseColorPickEntity::init(bufferSize); + BaseColorPickEntity::init(bufferSize); + + if(gammaValue != 0.0) { + //printf("Attempting to call SDL_SetGamma using value %f\n", gammaValue); + + if (SDL_SetGamma(gammaValue, gammaValue, gammaValue) < 0) { + printf("WARNING, SDL_SetGamma failed using value %f [%s]\n", gammaValue,SDL_GetError()); + } + } } } diff --git a/source/shared_lib/sources/platform/sdl/window_gl.cpp b/source/shared_lib/sources/platform/sdl/window_gl.cpp index 6b0acd660..05cfe766c 100644 --- a/source/shared_lib/sources/platform/sdl/window_gl.cpp +++ b/source/shared_lib/sources/platform/sdl/window_gl.cpp @@ -22,12 +22,15 @@ namespace Shared{ namespace Platform{ // class WindowGl // ===================================================== -void WindowGl::initGl(int colorBits, int depthBits, int stencilBits,bool hardware_acceleration, bool fullscreen_anti_aliasing){ +void WindowGl::initGl(int colorBits, int depthBits, int stencilBits, + bool hardware_acceleration, bool fullscreen_anti_aliasing, + float gammaValue) { context.setColorBits(colorBits); context.setDepthBits(depthBits); context.setStencilBits(stencilBits); context.setHardware_acceleration(hardware_acceleration); context.setFullscreen_anti_aliasing(fullscreen_anti_aliasing); + context.setGammaValue(gammaValue); context.init(); } diff --git a/source/shared_lib/sources/streflop/CMakeLists.txt b/source/shared_lib/sources/streflop/CMakeLists.txt index 3a7717e10..0cc9027c4 100644 --- a/source/shared_lib/sources/streflop/CMakeLists.txt +++ b/source/shared_lib/sources/streflop/CMakeLists.txt @@ -13,7 +13,7 @@ INCLUDE_DIRECTORIES( SET(STREFLOP_SRC ${STREFLOP_GLOBBED_CPP}) # use SSE unconditionally (FIXME?) -SET_SOURCE_FILES_PROPERTIES(${STREFLOP_SRC} PROPERTIES COMPILE_FLAGS "-DSTREFLOP_SSE -DLIBM_COMPILING_FLT32 -O3 ${CXXFLAGS}") +#SET_SOURCE_FILES_PROPERTIES(${STREFLOP_SRC} PROPERTIES COMPILE_FLAGS "-DSTREFLOP_SSE -DLIBM_COMPILING_FLT32 -O3 ${CXXFLAGS}") ADD_LIBRARY(streflop STATIC EXCLUDE_FROM_ALL ${STREFLOP_SRC}