add anisotropic filter in OpenGL options by Gaetan

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5180 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 88f3dd0c8ef41ee14b533a464c2c869a98932389
Former-commit-id: a8b73ed99ae093d683a0e49df967897b4e6a707f
This commit is contained in:
torcs-ng 2013-02-23 13:56:49 +00:00
parent 1710279d92
commit 004827ea10
7 changed files with 168 additions and 27 deletions

View file

@ -177,11 +177,17 @@ void GfglFeatures::detectStandardSupport()
&& gfglIsOpenGLExtensionSupported("GL_ARB_imaging"); && gfglIsOpenGLExtensionSupported("GL_ARB_imaging");
_mapSupportedBool[BumpMapping] = bValue; _mapSupportedBool[BumpMapping] = bValue;
// 10) Anisotropic filtrering
bValue = gfglIsOpenGLExtensionSupported("GL_EXT_texture_filter_anisotropic");
_mapSupportedInt[AnisotropicFiltering] = bValue?2:InvalidInt;
} }
// 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& bBumpMapping, bool& bStereoVision) bool& bAlpha, bool& bFullScreen, bool& bBumpMapping, bool& bStereoVision, int &nAniFilt)
{ {
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" : "");
@ -335,7 +341,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 &bBump, bool &bStereo, void* hparmConfig) bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, int &nAniFilt,void* hparmConfig)
{ {
// Clear support data. // Clear support data.
_mapSupportedBool.clear(); _mapSupportedBool.clear();
@ -351,6 +357,8 @@ bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth,
(int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_Y, pszNoUnit, 0); (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_Y, pszNoUnit, 0);
nDepth = nDepth =
(int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP, pszNoUnit, 0); (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP, pszNoUnit, 0);
nAniFilt =
(int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit, 0);
bAlpha = bAlpha =
std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL, GFSCR_VAL_NO)) std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL, GFSCR_VAL_NO))
== GFSCR_VAL_YES; == GFSCR_VAL_YES;
@ -473,10 +481,18 @@ bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth,
// 11) Bump Mapping. // 11) Bump Mapping.
const std::string strBumpMapping = const std::string strBumpMapping =
GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING, ""); GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING, "");
if (strTexComp == GFSCR_VAL_YES) if (strTexComp == GFSCR_VAL_YES) //strTexComp ? Bug ?
_mapSupportedBool[BumpMapping] = true; _mapSupportedBool[BumpMapping] = true;
else if (strTexComp == GFSCR_VAL_NO) else if (strTexComp == GFSCR_VAL_NO)
_mapSupportedBool[BumpMapping] = false; _mapSupportedBool[BumpMapping] = false;
// 11) Anisotropic Filtering.
const int nAF =
(int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING,
pszNoUnit, (tdble)0);
if (nMaxTexSize > 0)
_mapSupportedInt[AnisotropicFiltering] =nAF;
// Close config file if we open it. // Close config file if we open it.
if (!hparmConfig) if (!hparmConfig)
@ -489,7 +505,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 bBump, bool bStereo, void* hparmConfig) bool bAlpha, bool bFullScreen, bool bBump, bool bStereo, int nAniFilt, 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();
@ -514,7 +530,9 @@ void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth,
(tdble)nHeight); (tdble)nHeight);
GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP, pszNoUnit, GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP, pszNoUnit,
(tdble)nDepth); (tdble)nDepth);
GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL, GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
(tdble)nAniFilt);
GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL,
bAlpha ? GFSCR_VAL_YES : GFSCR_VAL_NO); bAlpha ? GFSCR_VAL_YES : GFSCR_VAL_NO);
GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_FSCR, GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_FSCR,
bFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO); bFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO);
@ -588,6 +606,13 @@ void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth,
GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING, GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING,
isSupported(BumpMapping) ? GFSCR_VAL_YES : GFSCR_VAL_NO); isSupported(BumpMapping) ? GFSCR_VAL_YES : GFSCR_VAL_NO);
// 12) Aniso Filtering
if (getSupported(AnisotropicFiltering) != InvalidInt)
GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
(tdble)getSupported(AnisotropicFiltering));
else
GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING);
} }
// Write new params to config file. // Write new params to config file.
@ -602,23 +627,23 @@ 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 bBump, bool bStereo, void* hparmConfig) bool bAlpha, bool bFullScreen, bool bBump, bool bStereo,int nAniFilt, 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();
// 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, nDetAni;
bool bDetFullScreen, bDetAlpha, bDetBump, bDetStereo; bool bDetFullScreen, bDetAlpha, bDetBump, bDetStereo;
bool bPrevSupportFound = bool bPrevSupportFound =
loadSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, hparm); loadSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, 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.
bool bSupportFound = true; bool bSupportFound = true;
if (!bPrevSupportFound || nWidth != nDetWidth || nHeight != nDetHeight || nDepth != nDetDepth if (!bPrevSupportFound || nWidth != nDetWidth || nHeight != nDetHeight || nDepth != nDetDepth
|| bAlpha != bDetAlpha || bFullScreen != bDetFullScreen || bStereo != bDetStereo || bBump != bDetBump) || bAlpha != bDetAlpha || bFullScreen != bDetFullScreen || bStereo != bDetStereo || bBump != bDetBump || nAniFilt!= nDetAni)
{ {
nDetWidth = nWidth; nDetWidth = nWidth;
nDetHeight = nHeight; nDetHeight = nHeight;
@ -627,11 +652,12 @@ bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth,
bDetAlpha = bAlpha; bDetAlpha = bAlpha;
bDetStereo = bStereo; bDetStereo = bStereo;
bDetBump = bBump; bDetBump = bBump;
nDetAni = nAniFilt;
bSupportFound = bSupportFound =
detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo); detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, nDetAni);
// Store support data in any case. // Store support data in any case.
storeSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, hparm); storeSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, 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)
@ -724,6 +750,8 @@ void GfglFeatures::dumpSupport() const
isSupported(StereoVision) ? "Yes" : "No"); isSupported(StereoVision) ? "Yes" : "No");
GfLogInfo(" Bump Mapping : %s\n", GfLogInfo(" Bump Mapping : %s\n",
isSupported(BumpMapping) ? "Yes" : "No"); isSupported(BumpMapping) ? "Yes" : "No");
GfLogInfo(" Anisotropic Filtering : %d\n",
getSupported(AnisotropicFiltering));
} }
// Load the selected OpenGL features from the config file. // Load the selected OpenGL features from the config file.
@ -809,6 +837,9 @@ void GfglFeatures::loadSelection(void* hparmConfig)
GFSCR_ATT_BUMPMAPPING_ENABLED)) GFSCR_ATT_BUMPMAPPING_ENABLED))
== GFSCR_ATT_BUMPMAPPING_ENABLED; == GFSCR_ATT_BUMPMAPPING_ENABLED;
// 12) Anisotropic Filtering : load from config file.
_mapSelectedInt[AnisotropicFiltering] = (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING,
pszNoUnit, (tdble)getSupported(AnisotropicFiltering));
// Close config file if we open it. // Close config file if we open it.
if (!hparmConfig) if (!hparmConfig)
closeConfigFile(hparm); closeConfigFile(hparm);
@ -880,6 +911,12 @@ void GfglFeatures::storeSelection(void* hparmConfig) const
GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_BUMPMAPPING, GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_BUMPMAPPING,
isSelected(BumpMapping) isSelected(BumpMapping)
? GFSCR_ATT_BUMPMAPPING_ENABLED : GFSCR_ATT_BUMPMAPPING_DISABLED); ? GFSCR_ATT_BUMPMAPPING_ENABLED : GFSCR_ATT_BUMPMAPPING_DISABLED);
if (getSupported(AnisotropicFiltering) != InvalidInt)
GfParmSetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
(tdble)getSelected(AnisotropicFiltering));
else
GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING);
// Write new params to config file. // Write new params to config file.
GfParmWriteFile(NULL, hparm, "Screen"); GfParmWriteFile(NULL, hparm, "Screen");
@ -919,6 +956,8 @@ void GfglFeatures::dumpSelection() const
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"); GfLogInfo(" Bump Mapping : %s\n", isSelected(BumpMapping) ? "On" : "Off");
GfLogInfo(" Anisotropic Filtering : %d\n",
getSupported(AnisotropicFiltering));
} }
// 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 bBump, bool bStereo, void* hparmConfig = 0); bool bAlpha, bool bFullScreen, bool bBump, bool bStereo,int nAniFilt, 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,7 +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 BumpMapping, // Bump Mapping
StereoVision // StereoVision StereoVision // StereoVision
}; };
void select(EFeatureBool eFeature, bool bSelected); void select(EFeatureBool eFeature, bool bSelected);
@ -113,7 +113,8 @@ class TGFCLIENT_API GfglFeatures
ColorDepth, AlphaDepth, ColorDepth, AlphaDepth,
TextureMaxSize, TextureMaxSize,
MultiTexturingUnits, MultiTexturingUnits,
MultiSamplingSamples MultiSamplingSamples,
AnisotropicFiltering
}; };
void select(EFeatureInt eFeature, int nSelectedValue); void select(EFeatureInt eFeature, int nSelectedValue);
int getSelected(EFeatureInt eFeature) const; int getSelected(EFeatureInt eFeature) const;
@ -128,14 +129,14 @@ class TGFCLIENT_API GfglFeatures
GfglFeatures(); 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& bBump, bool& bStereo, bool& bFullScreen); bool& bAlpha, bool& bBump, bool& bStereo, bool& bFullScreen, int& nAniFilt);
bool loadSupport(int &nWidth, int &nHeight, int &nDepth, bool loadSupport(int &nWidth, int &nHeight, int &nDepth,
bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, void* hparmConfig = 0); bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, int &nAniFilt, void* hparmConfig = 0);
void storeSupport(int nWidth, int nHeight, int nDepth, void storeSupport(int nWidth, int nHeight, int nDepth,
bool bAlpha, bool bFullScreen, bool bBump, bool bStereo, void* hparmConfig = 0); bool bAlpha, bool bFullScreen, bool bBump, bool bStereo,int nAniFilt, 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

@ -439,6 +439,12 @@ bool GfScrInit(int nWinWidth, int nWinHeight, int nFullScreen)
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_BUMPMAPPING, std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_BUMPMAPPING,
GFSCR_VAL_NO)) GFSCR_VAL_NO))
== GFSCR_VAL_YES; == GFSCR_VAL_YES;
int nAniFilt =
(int)GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_ANISOTROPICFILTERING, (char*)NULL, 0);
bool bStereo = bool bStereo =
std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_STEREOVISION, std::string(GfParmGetStr(hparmScreen, pszScrPropSec, GFSCR_ATT_STEREOVISION,
GFSCR_VAL_NO)) GFSCR_VAL_NO))
@ -463,7 +469,7 @@ bool GfScrInit(int nWinWidth, int nWinHeight, int nFullScreen)
// Warning: Restarts the game if the frame buffer specs changed since last call. // Warning: Restarts the game if the frame buffer specs changed since last call.
// If specified and possible, setup the best possible settings. // If specified and possible, setup the best possible settings.
if (GfglFeatures::self().checkBestSupport(nWinWidth, nWinHeight, nTotalDepth, if (GfglFeatures::self().checkBestSupport(nWinWidth, nWinHeight, nTotalDepth,
bAlphaChannel, bFullScreen, bBumpMap, bStereo, hparmScreen)) bAlphaChannel, bFullScreen, bBumpMap, bStereo,nAniFilt,hparmScreen))
{ {
// Load Open GL user settings from the config file. // Load Open GL user settings from the config file.
GfglFeatures::self().loadSelection(); GfglFeatures::self().loadSelection();
@ -815,4 +821,4 @@ int GfScrCaptureAsPNG(const char *filename)
GfLogError("Failed to capture screen to %s\n", filename); GfLogError("Failed to capture screen to %s\n", filename);
return nStatus; return nStatus;
} }

View file

@ -140,6 +140,12 @@
#define GFSCR_ATT_STEREOVISION_ENABLED "enabled" #define GFSCR_ATT_STEREOVISION_ENABLED "enabled"
#define GFSCR_ATT_STEREOVISION_DISABLED "disabled" #define GFSCR_ATT_STEREOVISION_DISABLED "disabled"
#define GFSCR_ATT_ANISOTROPICFILTERING "anisotropic filtering"
#define GFSCR_ATT_ANISOTROPICFILTERING_HIGH "high"
#define GFSCR_ATT_ANISOTROPICFILTERING_MEDIUM "medium"
#define GFSCR_ATT_ANISOTROPICFILTERING_DISABLED "disabled"
#define GFSCR_ATT_MULTISAMPLINGSAMPLES "multi-sampling samples" #define GFSCR_ATT_MULTISAMPLINGSAMPLES "multi-sampling samples"
// Open GL auto-detected features // Open GL auto-detected features

View file

@ -93,8 +93,8 @@ static void setupOpenGLFeatures(void)
// Don't do it twice. // Don't do it twice.
if (bInitialized) if (bInitialized)
return; return;
// Multi-texturing. // Multi-texturing.
grMaxTextureUnits = 1; grMaxTextureUnits = 1;
if (GfglFeatures::self().isSelected(GfglFeatures::MultiTexturing)) if (GfglFeatures::self().isSelected(GfglFeatures::MultiTexturing))
{ {

View file

@ -109,6 +109,8 @@ cgrMultiTexState* cgrStateFactory::getMultiTexState(cgrMultiTexState::tfnTexSche
*/ */
// SGI texture loading function. // SGI texture loading function.
bool grLoadSGI(const char *fname, ssgTextureInfo* info) bool grLoadSGI(const char *fname, ssgTextureInfo* info)
{ {
@ -222,6 +224,8 @@ cgrSGIHeader::cgrSGIHeader(const char *fname, ssgTextureInfo* info)
bool grMakeMipMaps (GLubyte *image, int xsize, int ysize, int zsize, int mipmap) bool grMakeMipMaps (GLubyte *image, int xsize, int ysize, int zsize, int mipmap)
{ {
if (!((xsize & (xsize-1))==0) || !((ysize & (ysize-1))==0)) { if (!((xsize & (xsize-1))==0) || !((ysize & (ysize-1))==0)) {
ulSetError ( UL_WARNING, "Map is not a power-of-two in size!" ) ; ulSetError ( UL_WARNING, "Map is not a power-of-two in size!" ) ;
return false ; return false ;
@ -380,6 +384,7 @@ bool grMakeMipMaps (GLubyte *image, int xsize, int ysize, int zsize, int mipmap)
GL_RGBA, GL_RGBA,
GL_UNSIGNED_BYTE, (GLvoid *) texels[i] ) ; GL_UNSIGNED_BYTE, (GLvoid *) texels[i] ) ;
/*int compressed; /*int compressed;
glGetTexLevelParameteriv(GL_TEXTURE_2D, map_level, GL_TEXTURE_COMPRESSED_ARB, &compressed); glGetTexLevelParameteriv(GL_TEXTURE_2D, map_level, GL_TEXTURE_COMPRESSED_ARB, &compressed);
if (compressed == GL_TRUE) { if (compressed == GL_TRUE) {
@ -398,6 +403,32 @@ bool grMakeMipMaps (GLubyte *image, int xsize, int ysize, int zsize, int mipmap)
return true; return true;
} }
void doAnisotropicFiltering(){
int aniS;
float aniD;
if(GfglFeatures::self().getSupported(GfglFeatures::AnisotropicFiltering)!=GfglFeatures::InvalidInt)
{
aniS = GfglFeatures::self().getSelected(GfglFeatures::AnisotropicFiltering);
GLfloat fLargest;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);
if(aniS ==1)
{
aniD = fLargest/2;
}
if(aniS==2)
{
aniD = fLargest;
}
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniD);/**/
}
}
bool grLoadPngTexture (const char *fname, ssgTextureInfo* info) bool grLoadPngTexture (const char *fname, ssgTextureInfo* info)
{ {
GLubyte *tex; GLubyte *tex;
@ -435,7 +466,11 @@ bool grLoadPngTexture (const char *fname, ssgTextureInfo* info)
// tex = tex2; // tex = tex2;
// #endif // WIN32 // #endif // WIN32
return grMakeMipMaps(tex, w, h, 4, mipmap) == TRUE ? true : false; bool res = grMakeMipMaps(tex, w, h, 4, mipmap) == TRUE ? true : false;
doAnisotropicFiltering();
return res;
} }
bool grLoadJpegTexture (const char *fname, ssgTextureInfo* info) bool grLoadJpegTexture (const char *fname, ssgTextureInfo* info)
@ -462,5 +497,10 @@ bool grLoadJpegTexture (const char *fname, ssgTextureInfo* info)
mipmap = doMipMap(fname, mipmap); mipmap = doMipMap(fname, mipmap);
return grMakeMipMaps(tex, w, h, 4, mipmap) == TRUE ? true : false;
bool res = grMakeMipMaps(tex, w, h, 4, mipmap) == TRUE ? true : false;
doAnisotropicFiltering();
return res;
} }

View file

@ -76,6 +76,18 @@ static int MultiTextureLabelId;
static int MultiTextureLeftButtonId; static int MultiTextureLeftButtonId;
static int MultiTextureRightButtonId; static int MultiTextureRightButtonId;
//Anisotropic-filtering
static const char *AAnisotropicFilteringTexts[] =
{GFSCR_ATT_ANISOTROPICFILTERING_DISABLED, GFSCR_ATT_ANISOTROPICFILTERING_MEDIUM,GFSCR_ATT_ANISOTROPICFILTERING_HIGH};
static const int NAnisotropicFiltering =
sizeof(AAnisotropicFilteringTexts) / sizeof(AAnisotropicFilteringTexts[0]);
static int NCurAnisotropicFilteringIndex = 0;
static int AnisotropicFilteringLabelId;
static int AnisotropicFilteringLeftButtonId;
static int AnisotropicFilteringRightButtonId;
// Multi-sampling (initialized in OpenGLMenuInit). // Multi-sampling (initialized in OpenGLMenuInit).
static std::vector<std::string> VecMultiSampleTexts; static std::vector<std::string> VecMultiSampleTexts;
static int NMultiSamples = 0; static int NMultiSamples = 0;
@ -113,6 +125,9 @@ static void onAccept(void *)
GfglFeatures::self().select(GfglFeatures::BumpMapping, strcmp(ABumpMappingTexts[NCurBumpMappingIndex], GfglFeatures::self().select(GfglFeatures::BumpMapping, strcmp(ABumpMappingTexts[NCurBumpMappingIndex],
GFSCR_ATT_BUMPMAPPING_ENABLED) ? false : true); GFSCR_ATT_BUMPMAPPING_ENABLED) ? false : true);
GfglFeatures::self().select(GfglFeatures::AnisotropicFiltering, NCurAnisotropicFilteringIndex);
// 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();
@ -121,7 +136,7 @@ static void onAccept(void *)
// But actually restart the game if the multi-sampling feature settings changed // But actually restart the game if the multi-sampling feature settings changed
// (we can't change this without re-initializing the video mode). // (we can't change this without re-initializing the video mode).
if (GfglFeatures::self().isSelected(GfglFeatures::MultiSampling) != BMultiSamplingWasSelected if (GfglFeatures::self().isSelected(GfglFeatures::MultiSampling) != BMultiSamplingWasSelected
|| GfglFeatures::self().getSelected(GfglFeatures::MultiSamplingSamples) != BPrevMultiSamplingSamples) || GfglFeatures::self().getSelected(GfglFeatures::MultiSamplingSamples) != BPrevMultiSamplingSamples)
{ {
// Shutdown the user interface. // Shutdown the user interface.
@ -129,7 +144,7 @@ static void onAccept(void *)
// Restart the game. // Restart the game.
GfuiApp().restart(); GfuiApp().restart();
} }
} }
// Toggle texture compression state enabled/disabled. // Toggle texture compression state enabled/disabled.
@ -174,13 +189,20 @@ static void changeMaxTextureSizeState(void *vp)
GfuiLabelSetText(ScrHandle, MaxTextureSizeLabelId, valuebuf); GfuiLabelSetText(ScrHandle, MaxTextureSizeLabelId, valuebuf);
} }
// Toggle texture compression state enabled/disabled. // Toggle bumpmapping state enabled/disabled.
static void changeBumpMappingState(void *vp) static void changeBumpMappingState(void *vp)
{ {
NCurBumpMappingIndex = (NCurBumpMappingIndex + (int)(long)vp + NBumpMapping) % NBumpMapping; NCurBumpMappingIndex = (NCurBumpMappingIndex + (int)(long)vp + NBumpMapping) % NBumpMapping;
GfuiLabelSetText(ScrHandle, BumpMappingLabelId, ABumpMappingTexts[NCurBumpMappingIndex]); GfuiLabelSetText(ScrHandle, BumpMappingLabelId, ABumpMappingTexts[NCurBumpMappingIndex]);
} }
// Toggle anisotropic filtering state enabled/disabled.
static void changeAnisotropicFilteringState(void *vp)
{
NCurAnisotropicFilteringIndex = (NCurAnisotropicFilteringIndex + (int)(long)vp + NAnisotropicFiltering) % NAnisotropicFiltering;
GfuiLabelSetText(ScrHandle, AnisotropicFilteringLabelId, AAnisotropicFilteringTexts[NCurAnisotropicFilteringIndex]);
}
static void onActivate(void * /* dummy */) static void onActivate(void * /* dummy */)
{ {
@ -342,6 +364,23 @@ static void onActivate(void * /* dummy */)
GfuiEnable(ScrHandle, BumpMappingRightButtonId, GFUI_DISABLE); GfuiEnable(ScrHandle, BumpMappingRightButtonId, GFUI_DISABLE);
GfuiLabelSetText(ScrHandle, BumpMappingLabelId, "Not supported"); GfuiLabelSetText(ScrHandle, BumpMappingLabelId, "Not supported");
} }
// Initialize current state and GUI from the GL features layer.
// 7) Anisotropic Filtering.
int ani_sup= GfglFeatures::self().getSupported(GfglFeatures::AnisotropicFiltering);
if (ani_sup!=GfglFeatures::InvalidInt)
{
NCurAnisotropicFilteringIndex =
GfglFeatures::self().getSelected(GfglFeatures::AnisotropicFiltering);
GfuiLabelSetText(ScrHandle, AnisotropicFilteringLabelId,
AAnisotropicFilteringTexts[NCurAnisotropicFilteringIndex]);
}
else
{
GfuiEnable(ScrHandle, AnisotropicFilteringLeftButtonId, GFUI_DISABLE);
GfuiEnable(ScrHandle, AnisotropicFilteringRightButtonId, GFUI_DISABLE);
GfuiLabelSetText(ScrHandle, AnisotropicFilteringLabelId, "Not supported");
}
} }
// OpenGL menu // OpenGL menu
@ -400,6 +439,16 @@ void* OpenGLMenuInit(void *prevMenu)
changeBumpMappingState); changeBumpMappingState);
BumpMappingLabelId = GfuiMenuCreateLabelControl(ScrHandle,hparmMenu,"BumpMappingLabel"); BumpMappingLabelId = GfuiMenuCreateLabelControl(ScrHandle,hparmMenu,"BumpMappingLabel");
// Anisotropic Filtering.
AnisotropicFilteringLeftButtonId =
GfuiMenuCreateButtonControl(ScrHandle, hparmMenu, "AnisotropicFilteringLeftArrowButton", (void*)-1,
changeAnisotropicFilteringState);
AnisotropicFilteringRightButtonId =
GfuiMenuCreateButtonControl(ScrHandle, hparmMenu, "AnisotropicFilteringRightArrowButton", (void*)+1,
changeAnisotropicFilteringState);
AnisotropicFilteringLabelId = GfuiMenuCreateLabelControl(ScrHandle,hparmMenu,"AnisotropicFilteringLabel");
GfuiMenuCreateButtonControl(ScrHandle,hparmMenu,"ApplyButton",NULL, onAccept); GfuiMenuCreateButtonControl(ScrHandle,hparmMenu,"ApplyButton",NULL, onAccept);
GfuiMenuCreateButtonControl(ScrHandle,hparmMenu,"CancelButton",prevMenu, GfuiScreenActivate); GfuiMenuCreateButtonControl(ScrHandle,hparmMenu,"CancelButton",prevMenu, GfuiScreenActivate);