diff --git a/src/common/rendering/gl/gl_framebuffer.cpp b/src/common/rendering/gl/gl_framebuffer.cpp index 96d8170b6..628756b6d 100644 --- a/src/common/rendering/gl/gl_framebuffer.cpp +++ b/src/common/rendering/gl/gl_framebuffer.cpp @@ -297,9 +297,9 @@ void OpenGLFrameBuffer::SetTextureFilterMode() if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode(); } -IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture() +IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(int numchannels) { - return new FHardwareTexture(true/*tex->bNoCompress*/); + return new FHardwareTexture(numchannels); } void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) diff --git a/src/common/rendering/gl/gl_framebuffer.h b/src/common/rendering/gl/gl_framebuffer.h index 28c4c4d2a..a99aef08c 100644 --- a/src/common/rendering/gl/gl_framebuffer.h +++ b/src/common/rendering/gl/gl_framebuffer.h @@ -41,7 +41,7 @@ public: void UpdatePalette() override; const char* DeviceName() const override; void SetTextureFilterMode() override; - IHardwareTexture *CreateHardwareTexture() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; void PrecacheMaterial(FMaterial *mat, int translation) override; void TextureFilterChanged() override; void BeginFrame() override; diff --git a/src/common/rendering/gl/gl_hwtexture.cpp b/src/common/rendering/gl/gl_hwtexture.cpp index 143aba183..c27304ee6 100644 --- a/src/common/rendering/gl/gl_hwtexture.cpp +++ b/src/common/rendering/gl/gl_hwtexture.cpp @@ -59,20 +59,6 @@ TexFilter_s TexFilter[]={ {GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST, true}, }; -int TexFormat[]={ - GL_RGBA8, - GL_RGB5_A1, - GL_RGBA4, - GL_RGBA2, - // [BB] Added compressed texture formats. - GL_COMPRESSED_RGBA_ARB, - GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, - GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, -}; - - - //=========================================================================== // // Static texture data diff --git a/src/common/rendering/gl/gl_hwtexture.h b/src/common/rendering/gl/gl_hwtexture.h index d25131d77..41d8ae44a 100644 --- a/src/common/rendering/gl/gl_hwtexture.h +++ b/src/common/rendering/gl/gl_hwtexture.h @@ -34,20 +34,21 @@ public: private: - bool forcenocompression; + bool forcenofilter; unsigned int glTexID = 0; unsigned int glDepthID = 0; // only used by camera textures unsigned int glBufferID = 0; - int glTextureBytes = 4; + int glTextureBytes; bool mipmapped = false; int GetDepthBuffer(int w, int h); public: - FHardwareTexture(bool nocompress) + FHardwareTexture(int numchannels = 4, bool disablefilter = false) { - forcenocompression = nocompress; + forcenofilter = disablefilter; + glTextureBytes = numchannels; } ~FHardwareTexture(); diff --git a/src/common/rendering/gl/gl_samplers.cpp b/src/common/rendering/gl/gl_samplers.cpp index a9f45dc2f..caaedd6cc 100644 --- a/src/common/rendering/gl/gl_samplers.cpp +++ b/src/common/rendering/gl/gl_samplers.cpp @@ -51,22 +51,33 @@ extern TexFilter_s TexFilter[]; FSamplerManager::FSamplerManager() { - glGenSamplers(7, mSamplers); + glGenSamplers(NUMSAMPLERS, mSamplers); + + 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[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); + SetTextureFilterMode(); - 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[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); - for (int i = 0; i < 7; i++) + for (int i = 0; i < NUMSAMPLERS; i++) { FString name; name.Format("mSamplers[%d]", i); @@ -77,7 +88,7 @@ FSamplerManager::FSamplerManager() FSamplerManager::~FSamplerManager() { UnbindAll(); - glDeleteSamplers(7, mSamplers); + glDeleteSamplers(NUMSAMPLERS, mSamplers); } void FSamplerManager::UnbindAll() @@ -107,10 +118,10 @@ void FSamplerManager::SetTextureFilterMode() glSamplerParameteri(mSamplers[i], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_filter_anisotropic); } - glSamplerParameteri(mSamplers[4], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); - glSamplerParameteri(mSamplers[4], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); - glSamplerParameteri(mSamplers[6], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); - glSamplerParameteri(mSamplers[6], 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); } diff --git a/src/common/rendering/gl/gl_samplers.h b/src/common/rendering/gl/gl_samplers.h index 93c8c7419..109f910a5 100644 --- a/src/common/rendering/gl/gl_samplers.h +++ b/src/common/rendering/gl/gl_samplers.h @@ -2,15 +2,15 @@ #define __GL_SAMPLERS_H #include "gl_hwtexture.h" +#include "textures.h" namespace OpenGLRenderer { + 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[7]; + unsigned int mSamplers[NUMSAMPLERS]; void UnbindAll(); diff --git a/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp index 19ecb6871..d9cb212e3 100644 --- a/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -305,7 +305,7 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) } } -IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture() +IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture(int numchannels) { return new PolyHardwareTexture(); } diff --git a/src/common/rendering/polyrenderer/backend/poly_framebuffer.h b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h index c96dfa321..68e722a2b 100644 --- a/src/common/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h @@ -44,7 +44,7 @@ public: void AmbientOccludeScene(float m5) override; //void SetSceneRenderTarget(bool useSSAO) override; - IHardwareTexture *CreateHardwareTexture() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override; diff --git a/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h b/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h index 8ae178127..aaf613d98 100644 --- a/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h +++ b/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h @@ -104,7 +104,7 @@ public: FVector3 u = normalize3(eyeCoordPos); FVector3 n = normalize3(mul(Viewpoint->mNormalViewMatrix, FVector4(parmTexCoord.X, 0.0f, parmTexCoord.Y, 0.0f))); FVector3 r = reflect(u, n); - float m = 2.0f * sqrt(r.X*r.X + r.Y*r.Y + (r.Z + 1.0f)*(r.Z + 1.0f)); + float m = 2.0f * sqrtf(r.X*r.X + r.Y*r.Y + (r.Z + 1.0f)*(r.Z + 1.0f)); vTexCoord.X = r.X / m + 0.5f; vTexCoord.Y = r.Y / m + 0.5f; } @@ -138,13 +138,13 @@ public: private: static FVector3 normalize(const FVector3 &a) { - float rcplen = 1.0f / sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z); + float rcplen = 1.0f / sqrtf(a.X * a.X + a.Y * a.Y + a.Z * a.Z); return FVector3(a.X * rcplen, a.Y * rcplen, a.Z * rcplen); } static FVector3 normalize3(const FVector4 &a) { - float rcplen = 1.0f / sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z); + float rcplen = 1.0f / sqrtf(a.X * a.X + a.Y * a.Y + a.Z * a.Z); return FVector3(a.X * rcplen, a.Y * rcplen, a.Z * rcplen); } diff --git a/src/common/rendering/v_video.cpp b/src/common/rendering/v_video.cpp index 9a4b455f8..7035e54cc 100644 --- a/src/common/rendering/v_video.cpp +++ b/src/common/rendering/v_video.cpp @@ -457,9 +457,9 @@ DEFINE_GLOBAL(CleanYfac_1) DEFINE_GLOBAL(CleanWidth_1) DEFINE_GLOBAL(CleanHeight_1) -IHardwareTexture* CreateHardwareTexture() +IHardwareTexture* CreateHardwareTexture(int numchannels) { - return screen->CreateHardwareTexture(); + return screen->CreateHardwareTexture(numchannels); } //========================================================================== diff --git a/src/common/rendering/v_video.h b/src/common/rendering/v_video.h index e284ca79f..1cb32573e 100644 --- a/src/common/rendering/v_video.h +++ b/src/common/rendering/v_video.h @@ -197,7 +197,7 @@ public: // Delete any resources that need to be deleted after restarting with a different IWAD virtual void SetTextureFilterMode() {} - virtual IHardwareTexture *CreateHardwareTexture() { return nullptr; } + virtual IHardwareTexture *CreateHardwareTexture(int numchannels) { return nullptr; } virtual void PrecacheMaterial(FMaterial *mat, int translation) {} virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags); virtual void TextureFilterChanged() {} diff --git a/src/common/rendering/vulkan/system/vk_framebuffer.cpp b/src/common/rendering/vulkan/system/vk_framebuffer.cpp index 8cc0046ea..76e9c219f 100644 --- a/src/common/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/common/rendering/vulkan/system/vk_framebuffer.cpp @@ -379,7 +379,7 @@ void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) } } -IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture() +IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture(int numchannels) { return new VkHardwareTexture(); } diff --git a/src/common/rendering/vulkan/system/vk_framebuffer.h b/src/common/rendering/vulkan/system/vk_framebuffer.h index 537879e6a..b325466fe 100644 --- a/src/common/rendering/vulkan/system/vk_framebuffer.h +++ b/src/common/rendering/vulkan/system/vk_framebuffer.h @@ -89,7 +89,7 @@ public: void ImageTransitionScene(bool unknown) override; void SetActiveRenderTarget() override; - IHardwareTexture *CreateHardwareTexture() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 293082607..4f5c301db 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -29,8 +29,6 @@ #include "c_cvars.h" #include "v_video.h" -IHardwareTexture* CreateHardwareTexture(); - //=========================================================================== // // Constructor diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 016ac4fec..e8626eaf7 100644 --- a/src/common/textures/texture.cpp +++ b/src/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/src/common/textures/textures.h b/src/common/textures/textures.h index b3e900ef6..9fc99bda9 100644 --- a/src/common/textures/textures.h +++ b/src/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