- route texture binding through the renderstate class for better control. Currently it's just a direct passthrough but this will change.

This commit is contained in:
Christoph Oelckers 2014-09-09 12:00:42 +02:00
parent d5633701b4
commit 4bb320a27c
16 changed files with 37 additions and 35 deletions

View file

@ -303,7 +303,7 @@ void FDMDModel::RenderFrame(FTexture * skin, int frameno, int frameno2, double i
FMaterial * tex = FMaterial::ValidateTexture(skin, false); FMaterial * tex = FMaterial::ValidateTexture(skin, false);
tex->Bind(CLAMP_NONE, translation, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_NONE, translation, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
GLRenderer->mModelVBO->SetupFrame(frames[frameno].vindex, frames[frameno2].vindex, inter); GLRenderer->mModelVBO->SetupFrame(frames[frameno].vindex, frames[frameno2].vindex, inter);

View file

@ -267,7 +267,7 @@ void FMD3Model::RenderFrame(FTexture * skin, int frameno, int frameno2, double i
FMaterial * tex = FMaterial::ValidateTexture(surfaceSkin, false); FMaterial * tex = FMaterial::ValidateTexture(surfaceSkin, false);
tex->Bind(CLAMP_NONE, translation, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_NONE, translation, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
GLRenderer->mModelVBO->SetupFrame(surf->vindex + frameno * surf->numVertices, surf->vindex + frameno2 * surf->numVertices, inter); GLRenderer->mModelVBO->SetupFrame(surf->vindex + frameno * surf->numVertices, surf->vindex + frameno2 * surf->numVertices, inter);

View file

@ -417,7 +417,7 @@ int FVoxelModel::FindFrame(const char * name)
void FVoxelModel::RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation) void FVoxelModel::RenderFrame(FTexture * skin, int frame, int frame2, double inter, int translation)
{ {
FMaterial * tex = FMaterial::ValidateTexture(skin, false); FMaterial * tex = FMaterial::ValidateTexture(skin, false);
tex->Bind(CLAMP_NOFILTER, translation, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_NOFILTER, translation, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
GLRenderer->mModelVBO->SetupFrame(vindex, vindex, 0.f); GLRenderer->mModelVBO->SetupFrame(vindex, vindex, 0.f);

View file

@ -329,7 +329,7 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms)
} }
} }
gl_SetRenderStyle(parms.style, !parms.masked, false); gl_SetRenderStyle(parms.style, !parms.masked, false);
gltex->Bind(CLAMP_XY_NOMIP, translation, 0, !!(parms.style.Flags & STYLEF_RedIsAlpha)); gl_RenderState.SetMaterial(gltex, CLAMP_XY_NOMIP, translation, 0, !!(parms.style.Flags & STYLEF_RedIsAlpha));
u1 = gltex->GetUL(); u1 = gltex->GetUL();
v1 = gltex->GetVT(); v1 = gltex->GetVT();
@ -339,7 +339,7 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms)
} }
else else
{ {
gltex->Bind(CLAMP_XY_NOMIP, 0, -1, false); gl_RenderState.SetMaterial(gltex, CLAMP_XY_NOMIP, 0, -1, false);
u1 = 0.f; u1 = 0.f;
v1 = 1.f; v1 = 1.f;
u2 = 1.f; u2 = 1.f;
@ -493,7 +493,7 @@ void FGLRenderer::FlatFill (int left, int top, int right, int bottom, FTexture *
if (!gltexture) return; if (!gltexture) return;
gltexture->Bind(CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
// scaling is not used here. // scaling is not used here.
if (!local_origin) if (!local_origin)
@ -586,7 +586,7 @@ void FGLRenderer::FillSimplePoly(FTexture *texture, FVector2 *points, int npoint
gl_SetColor(lightlevel, 0, cm, 1.f); gl_SetColor(lightlevel, 0, cm, 1.f);
gltexture->Bind(CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
int i; int i;
float rot = float(rotation * M_PI / float(1u << 31)); float rot = float(rotation * M_PI / float(1u << 31));

View file

@ -5,6 +5,7 @@
#include "gl/system/gl_interface.h" #include "gl/system/gl_interface.h"
#include "gl/data/gl_data.h" #include "gl/data/gl_data.h"
#include "gl/data/gl_matrix.h" #include "gl/data/gl_matrix.h"
#include "gl/textures/gl_material.h"
#include "c_cvars.h" #include "c_cvars.h"
#include "r_defs.h" #include "r_defs.h"
@ -97,10 +98,11 @@ public:
void Reset(); void Reset();
void SetShader(int shaderindex, float warptime) void SetMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader, bool alphatexture)
{ {
mEffectState = shaderindex; mEffectState = overrideshader >= 0? overrideshader : mat->mShaderIndex;
mShaderTimer = warptime; mShaderTimer = mat->tex->gl_info.shaderspeed;
mat->Bind(clampmode, translation, alphatexture);
} }
void Apply(); void Apply();

View file

@ -319,7 +319,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
gl_SetRenderStyle(decal->RenderStyle, false, false); gl_SetRenderStyle(decal->RenderStyle, false, false);
tex->Bind(CLAMP_XY, decal->Translation, 0, !!(decal->RenderStyle.Flags & STYLEF_RedIsAlpha)); gl_RenderState.SetMaterial(tex, CLAMP_XY, decal->Translation, 0, !!(decal->RenderStyle.Flags & STYLEF_RedIsAlpha));
// If srcalpha is one it looks better with a higher alpha threshold // If srcalpha is one it looks better with a higher alpha threshold

View file

@ -1097,7 +1097,7 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo
int rel = getExtraLight(); int rel = getExtraLight();
gl_SetColor(lightlevel, rel, Colormap, 1.0f); gl_SetColor(lightlevel, rel, Colormap, 1.0f);
gl_SetFog(lightlevel, rel, &Colormap, false); gl_SetFog(lightlevel, rel, &Colormap, false);
gltexture->Bind(CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
float fviewx = FIXED2FLOAT(viewx); float fviewx = FIXED2FLOAT(viewx);
float fviewy = FIXED2FLOAT(viewy); float fviewy = FIXED2FLOAT(viewy);

View file

@ -341,7 +341,7 @@ void GLFlat::Draw(int pass, bool trans) // trans only has meaning for GLPASS_LIG
case GLPASS_ALL: case GLPASS_ALL:
gl_SetColor(lightlevel, rel, Colormap,1.0f); gl_SetColor(lightlevel, rel, Colormap,1.0f);
gl_SetFog(lightlevel, rel, &Colormap, false); gl_SetFog(lightlevel, rel, &Colormap, false);
gltexture->Bind(CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
gl_SetPlaneTextureRotation(&plane, gltexture); gl_SetPlaneTextureRotation(&plane, gltexture);
DrawSubsectors(pass, (pass == GLPASS_ALL || dynlightindex > -1), false); DrawSubsectors(pass, (pass == GLPASS_ALL || dynlightindex > -1), false);
gl_RenderState.EnableTextureMatrix(false); gl_RenderState.EnableTextureMatrix(false);
@ -367,7 +367,7 @@ void GLFlat::Draw(int pass, bool trans) // trans only has meaning for GLPASS_LIG
} }
else else
{ {
gltexture->Bind(CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
gl_SetPlaneTextureRotation(&plane, gltexture); gl_SetPlaneTextureRotation(&plane, gltexture);
DrawSubsectors(pass, true, true); DrawSubsectors(pass, true, true);
gl_RenderState.EnableTextureMatrix(false); gl_RenderState.EnableTextureMatrix(false);

View file

@ -1011,7 +1011,7 @@ void GLHorizonPortal::DrawContents()
} }
gltexture->Bind(CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
gl_SetPlaneTextureRotation(sp, gltexture); gl_SetPlaneTextureRotation(sp, gltexture);
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);

View file

@ -1119,7 +1119,7 @@ void FGLInterface::RenderTextureView (FCanvasTexture *tex, AActor *Viewpoint, in
if (!usefb) if (!usefb)
{ {
glFlush(); glFlush();
gltex->Bind(0, 0, -1, false); gl_RenderState.SetMaterial(gltex, 0, 0, -1, false);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bounds.width, bounds.height); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, bounds.width, bounds.height);
} }
else else

View file

@ -268,7 +268,7 @@ void RenderDome(FMaterial * tex, float x_offset, float y_offset, bool mirror, in
if (tex) if (tex)
{ {
tex->Bind(CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_NONE, 0, -1, false);
texw = tex->TextureWidth(); texw = tex->TextureWidth();
texh = tex->TextureHeight(); texh = tex->TextureHeight();
gl_RenderState.EnableModelMatrix(true); gl_RenderState.EnableModelMatrix(true);
@ -333,7 +333,7 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
// north // north
tex = FMaterial::ValidateTexture(sb->faces[0], false); tex = FMaterial::ValidateTexture(sb->faces[0], false);
tex->Bind(CLAMP_XY, 0, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
ptr = GLRenderer->mVBO->GetBuffer(); ptr = GLRenderer->mVBO->GetBuffer();
@ -349,7 +349,7 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
// east // east
tex = FMaterial::ValidateTexture(sb->faces[1], false); tex = FMaterial::ValidateTexture(sb->faces[1], false);
tex->Bind(CLAMP_XY, 0, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
ptr = GLRenderer->mVBO->GetBuffer(); ptr = GLRenderer->mVBO->GetBuffer();
@ -365,7 +365,7 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
// south // south
tex = FMaterial::ValidateTexture(sb->faces[2], false); tex = FMaterial::ValidateTexture(sb->faces[2], false);
tex->Bind(CLAMP_XY, 0, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
ptr = GLRenderer->mVBO->GetBuffer(); ptr = GLRenderer->mVBO->GetBuffer();
@ -381,7 +381,7 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
// west // west
tex = FMaterial::ValidateTexture(sb->faces[3], false); tex = FMaterial::ValidateTexture(sb->faces[3], false);
tex->Bind(CLAMP_XY, 0, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
ptr = GLRenderer->mVBO->GetBuffer(); ptr = GLRenderer->mVBO->GetBuffer();
@ -425,7 +425,7 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
// top // top
tex = FMaterial::ValidateTexture(sb->faces[faces], false); tex = FMaterial::ValidateTexture(sb->faces[faces], false);
tex->Bind(CLAMP_XY, 0, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
ptr = GLRenderer->mVBO->GetBuffer(); ptr = GLRenderer->mVBO->GetBuffer();
@ -441,7 +441,7 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
// bottom // bottom
tex = FMaterial::ValidateTexture(sb->faces[faces+1], false); tex = FMaterial::ValidateTexture(sb->faces[faces+1], false);
tex->Bind(CLAMP_XY, 0, -1, false); gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
gl_RenderState.Apply(); gl_RenderState.Apply();
ptr = GLRenderer->mVBO->GetBuffer(); ptr = GLRenderer->mVBO->GetBuffer();

View file

@ -214,7 +214,7 @@ void GLSprite::Draw(int pass)
gl_RenderState.SetFog(0, 0); gl_RenderState.SetFog(0, 0);
} }
if (gltexture) gltexture->Bind(CLAMP_XY, translation, OverrideShader, !!(RenderStyle.Flags & STYLEF_RedIsAlpha)); if (gltexture) gl_RenderState.SetMaterial(gltexture, CLAMP_XY, translation, OverrideShader, !!(RenderStyle.Flags & STYLEF_RedIsAlpha));
else if (!modelframe) gl_RenderState.EnableTexture(false); else if (!modelframe) gl_RenderState.EnableTexture(false);
if (!modelframe) if (!modelframe)

View file

@ -274,7 +274,7 @@ void GLWall::RenderMirrorSurface()
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
FMaterial * pat=FMaterial::ValidateTexture(GLRenderer->mirrortexture, false); FMaterial * pat=FMaterial::ValidateTexture(GLRenderer->mirrortexture, false);
pat->Bind(CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(pat, CLAMP_NONE, 0, -1, false);
flags &= ~GLWF_GLOW; flags &= ~GLWF_GLOW;
RenderWall(RWF_BLANK); RenderWall(RWF_BLANK);
@ -326,7 +326,7 @@ void GLWall::RenderTranslucentWall()
if (gltexture) if (gltexture)
{ {
gl_RenderState.EnableGlow(!!(flags & GLWF_GLOW)); gl_RenderState.EnableGlow(!!(flags & GLWF_GLOW));
gltexture->Bind(flags & 3, 0, -1, false); gl_RenderState.SetMaterial(gltexture, flags & 3, 0, -1, false);
extra = getExtraLight(); extra = getExtraLight();
} }
else else
@ -390,7 +390,7 @@ void GLWall::Draw(int pass)
else gl_SetFog(255, 0, NULL, false); else gl_SetFog(255, 0, NULL, false);
gl_RenderState.EnableGlow(!!(flags & GLWF_GLOW)); gl_RenderState.EnableGlow(!!(flags & GLWF_GLOW));
gltexture->Bind(flags & 3, false, -1, false); gl_RenderState.SetMaterial(gltexture, flags & 3, false, -1, false);
RenderWall(RWF_TEXTURED|RWF_GLOW); RenderWall(RWF_TEXTURED|RWF_GLOW);
gl_RenderState.EnableGlow(false); gl_RenderState.EnableGlow(false);
break; break;

View file

@ -96,7 +96,7 @@ void FGLRenderer::DrawPSprite (player_t * player,pspdef_t *psp,fixed_t sx, fixed
FMaterial * tex = FMaterial::ValidateTexture(lump, true, false); FMaterial * tex = FMaterial::ValidateTexture(lump, true, false);
if (!tex) return; if (!tex) return;
tex->Bind(CLAMP_XY_NOMIP, 0, OverrideShader, alphatexture); gl_RenderState.SetMaterial(tex, CLAMP_XY_NOMIP, 0, OverrideShader, alphatexture);
int vw = viewwidth; int vw = viewwidth;
int vh = viewheight; int vh = viewheight;

View file

@ -616,11 +616,9 @@ static int lastclamp;
static int lasttrans; static int lasttrans;
static bool lastalpha; static bool lastalpha;
void FMaterial::Bind(int clampmode, int translation, int overrideshader, bool alphatexture)
{
int shaderindex = overrideshader >= 0? overrideshader : mShaderIndex;
gl_RenderState.SetShader(shaderindex, tex->gl_info.shaderspeed);
void FMaterial::Bind(int clampmode, int translation, bool alphatexture)
{
// avoid rebinding the same texture multiple times. // avoid rebinding the same texture multiple times.
if (this == last && lastclamp == clampmode && translation == lasttrans && lastalpha == alphatexture) return; if (this == last && lastclamp == clampmode && translation == lasttrans && lastalpha == alphatexture) return;
last = this; last = this;
@ -636,7 +634,7 @@ void FMaterial::Bind(int clampmode, int translation, int overrideshader, bool al
else if (tex->bWarped && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; else if (tex->bWarped && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;
const FHardwareTexture *gltexture = mBaseLayer->Bind(0, clampmode, translation, alphatexture, allowhires? tex:NULL); const FHardwareTexture *gltexture = mBaseLayer->Bind(0, clampmode, translation, alphatexture, allowhires? tex:NULL);
if (gltexture != NULL && shaderindex > 0 && overrideshader == -1) if (gltexture != NULL)
{ {
for(unsigned i=0;i<mTextureLayers.Size();i++) for(unsigned i=0;i<mTextureLayers.Size();i++)
{ {
@ -671,7 +669,7 @@ void FMaterial::Bind(int clampmode, int translation, int overrideshader, bool al
//=========================================================================== //===========================================================================
void FMaterial::Precache() void FMaterial::Precache()
{ {
Bind(0, 0, 0, false); Bind(0, 0, false);
} }
//=========================================================================== //===========================================================================

View file

@ -93,6 +93,8 @@ public:
class FMaterial class FMaterial
{ {
friend class FRenderState;
struct FTextureLayer struct FTextureLayer
{ {
FTexture *texture; FTexture *texture;
@ -137,7 +139,7 @@ public:
} }
//void Bind(int clamp = 0, int translation = 0, int overrideshader = 0, bool alphatexture = false); //void Bind(int clamp = 0, int translation = 0, int overrideshader = 0, bool alphatexture = false);
void Bind(int clamp, int translation, int overrideshader, bool alphatexture); void Bind(int clamp, int translation, bool alphatexture);
unsigned char * CreateTexBuffer(int translation, int & w, int & h, bool allowhires=true) const unsigned char * CreateTexBuffer(int translation, int & w, int & h, bool allowhires=true) const
{ {