mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-27 05:30:56 +00:00
- texture sampler cleanup.
This commit is contained in:
parent
c892fb1ddb
commit
a517b04908
16 changed files with 63 additions and 63 deletions
|
@ -297,9 +297,9 @@ void OpenGLFrameBuffer::SetTextureFilterMode()
|
||||||
if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->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)
|
void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
void UpdatePalette() override;
|
void UpdatePalette() override;
|
||||||
const char* DeviceName() const override;
|
const char* DeviceName() const override;
|
||||||
void SetTextureFilterMode() override;
|
void SetTextureFilterMode() override;
|
||||||
IHardwareTexture *CreateHardwareTexture() override;
|
IHardwareTexture *CreateHardwareTexture(int numchannels) override;
|
||||||
void PrecacheMaterial(FMaterial *mat, int translation) override;
|
void PrecacheMaterial(FMaterial *mat, int translation) override;
|
||||||
void TextureFilterChanged() override;
|
void TextureFilterChanged() override;
|
||||||
void BeginFrame() override;
|
void BeginFrame() override;
|
||||||
|
|
|
@ -59,20 +59,6 @@ TexFilter_s TexFilter[]={
|
||||||
{GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST, true},
|
{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
|
// Static texture data
|
||||||
|
|
|
@ -34,20 +34,21 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool forcenocompression;
|
bool forcenofilter;
|
||||||
|
|
||||||
unsigned int glTexID = 0;
|
unsigned int glTexID = 0;
|
||||||
unsigned int glDepthID = 0; // only used by camera textures
|
unsigned int glDepthID = 0; // only used by camera textures
|
||||||
unsigned int glBufferID = 0;
|
unsigned int glBufferID = 0;
|
||||||
int glTextureBytes = 4;
|
int glTextureBytes;
|
||||||
bool mipmapped = false;
|
bool mipmapped = false;
|
||||||
|
|
||||||
int GetDepthBuffer(int w, int h);
|
int GetDepthBuffer(int w, int h);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FHardwareTexture(bool nocompress)
|
FHardwareTexture(int numchannels = 4, bool disablefilter = false)
|
||||||
{
|
{
|
||||||
forcenocompression = nocompress;
|
forcenofilter = disablefilter;
|
||||||
|
glTextureBytes = numchannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
~FHardwareTexture();
|
~FHardwareTexture();
|
||||||
|
|
|
@ -51,22 +51,33 @@ extern TexFilter_s TexFilter[];
|
||||||
|
|
||||||
FSamplerManager::FSamplerManager()
|
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();
|
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;
|
FString name;
|
||||||
name.Format("mSamplers[%d]", i);
|
name.Format("mSamplers[%d]", i);
|
||||||
|
@ -77,7 +88,7 @@ FSamplerManager::FSamplerManager()
|
||||||
FSamplerManager::~FSamplerManager()
|
FSamplerManager::~FSamplerManager()
|
||||||
{
|
{
|
||||||
UnbindAll();
|
UnbindAll();
|
||||||
glDeleteSamplers(7, mSamplers);
|
glDeleteSamplers(NUMSAMPLERS, mSamplers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSamplerManager::UnbindAll()
|
void FSamplerManager::UnbindAll()
|
||||||
|
@ -107,10 +118,10 @@ void FSamplerManager::SetTextureFilterMode()
|
||||||
glSamplerParameteri(mSamplers[i], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
glSamplerParameteri(mSamplers[i], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_filter_anisotropic);
|
glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_filter_anisotropic);
|
||||||
}
|
}
|
||||||
glSamplerParameteri(mSamplers[4], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter);
|
glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter);
|
||||||
glSamplerParameteri(mSamplers[4], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
glSamplerParameteri(mSamplers[6], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter);
|
glSamplerParameteri(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter);
|
||||||
glSamplerParameteri(mSamplers[6], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
glSamplerParameteri(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
#define __GL_SAMPLERS_H
|
#define __GL_SAMPLERS_H
|
||||||
|
|
||||||
#include "gl_hwtexture.h"
|
#include "gl_hwtexture.h"
|
||||||
|
#include "textures.h"
|
||||||
|
|
||||||
namespace OpenGLRenderer
|
namespace OpenGLRenderer
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
class FSamplerManager
|
class FSamplerManager
|
||||||
{
|
{
|
||||||
// We need 6 different samplers: 4 for the different clamping modes,
|
unsigned int mSamplers[NUMSAMPLERS];
|
||||||
// one for 2D-textures and one for voxel textures
|
|
||||||
unsigned int mSamplers[7];
|
|
||||||
|
|
||||||
void UnbindAll();
|
void UnbindAll();
|
||||||
|
|
||||||
|
|
|
@ -305,7 +305,7 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture()
|
IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture(int numchannels)
|
||||||
{
|
{
|
||||||
return new PolyHardwareTexture();
|
return new PolyHardwareTexture();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
void AmbientOccludeScene(float m5) override;
|
void AmbientOccludeScene(float m5) override;
|
||||||
//void SetSceneRenderTarget(bool useSSAO) override;
|
//void SetSceneRenderTarget(bool useSSAO) override;
|
||||||
|
|
||||||
IHardwareTexture *CreateHardwareTexture() override;
|
IHardwareTexture *CreateHardwareTexture(int numchannels) override;
|
||||||
IVertexBuffer *CreateVertexBuffer() override;
|
IVertexBuffer *CreateVertexBuffer() override;
|
||||||
IIndexBuffer *CreateIndexBuffer() override;
|
IIndexBuffer *CreateIndexBuffer() override;
|
||||||
IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override;
|
IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override;
|
||||||
|
|
|
@ -104,7 +104,7 @@ public:
|
||||||
FVector3 u = normalize3(eyeCoordPos);
|
FVector3 u = normalize3(eyeCoordPos);
|
||||||
FVector3 n = normalize3(mul(Viewpoint->mNormalViewMatrix, FVector4(parmTexCoord.X, 0.0f, parmTexCoord.Y, 0.0f)));
|
FVector3 n = normalize3(mul(Viewpoint->mNormalViewMatrix, FVector4(parmTexCoord.X, 0.0f, parmTexCoord.Y, 0.0f)));
|
||||||
FVector3 r = reflect(u, n);
|
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.X = r.X / m + 0.5f;
|
||||||
vTexCoord.Y = r.Y / m + 0.5f;
|
vTexCoord.Y = r.Y / m + 0.5f;
|
||||||
}
|
}
|
||||||
|
@ -138,13 +138,13 @@ public:
|
||||||
private:
|
private:
|
||||||
static FVector3 normalize(const FVector3 &a)
|
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);
|
return FVector3(a.X * rcplen, a.Y * rcplen, a.Z * rcplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FVector3 normalize3(const FVector4 &a)
|
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);
|
return FVector3(a.X * rcplen, a.Y * rcplen, a.Z * rcplen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -457,9 +457,9 @@ DEFINE_GLOBAL(CleanYfac_1)
|
||||||
DEFINE_GLOBAL(CleanWidth_1)
|
DEFINE_GLOBAL(CleanWidth_1)
|
||||||
DEFINE_GLOBAL(CleanHeight_1)
|
DEFINE_GLOBAL(CleanHeight_1)
|
||||||
|
|
||||||
IHardwareTexture* CreateHardwareTexture()
|
IHardwareTexture* CreateHardwareTexture(int numchannels)
|
||||||
{
|
{
|
||||||
return screen->CreateHardwareTexture();
|
return screen->CreateHardwareTexture(numchannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -197,7 +197,7 @@ public:
|
||||||
|
|
||||||
// Delete any resources that need to be deleted after restarting with a different IWAD
|
// Delete any resources that need to be deleted after restarting with a different IWAD
|
||||||
virtual void SetTextureFilterMode() {}
|
virtual void SetTextureFilterMode() {}
|
||||||
virtual IHardwareTexture *CreateHardwareTexture() { return nullptr; }
|
virtual IHardwareTexture *CreateHardwareTexture(int numchannels) { return nullptr; }
|
||||||
virtual void PrecacheMaterial(FMaterial *mat, int translation) {}
|
virtual void PrecacheMaterial(FMaterial *mat, int translation) {}
|
||||||
virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags);
|
virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags);
|
||||||
virtual void TextureFilterChanged() {}
|
virtual void TextureFilterChanged() {}
|
||||||
|
|
|
@ -379,7 +379,7 @@ void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture()
|
IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture(int numchannels)
|
||||||
{
|
{
|
||||||
return new VkHardwareTexture();
|
return new VkHardwareTexture();
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public:
|
||||||
void ImageTransitionScene(bool unknown) override;
|
void ImageTransitionScene(bool unknown) override;
|
||||||
void SetActiveRenderTarget() override;
|
void SetActiveRenderTarget() override;
|
||||||
|
|
||||||
IHardwareTexture *CreateHardwareTexture() override;
|
IHardwareTexture *CreateHardwareTexture(int numchannels) override;
|
||||||
FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override;
|
FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override;
|
||||||
IVertexBuffer *CreateVertexBuffer() override;
|
IVertexBuffer *CreateVertexBuffer() override;
|
||||||
IIndexBuffer *CreateIndexBuffer() override;
|
IIndexBuffer *CreateIndexBuffer() override;
|
||||||
|
|
|
@ -29,8 +29,6 @@
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
|
|
||||||
IHardwareTexture* CreateHardwareTexture();
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// Constructor
|
// Constructor
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
|
|
||||||
// Wrappers to keep the definitions of these classes out of here.
|
// 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.
|
// Make sprite offset adjustment user-configurable per renderer.
|
||||||
int r_spriteadjustSW, r_spriteadjustHW;
|
int r_spriteadjustSW, r_spriteadjustHW;
|
||||||
|
@ -514,7 +514,7 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags)
|
||||||
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags);
|
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags);
|
||||||
if (hwtex == nullptr)
|
if (hwtex == nullptr)
|
||||||
{
|
{
|
||||||
hwtex = CreateHardwareTexture();
|
hwtex = CreateHardwareTexture(4);
|
||||||
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
|
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
|
||||||
}
|
}
|
||||||
return hwtex;
|
return hwtex;
|
||||||
|
@ -535,7 +535,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
|
||||||
Height = h;
|
Height = h;
|
||||||
Format = bits;
|
Format = bits;
|
||||||
//bNoCompress = true;
|
//bNoCompress = true;
|
||||||
auto hwtex = CreateHardwareTexture();
|
auto hwtex = CreateHardwareTexture(4);
|
||||||
// todo: Initialize here.
|
// todo: Initialize here.
|
||||||
SystemTextures.AddHardwareTexture(0, false, hwtex);
|
SystemTextures.AddHardwareTexture(0, false, hwtex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,12 +54,16 @@ class IHardwareTexture;
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
CLAMP_NONE = 0,
|
CLAMP_NONE = 0,
|
||||||
CLAMP_X = 1,
|
CLAMP_X,
|
||||||
CLAMP_Y = 2,
|
CLAMP_Y,
|
||||||
CLAMP_XY = 3,
|
CLAMP_XY,
|
||||||
CLAMP_XY_NOMIP = 4,
|
CLAMP_XY_NOMIP,
|
||||||
CLAMP_NOFILTER = 5,
|
CLAMP_NOFILTER,
|
||||||
CLAMP_CAMTEX = 6,
|
CLAMP_NOFILTER_X,
|
||||||
|
CLAMP_NOFILTER_Y,
|
||||||
|
CLAMP_NOFILTER_XY,
|
||||||
|
CLAMP_CAMTEX,
|
||||||
|
NUMSAMPLERS
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MaterialShaderIndex
|
enum MaterialShaderIndex
|
||||||
|
|
Loading…
Reference in a new issue