- texture sampler cleanup.

This commit is contained in:
Christoph Oelckers 2020-05-28 22:51:17 +02:00
parent c892fb1ddb
commit a517b04908
16 changed files with 63 additions and 63 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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

View file

@ -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();

View file

@ -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);
}

View file

@ -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();

View file

@ -305,7 +305,7 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
}
}
IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture()
IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture(int numchannels)
{
return new PolyHardwareTexture();
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
}
//==========================================================================

View file

@ -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() {}

View file

@ -379,7 +379,7 @@ void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
}
}
IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture()
IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture(int numchannels)
{
return new VkHardwareTexture();
}

View file

@ -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;

View file

@ -29,8 +29,6 @@
#include "c_cvars.h"
#include "v_video.h"
IHardwareTexture* CreateHardwareTexture();
//===========================================================================
//
// Constructor

View file

@ -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);
}

View file

@ -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