From 72889540a53d9fe6a5aaf1e0beebda69e246583f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 28 May 2020 23:48:50 +0200 Subject: [PATCH] - use GZDoom's gl_samplers.cpp --- source/CMakeLists.txt | 6 +- source/build/include/build.h | 5 +- source/build/src/animvpx.cpp | 2 +- source/build/src/polymost.cpp | 41 ++------- .../rendering/gl}/gl_debug.cpp | 4 +- .../system => common/rendering/gl}/gl_debug.h | 2 +- .../rendering/gl}/gl_samplers.cpp | 83 +++++++++++-------- source/common/rendering/gl/gl_samplers.h | 29 +++++++ source/common/textures/hw_material.cpp | 2 - source/common/textures/texture.cpp | 6 +- source/common/textures/textures.h | 16 ++-- .../rendering/gl/renderer/gl_postprocess.cpp | 2 +- .../gl/renderer/gl_renderbuffers.cpp | 2 +- .../rendering/gl/renderer/gl_renderer.cpp | 2 +- .../rendering/gl/shaders/gl_shaderprogram.cpp | 2 +- .../rendering/gl/system/gl_framebuffer.cpp | 2 +- .../core/rendering/gl/system/gl_framebuffer.h | 2 +- source/core/rendering/v_framebuffer.cpp | 4 +- source/core/rendering/v_video.cpp | 2 +- source/core/rendering/v_video.h | 2 +- source/duke3d/src/anim.cpp | 8 +- source/glbackend/gl_samplers.h | 43 ---------- source/glbackend/gl_texture.cpp | 4 + source/glbackend/glbackend.cpp | 18 +++- source/glbackend/glbackend.h | 15 +++- source/rr/src/anim.cpp | 4 +- source/rr/src/premap.cpp | 4 - wadsrc/static/engine/menudef.txt | 4 +- 28 files changed, 160 insertions(+), 156 deletions(-) rename source/{core/rendering/gl/system => common/rendering/gl}/gl_debug.cpp (99%) rename source/{core/rendering/gl/system => common/rendering/gl}/gl_debug.h (96%) rename source/{glbackend => common/rendering/gl}/gl_samplers.cpp (53%) create mode 100644 source/common/rendering/gl/gl_samplers.h delete mode 100644 source/glbackend/gl_samplers.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 059fd8202..4080768ec 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -713,7 +713,7 @@ set( FASTMATH_SOURCES set (PCH_SOURCES glbackend/gl_hwtexture.cpp - glbackend/gl_samplers.cpp + #glbackend/gl_samplers.cpp glbackend/gl_shader.cpp glbackend/glbackend.cpp glbackend/gl_palmanager.cpp @@ -866,6 +866,8 @@ set (PCH_SOURCES common/objects/dobjgc.cpp common/objects/dobjtype.cpp common/rendering/gl_load/gl_interface.cpp + common/rendering/gl/gl_debug.cpp + common/rendering/gl/gl_samplers.cpp common/scripting/core/dictionary.cpp common/scripting/core/dynarrays.cpp common/scripting/core/symbols.cpp @@ -914,7 +916,6 @@ set (PCH_SOURCES core/rendering/gl/renderer/gl_renderbuffers.cpp core/rendering/gl/shaders/gl_shaderprogram.cpp core/rendering/gl/system/gl_buffers.cpp - core/rendering/gl/system/gl_debug.cpp core/rendering/gl/system/gl_framebuffer.cpp core/rendering/hwrenderer/data/flatvertices.cpp core/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -1036,6 +1037,7 @@ include_directories( common/objects common/rendering common/rendering/gl_load + common/rendering/gl common/scripting/vm common/scripting/jit common/scripting/core diff --git a/source/build/include/build.h b/source/build/include/build.h index fbb68b52c..33bfa7d66 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -1087,7 +1087,6 @@ void renderSetRollAngle(float rolla); // clamping is for sprites, repeating is for walls void tileInvalidate(int tilenume, int32_t pal, int32_t how); -void polymost_glreset(void); void PrecacheHardwareTextures(int nTile); void Polymost_Startup(); @@ -1114,8 +1113,8 @@ EXTERN_CVAR(Bool, hw_animsmoothing) EXTERN_CVAR(Bool, hw_hightile) EXTERN_CVAR(Bool, hw_models) EXTERN_CVAR(Float, hw_shadescale) -EXTERN_CVAR(Int, hw_anisotropy) -EXTERN_CVAR(Int, hw_texfilter) +EXTERN_CVAR(Float, gl_texture_filter_anisotropic) +EXTERN_CVAR(Int, gl_texture_filter) extern bool hw_int_useindexedcolortextures; EXTERN_CVAR(Bool, hw_useindexedcolortextures) EXTERN_CVAR(Bool, hw_parallaxskypanning) diff --git a/source/build/src/animvpx.cpp b/source/build/src/animvpx.cpp index 077a0d051..8fffb06fb 100644 --- a/source/build/src/animvpx.cpp +++ b/source/build/src/animvpx.cpp @@ -421,7 +421,7 @@ void animvpx_setup_glstate(int32_t animvpx_flags) vpxtex[0] = MakeGameTexture(new VPXTexture, nullptr, ETextureType::Special); vpxtex[1] = MakeGameTexture(new VPXTexture, nullptr, ETextureType::Special); - if ((animvpx_flags & CUTSCENE_TEXTUREFILTER && hw_texfilter == TEXFILTER_ON) || animvpx_flags & CUTSCENE_FORCEFILTER || + if ((animvpx_flags & CUTSCENE_TEXTUREFILTER && gl_texture_filter == TEXFILTER_ON) || animvpx_flags & CUTSCENE_FORCEFILTER || (!(animvpx_flags & CUTSCENE_TEXTUREFILTER) && !(animvpx_flags & CUTSCENE_FORCENOFILTER))) // if no flags, then use filter for IVFs { sampler = CLAMP_XY; diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 8a7d2ed96..3a65158e3 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -37,7 +37,7 @@ CUSTOM_CVARD(Bool, hw_useindexedcolortextures, false, CVAR_ARCHIVE | CVAR_GLOBAL } -CUSTOM_CVARD(Int, hw_texfilter, TEXFILTER_ON, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "changes the texture filtering settings") +CUSTOM_CVARD(Int, gl_texture_filter, TEXFILTER_ON, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL, "changes the texture filtering settings") { static const char* const glfiltermodes[] = { @@ -54,11 +54,11 @@ CUSTOM_CVARD(Int, hw_texfilter, TEXFILTER_ON, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, else { gltexapplyprops(); - Printf("Texture filtering mode changed to %s\n", glfiltermodes[hw_texfilter]); + Printf("Texture filtering mode changed to %s\n", glfiltermodes[gl_texture_filter]); } } -CUSTOM_CVARD(Int, hw_anisotropy, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "changes the OpenGL texture anisotropy setting") +CUSTOM_CVARD(Float, gl_texture_filter_anisotropic, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL, "changes the OpenGL texture anisotropy setting") { gltexapplyprops(); } @@ -116,8 +116,6 @@ static int32_t drawpoly_srepeat = 0, drawpoly_trepeat = 0; static int32_t lastglpolygonmode = 0; //FUK -static FHardwareTexture *polymosttext = 0; - static int32_t r_yshearing = 0; // used for fogcalc @@ -145,23 +143,18 @@ void polymost_outputGLDebugMessage(uint8_t severity, const char* format, ...) void gltexapplyprops(void) { - if (videoGetRenderMode() == REND_CLASSIC) - return; - if (GLInterface.glinfo.maxanisotropy > 1.f) { - if (hw_anisotropy <= 0 || hw_anisotropy > GLInterface.glinfo.maxanisotropy) - hw_anisotropy = (int32_t)GLInterface.glinfo.maxanisotropy; + if (gl_texture_filter_anisotropic <= 0 || gl_texture_filter_anisotropic > GLInterface.glinfo.maxanisotropy) + gl_texture_filter_anisotropic = (int32_t)GLInterface.glinfo.maxanisotropy; } - GLInterface.mSamplers->SetTextureFilterMode(hw_texfilter, hw_anisotropy); - // do not force switch indexed textures with the filter. + GLInterface.mSamplers->SetTextureFilterMode(); } //-------------------------------------------------------------------------------------------------- //Use this for both initialization and uninitialization of OpenGL. -static int32_t gltexcacnum = -1; //in-place multiply m0=m0*m1 static float* multiplyMatrix4f(float m0[4*4], const float m1[4*4]) @@ -201,26 +194,8 @@ static float* multiplyMatrix4f(float m0[4*4], const float m1[4*4]) void polymost_glreset() { //Reset if this is -1 (meaning 1st texture call ever), or > 0 (textures in memory) - if (gltexcacnum < 0) - { - gltexcacnum = 0; - - //For 2D calls before 1st polymost_drawrooms() - gcosang = gcosang2 = 16384.f/262144.f; - gsinang = gsinang2 = 0.f; - } - else - { - TexMan.FlushAll(); - } - - if (polymosttext) - delete polymosttext; - polymosttext=nullptr; - -#ifdef DEBUGGINGAIDS - Printf("polymost_glreset()\n"); -#endif + gcosang = gcosang2 = 16384.f/262144.f; + gsinang = gsinang2 = 0.f; } FileReader GetBaseResource(const char* fn); diff --git a/source/core/rendering/gl/system/gl_debug.cpp b/source/common/rendering/gl/gl_debug.cpp similarity index 99% rename from source/core/rendering/gl/system/gl_debug.cpp rename to source/common/rendering/gl/gl_debug.cpp index 60bb78ea4..c6c3adbfc 100644 --- a/source/core/rendering/gl/system/gl_debug.cpp +++ b/source/common/rendering/gl/gl_debug.cpp @@ -20,8 +20,8 @@ */ #include "templates.h" -#include "gl_load/gl_system.h" -#include "gl/system/gl_debug.h" +#include "gl_system.h" +#include "gl_debug.h" #include "stats.h" #include "printf.h" #include diff --git a/source/core/rendering/gl/system/gl_debug.h b/source/common/rendering/gl/gl_debug.h similarity index 96% rename from source/core/rendering/gl/system/gl_debug.h rename to source/common/rendering/gl/gl_debug.h index b989adc6e..e9d64a110 100644 --- a/source/core/rendering/gl/system/gl_debug.h +++ b/source/common/rendering/gl/gl_debug.h @@ -2,7 +2,7 @@ #define __GL_DEBUG_H #include -#include "gl_load/gl_interface.h" +#include "gl_interface.h" #include "c_cvars.h" #include "v_video.h" diff --git a/source/glbackend/gl_samplers.cpp b/source/common/rendering/gl/gl_samplers.cpp similarity index 53% rename from source/glbackend/gl_samplers.cpp rename to source/common/rendering/gl/gl_samplers.cpp index c8177719d..a0573c468 100644 --- a/source/glbackend/gl_samplers.cpp +++ b/source/common/rendering/gl/gl_samplers.cpp @@ -32,63 +32,68 @@ **--------------------------------------------------------------------------- ** */ +#include "gl_system.h" +#include "c_cvars.h" -#include "gl_load.h" -#include "glbackend.h" +#include "gl_interface.h" +#include "hw_cvars.h" +#include "gl_debug.h" +#include "gl_renderer.h" +#include "gl_samplers.h" +#include "hw_material.h" +#include "i_interface.h" -struct TexFilter_s +namespace OpenGLRenderer { - int minfilter; - int magfilter; - bool mipmapping; -} ; -TexFilter_s TexFilter[]={ - {GL_NEAREST, GL_NEAREST, false}, - {GL_LINEAR, GL_LINEAR, false}, - {GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST, true}, - {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}, -}; - +extern TexFilter_s TexFilter[]; + FSamplerManager::FSamplerManager() { - glGenSamplers(NumSamplers, mSamplers); + glGenSamplers(NUMSAMPLERS, mSamplers); - for (int i = SamplerNoFilterRepeat; i <= SamplerNoFilterClampXY; i++) + glSamplerParameteri(mSamplers[CLAMP_X], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_Y], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_XY], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_XY], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_NOFILTER_X], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_NOFILTER_Y], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_NOFILTER_XY], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_NOFILTER_XY], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + for (int i = CLAMP_NOFILTER; i <= CLAMP_NOFILTER_XY; 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[CLAMP_XY_NOMIP], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameterf(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); + glSamplerParameterf(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); - 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); + SetTextureFilterMode(); - glSamplerParameteri(mSamplers[Sampler2DFiltered], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[Sampler2DFiltered], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + for (int i = 0; i < NUMSAMPLERS; i++) + { + FString name; + name.Format("mSamplers[%d]", i); + FGLDebug::LabelObject(GL_SAMPLER, mSamplers[i], name.GetChars()); + } } FSamplerManager::~FSamplerManager() { UnbindAll(); - glDeleteSamplers(NumSamplers, mSamplers); + glDeleteSamplers(NUMSAMPLERS, mSamplers); } void FSamplerManager::UnbindAll() { - for (int i = 0; i < 16 /* fixme */; i++) + for (int i = 0; i < IHardwareTexture::MAX_TEXTURES; i++) { glBindSampler(i, 0); } @@ -102,16 +107,22 @@ uint8_t FSamplerManager::Bind(int texunit, int num, int lastval) } -void FSamplerManager::SetTextureFilterMode(int filter, int anisotropy) +void FSamplerManager::SetTextureFilterMode() { UnbindAll(); + int filter = sysCallbacks && sysCallbacks->DisableTextureFilter && sysCallbacks->DisableTextureFilter() ? 0 : gl_texture_filter; - for (int i = SamplerRepeat; i <= SamplerClampXY; i++) + for (int i = 0; i < 4; 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); + glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_filter_anisotropic); } - glSamplerParameteri(mSamplers[Sampler2DFiltered], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); - glSamplerParameteri(mSamplers[Sampler2DFiltered], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); } + + +} \ No newline at end of file diff --git a/source/common/rendering/gl/gl_samplers.h b/source/common/rendering/gl/gl_samplers.h new file mode 100644 index 000000000..f22e40cdb --- /dev/null +++ b/source/common/rendering/gl/gl_samplers.h @@ -0,0 +1,29 @@ +#ifndef __GL_SAMPLERS_H +#define __GL_SAMPLERS_H + +#include "textures.h" + +namespace OpenGLRenderer +{ + + +class FSamplerManager +{ + unsigned int mSamplers[NUMSAMPLERS]; + + void UnbindAll(); + +public: + + FSamplerManager(); + ~FSamplerManager(); + + uint8_t Bind(int texunit, int num, int lastval); + void SetTextureFilterMode(); + + +}; + +} +#endif + diff --git a/source/common/textures/hw_material.cpp b/source/common/textures/hw_material.cpp index 574b5f10b..ddedcbae1 100644 --- a/source/common/textures/hw_material.cpp +++ b/source/common/textures/hw_material.cpp @@ -29,8 +29,6 @@ #include "c_cvars.h" #include "v_video.h" -IHardwareTexture* CreateHardwareTexture(); - //=========================================================================== // // Constructor diff --git a/source/common/textures/texture.cpp b/source/common/textures/texture.cpp index 016ac4fec..e8626eaf7 100644 --- a/source/common/textures/texture.cpp +++ b/source/common/textures/texture.cpp @@ -50,7 +50,7 @@ #include "c_cvars.h" // Wrappers to keep the definitions of these classes out of here. -IHardwareTexture* CreateHardwareTexture(); +IHardwareTexture* CreateHardwareTexture(int numchannels); // Make sprite offset adjustment user-configurable per renderer. int r_spriteadjustSW, r_spriteadjustHW; @@ -514,7 +514,7 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags) IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags); if (hwtex == nullptr) { - hwtex = CreateHardwareTexture(); + hwtex = CreateHardwareTexture(4); SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex); } return hwtex; @@ -535,7 +535,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) Height = h; Format = bits; //bNoCompress = true; - auto hwtex = CreateHardwareTexture(); + auto hwtex = CreateHardwareTexture(4); // todo: Initialize here. SystemTextures.AddHardwareTexture(0, false, hwtex); } diff --git a/source/common/textures/textures.h b/source/common/textures/textures.h index b3e900ef6..9fc99bda9 100644 --- a/source/common/textures/textures.h +++ b/source/common/textures/textures.h @@ -54,12 +54,16 @@ class IHardwareTexture; enum { CLAMP_NONE = 0, - CLAMP_X = 1, - CLAMP_Y = 2, - CLAMP_XY = 3, - CLAMP_XY_NOMIP = 4, - CLAMP_NOFILTER = 5, - CLAMP_CAMTEX = 6, + CLAMP_X, + CLAMP_Y, + CLAMP_XY, + CLAMP_XY_NOMIP, + CLAMP_NOFILTER, + CLAMP_NOFILTER_X, + CLAMP_NOFILTER_Y, + CLAMP_NOFILTER_XY, + CLAMP_CAMTEX, + NUMSAMPLERS }; enum MaterialShaderIndex diff --git a/source/core/rendering/gl/renderer/gl_postprocess.cpp b/source/core/rendering/gl/renderer/gl_postprocess.cpp index 2c7afe0ad..fa3e23c35 100644 --- a/source/core/rendering/gl/renderer/gl_postprocess.cpp +++ b/source/core/rendering/gl/renderer/gl_postprocess.cpp @@ -24,7 +24,7 @@ #include "gl/system/gl_buffers.h" #include "gl/system/gl_framebuffer.h" #include "gamecvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" //#include "gl/renderer/gl_renderstate.h" #include "gl/renderer/gl_renderbuffers.h" #include "gl/renderer/gl_renderer.h" diff --git a/source/core/rendering/gl/renderer/gl_renderbuffers.cpp b/source/core/rendering/gl/renderer/gl_renderbuffers.cpp index bdc7ca5f1..67ae6a269 100644 --- a/source/core/rendering/gl/renderer/gl_renderbuffers.cpp +++ b/source/core/rendering/gl/renderer/gl_renderbuffers.cpp @@ -24,7 +24,7 @@ #include "printf.h" #include "gl_load/gl_interface.h" #include "gamecvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderbuffers.h" #include "gl/renderer/gl_postprocessstate.h" diff --git a/source/core/rendering/gl/renderer/gl_renderer.cpp b/source/core/rendering/gl/renderer/gl_renderer.cpp index 6b93fbd28..6af6e6d0b 100644 --- a/source/core/rendering/gl/renderer/gl_renderer.cpp +++ b/source/core/rendering/gl/renderer/gl_renderer.cpp @@ -46,7 +46,7 @@ #include "gl_load/gl_interface.h" #include "gl/system/gl_framebuffer.h" #include "gamecvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "gl/renderer/gl_renderer.h" //#include "gl/renderer/gl_renderstate.h" #include "gl/renderer/gl_renderbuffers.h" diff --git a/source/core/rendering/gl/shaders/gl_shaderprogram.cpp b/source/core/rendering/gl/shaders/gl_shaderprogram.cpp index a7b9bf7a4..1fc6f507a 100644 --- a/source/core/rendering/gl/shaders/gl_shaderprogram.cpp +++ b/source/core/rendering/gl/shaders/gl_shaderprogram.cpp @@ -23,7 +23,7 @@ #include "v_video.h" #include "gl_load/gl_interface.h" #include "gamecvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "gl/shaders/gl_shaderprogram.h" #include "hwrenderer/utility/hw_shaderpatcher.h" #include "filesystem.h" diff --git a/source/core/rendering/gl/system/gl_framebuffer.cpp b/source/core/rendering/gl/system/gl_framebuffer.cpp index bd48bb054..259561508 100644 --- a/source/core/rendering/gl/system/gl_framebuffer.cpp +++ b/source/core/rendering/gl/system/gl_framebuffer.cpp @@ -288,7 +288,7 @@ void OpenGLFrameBuffer::SetTextureFilterMode() //if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode(); } -IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture() +IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(int numchannels) { return nullptr;// new FHardwareTexture(true/*tex->bNoCompress*/); } diff --git a/source/core/rendering/gl/system/gl_framebuffer.h b/source/core/rendering/gl/system/gl_framebuffer.h index d4bf644d1..ba4dd0071 100644 --- a/source/core/rendering/gl/system/gl_framebuffer.h +++ b/source/core/rendering/gl/system/gl_framebuffer.h @@ -29,7 +29,7 @@ public: void WriteSavePic(FileWriter* file, int width, int height) override; #ifdef IMPLEMENT_IT void SetTextureFilterMode() override; - IHardwareTexture *CreateHardwareTexture() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; void PrecacheMaterial(FMaterial *mat, int translation) override; FModelRenderer *CreateModelRenderer(int mli) override; void TextureFilterChanged() override; diff --git a/source/core/rendering/v_framebuffer.cpp b/source/core/rendering/v_framebuffer.cpp index c5765d88d..6cddade31 100644 --- a/source/core/rendering/v_framebuffer.cpp +++ b/source/core/rendering/v_framebuffer.cpp @@ -399,7 +399,7 @@ void DFrameBuffer::FinishScene() } } -IHardwareTexture* CreateHardwareTexture() +IHardwareTexture* CreateHardwareTexture(int numchannels) { - return screen->CreateHardwareTexture(); + return screen->CreateHardwareTexture(numchannels); } diff --git a/source/core/rendering/v_video.cpp b/source/core/rendering/v_video.cpp index 65821f0a8..11f34433e 100644 --- a/source/core/rendering/v_video.cpp +++ b/source/core/rendering/v_video.cpp @@ -396,7 +396,7 @@ void V_Init2() Polymost_Startup(); GLInterface.Init(SCREENHEIGHT); GLInterface.InitGLState(4, 4/*glmultisample*/); - GLInterface.mSamplers->SetTextureFilterMode(hw_texfilter, hw_anisotropy); + GLInterface.mSamplers->SetTextureFilterMode(); //setsizeneeded = true; } diff --git a/source/core/rendering/v_video.h b/source/core/rendering/v_video.h index 60ae4a4a5..c0809513c 100644 --- a/source/core/rendering/v_video.h +++ b/source/core/rendering/v_video.h @@ -230,7 +230,7 @@ public: // Delete any resources that need to be deleted after restarting with a different IWAD virtual void CleanForRestart() {} virtual void SetTextureFilterMode() {} - virtual IHardwareTexture *CreateHardwareTexture() { return nullptr; } + virtual IHardwareTexture *CreateHardwareTexture(int numchannels) { return nullptr; } virtual void PrecacheMaterial(FMaterial *mat, int translation) {} virtual FModelRenderer *CreateModelRenderer(int mli) { return nullptr; } virtual void TextureFilterChanged() {} diff --git a/source/duke3d/src/anim.cpp b/source/duke3d/src/anim.cpp index fcb292727..15f38ee48 100644 --- a/source/duke3d/src/anim.cpp +++ b/source/duke3d/src/anim.cpp @@ -403,7 +403,7 @@ int32_t Anim_Play(const char *fn) #endif // ANM playback --- v v v --- - int32_t ogltexfiltermode = hw_texfilter; + int32_t ogltexfiltermode = gl_texture_filter; TArray buffer; auto fr = fileSystem.OpenFileReader(fn); @@ -435,8 +435,8 @@ int32_t Anim_Play(const char *fn) goto end_anim; } - if ((anim->frameflags & CUTSCENE_TEXTUREFILTER && hw_texfilter == TEXFILTER_ON) || anim->frameflags & CUTSCENE_FORCEFILTER) - hw_texfilter = TEXFILTER_ON; + if ((anim->frameflags & CUTSCENE_TEXTUREFILTER && gl_texture_filter == TEXFILTER_ON) || anim->frameflags & CUTSCENE_FORCEFILTER) + gl_texture_filter = TEXFILTER_ON; ototalclock = totalclock; @@ -522,7 +522,7 @@ int32_t Anim_Play(const char *fn) } end_anim_restore_gl: - hw_texfilter = ogltexfiltermode; + gl_texture_filter = ogltexfiltermode; gltexapplyprops(); end_anim: inputState.ClearAllInput(); diff --git a/source/glbackend/gl_samplers.h b/source/glbackend/gl_samplers.h deleted file mode 100644 index 3842dcd8b..000000000 --- a/source/glbackend/gl_samplers.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __GL_SAMPLERS_H -#define __GL_SAMPLERS_H - -#include - -enum ESampler -{ - NoSampler = -1, - SamplerRepeat, - SamplerClampX, - SamplerClampY, - SamplerClampXY, - SamplerNoFilterRepeat, - SamplerNoFilterClampX, - SamplerNoFilterClampY, - SamplerNoFilterClampXY, - Sampler2DFiltered, // Currently unused shpuld be used for 2D content - NumSamplers -}; - - -class FSamplerManager -{ - // We need 6 different samplers: 4 for the different clamping modes, - // one for 2D-textures and one for voxel textures - unsigned int mSamplers[NumSamplers]; - - void UnbindAll(); - void CreateSamplers(); - -public: - - FSamplerManager(); - ~FSamplerManager(); - - uint8_t Bind(int texunit, int num, int lastval); - void SetTextureFilterMode(int mode, int aniso); - - -}; - -#endif - diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index 4a35ddcf4..f739bdde8 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -274,6 +274,10 @@ bool GLInstance::SetTextureInternal(int picnum, FGameTexture* tex, int palette, { sampler = sampler + SamplerNoFilterRepeat - SamplerRepeat; } + else if (tex->isHardwareCanvas()) + { + sampler = CLAMP_CAMTEX; + } UseDetailMapping(false); UseGlowMapping(false); UseBrightmaps(false); diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 28e64be1d..8dde82572 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -52,6 +52,22 @@ float shadediv[MAXPALOOKUPS]; +namespace OpenGLRenderer +{ + + + TexFilter_s TexFilter[] = { + {GL_NEAREST, GL_NEAREST, false}, + {GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST, true}, + {GL_LINEAR, GL_LINEAR, false}, + {GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR, true}, + {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, true}, + {GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST, true}, + {GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST, true}, + }; + +} + static int blendstyles[] = { GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }; static int renderops[] = { GL_FUNC_ADD, GL_FUNC_ADD, GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT }; int depthf[] = { GL_ALWAYS, GL_LESS, GL_EQUAL, GL_LEQUAL }; @@ -85,7 +101,7 @@ void GLInstance::Init(int ydim) { if (!mSamplers) { - mSamplers = new FSamplerManager; + mSamplers = new OpenGLRenderer::FSamplerManager; } //glinfo.bufferstorage = !!strstr(glinfo.extensions, "GL_ARB_buffer_storage"); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 05be4e1da..a740d70ae 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -20,6 +20,19 @@ class F2DDrawer; struct palette_t; extern int xdim, ydim; +enum ESampler +{ + NoSampler = -1, + SamplerRepeat = CLAMP_NONE, + SamplerClampX = CLAMP_X, + SamplerClampY = CLAMP_Y, + SamplerClampXY = CLAMP_XY, + Sampler2DFiltered = CLAMP_XY_NOMIP, // Currently unused shpuld be used for 2D content + SamplerNoFilterRepeat = CLAMP_NOFILTER, + SamplerNoFilterClampX = CLAMP_NOFILTER_X, + SamplerNoFilterClampY = CLAMP_NOFILTER_Y, + SamplerNoFilterClampXY = CLAMP_NOFILTER_XY, +}; enum { PALSWAP_TEXTURE_SIZE = 2048 @@ -131,7 +144,7 @@ class GLInstance public: glinfo_t glinfo; - FSamplerManager *mSamplers; + OpenGLRenderer::FSamplerManager *mSamplers; void Init(int y); void InitGLState(int fogmode, int multisample); diff --git a/source/rr/src/anim.cpp b/source/rr/src/anim.cpp index 4fef90685..4cf94011c 100644 --- a/source/rr/src/anim.cpp +++ b/source/rr/src/anim.cpp @@ -436,7 +436,7 @@ int32_t Anim_Play(const char *fn) #endif // ANM playback --- v v v --- - int32_t ogltexfiltermode = hw_texfilter; + int32_t ogltexfiltermode = gl_texture_filter; auto fr = fileSystem.OpenFileReader(fn); if (!fr.isOpen()) @@ -561,7 +561,7 @@ int32_t Anim_Play(const char *fn) } end_anim_restore_gl: - hw_texfilter = ogltexfiltermode; + gl_texture_filter = ogltexfiltermode; gltexapplyprops(); end_anim: inputState.ClearAllInput(); diff --git a/source/rr/src/premap.cpp b/source/rr/src/premap.cpp index f117cc3ef..dfad8aa7c 100644 --- a/source/rr/src/premap.cpp +++ b/source/rr/src/premap.cpp @@ -573,10 +573,6 @@ void G_CacheMapData(void) S_TryPlaySpecialMusic(MUS_LOADING); -#if defined EDUKE32_TOUCH_DEVICES && defined USE_OPENGL - polymost_glreset(); -#endif - starttime = timerGetTicks(); cacheAllSounds(); diff --git a/wadsrc/static/engine/menudef.txt b/wadsrc/static/engine/menudef.txt index 1ea359b0c..94fd45f1e 100644 --- a/wadsrc/static/engine/menudef.txt +++ b/wadsrc/static/engine/menudef.txt @@ -1231,8 +1231,8 @@ OptionMenu "VideoOptions" //protected Slider "$DSPLYMNU_FOV", "r_fov", 60, 130, 10, 1 StaticText "" - Option "$GLTEXMNU_TEXFILTER", hw_texfilter, "FilterModes" - Option "$GLTEXMNU_ANISOTROPIC", hw_anisotropy, "Anisotropy" + Option "$GLTEXMNU_TEXFILTER", gl_texture_filter, "FilterModes" + Option "$GLTEXMNU_ANISOTROPIC", gl_texture_filter_anisotropic, "Anisotropy" }