- fixed caching of texture sampler state for old hardware.

- fixed handling of CLAMP_XY_NOMIP sampler mode. This cannot be lumped together with CLAMP_XY because it has different mipmap requirements.
This commit is contained in:
Christoph Oelckers 2016-05-03 13:39:41 +02:00
parent 4d7be0e20e
commit 0e14f00b51
4 changed files with 22 additions and 20 deletions

View file

@ -168,7 +168,7 @@ void gl_LoadExtensions()
gl.vendorstring = (char*)glGetString(GL_VENDOR); gl.vendorstring = (char*)glGetString(GL_VENDOR);
gl.lightmethod = LM_SOFTWARE; gl.lightmethod = LM_SOFTWARE;
if (gl.version >= 3.3f || CheckExtension("GL_ARB_sampler_objects")) if ((gl.version >= 3.3f || CheckExtension("GL_ARB_sampler_objects")) && !Args->CheckParm("-nosampler"))
{ {
gl.flags |= RFL_SAMPLER_OBJECTS; gl.flags |= RFL_SAMPLER_OBJECTS;
} }

View file

@ -346,7 +346,8 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int transla
delete[] buffer; delete[] buffer;
} }
if (tex->bHasCanvas) static_cast<FCanvasTexture*>(tex)->NeedUpdate(); if (tex->bHasCanvas) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
if (lastSampler != clampmode || lastTranslation != translation) if (translation != lastTranslation) lastSampler = 254;
if (lastSampler != clampmode)
lastSampler = GLRenderer->mSamplerManager->Bind(texunit, clampmode, lastSampler); lastSampler = GLRenderer->mSamplerManager->Bind(texunit, clampmode, lastSampler);
lastTranslation = translation; lastTranslation = translation;
return hwtex; return hwtex;

View file

@ -86,7 +86,6 @@ void FSamplerManager::UnbindAll()
{ {
for (int i = 0; i < FHardwareTexture::MAX_TEXTURES; i++) for (int i = 0; i < FHardwareTexture::MAX_TEXTURES; i++)
{ {
mLastBound[i] = 0;
glBindSampler(i, 0); glBindSampler(i, 0);
} }
} }
@ -97,12 +96,8 @@ BYTE FSamplerManager::Bind(int texunit, int num, int lastval)
if (gl.flags & RFL_SAMPLER_OBJECTS) if (gl.flags & RFL_SAMPLER_OBJECTS)
{ {
unsigned int samp = mSamplers[num]; unsigned int samp = mSamplers[num];
//if (samp != mLastBound[texunit]) glBindSampler(texunit, samp);
{ return 255;
glBindSampler(texunit, samp);
mLastBound[texunit] = samp;
return 255;
}
} }
else else
{ {
@ -112,7 +107,7 @@ BYTE FSamplerManager::Bind(int texunit, int num, int lastval)
case CLAMP_NONE: case CLAMP_NONE:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (lastval > CLAMP_XY_NOMIP) if (lastval >= CLAMP_XY_NOMIP)
{ {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].minfilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].minfilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter);
@ -123,7 +118,7 @@ BYTE FSamplerManager::Bind(int texunit, int num, int lastval)
case CLAMP_X: case CLAMP_X:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if (lastval > CLAMP_XY_NOMIP) if (lastval >= CLAMP_XY_NOMIP)
{ {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].minfilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].minfilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter);
@ -134,7 +129,18 @@ BYTE FSamplerManager::Bind(int texunit, int num, int lastval)
case CLAMP_Y: case CLAMP_Y:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (lastval > CLAMP_XY_NOMIP) if (lastval >= CLAMP_XY_NOMIP)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].minfilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_filter_anisotropic);
}
break;
case CLAMP_XY:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (lastval >= CLAMP_XY_NOMIP)
{ {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].minfilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].minfilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter);
@ -143,15 +149,11 @@ BYTE FSamplerManager::Bind(int texunit, int num, int lastval)
break; break;
case CLAMP_XY_NOMIP: case CLAMP_XY_NOMIP:
case CLAMP_XY:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if (lastval > CLAMP_XY_NOMIP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].magfilter);
{ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[gl_texture_filter].minfilter); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[gl_texture_filter].magfilter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_filter_anisotropic);
}
break; break;
case CLAMP_NOFILTER: case CLAMP_NOFILTER:

View file

@ -8,7 +8,6 @@ class FSamplerManager
// We need 6 different samplers: 4 for the different clamping modes, // We need 6 different samplers: 4 for the different clamping modes,
// one for 2D-textures and one for voxel textures // one for 2D-textures and one for voxel textures
unsigned int mSamplers[7]; unsigned int mSamplers[7];
unsigned int mLastBound[FHardwareTexture::MAX_TEXTURES];
void UnbindAll(); void UnbindAll();