From b209b1f960a69e28ec557d10601cfcbe77bab14b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Jan 2020 14:08:48 +0100 Subject: [PATCH] - make sure that the first matrix is always the identity matrix. It was just random luck that it was always put there before. - let the matrix setters return the previous value for easy restoring without creating yet another matrix. --- source/glbackend/glbackend.cpp | 15 ++++++--------- source/glbackend/glbackend.h | 14 ++++++++++---- source/glbackend/hw_draw2d.cpp | 6 +++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 7257ce950..b2b366d11 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -73,7 +73,8 @@ GLInstance GLInterface; GLInstance::GLInstance() :palmanager(this) { - + VSMatrix mat(0); + matrixArray.Push(mat); } void ImGui_Init_Backend(); @@ -239,9 +240,6 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) void GLInstance::DrawElement(EDrawType type, size_t start, size_t count, PolymostRenderState &renderState) { - // Todo: Based on the current tinting flags and the texture type (indexed texture and APPLYOVERPALSWAP not set) this may have to reset the palette for the draw call / texture creation. - bool applied = false; - if (activeShader == polymostShader) { glVertexAttrib4fv(2, renderState.Color); @@ -262,24 +260,23 @@ void GLInstance::DoDraw() { for (auto& rs : rendercommands) { - // Todo: Based on the current tinting flags and the texture type (indexed texture and APPLYOVERPALSWAP not set) this may have to reset the palette for the draw call / texture creation. - bool applied = false; - glVertexAttrib4fv(2, rs.Color); if (rs.Color[3] != 1.f) rs.Flags &= ~RF_Brightmapping; // The way the colormaps are set up means that brightmaps cannot be used on translucent content at all. rs.Apply(polymostShader, lastState); glDrawArrays(primtypes[rs.primtype], rs.vindex, rs.vcount); } rendercommands.Clear(); - matrixArray.Clear(); + matrixArray.Resize(1); } -void GLInstance::SetMatrix(int num, const VSMatrix *mat) +int GLInstance::SetMatrix(int num, const VSMatrix *mat) { + int r = renderState.matrixIndex[num]; if (num == Matrix_Projection) mProjectionM5 = mat->get()[5]; renderState.matrixIndex[num] = matrixArray.Size(); matrixArray.Push(*mat); + return r; } void GLInstance::ReadPixels(int xdim, int ydim, uint8_t* buffer) diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 14bfabfcf..ca281e096 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -208,14 +208,20 @@ public: void ClearBufferState(); float GetProjectionM5() { return mProjectionM5; } - void SetMatrix(int num, const VSMatrix *mat ); - void SetMatrix(int num, const float *mat) + int SetMatrix(int num, const VSMatrix *mat ); + int SetMatrix(int num, const float *mat) { - SetMatrix(num, reinterpret_cast(mat)); + return SetMatrix(num, reinterpret_cast(mat)); } - void SetIdentityMatrix(int num) + int SetIdentityMatrix(int num) { + auto r = renderState.matrixIndex[num]; renderState.matrixIndex[num] = 0; + return r; + } + void RestoreMatrix(int num, int index) + { + renderState.matrixIndex[num] = index; } void SetPolymostShader(); diff --git a/source/glbackend/hw_draw2d.cpp b/source/glbackend/hw_draw2d.cpp index 7d4dfc87d..60a6140e1 100644 --- a/source/glbackend/hw_draw2d.cpp +++ b/source/glbackend/hw_draw2d.cpp @@ -97,9 +97,9 @@ void polymost_dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16 void GLInstance::Draw2D(F2DDrawer *drawer) { VSMatrix mat(0); - SetMatrix(Matrix_View, mat.get()); - SetMatrix(Matrix_ModelView, mat.get()); - SetMatrix(Matrix_Detail, mat.get()); + SetIdentityMatrix(Matrix_View); + SetIdentityMatrix(Matrix_ModelView); + SetIdentityMatrix(Matrix_Detail); mat.ortho(0, xdim, ydim, 0, -1, 1); SetMatrix(Matrix_Projection, mat.get()); SetViewport(0, 0, xdim, ydim);