- 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.
This commit is contained in:
Christoph Oelckers 2020-01-19 14:08:48 +01:00
parent 57a455d6cb
commit b209b1f960
3 changed files with 19 additions and 16 deletions

View file

@ -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)

View file

@ -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<const VSMatrix*>(mat));
return SetMatrix(num, reinterpret_cast<const VSMatrix*>(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();

View file

@ -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);