- viewport and scissor moved to render state.

This commit is contained in:
Christoph Oelckers 2020-01-03 10:48:01 +01:00
parent cfc0ba48cb
commit 27ed6cdae5
3 changed files with 45 additions and 21 deletions

View file

@ -37,6 +37,8 @@ enum PRSFlags
STF_WIREFRAME = 512, STF_WIREFRAME = 512,
STF_CLEARCOLOR = 1024, STF_CLEARCOLOR = 1024,
STF_CLEARDEPTH = 2048, STF_CLEARDEPTH = 2048,
STF_VIEWPORTSET = 4096,
STF_SCISSORSET = 4096,
}; };
@ -57,6 +59,8 @@ struct PolymostRenderState
int StateFlags = STF_COLORMASK|STF_DEPTHMASK; int StateFlags = STF_COLORMASK|STF_DEPTHMASK;
FRenderStyle Style{}; FRenderStyle Style{};
PalEntry ClearColor = 0; PalEntry ClearColor = 0;
short vp_x, vp_y, vp_w, vp_h;
short sc_x, sc_y, sc_w, sc_h;
PalEntry FogColor; PalEntry FogColor;

View file

@ -340,18 +340,6 @@ void GLInstance::SetMatrix(int num, const VSMatrix *mat)
} }
} }
void GLInstance::SetScissor(int x1, int y1, int x2, int y2)
{
glScissor(x1, y1, x2, y2);
glEnable(GL_SCISSOR_TEST);
}
void GLInstance::DisableScissor()
{
glDisable(GL_SCISSOR_TEST);
}
void GLInstance::SetColor(float r, float g, float b, float a) void GLInstance::SetColor(float r, float g, float b, float a)
{ {
glVertexAttrib4f(2, r, g, b, a); glVertexAttrib4f(2, r, g, b, a);
@ -364,11 +352,6 @@ void GLInstance::SetDepthFunc(int func)
glDepthFunc(f[func]); glDepthFunc(f[func]);
} }
void GLInstance::SetViewport(int x, int y, int w, int h)
{
glViewport(x, y, w, h);
}
void GLInstance::ReadPixels(int xdim, int ydim, uint8_t* buffer) void GLInstance::ReadPixels(int xdim, int ydim, uint8_t* buffer)
{ {
glReadPixels(0, 0, xdim, ydim, GL_RGB, GL_UNSIGNED_BYTE, buffer); glReadPixels(0, 0, xdim, ydim, GL_RGB, GL_UNSIGNED_BYTE, buffer);
@ -494,8 +477,23 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState &oldState)
if (StateFlags & STF_CLEARCOLOR) bit |= GL_COLOR_BUFFER_BIT; if (StateFlags & STF_CLEARCOLOR) bit |= GL_COLOR_BUFFER_BIT;
if (StateFlags & STF_CLEARDEPTH) bit |= GL_DEPTH_BUFFER_BIT; if (StateFlags & STF_CLEARDEPTH) bit |= GL_DEPTH_BUFFER_BIT;
glClear(bit); glClear(bit);
StateFlags &= ~(STF_CLEARCOLOR|STF_CLEARDEPTH);
} }
if (StateFlags & STF_VIEWPORTSET)
{
glViewport(vp_x, vp_y, vp_w, vp_h);
}
if (StateFlags & STF_SCISSORSET)
{
if (sc_x >= 0)
{
glScissor(sc_x, sc_y, sc_w, sc_h);
glEnable(GL_SCISSOR_TEST);
}
else
glDisable(GL_SCISSOR_TEST);
}
StateFlags &= ~(STF_CLEARCOLOR | STF_CLEARDEPTH | STF_VIEWPORTSET | STF_SCISSORSET);
oldState.Flags = StateFlags; oldState.Flags = StateFlags;
} }
if (Style != oldState.Style) if (Style != oldState.Style)

View file

@ -287,10 +287,7 @@ public:
SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f)); SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f));
} }
void SetScissor(int x1, int y1, int x2, int y2);
void DisableScissor();
void SetDepthFunc(int func); void SetDepthFunc(int func);
void SetViewport(int x, int y, int w, int h);
void SetPolymostShader(); void SetPolymostShader();
void SetSurfaceShader(); void SetSurfaceShader();
void SetVPXShader(); void SetVPXShader();
@ -405,6 +402,31 @@ public:
if (depth) renderState.StateFlags |= STF_CLEARDEPTH; if (depth) renderState.StateFlags |= STF_CLEARDEPTH;
} }
void SetViewport(int x, int y, int w, int h)
{
renderState.vp_x = (short)x;
renderState.vp_y = (short)y;
renderState.vp_w = (short)w;
renderState.vp_h = (short)h;
renderState.StateFlags |= STF_VIEWPORTSET;
}
void SetScissor(int x1, int y1, int x2, int y2)
{
renderState.sc_x = (short)x1;
renderState.sc_y = (short)y1;
renderState.sc_w = (short)x2;
renderState.sc_h = (short)y2;
renderState.StateFlags |= STF_SCISSORSET;
}
void DisableScissor()
{
renderState.sc_x = -1;
renderState.StateFlags |= STF_SCISSORSET;
}
void ClearScreen(PalEntry pe) void ClearScreen(PalEntry pe)
{ {
//twod->Clear(); //twod->Clear();