mirror of
https://github.com/ZDoom/gzdoom-last-svn.git
synced 2025-05-31 09:21:06 +00:00
- found one major opportunity for optimization: Changing clamping settings for textures is extremely expensive.
As a consequence there will now be multiple hardware textures for the same game texture in different clamping modes. Depending on the current view this can boost performance by more than 10%. git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@569 b0f79afe-0144-0410-b225-9a4edf0717df
This commit is contained in:
parent
0b27afb4c9
commit
f613e3c9ac
8 changed files with 98 additions and 92 deletions
|
@ -187,28 +187,6 @@ void FGLRenderer::FlushTextures()
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
void FGLRenderer::PrecacheTexture(FTexture *tex)
|
||||
{
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(tex);
|
||||
if (gltex)
|
||||
{
|
||||
if (tex->UseType==FTexture::TEX_Sprite)
|
||||
{
|
||||
gltex->BindPatch(CM_DEFAULT, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
gltex->Bind (CM_DEFAULT, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
bool FGLRenderer::StartOffscreen()
|
||||
{
|
||||
if (gl.flags & RFL_FRAMEBUFFER)
|
||||
|
@ -240,18 +218,6 @@ void FGLRenderer::EndOffscreen()
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
void FGLRenderer::UncacheTexture(FTexture *tex)
|
||||
{
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(tex);
|
||||
if (gltex) gltex->Clean(true);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
unsigned char *FGLRenderer::GetTextureBuffer(FTexture *tex, int &w, int &h)
|
||||
{
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(tex);
|
||||
|
|
|
@ -121,8 +121,6 @@ public:
|
|||
void ProcessSector(sector_t *fakesector, subsector_t *sub);
|
||||
void FlushTextures();
|
||||
void RenderTextureView (FCanvasTexture *self, AActor *viewpoint, int fov);
|
||||
void PrecacheTexture(FTexture *tex);
|
||||
void UncacheTexture(FTexture *tex);
|
||||
unsigned char *GetTextureBuffer(FTexture *tex, int &w, int &h);
|
||||
void SetupLevel();
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ unsigned * FHardwareTexture::GetTexID(int cm, int translation)
|
|||
// Binds this patch
|
||||
//
|
||||
//===========================================================================
|
||||
unsigned int FHardwareTexture::Bind(int texunit, int cm,int translation, int clampmode)
|
||||
unsigned int FHardwareTexture::Bind(int texunit, int cm,int translation)
|
||||
{
|
||||
unsigned int * pTexID=GetTexID(cm, translation);
|
||||
|
||||
|
@ -419,24 +419,3 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
|||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// SetTextureClamp
|
||||
// sets and caches the texture clamping mode
|
||||
// while this operation was not problematic on XP
|
||||
// it appears to cause severe slowdowns on Vista so cache the
|
||||
// clamping mode and only set when it really changes
|
||||
//
|
||||
//===========================================================================
|
||||
void FHardwareTexture::SetTextureClamp(int newclampmode)
|
||||
{
|
||||
if (!gl_clamp_per_texture || (clampmode&GLT_CLAMPX) != (newclampmode&GLT_CLAMPX))
|
||||
{
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, newclampmode&GLT_CLAMPX? GL_CLAMP_TO_EDGE : GL_REPEAT);
|
||||
}
|
||||
if (!gl_clamp_per_texture || (clampmode&GLT_CLAMPY) != (newclampmode&GLT_CLAMPY))
|
||||
{
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, newclampmode&GLT_CLAMPY? GL_CLAMP_TO_EDGE : GL_REPEAT);
|
||||
}
|
||||
clampmode = newclampmode;
|
||||
}
|
||||
|
|
|
@ -69,10 +69,9 @@ public:
|
|||
|
||||
void BindToFrameBuffer();
|
||||
|
||||
unsigned int Bind(int texunit, int cm, int translation=0, int clampmode = -1);
|
||||
unsigned int Bind(int texunit, int cm, int translation=0);
|
||||
unsigned int CreateTexture(unsigned char * buffer, int w, int h,bool wrap, int texunit, int cm, int translation=0);
|
||||
void Resize(int _width, int _height) ;
|
||||
void SetTextureClamp(int clampmode);
|
||||
|
||||
void Clean(bool all);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ FGLTexture::FGLTexture(FTexture * tx, bool expandpatches)
|
|||
tex = tx;
|
||||
|
||||
glpatch=NULL;
|
||||
gltexture=NULL;
|
||||
for(int i=0;i<5;i++) gltexture[i]=NULL;
|
||||
HiresLump=-1;
|
||||
hirestexture = NULL;
|
||||
currentwarp = 0;
|
||||
|
@ -164,13 +164,16 @@ unsigned char *FGLTexture::LoadHiresTexture(int *width, int *height, int cm)
|
|||
|
||||
void FGLTexture::Clean(bool all)
|
||||
{
|
||||
if (gltexture)
|
||||
for(int i=0;i<5;i++)
|
||||
{
|
||||
if (!all) gltexture->Clean(false);
|
||||
else
|
||||
if (gltexture[i])
|
||||
{
|
||||
delete gltexture;
|
||||
gltexture=NULL;
|
||||
if (!all) gltexture[i]->Clean(false);
|
||||
else
|
||||
{
|
||||
delete gltexture[i];
|
||||
gltexture[i]=NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (glpatch)
|
||||
|
@ -350,12 +353,14 @@ unsigned char * FGLTexture::CreateTexBuffer(int _cm, int translation, int & w, i
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
bool FGLTexture::CreateTexture()
|
||||
FHardwareTexture *FGLTexture::CreateTexture(int clampmode)
|
||||
{
|
||||
if (tex->UseType==FTexture::TEX_Null) return false; // Cannot register a NULL texture
|
||||
if (!gltexture) gltexture=new FHardwareTexture(tex->GetWidth(), tex->GetHeight(), true, true);
|
||||
if (gltexture) return true;
|
||||
return false;
|
||||
if (tex->UseType==FTexture::TEX_Null) return NULL; // Cannot register a NULL texture
|
||||
if (!gltexture[clampmode])
|
||||
{
|
||||
gltexture[clampmode] = new FHardwareTexture(tex->GetWidth(), tex->GetHeight(), true, true);
|
||||
}
|
||||
return gltexture[clampmode];
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -375,6 +380,7 @@ bool FGLTexture::CreatePatch()
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Binds a texture to the renderer
|
||||
|
@ -390,17 +396,35 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int cm, int clampmode, int
|
|||
else if (translation == TRANSLATION(TRANSLATION_Standard, 7)) translation = CM_ICE;
|
||||
else translation = GLTranslationPalette::GetInternalTranslation(translation);
|
||||
|
||||
if (CreateTexture())
|
||||
FHardwareTexture *hwtex;
|
||||
|
||||
if (gltexture[4] != NULL && clampmode < 4 && gltexture[clampmode] == NULL)
|
||||
{
|
||||
hwtex = gltexture[clampmode] = gltexture[4];
|
||||
gltexture[4] = NULL;
|
||||
|
||||
if (hwtex->Bind(texunit, cm, translation))
|
||||
{
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (clampmode & GLT_CLAMPX)? GL_CLAMP_TO_EDGE : GL_REPEAT);
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (clampmode & GLT_CLAMPY)? GL_CLAMP_TO_EDGE : GL_REPEAT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hwtex = CreateTexture(clampmode);
|
||||
}
|
||||
|
||||
if (hwtex)
|
||||
{
|
||||
if (warp != 0 || currentwarp != warp)
|
||||
{
|
||||
// must recreate the texture
|
||||
Clean(true);
|
||||
CreateTexture();
|
||||
hwtex = CreateTexture(clampmode);
|
||||
}
|
||||
|
||||
// Bind it to the system.
|
||||
if (!gltexture->Bind(texunit, cm, translation, clampmode))
|
||||
if (!hwtex->Bind(texunit, cm, translation))
|
||||
{
|
||||
|
||||
int w, h;
|
||||
|
@ -413,18 +437,19 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int cm, int clampmode, int
|
|||
buffer = CreateTexBuffer(cm, translation, w, h, false, allowhires, warp);
|
||||
tex->ProcessData(buffer, w, h, false);
|
||||
}
|
||||
if (!gltexture->CreateTexture(buffer, w, h, true, texunit, cm, translation))
|
||||
if (!hwtex->CreateTexture(buffer, w, h, true, texunit, cm, translation))
|
||||
{
|
||||
// could not create texture
|
||||
delete buffer;
|
||||
return NULL;
|
||||
}
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (clampmode & GLT_CLAMPX)? GL_CLAMP_TO_EDGE : GL_REPEAT);
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (clampmode & GLT_CLAMPY)? GL_CLAMP_TO_EDGE : GL_REPEAT);
|
||||
delete buffer;
|
||||
}
|
||||
gltexture->SetTextureClamp(clampmode);
|
||||
|
||||
if (tex->bHasCanvas) static_cast<FCanvasTexture*>(tex)->NeedUpdate();
|
||||
return gltexture;
|
||||
return hwtex;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -454,7 +479,7 @@ const FHardwareTexture * FGLTexture::BindPatch(int texunit, int cm, int translat
|
|||
}
|
||||
|
||||
// Bind it to the system.
|
||||
if (!glpatch->Bind(texunit, cm, translation, -1))
|
||||
if (!glpatch->Bind(texunit, cm, translation))
|
||||
{
|
||||
int w, h;
|
||||
|
||||
|
@ -468,9 +493,6 @@ const FHardwareTexture * FGLTexture::BindPatch(int texunit, int cm, int translat
|
|||
return NULL;
|
||||
}
|
||||
delete buffer;
|
||||
}
|
||||
if (gl_render_precise)
|
||||
{
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
@ -479,7 +501,6 @@ const FHardwareTexture * FGLTexture::BindPatch(int texunit, int cm, int translat
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
|
@ -621,6 +642,8 @@ FMaterial::~FMaterial()
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Binds a texture to the renderer
|
||||
|
@ -636,6 +659,10 @@ const WorldTextureInfo *FMaterial::Bind(int cm, int clampmode, int translation)
|
|||
|
||||
int softwarewarp = gl_RenderState.SetupShader(tex->bHasCanvas, shaderindex, cm, tex->gl_info.shaderspeed);
|
||||
|
||||
if (tex->bHasCanvas) clampmode = 0;
|
||||
else if (clampmode != -1) clampmode &= 3;
|
||||
else clampmode = 4;
|
||||
|
||||
wti.gltexture = mBaseLayer->Bind(0, cm, clampmode, translation, allowhires, softwarewarp);
|
||||
if (wti.gltexture != NULL && shaderindex > 0)
|
||||
{
|
||||
|
@ -697,6 +724,32 @@ const PatchTextureInfo * FMaterial::BindPatch(int cm, int translation)
|
|||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
void FMaterial::Precache()
|
||||
{
|
||||
if (tex->UseType==FTexture::TEX_Sprite)
|
||||
{
|
||||
BindPatch(CM_DEFAULT, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int cached = 0;
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
if (mBaseLayer->gltexture[i] != 0)
|
||||
{
|
||||
Bind (CM_DEFAULT, i, 0);
|
||||
cached++;
|
||||
}
|
||||
if (cached == 0) Bind(CM_DEFAULT, -1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
|
@ -705,9 +758,17 @@ const PatchTextureInfo * FMaterial::BindPatch(int cm, int translation)
|
|||
|
||||
const WorldTextureInfo *FMaterial::GetWorldTextureInfo()
|
||||
{
|
||||
if (mBaseLayer->CreateTexture())
|
||||
for(int i=0;i<5;i++)
|
||||
{
|
||||
wti.gltexture = mBaseLayer->gltexture;
|
||||
if (mBaseLayer->gltexture[i])
|
||||
{
|
||||
wti.gltexture = mBaseLayer->gltexture[i];
|
||||
return &wti;
|
||||
}
|
||||
}
|
||||
if (mBaseLayer->CreateTexture(4))
|
||||
{
|
||||
wti.gltexture = mBaseLayer->gltexture[4];
|
||||
return &wti;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -846,7 +907,7 @@ void FMaterial::BindToFrameBuffer()
|
|||
mBaseLayer->Bind(0, CM_DEFAULT, 0, 0, false, false);
|
||||
FHardwareTexture::Unbind(0);
|
||||
}
|
||||
mBaseLayer->gltexture->BindToFrameBuffer();
|
||||
mBaseLayer->gltexture[0]->BindToFrameBuffer();
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
int HiresLump;
|
||||
|
||||
private:
|
||||
FHardwareTexture *gltexture;
|
||||
FHardwareTexture *gltexture[5];
|
||||
FHardwareTexture *glpatch;
|
||||
|
||||
int currentwarp;
|
||||
|
@ -91,7 +91,8 @@ private:
|
|||
unsigned char * LoadHiresTexture(int *width, int *height, int cm);
|
||||
BYTE *WarpBuffer(BYTE *buffer, int Width, int Height, int warp);
|
||||
|
||||
bool CreateTexture();
|
||||
FHardwareTexture *CreateTexture(int clampmode);
|
||||
//bool CreateTexture();
|
||||
bool CreatePatch();
|
||||
|
||||
const FHardwareTexture *Bind(int texunit, int cm, int clamp, int translation, bool allowhires, int warp);
|
||||
|
@ -148,6 +149,7 @@ public:
|
|||
|
||||
FMaterial(FTexture *tex, bool forceexpand);
|
||||
~FMaterial();
|
||||
void Precache();
|
||||
|
||||
const WorldTextureInfo * Bind(int cm, int clamp=0, int translation=0);
|
||||
const PatchTextureInfo * BindPatch(int cm, int translation=0);
|
||||
|
|
|
@ -314,7 +314,8 @@ void FTexture::PrecacheGL()
|
|||
{
|
||||
if (gl_precache)
|
||||
{
|
||||
GLRenderer->PrecacheTexture(this);
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(this);
|
||||
if (gltex) gltex->Precache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,7 +327,7 @@ void FTexture::PrecacheGL()
|
|||
|
||||
void FTexture::UncacheGL()
|
||||
{
|
||||
GLRenderer->UncacheTexture(this);
|
||||
if (gl_info.Material) gl_info.Material->Clean(true);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -41,15 +41,15 @@
|
|||
|
||||
/** Lots of different version numbers **/
|
||||
|
||||
#define DOTVERSIONSTR_NOREV "1.3.3 beta"
|
||||
#define DOTVERSIONSTR_NOREV "1.3.4 beta"
|
||||
#define ZDVER_STRING "2.3.1"
|
||||
|
||||
// The version string the user actually sees.
|
||||
#define DOTVERSIONSTR DOTVERSIONSTR_NOREV " (r" SVN_REVISION_STRING ") / ZDoom" ZDVER_STRING " (r" ZD_SVN_REVISION_STRING ")"
|
||||
|
||||
// The version as seen in the Windows resource
|
||||
#define RC_FILEVERSION 1,3,3,SVN_REVISION_NUMBER
|
||||
#define RC_PRODUCTVERSION 1,3,3,0
|
||||
#define RC_FILEVERSION 1,3,4,SVN_REVISION_NUMBER
|
||||
#define RC_PRODUCTVERSION 1,3,4,0
|
||||
#define RC_FILEVERSION2 DOTVERSIONSTR
|
||||
#define RC_PRODUCTVERSION2 "1.3"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue