From f1d55414cdff150a68f63c36169b0b4719e6cefd Mon Sep 17 00:00:00 2001 From: torcs-ng Date: Thu, 21 Jun 2012 20:04:09 +0000 Subject: [PATCH] add bump mapping openglconfig git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@4759 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: af21243702e63a47285948c6b710b0b711b70d05 Former-commit-id: b2b3d06edf27e69bf9cce4b88cceaa0919f3bba1 --- src/libs/tgfclient/glfeatures.cpp | 62 ++++++++++++++++--- src/libs/tgfclient/glfeatures.h | 9 +-- src/libs/tgfclient/guiscreen.h | 4 ++ .../legacymenu/confscreens/openglconfig.cpp | 55 ++++++++++++++++ 4 files changed, 117 insertions(+), 13 deletions(-) diff --git a/src/libs/tgfclient/glfeatures.cpp b/src/libs/tgfclient/glfeatures.cpp index 2e87b2574..2a5561846 100644 --- a/src/libs/tgfclient/glfeatures.cpp +++ b/src/libs/tgfclient/glfeatures.cpp @@ -167,11 +167,20 @@ void GfglFeatures::detectStandardSupport() // 9) Stereo Vision (need a proper check) _mapSupportedBool[StereoVision] = false; + + //10) Bump Mapping + bool bValueBump = gfglIsOpenGLExtensionSupported("GL_ARB_multitexture") && + gfglIsOpenGLExtensionSupported("GL_ARB_texture_cube_map") && + gfglIsOpenGLExtensionSupported("GL_ARB_texture_env_combine") && + gfglIsOpenGLExtensionSupported("GL_ARB_texture_env_dot3") && + gfglIsOpenGLExtensionSupported("GL_ARB_imaging"); + + _mapSupportedBool[BumpMapping] = bValueBump; } // Best supported features detection for the given specs of the frame buffer. bool GfglFeatures::detectBestSupport(int& nWidth, int& nHeight, int& nDepth, - bool& bAlpha, bool& bFullScreen, bool& bStereoVision) + bool& bAlpha, bool& bFullScreen, bool& bBumpMapping, bool& bStereoVision) { GfLogInfo("Detecting best supported features for a %dx%dx%d%s frame buffer.\n", nWidth, nHeight, nDepth, bFullScreen ? " full-screen" : ""); @@ -185,6 +194,7 @@ bool GfglFeatures::detectBestSupport(int& nWidth, int& nHeight, int& nDepth, int nAlphaChannel = bAlpha ? 1 : 0; int nCurrDepth = nDepth; int nFullScreen = bFullScreen ? 1 : 0; + int nBump = bBumpMapping ? 1 : 0; int nStereoVision = bStereoVision ? 1 : 0; while (!pWinSurface && nFullScreen >= 0) @@ -324,7 +334,7 @@ bool GfglFeatures::detectBestSupport(int& nWidth, int& nHeight, int& nDepth, } bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth, - bool &bAlpha, bool &bFullScreen, bool &bStereo, void* hparmConfig) + bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, void* hparmConfig) { // Clear support data. _mapSupportedBool.clear(); @@ -349,6 +359,9 @@ bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth, bStereo = std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION, GFSCR_VAL_NO)) == GFSCR_VAL_YES; + bBump = + std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BUMPMAPPING, GFSCR_VAL_NO)) + == GFSCR_VAL_YES; // Check that we have something supported, and return if not. if (nWidth == 0 || nHeight == 0 || nDepth == 0) @@ -455,6 +468,14 @@ bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth, _mapSupportedBool[StereoVision] = true; else if (strStereoVision == GFSCR_VAL_NO) _mapSupportedBool[StereoVision] = false; + + // 11) Bump Mapping. + const std::string strBumpMapping = + GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING, ""); + if (strTexComp == GFSCR_VAL_YES) + _mapSupportedBool[BumpMapping] = true; + else if (strTexComp == GFSCR_VAL_NO) + _mapSupportedBool[BumpMapping] = false; // Close config file if we open it. if (!hparmConfig) @@ -467,7 +488,7 @@ bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth, } void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth, - bool bAlpha, bool bFullScreen, bool bStereo, void* hparmConfig) + bool bAlpha, bool bFullScreen, bool bBump, bool bStereo, void* hparmConfig) { // Open the config file if not already done. void* hparm = hparmConfig ? hparmConfig : openConfigFile(); @@ -498,6 +519,8 @@ void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth, bFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO); GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION, bStereo ? GFSCR_VAL_YES : GFSCR_VAL_NO); + GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BUMPMAPPING, + bBump ? GFSCR_VAL_YES : GFSCR_VAL_NO); // Write new values (remove the ones with no value supported). // 1) Double-buffer. @@ -559,7 +582,12 @@ void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth, // 10) Stereo Vision GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_STEREOVISION, isSupported(StereoVision) ? GFSCR_VAL_YES : GFSCR_VAL_NO); - } + + // 11) Bump Mapping + GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING, + isSupported(BumpMapping) ? GFSCR_VAL_YES : GFSCR_VAL_NO); + + } // Write new params to config file. GfParmWriteFile(NULL, hparm, "Screen"); @@ -573,7 +601,7 @@ void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth, } bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth, - bool bAlpha, bool bFullScreen, bool bStereo, void* hparmConfig) + bool bAlpha, bool bFullScreen, bool bBump, bool bStereo, void* hparmConfig) { // Open the config file if not already done. void* hparm = hparmConfig ? hparmConfig : openConfigFile(); @@ -581,9 +609,9 @@ bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth, // Get the frame buffer specs that are associated with the detected // Open GL features in the config file, if any. int nDetWidth, nDetHeight, nDetDepth; - bool bDetFullScreen, bDetAlpha, bDetStereo; + bool bDetFullScreen, bDetAlpha, bDetBump, bDetStereo; bool bPrevSupportFound = - loadSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetStereo, hparm); + loadSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, hparm); // Compare with the requested frame buffer specs // and run a new supported feature detection if any diffference. @@ -597,11 +625,12 @@ bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth, bDetFullScreen = bFullScreen; bDetAlpha = bAlpha; bDetStereo = bStereo; + bDetBump = bBump; bSupportFound = - detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetStereo); + detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo); // Store support data in any case. - storeSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetStereo, hparm); + storeSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, hparm); // If frame buffer specs supported, update relevant user settings and restart. if (bSupportFound) @@ -692,6 +721,8 @@ void GfglFeatures::dumpSupport() const GfLogInfo("\n"); GfLogInfo(" Stereo Vision : %s\n", isSupported(StereoVision) ? "Yes" : "No"); + GfLogInfo(" Bump Mapping : %s\n", + isSupported(BumpMapping) ? "Yes" : "No"); } // Load the selected OpenGL features from the config file. @@ -770,6 +801,13 @@ void GfglFeatures::loadSelection(void* hparmConfig) GFSCR_ATT_STEREOVISION_ENABLED)) == GFSCR_ATT_STEREOVISION_ENABLED; + // 11) Bump Mapping : load from config file. + _mapSelectedBool[BumpMapping] = + isSupported(BumpMapping) + && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_BUMPMAPPING, + GFSCR_ATT_BUMPMAPPING_ENABLED)) + == GFSCR_ATT_BUMPMAPPING_ENABLED; + // Close config file if we open it. if (!hparmConfig) closeConfigFile(hparm); @@ -810,6 +848,7 @@ void GfglFeatures::storeSelection(void* hparmConfig) const else GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES); + // Force 'best possible' mode for video initialization when anti-aliasing selected if (isSelected(MultiSampling)) { @@ -836,6 +875,10 @@ void GfglFeatures::storeSelection(void* hparmConfig) const GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_STEREOVISION, isSelected(StereoVision) ? GFSCR_ATT_STEREOVISION_ENABLED : GFSCR_ATT_STEREOVISION_DISABLED); + + GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_BUMPMAPPING, + isSelected(BumpMapping) + ? GFSCR_ATT_BUMPMAPPING_ENABLED : GFSCR_ATT_BUMPMAPPING_DISABLED); // Write new params to config file. GfParmWriteFile(NULL, hparm, "Screen"); @@ -874,6 +917,7 @@ void GfglFeatures::dumpSelection() const GfLogInfo(" (%d samples)", getSelected(MultiSamplingSamples)); GfLogInfo("\n"); GfLogInfo(" Stereo vision : %s\n", isSelected(StereoVision) ? "On" : "Off"); + GfLogInfo(" Bump Mapping : %s\n", isSelected(BumpMapping) ? "On" : "Off"); } // Bool features management. diff --git a/src/libs/tgfclient/glfeatures.h b/src/libs/tgfclient/glfeatures.h index 1d18fc9bb..ac6c95ab0 100644 --- a/src/libs/tgfclient/glfeatures.h +++ b/src/libs/tgfclient/glfeatures.h @@ -66,7 +66,7 @@ class TGFCLIENT_API GfglFeatures // Check best supported OpenGL features, and store report to the config file // (default = GFSCR_CONF_FILE). May restart the game. bool checkBestSupport(int nWidth, int nHeight, int nDepth, - bool bAlpha, bool bFullScreen, bool bStereo, void* hparmConfig = 0); + bool bAlpha, bool bFullScreen, bool bBump, bool bStereo, void* hparmConfig = 0); // Detect standard supported features. Don't restart the game. // Precondiftion: SDL_setVideoMode(...) @@ -99,6 +99,7 @@ class TGFCLIENT_API GfglFeatures TextureNonPowerOf2, // GL_ARB_texture_non_power_of_two, in case mipmapping needed. MultiTexturing, // GL_ARB_multitexture MultiSampling, // GL_ARB_multisample + BumpMapping, // Bump Mapping StereoVision // StereoVision }; void select(EFeatureBool eFeature, bool bSelected); @@ -128,13 +129,13 @@ class TGFCLIENT_API GfglFeatures // Update supported OpenGL features according to the given frame buffer specs. bool detectBestSupport(int& nWidth, int& nHeight, int& nDepth, - bool& bAlpha, bool& bStereo, bool& bFullScreen); + bool& bAlpha, bool& bBump, bool& bStereo, bool& bFullScreen); bool loadSupport(int &nWidth, int &nHeight, int &nDepth, - bool &bAlpha, bool &bFullScreen, bool &bStereo, void* hparmConfig = 0); + bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, void* hparmConfig = 0); void storeSupport(int nWidth, int nHeight, int nDepth, - bool bAlpha, bool bFullScreen, bool bStereo, void* hparmConfig = 0); + bool bAlpha, bool bFullScreen, bool bBump, bool bStereo, void* hparmConfig = 0); static void* openConfigFile(); static void closeConfigFile(void* hparmConfig, bool bWrite = false); diff --git a/src/libs/tgfclient/guiscreen.h b/src/libs/tgfclient/guiscreen.h index c22145188..8a1d075f1 100644 --- a/src/libs/tgfclient/guiscreen.h +++ b/src/libs/tgfclient/guiscreen.h @@ -122,6 +122,10 @@ #define GFSCR_ATT_TEXTURECOMPRESSION_ENABLED "enabled" #define GFSCR_ATT_TEXTURECOMPRESSION_DISABLED "disabled" +#define GFSCR_ATT_BUMPMAPPING "bump mapping" +#define GFSCR_ATT_BUMPMAPPING_ENABLED "enabled" +#define GFSCR_ATT_BUMPMAPPING_DISABLED "disabled" + #define GFSCR_ATT_MAXTEXTURESIZE "max texture size" #define GFSCR_ATT_MULTITEXTURING "multi-texturing" diff --git a/src/modules/userinterface/legacymenu/confscreens/openglconfig.cpp b/src/modules/userinterface/legacymenu/confscreens/openglconfig.cpp index 1d835dbc7..0ed937db2 100644 --- a/src/modules/userinterface/legacymenu/confscreens/openglconfig.cpp +++ b/src/modules/userinterface/legacymenu/confscreens/openglconfig.cpp @@ -47,6 +47,16 @@ static int TextureCompLabelId; static int TextureCompLeftButtonId; static int TextureCompRightButtonId; +// Bump Mapping. +static const char *ABumpMappingTexts[] = + {GFSCR_ATT_BUMPMAPPING_DISABLED, GFSCR_ATT_BUMPMAPPING_ENABLED}; +static const int NBumpMapping = + sizeof(ABumpMappingTexts) / sizeof(ABumpMappingTexts[0]); +static int NCurBumpMappingIndex = 0; +static int BumpMappingLabelId; +static int BumpMappingLeftButtonId; +static int BumpMappingRightButtonId; + // Max texture size (WARNING: the order in the list is important, do not change). static int AMaxTextureSizeTexts[] = {8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384}; static int NMaxTextureSizes = sizeof(AMaxTextureSizeTexts) / sizeof(AMaxTextureSizeTexts[0]); @@ -100,6 +110,9 @@ static void onAccept(void *) GfglFeatures::self().select(GfglFeatures::MultiSamplingSamples, (int)pow(2.0, (double)NCurMultiSampleIndex)); + GfglFeatures::self().select(GfglFeatures::BumpMapping, strcmp(ABumpMappingTexts[NCurBumpMappingIndex], + GFSCR_ATT_BUMPMAPPING_ENABLED) ? false : true); + // Store settings from the GL features layer to the screen.xml file. GfglFeatures::self().storeSelection(); @@ -161,6 +174,13 @@ static void changeMaxTextureSizeState(void *vp) GfuiLabelSetText(ScrHandle, MaxTextureSizeLabelId, valuebuf); } +// Toggle texture compression state enabled/disabled. +static void changeBumpMappingState(void *vp) +{ + NCurBumpMappingIndex = (NCurBumpMappingIndex + (int)(long)vp + NBumpMapping) % NBumpMapping; + GfuiLabelSetText(ScrHandle, BumpMappingLabelId, ABumpMappingTexts[NCurBumpMappingIndex]); +} + static void onActivate(void * /* dummy */) { @@ -296,6 +316,32 @@ static void onActivate(void * /* dummy */) GfuiEnable(ScrHandle, MultiSampleRightButtonId, GFUI_DISABLE); GfuiLabelSetText(ScrHandle, MultiSampleLabelId, "Not supported"); } + + // Initialize current state and GUI from the GL features layer. + // 6) Bump Mapping. + if (GfglFeatures::self().isSupported(GfglFeatures::BumpMapping)) + { + const char *pszBumpMapping = + GfglFeatures::self().isSelected(GfglFeatures::BumpMapping) + ? GFSCR_ATT_BUMPMAPPING_ENABLED : GFSCR_ATT_BUMPMAPPING_DISABLED; + for (i = 0; i < NBumpMapping; i++) + { + if (!strcmp(pszBumpMapping, ABumpMappingTexts[i])) + { + NCurBumpMappingIndex = i; + break; + } + } + + GfuiLabelSetText(ScrHandle, BumpMappingLabelId, + ABumpMappingTexts[NCurBumpMappingIndex]); + } + else + { + GfuiEnable(ScrHandle, BumpMappingLeftButtonId, GFUI_DISABLE); + GfuiEnable(ScrHandle, BumpMappingRightButtonId, GFUI_DISABLE); + GfuiLabelSetText(ScrHandle, BumpMappingLabelId, "Not supported"); + } } // OpenGL menu @@ -345,6 +391,15 @@ void* OpenGLMenuInit(void *prevMenu) changeMultiSampleState); MultiSampleLabelId = GfuiMenuCreateLabelControl(ScrHandle,hparmMenu,"MultiSampleLabel"); + // Bump Mapping. + BumpMappingLeftButtonId = + GfuiMenuCreateButtonControl(ScrHandle, hparmMenu, "BumpMappingLeftArrowButton", (void*)-1, + changeBumpMappingState); + BumpMappingRightButtonId = + GfuiMenuCreateButtonControl(ScrHandle, hparmMenu, "BumpMappingRightArrowButton", (void*)+1, + changeBumpMappingState); + BumpMappingLabelId = GfuiMenuCreateLabelControl(ScrHandle,hparmMenu,"BumpMappingLabel"); + GfuiMenuCreateButtonControl(ScrHandle,hparmMenu,"ApplyButton",NULL, onAccept); GfuiMenuCreateButtonControl(ScrHandle,hparmMenu,"CancelButton",prevMenu, GfuiScreenActivate);