- moved matrices to render state.

This commit is contained in:
Christoph Oelckers 2020-01-03 23:38:50 +01:00
parent 9de5814063
commit d4b32c535a
7 changed files with 47 additions and 79 deletions

View File

@ -1801,7 +1801,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
GLInterface.SetCull(Cull_None);
VSMatrix identity(0);
GLInterface.SetMatrix(Matrix_ModelView, &identity);
GLInterface.SetIdentityMatrix(Matrix_ModelView);
GLInterface.SetTinting(0, 0, PalEntry(255, 255, 255));
GLInterface.SetClamp(prevClamp);

View File

@ -348,7 +348,7 @@ static void resizeglcheck(void)
m[3][2] = -(2.f * farclip * nearclip) / (farclip - nearclip);
GLInterface.SetMatrix(Matrix_Projection, &m[0][0]);
VSMatrix identity(0);
GLInterface.SetMatrix(Matrix_ModelView, &identity);
GLInterface.SetIdentityMatrix(Matrix_ModelView);
}
}
@ -451,11 +451,7 @@ static void polymost_updaterotmat(void)
static void polymost_identityrotmat(void)
{
if (1)
{
VSMatrix matrix(0);
GLInterface.SetMatrix(Matrix_View, &matrix);
}
GLInterface.SetIdentityMatrix(Matrix_View);
}
static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, int32_t method, const vec2_16_t& tilesiz);
@ -4681,7 +4677,7 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a,
GLInterface.SetMatrix(Matrix_Projection, &m[0][0]);
VSMatrix identity(0);
GLInterface.SetMatrix(Matrix_ModelView, &identity);
GLInterface.SetIdentityMatrix(Matrix_ModelView);
}
if (hud->flags & HUDFLAG_NODEPTH)

View File

@ -1189,7 +1189,7 @@ int32_t polymost_voxdraw(voxmodel_t *m, tspriteptr_t const tspr)
GLInterface.SetDepthFunc(Depth_Less);
}
VSMatrix identity(0);
GLInterface.SetMatrix(Matrix_ModelView, &identity);
GLInterface.SetIdentityMatrix(Matrix_ModelView);
GLInterface.SetFadeDisable(false);
GLInterface.SetTinting(0, 0, PalEntry(255, 255, 255));
return 1;

View File

@ -6,6 +6,17 @@
class PolymostShader;
struct GLState;
enum EMatrixType
{
Matrix_View,
Matrix_Projection,
Matrix_ModelView,
Matrix_Detail,
Matrix_Texture,
// These are the only ones being used.
NUMMATRICES
};
enum PRSFlags
{
RF_ColorOnly = 1,
@ -56,6 +67,7 @@ struct PolymostRenderState
float AlphaThreshold = 0.5f;
bool AlphaTest = true;
float Color[4] = { 1,1,1,1 };
short matrixIndex[NUMMATRICES] = { -1,-1,-1,-1,-1 };
int StateFlags = STF_COLORMASK|STF_DEPTHMASK;
FRenderStyle Style{};

View File

@ -55,6 +55,7 @@ static int blendstyles[] = { GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALP
static int renderops[] = { GL_FUNC_ADD, GL_FUNC_ADD, GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT };
int depthf[] = { GL_ALWAYS, GL_LESS, GL_EQUAL, GL_LEQUAL };
static TArray<VSMatrix> matrixArray;
FileReader GetResource(const char* fn)
{
@ -211,16 +212,6 @@ std::pair<size_t, BaseVertex *> GLInstance::AllocVertices(size_t num)
return std::make_pair((size_t)0, Buffer.data());
}
void GLInstance::RestoreTextureProps()
{
// todo: reset everything that's needed to ensure proper functionality
VSMatrix identity(0);
if (MatrixChange & 1) GLInterface.SetMatrix(Matrix_Texture, &identity);
if (MatrixChange & 2) GLInterface.SetMatrix(Matrix_Detail, &identity);
MatrixChange = 0;
}
static GLint primtypes[] =
{
GL_TRIANGLES,
@ -279,7 +270,13 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count)
{
glDrawArrays(primtypes[type], start, count);
}
if (MatrixChange) RestoreTextureProps();
if (MatrixChange)
{
if (MatrixChange & 1) SetIdentityMatrix(Matrix_Texture);
if (MatrixChange & 2) SetIdentityMatrix(Matrix_Detail);
MatrixChange = 0;
}
matrixArray.Resize(1);
}
void GLInstance::BindTexture(int texunit, FHardwareTexture *tex, int sampler)
@ -320,32 +317,8 @@ void GLInstance::UnbindAllTextures()
void GLInstance::SetMatrix(int num, const VSMatrix *mat)
{
matrices[num] = *mat;
switch(num)
{
default:
return;
case Matrix_View:
polymostShader->RotMatrix.Set(mat->get());
break;
case Matrix_Projection:
polymostShader->ProjectionMatrix.Set(mat->get());
break;
case Matrix_ModelView:
polymostShader->ModelMatrix.Set(mat->get());
break;
case Matrix_Detail:
polymostShader->DetailMatrix.Set(mat->get());
break;
case Matrix_Texture:
polymostShader->TextureMatrix.Set(mat->get());
break;
}
renderState.matrixIndex[num] = matrixArray.Size();
matrixArray.Push(*mat);
}
void GLInstance::ReadPixels(int xdim, int ydim, uint8_t* buffer)
@ -517,6 +490,16 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
shader->AlphaThreshold.Set(AlphaTest ? AlphaThreshold : -1.f);
shader->Brightness.Set(Brightness);
shader->FogColor.Set(FogColor);
if (matrixIndex[Matrix_View] != -1)
shader->RotMatrix.Set(matrixArray[matrixIndex[Matrix_View]].get());
if (matrixIndex[Matrix_Projection] != -1)
shader->ProjectionMatrix.Set(matrixArray[matrixIndex[Matrix_Projection]].get());
if (matrixIndex[Matrix_ModelView] != -1)
shader->ModelMatrix.Set(matrixArray[matrixIndex[Matrix_ModelView]].get());
if (matrixIndex[Matrix_Detail] != -1)
shader->DetailMatrix.Set(matrixArray[matrixIndex[Matrix_Detail]].get());
if (matrixIndex[Matrix_Texture] != -1)
shader->TextureMatrix.Set(matrixArray[matrixIndex[Matrix_Texture]].get());
memset(matrixIndex, -1, sizeof(matrixIndex));
}

View File

@ -131,17 +131,6 @@ enum EDrawType
DT_LINES
};
enum EMatrixType
{
Matrix_View,
Matrix_Projection,
Matrix_ModelView,
Matrix_Detail,
Matrix_Texture,
// These are the only ones being used.
NUMMATRICES
};
enum ECull
{
Cull_None,
@ -280,14 +269,16 @@ public:
{
SetMatrix(num, reinterpret_cast<const VSMatrix*>(mat));
}
void SetIdentityMatrix(int num)
{
renderState.matrixIndex[num] = 0;
}
void SetPolymostShader();
void SetSurfaceShader();
void SetVPXShader();
void SetPalette(int palette);
bool ApplyTextureProps(FTexture *tex, int pal);
void RestoreTextureProps();
void ReadPixels(int w, int h, uint8_t* buffer);
void SetPaletteData(int index, const uint8_t* data)

View File

@ -233,11 +233,8 @@ void GLInstance::Draw2D(F2DDrawer *drawer)
void fullscreen_tint_gl(PalEntry pe)
{
// Todo: reroute to the 2D drawer
auto oldproj = GLInterface.GetMatrix(Matrix_Projection);
auto oldmv = GLInterface.GetMatrix(Matrix_ModelView);
VSMatrix identity(0);
GLInterface.SetMatrix(Matrix_Projection, &identity);
GLInterface.SetMatrix(Matrix_ModelView, &identity);
GLInterface.SetIdentityMatrix(Matrix_Projection);
GLInterface.SetIdentityMatrix(Matrix_ModelView);
GLInterface.EnableDepthTest(false);
GLInterface.EnableAlphaTest(false);
@ -255,21 +252,14 @@ void fullscreen_tint_gl(PalEntry pe)
vt[2].Set(.0f, -2.5f);
GLInterface.Draw(DT_TRIANGLES, data.first, 3);
GLInterface.UseColorOnly(false);
GLInterface.SetMatrix(Matrix_Projection, &oldproj);
GLInterface.SetMatrix(Matrix_ModelView, &oldmv);
}
void fullscreen_tint_gl_blood(int tint_blood_r, int tint_blood_g, int tint_blood_b)
{
if (!(tint_blood_r | tint_blood_g | tint_blood_b))
return;
auto oldproj = GLInterface.GetMatrix(Matrix_Projection);
auto oldmv = GLInterface.GetMatrix(Matrix_ModelView);
VSMatrix identity(0);
GLInterface.SetMatrix(Matrix_Projection, &identity);
GLInterface.SetMatrix(Matrix_ModelView, &identity);
GLInterface.SetIdentityMatrix(Matrix_Projection);
GLInterface.SetIdentityMatrix(Matrix_ModelView);
GLInterface.EnableDepthTest(false);
GLInterface.EnableAlphaTest(false);
@ -296,10 +286,6 @@ void fullscreen_tint_gl_blood(int tint_blood_r, int tint_blood_g, int tint_blood
GLInterface.SetColorub(255, 255, 255, 255);
GLInterface.SetRenderStyle(LegacyRenderStyles[STYLE_Translucent]);
GLInterface.UseColorOnly(false);
GLInterface.SetMatrix(Matrix_Projection, &oldproj);
GLInterface.SetMatrix(Matrix_ModelView, &oldmv);
}
static int32_t tint_blood_r = 0, tint_blood_g = 0, tint_blood_b = 0;