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
This commit is contained in:
torcs-ng 2012-06-21 20:04:09 +00:00
parent 5ded4ae245
commit f1d55414cd
4 changed files with 117 additions and 13 deletions

View file

@ -167,11 +167,20 @@ void GfglFeatures::detectStandardSupport()
// 9) Stereo Vision (need a proper check) // 9) Stereo Vision (need a proper check)
_mapSupportedBool[StereoVision] = false; _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. // Best supported features detection for the given specs of the frame buffer.
bool GfglFeatures::detectBestSupport(int& nWidth, int& nHeight, int& nDepth, 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", GfLogInfo("Detecting best supported features for a %dx%dx%d%s frame buffer.\n",
nWidth, nHeight, nDepth, bFullScreen ? " full-screen" : ""); 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 nAlphaChannel = bAlpha ? 1 : 0;
int nCurrDepth = nDepth; int nCurrDepth = nDepth;
int nFullScreen = bFullScreen ? 1 : 0; int nFullScreen = bFullScreen ? 1 : 0;
int nBump = bBumpMapping ? 1 : 0;
int nStereoVision = bStereoVision ? 1 : 0; int nStereoVision = bStereoVision ? 1 : 0;
while (!pWinSurface && nFullScreen >= 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 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. // Clear support data.
_mapSupportedBool.clear(); _mapSupportedBool.clear();
@ -349,6 +359,9 @@ bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth,
bStereo = bStereo =
std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION, GFSCR_VAL_NO)) std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION, GFSCR_VAL_NO))
== GFSCR_VAL_YES; == 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. // Check that we have something supported, and return if not.
if (nWidth == 0 || nHeight == 0 || nDepth == 0) if (nWidth == 0 || nHeight == 0 || nDepth == 0)
@ -456,6 +469,14 @@ bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth,
else if (strStereoVision == GFSCR_VAL_NO) else if (strStereoVision == GFSCR_VAL_NO)
_mapSupportedBool[StereoVision] = false; _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. // Close config file if we open it.
if (!hparmConfig) if (!hparmConfig)
closeConfigFile(hparm); closeConfigFile(hparm);
@ -467,7 +488,7 @@ bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth,
} }
void GfglFeatures::storeSupport(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. // Open the config file if not already done.
void* hparm = hparmConfig ? hparmConfig : openConfigFile(); 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); bFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO);
GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION, GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION,
bStereo ? GFSCR_VAL_YES : GFSCR_VAL_NO); 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). // Write new values (remove the ones with no value supported).
// 1) Double-buffer. // 1) Double-buffer.
@ -559,6 +582,11 @@ void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth,
// 10) Stereo Vision // 10) Stereo Vision
GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_STEREOVISION, GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_STEREOVISION,
isSupported(StereoVision) ? GFSCR_VAL_YES : GFSCR_VAL_NO); 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. // Write new params to config file.
@ -573,7 +601,7 @@ void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth,
} }
bool GfglFeatures::checkBestSupport(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. // Open the config file if not already done.
void* hparm = hparmConfig ? hparmConfig : openConfigFile(); 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 // Get the frame buffer specs that are associated with the detected
// Open GL features in the config file, if any. // Open GL features in the config file, if any.
int nDetWidth, nDetHeight, nDetDepth; int nDetWidth, nDetHeight, nDetDepth;
bool bDetFullScreen, bDetAlpha, bDetStereo; bool bDetFullScreen, bDetAlpha, bDetBump, bDetStereo;
bool bPrevSupportFound = 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 // Compare with the requested frame buffer specs
// and run a new supported feature detection if any diffference. // 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; bDetFullScreen = bFullScreen;
bDetAlpha = bAlpha; bDetAlpha = bAlpha;
bDetStereo = bStereo; bDetStereo = bStereo;
bDetBump = bBump;
bSupportFound = bSupportFound =
detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetStereo); detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo);
// Store support data in any case. // 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 frame buffer specs supported, update relevant user settings and restart.
if (bSupportFound) if (bSupportFound)
@ -692,6 +721,8 @@ void GfglFeatures::dumpSupport() const
GfLogInfo("\n"); GfLogInfo("\n");
GfLogInfo(" Stereo Vision : %s\n", GfLogInfo(" Stereo Vision : %s\n",
isSupported(StereoVision) ? "Yes" : "No"); isSupported(StereoVision) ? "Yes" : "No");
GfLogInfo(" Bump Mapping : %s\n",
isSupported(BumpMapping) ? "Yes" : "No");
} }
// Load the selected OpenGL features from the config file. // 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))
== 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. // Close config file if we open it.
if (!hparmConfig) if (!hparmConfig)
closeConfigFile(hparm); closeConfigFile(hparm);
@ -810,6 +848,7 @@ void GfglFeatures::storeSelection(void* hparmConfig) const
else else
GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES); GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES);
// Force 'best possible' mode for video initialization when anti-aliasing selected // Force 'best possible' mode for video initialization when anti-aliasing selected
if (isSelected(MultiSampling)) if (isSelected(MultiSampling))
{ {
@ -837,6 +876,10 @@ void GfglFeatures::storeSelection(void* hparmConfig) const
isSelected(StereoVision) isSelected(StereoVision)
? GFSCR_ATT_STEREOVISION_ENABLED : GFSCR_ATT_STEREOVISION_DISABLED); ? 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. // Write new params to config file.
GfParmWriteFile(NULL, hparm, "Screen"); GfParmWriteFile(NULL, hparm, "Screen");
@ -874,6 +917,7 @@ void GfglFeatures::dumpSelection() const
GfLogInfo(" (%d samples)", getSelected(MultiSamplingSamples)); GfLogInfo(" (%d samples)", getSelected(MultiSamplingSamples));
GfLogInfo("\n"); GfLogInfo("\n");
GfLogInfo(" Stereo vision : %s\n", isSelected(StereoVision) ? "On" : "Off"); GfLogInfo(" Stereo vision : %s\n", isSelected(StereoVision) ? "On" : "Off");
GfLogInfo(" Bump Mapping : %s\n", isSelected(BumpMapping) ? "On" : "Off");
} }
// Bool features management. // Bool features management.

View file

@ -66,7 +66,7 @@ class TGFCLIENT_API GfglFeatures
// Check best supported OpenGL features, and store report to the config file // Check best supported OpenGL features, and store report to the config file
// (default = GFSCR_CONF_FILE). May restart the game. // (default = GFSCR_CONF_FILE). May restart the game.
bool checkBestSupport(int nWidth, int nHeight, int nDepth, 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. // Detect standard supported features. Don't restart the game.
// Precondiftion: SDL_setVideoMode(...) // Precondiftion: SDL_setVideoMode(...)
@ -99,6 +99,7 @@ class TGFCLIENT_API GfglFeatures
TextureNonPowerOf2, // GL_ARB_texture_non_power_of_two, in case mipmapping needed. TextureNonPowerOf2, // GL_ARB_texture_non_power_of_two, in case mipmapping needed.
MultiTexturing, // GL_ARB_multitexture MultiTexturing, // GL_ARB_multitexture
MultiSampling, // GL_ARB_multisample MultiSampling, // GL_ARB_multisample
BumpMapping, // Bump Mapping
StereoVision // StereoVision StereoVision // StereoVision
}; };
void select(EFeatureBool eFeature, bool bSelected); 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. // Update supported OpenGL features according to the given frame buffer specs.
bool detectBestSupport(int& nWidth, int& nHeight, int& nDepth, 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 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, 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* openConfigFile();
static void closeConfigFile(void* hparmConfig, bool bWrite = false); static void closeConfigFile(void* hparmConfig, bool bWrite = false);

View file

@ -122,6 +122,10 @@
#define GFSCR_ATT_TEXTURECOMPRESSION_ENABLED "enabled" #define GFSCR_ATT_TEXTURECOMPRESSION_ENABLED "enabled"
#define GFSCR_ATT_TEXTURECOMPRESSION_DISABLED "disabled" #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_MAXTEXTURESIZE "max texture size"
#define GFSCR_ATT_MULTITEXTURING "multi-texturing" #define GFSCR_ATT_MULTITEXTURING "multi-texturing"

View file

@ -47,6 +47,16 @@ static int TextureCompLabelId;
static int TextureCompLeftButtonId; static int TextureCompLeftButtonId;
static int TextureCompRightButtonId; 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). // 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 AMaxTextureSizeTexts[] = {8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384};
static int NMaxTextureSizes = sizeof(AMaxTextureSizeTexts) / sizeof(AMaxTextureSizeTexts[0]); static int NMaxTextureSizes = sizeof(AMaxTextureSizeTexts) / sizeof(AMaxTextureSizeTexts[0]);
@ -100,6 +110,9 @@ static void onAccept(void *)
GfglFeatures::self().select(GfglFeatures::MultiSamplingSamples, GfglFeatures::self().select(GfglFeatures::MultiSamplingSamples,
(int)pow(2.0, (double)NCurMultiSampleIndex)); (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. // Store settings from the GL features layer to the screen.xml file.
GfglFeatures::self().storeSelection(); GfglFeatures::self().storeSelection();
@ -161,6 +174,13 @@ static void changeMaxTextureSizeState(void *vp)
GfuiLabelSetText(ScrHandle, MaxTextureSizeLabelId, valuebuf); 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 */) static void onActivate(void * /* dummy */)
{ {
@ -296,6 +316,32 @@ static void onActivate(void * /* dummy */)
GfuiEnable(ScrHandle, MultiSampleRightButtonId, GFUI_DISABLE); GfuiEnable(ScrHandle, MultiSampleRightButtonId, GFUI_DISABLE);
GfuiLabelSetText(ScrHandle, MultiSampleLabelId, "Not supported"); 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 // OpenGL menu
@ -345,6 +391,15 @@ void* OpenGLMenuInit(void *prevMenu)
changeMultiSampleState); changeMultiSampleState);
MultiSampleLabelId = GfuiMenuCreateLabelControl(ScrHandle,hparmMenu,"MultiSampleLabel"); 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,"ApplyButton",NULL, onAccept);
GfuiMenuCreateButtonControl(ScrHandle,hparmMenu,"CancelButton",prevMenu, GfuiScreenActivate); GfuiMenuCreateButtonControl(ScrHandle,hparmMenu,"CancelButton",prevMenu, GfuiScreenActivate);