- 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
This commit is contained in:
Mark Vejvoda
2011-12-23 08:20:54 +00:00
parent f38c8c9f63
commit 2e94c32d59
14 changed files with 103 additions and 22 deletions

View File

@@ -3,13 +3,13 @@
include(CheckFunctionExists) include(CheckFunctionExists)
include(AddFileDependencies) include(AddFileDependencies)
macro(special_add_library lib) #macro(special_add_library lib)
if (WIN32) # if (WIN32)
add_library(${lib} STATIC ${ARGN}) # add_library(${lib} STATIC ${ARGN})
else (WIN32) # else (WIN32)
add_library(${lib} SHARED ${ARGN}) # add_library(${lib} SHARED ${ARGN})
endif (WIN32) # endif (WIN32)
endmacro(special_add_library) #endmacro(special_add_library)
macro(special_check_for_sse _max_sse_level_desired) macro(special_check_for_sse _max_sse_level_desired)
set(${_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") set(SSE_FLAGS "-msse -mfpmath=sse")
message(STATUS "Found SSE extensions, using flags: ${SSE_FLAGS}") message(STATUS "Found SSE extensions, using flags: ${SSE_FLAGS}")
endif() endif()
add_definitions(${SSE_FLAGS})
elseif(MSVC) elseif(MSVC)
check_cxx_source_runs(" check_cxx_source_runs("
#include <emmintrin.h> #include <emmintrin.h>
@@ -96,6 +99,8 @@ macro(special_check_for_sse _max_sse_level_desired)
message(STATUS "Found SSE2 extensions") message(STATUS "Found SSE2 extensions")
set(SSE_FLAGS "/arch:SSE2 /fp:fast -D__SSE__ -D__SSE2__" ) set(SSE_FLAGS "/arch:SSE2 /fp:fast -D__SSE__ -D__SSE2__" )
endif() endif()
add_definitions(${SSE_FLAGS})
endif() endif()
endmacro(special_check_for_sse) endmacro(special_check_for_sse)

View File

@@ -212,7 +212,7 @@ void fatal(const char *s, ...) // failure exit
if(SDL_WasInit(SDL_INIT_VIDEO)) { if(SDL_WasInit(SDL_INIT_VIDEO)) {
SDL_ShowCursor(1); SDL_ShowCursor(1);
SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_WM_GrabInput(SDL_GRAB_OFF);
SDL_SetGamma(1, 1, 1); //SDL_SetGamma(1, 1, 1);
} }
#ifdef WIN32 #ifdef WIN32
LPWSTR wstr = Ansi2WideString(errText.c_str()); 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<string> 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 // Set some statics based on ini entries
SystemFlags::ENABLE_THREADED_LOGGING = config.getBool("ThreadedLogging","true"); SystemFlags::ENABLE_THREADED_LOGGING = config.getBool("ThreadedLogging","true");
FontGl::setDefault_fontType(config.getString("DefaultFont",FontGl::getDefault_fontType().c_str())); FontGl::setDefault_fontType(config.getString("DefaultFont",FontGl::getDefault_fontType().c_str()));

View File

@@ -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__); 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__); 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() { void Program::reInitGl() {
if(window != NULL) { if(window != NULL) {
Config &config= Config::getInstance(); 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"));
} }
} }

View File

@@ -348,9 +348,9 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST
ENDIF() ENDIF()
# FIXME: hackish... # FIXME: hackish...
IF(WANT_STREFLOP) # IF(WANT_STREFLOP)
SET(STREFLOP_PROPERTIES "-DSTREFLOP_SSE -DLIBM_COMPILING_FLT32") # SET(STREFLOP_PROPERTIES "-DSTREFLOP_SSE -DLIBM_COMPILING_FLT32")
ENDIF() # ENDIF()
SET_SOURCE_FILES_PROPERTIES(${MG_SOURCE_FILES} PROPERTIES COMPILE_FLAGS SET_SOURCE_FILES_PROPERTIES(${MG_SOURCE_FILES} PROPERTIES COMPILE_FLAGS
"${PLATFORM_SPECIFIC_DEFINES} ${STREFLOP_PROPERTIES} ${CXXFLAGS}") "${PLATFORM_SPECIFIC_DEFINES} ${STREFLOP_PROPERTIES} ${CXXFLAGS}")

View File

@@ -31,6 +31,7 @@ protected:
uint32 stencilBits; uint32 stencilBits;
int8 hardware_acceleration; int8 hardware_acceleration;
int8 fullscreen_anti_aliasing; int8 fullscreen_anti_aliasing;
float gammaValue;
public: public:
Context(); Context();
@@ -41,12 +42,14 @@ public:
uint32 getStencilBits() const {return stencilBits;} uint32 getStencilBits() const {return stencilBits;}
int8 getHardware_acceleration() const { return hardware_acceleration; } int8 getHardware_acceleration() const { return hardware_acceleration; }
int8 getFullscreen_anti_aliasing() const { return fullscreen_anti_aliasing; } int8 getFullscreen_anti_aliasing() const { return fullscreen_anti_aliasing; }
float getGammaValue() const { return gammaValue; }
void setColorBits(uint32 colorBits) {this->colorBits= colorBits;} void setColorBits(uint32 colorBits) {this->colorBits= colorBits;}
void setDepthBits(uint32 depthBits) {this->depthBits= depthBits;} void setDepthBits(uint32 depthBits) {this->depthBits= depthBits;}
void setStencilBits(uint32 stencilBits) {this->stencilBits= stencilBits;} void setStencilBits(uint32 stencilBits) {this->stencilBits= stencilBits;}
void setHardware_acceleration(int8 value) { hardware_acceleration = value; } void setHardware_acceleration(int8 value) { hardware_acceleration = value; }
void setFullscreen_anti_aliasing(int8 value) { fullscreen_anti_aliasing = value; } void setFullscreen_anti_aliasing(int8 value) { fullscreen_anti_aliasing = value; }
void setGammaValue(float value) { gammaValue = value; }
virtual void init()= 0; virtual void init()= 0;
virtual void end()= 0; virtual void end()= 0;

View File

@@ -51,7 +51,9 @@ public:
PlatformContextGl(); PlatformContextGl();
virtual ~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 end();
virtual void makeCurrent(); virtual void makeCurrent();

View File

@@ -64,6 +64,7 @@ const char *GAME_ARGS[] = {
"--colorbits", "--colorbits",
"--depthbits", "--depthbits",
"--fullscreen", "--fullscreen",
"--set-gamma",
"--use-font", "--use-font",
"--font-basesize", "--font-basesize",
@@ -115,10 +116,13 @@ enum GAME_ARG_TYPE {
GAME_ARG_USE_COLORBITS, GAME_ARG_USE_COLORBITS,
GAME_ARG_USE_DEPTHBITS, GAME_ARG_USE_DEPTHBITS,
GAME_ARG_USE_FULLSCREEN, GAME_ARG_USE_FULLSCREEN,
GAME_ARG_SET_GAMMA,
GAME_ARG_USE_FONT, GAME_ARG_USE_FONT,
GAME_ARG_FONT_BASESIZE, GAME_ARG_FONT_BASESIZE,
GAME_ARG_VERBOSE_MODE GAME_ARG_VERBOSE_MODE,
GAME_ARG_END
}; };
void printParameterHelp(const char *argv0, bool foundInvalidArgs) { 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\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 \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%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\tWhere x is the path and name of a font file supported");
printf("\n \t\t by freetype2."); 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) { int mainSetup(int argc, char **argv) {
bool haveSpecialOutputCommandLineOption = false; 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 || 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_SDL_INFO]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LUA_INFO]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LUA_INFO]) == true ||

View File

@@ -29,7 +29,9 @@ private:
ContextGl context; ContextGl context;
public: 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 makeCurrentGl();
void swapBuffersGl(); void swapBuffersGl();
}; };

View File

@@ -25,7 +25,7 @@ Context::Context() {
stencilBits= 0; stencilBits= 0;
hardware_acceleration=0; hardware_acceleration=0;
fullscreen_anti_aliasing=0; fullscreen_anti_aliasing=0;
gammaValue=0;
} }
}}//end namespace }}//end namespace

View File

@@ -32,7 +32,10 @@ ContextGl::ContextGl() : Context() {
} }
void ContextGl::init() { 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() { ContextGl::~ContextGl() {

View File

@@ -1587,6 +1587,11 @@ bool changeVideoMode(int resW, int resH, int colorBits, int ) {
void restoreVideoMode(bool exitingApp) { void restoreVideoMode(bool exitingApp) {
//SDL_Quit(); //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() { int getScreenW() {

View File

@@ -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__); 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__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -210,6 +212,14 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool
int bufferSize = (resW * resH * BaseColorPickEntity::COLOR_COMPONENTS); 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());
}
}
} }
} }

View File

@@ -22,12 +22,15 @@ namespace Shared{ namespace Platform{
// class WindowGl // 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.setColorBits(colorBits);
context.setDepthBits(depthBits); context.setDepthBits(depthBits);
context.setStencilBits(stencilBits); context.setStencilBits(stencilBits);
context.setHardware_acceleration(hardware_acceleration); context.setHardware_acceleration(hardware_acceleration);
context.setFullscreen_anti_aliasing(fullscreen_anti_aliasing); context.setFullscreen_anti_aliasing(fullscreen_anti_aliasing);
context.setGammaValue(gammaValue);
context.init(); context.init();
} }

View File

@@ -13,7 +13,7 @@ INCLUDE_DIRECTORIES(
SET(STREFLOP_SRC ${STREFLOP_GLOBBED_CPP}) SET(STREFLOP_SRC ${STREFLOP_GLOBBED_CPP})
# use SSE unconditionally (FIXME?) # 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 ADD_LIBRARY(streflop STATIC EXCLUDE_FROM_ALL
${STREFLOP_SRC} ${STREFLOP_SRC}