From d4fc13fba5e09a036f8e976c1464896c1a6ba84b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 19 Oct 2019 19:10:09 +0200 Subject: [PATCH] - cleaned up the sampler manager's content names and added the missing types to allow easier switching between indexed (no filtering) and non-indexed (filter as per user option). --- source/build/src/animvpx.cpp | 4 +-- source/build/src/glsurface.cpp | 4 +-- source/build/src/polymost.cpp | 10 ++----- source/build/src/texcache.cpp | 1 + source/build/src/voxmodel.cpp | 2 +- source/glbackend/gl_palmanager.cpp | 6 ++-- source/glbackend/gl_samplers.cpp | 48 +++++++++++++++--------------- source/glbackend/gl_samplers.h | 9 +++--- 8 files changed, 40 insertions(+), 44 deletions(-) diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index c8a7b8260..a612db7b0 100644 --- a/source/build/src/animvpx.cpp +++ b/source/build/src/animvpx.cpp @@ -365,11 +365,11 @@ void animvpx_setup_glstate(int32_t animvpx_flags) if ((animvpx_flags & CUTSCENE_TEXTUREFILTER && gltexfiltermode == TEXFILTER_ON) || animvpx_flags & CUTSCENE_FORCEFILTER || (!(animvpx_flags & CUTSCENE_TEXTUREFILTER) && !(animvpx_flags & CUTSCENE_FORCENOFILTER))) // if no flags, then use filter for IVFs { - sampler = Sampler2DFiltered; + sampler = SamplerClampXY; } else { - sampler = Sampler2DNoFilter; + sampler = SamplerNoFilterClampXY; } texuploaded = 0; diff --git a/source/build/src/glsurface.cpp b/source/build/src/glsurface.cpp index d392eb8f2..1e5589725 100644 --- a/source/build/src/glsurface.cpp +++ b/source/build/src/glsurface.cpp @@ -55,7 +55,7 @@ void glsurface_setPalette(void* pPalette) paletteTexture->CreateTexture(256, 1, false, false); } paletteTexture->LoadTexture(palette); - GLInterface.BindTexture(1, paletteTexture, Sampler2DNoFilter); + GLInterface.BindTexture(1, paletteTexture, SamplerNoFilterClampXY); } void* glsurface_getBuffer() @@ -74,7 +74,7 @@ void glsurface_blitBuffer() return; bufferTexture->LoadTexture(buffer.Data()); - GLInterface.BindTexture(0, bufferTexture, Sampler2DNoFilter); + GLInterface.BindTexture(0, bufferTexture, SamplerNoFilterClampXY); auto data = GLInterface.AllocVertices(4); auto vt = data.second; diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 7cc9a47c8..108626ca2 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -171,13 +171,8 @@ void gltexapplyprops(void) glanisotropy = (int32_t)GLInterface.glinfo.maxanisotropy; } -#if 1 - GLInterface.mSamplers->SetTextureFilterMode(0, 1); - r_useindexedcolortextures = true;// !gltexfiltermode; -#else GLInterface.mSamplers->SetTextureFilterMode(gltexfiltermode, glanisotropy); - r_useindexedcolortextures = false;// !gltexfiltermode; -#endif + // do not force switch indexed textures with the filter. } //-------------------------------------------------------------------------------------------------- @@ -4670,7 +4665,6 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, glox1 = -1; //Force fullscreen (glox1=-1 forces it to restore) } - if (videoGetRenderMode() < REND_POLYMER) { Bmemset(m, 0, sizeof(m)); @@ -5237,7 +5231,7 @@ static int32_t gen_font_glyph_tex(void) polymosttext->CreateTexture(256, 128, false, false); polymosttext->LoadTexture((uint8_t*)tbuf); - polymosttext->SetSampler(Sampler2DNoFilter); + polymosttext->SetSampler(SamplerNoFilterClampXY); Xfree(tbuf); return 0; diff --git a/source/build/src/texcache.cpp b/source/build/src/texcache.cpp index f7f527f61..4d47805a3 100644 --- a/source/build/src/texcache.cpp +++ b/source/build/src/texcache.cpp @@ -157,6 +157,7 @@ bool GLInstance::SetTextureInternal(int picnum, FTexture* tex, int palette, int if (mtex) { auto sampler = (method & DAMETH_CLAMPED) ? (sampleroverride != -1 ? sampleroverride : SamplerClampXY) : SamplerRepeat; + if (TextureType == TT_INDEXED) sampler = sampler + SamplerNoFilterRepeat - SamplerRepeat; BindTexture(0, mtex, sampler); if (rep && (rep->scale.x != 1.0f || rep->scale.y != 1.0f || xpanning != 0 || ypanning != 0)) diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index eba530d35..dd1343513 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -71,7 +71,7 @@ FHardwareTexture *gloadtex(const int32_t *picbuf, int32_t xsiz, int32_t ysiz, in auto tex = GLInterface.NewTexture(); tex->CreateTexture(xsiz, ysiz, false, false); tex->LoadTexture((uint8_t*)pic2); - tex->SetSampler(SamplerNoFilter); + tex->SetSampler(SamplerNoFilterClampXY); Xfree(pic2); return tex; diff --git a/source/glbackend/gl_palmanager.cpp b/source/glbackend/gl_palmanager.cpp index a6afd32d0..725420290 100644 --- a/source/glbackend/gl_palmanager.cpp +++ b/source/glbackend/gl_palmanager.cpp @@ -210,7 +210,7 @@ void PaletteManager::BindPalette(int index) auto p = GLInterface.NewTexture(); p->CreateTexture(256, 1, false, false); p->LoadTexture((uint8_t*)transientpalette.colors); - p->SetSampler(Sampler2DNoFilter); + p->SetSampler(SamplerNoFilterClampXY); transientpalette.paltexture = p; } inst->BindTexture(2, transientpalette.paltexture); @@ -226,7 +226,7 @@ void PaletteManager::BindPalette(int index) auto p = GLInterface.NewTexture(); p->CreateTexture(256, 1, false, false); p->LoadTexture((uint8_t*)palettes[uindex].colors); - p->SetSampler(Sampler2DNoFilter); + p->SetSampler(SamplerNoFilterClampXY); palettes[uindex].paltexture = p; } inst->BindTexture(2, palettes[uindex].paltexture); @@ -268,7 +268,7 @@ void PaletteManager::BindPalswap(int index) auto p = GLInterface.NewTexture(); p->CreateTexture(256, numshades, true, false); p->LoadTexture((uint8_t*)ps.lookup); - p->SetSampler(Sampler2DNoFilter); + p->SetSampler(SamplerNoFilterClampXY); ps.swaptexture = p; } inst->BindTexture(1, ps.swaptexture); diff --git a/source/glbackend/gl_samplers.cpp b/source/glbackend/gl_samplers.cpp index 0481c9d60..a00a3bfdf 100644 --- a/source/glbackend/gl_samplers.cpp +++ b/source/glbackend/gl_samplers.cpp @@ -50,34 +50,34 @@ TexFilter_s TexFilter[]={ {GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR, true}, {GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST, true}, {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, true}, - //{GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST, true}, + {GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST, true}, }; FSamplerManager::FSamplerManager() { glGenSamplers(NumSamplers, mSamplers); - glSamplerParameteri(mSamplers[5], GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glSamplerParameteri(mSamplers[5], GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glSamplerParameterf(mSamplers[5], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); - glSamplerParameterf(mSamplers[4], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); - glSamplerParameterf(mSamplers[6], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); - glSamplerParameteri(mSamplers[6], GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glSamplerParameteri(mSamplers[6], GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameterf(mSamplers[7], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); - glSamplerParameteri(mSamplers[7], GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glSamplerParameteri(mSamplers[7], GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glSamplerParameteri(mSamplers[1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[2], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[3], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[3], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[4], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[4], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[6], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[6], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[7], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[7], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + for (int i = SamplerNoFilterRepeat; i <= SamplerNoFilterClampXY; i++) + { + glSamplerParameteri(mSamplers[i], GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glSamplerParameteri(mSamplers[i], GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); + } + + glSamplerParameteri(mSamplers[SamplerClampX], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[SamplerClampY], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[SamplerClampXY], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[SamplerClampXY], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glSamplerParameteri(mSamplers[SamplerNoFilterClampX], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[SamplerNoFilterClampY], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[SamplerNoFilterClampXY], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[SamplerNoFilterClampXY], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glSamplerParameteri(mSamplers[Sampler2DFiltered], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[Sampler2DFiltered], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } FSamplerManager::~FSamplerManager() @@ -106,12 +106,12 @@ void FSamplerManager::SetTextureFilterMode(int filter, int anisotropy) { UnbindAll(); - for (int i = 0; i < 4; i++) + for (int i = SamplerRepeat; i <= SamplerClampXY; i++) { glSamplerParameteri(mSamplers[i], GL_TEXTURE_MIN_FILTER, TexFilter[filter].minfilter); glSamplerParameteri(mSamplers[i], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); } - glSamplerParameteri(mSamplers[4], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); - glSamplerParameteri(mSamplers[4], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[Sampler2DFiltered], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[Sampler2DFiltered], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); } diff --git a/source/glbackend/gl_samplers.h b/source/glbackend/gl_samplers.h index 95cd05405..3842dcd8b 100644 --- a/source/glbackend/gl_samplers.h +++ b/source/glbackend/gl_samplers.h @@ -10,10 +10,11 @@ enum ESampler SamplerClampX, SamplerClampY, SamplerClampXY, - Sampler2D, - SamplerNoFilter, - Sampler2DFiltered, - Sampler2DNoFilter, + SamplerNoFilterRepeat, + SamplerNoFilterClampX, + SamplerNoFilterClampY, + SamplerNoFilterClampXY, + Sampler2DFiltered, // Currently unused shpuld be used for 2D content NumSamplers };