metal: implement depth/stencil state

This commit is contained in:
Alex Szpakowski
2020-06-14 21:14:56 -03:00
parent 9d2dca5740
commit 9aa9319eb5
9 changed files with 121 additions and 70 deletions
+13 -11
View File
@@ -1119,7 +1119,8 @@ void Graphics::setScissor()
void Graphics::drawToStencilBuffer(StencilAction action, int value)
{
const auto &rts = states.back().renderTargets;
DisplayState &state = states.back();
const auto &rts = state.renderTargets;
love::graphics::Texture *dstexture = rts.depthStencil.texture.get();
if (!isRenderTargetActive() && !windowHasStencil)
@@ -1129,7 +1130,8 @@ void Graphics::drawToStencilBuffer(StencilAction action, int value)
flushBatchedDraws();
writingToStencil = true;
state.stencil.action = action;
state.stencil.value = value;
// Disable color writes but don't save the state for it.
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
@@ -1169,33 +1171,33 @@ void Graphics::drawToStencilBuffer(StencilAction action, int value)
void Graphics::stopDrawToStencilBuffer()
{
if (!writingToStencil)
DisplayState &state = states.back();
if (state.stencil.action == STENCIL_KEEP)
return;
flushBatchedDraws();
writingToStencil = false;
const DisplayState &state = states.back();
state.stencil.action = STENCIL_KEEP;
// Revert the color write mask.
setColorMask(state.colorMask);
// Use the user-set stencil test state when writes are disabled.
setStencilTest(state.stencilCompare, state.stencilTestValue);
setStencilTest(state.stencil.compare, state.stencil.value);
}
void Graphics::setStencilTest(CompareMode compare, int value)
{
DisplayState &state = states.back();
if (state.stencilCompare != compare || state.stencilTestValue != value)
if (state.stencil.compare != compare || state.stencil.value != value)
flushBatchedDraws();
state.stencilCompare = compare;
state.stencilTestValue = value;
state.stencil.compare = compare;
state.stencil.value = value;
if (writingToStencil)
if (state.stencil.action != STENCIL_KEEP)
return;
if (compare == COMPARE_ALWAYS)
-10
View File
@@ -42,7 +42,6 @@ Shader::Shader(love::graphics::ShaderStage *vertex, love::graphics::ShaderStage
, program(0)
, builtinUniforms()
, builtinUniformInfo()
, builtinAttributes()
, lastPointSize(0.0f)
{
// load shader source and create program object
@@ -343,15 +342,6 @@ bool Shader::loadVolatile()
// Get all active uniform variables in this shader from OpenGL.
mapActiveUniforms();
for (int i = 0; i < int(ATTRIB_MAX_ENUM); i++)
{
const char *name = nullptr;
if (vertex::getConstant(BuiltinVertexAttribute(i), name))
builtinAttributes[i] = glGetAttribLocation(program, name);
else
builtinAttributes[i] = -1;
}
if (current == this)
{
// make sure glUseProgram gets called.
-3
View File
@@ -102,9 +102,6 @@ private:
GLint builtinUniforms[BUILTIN_MAX_ENUM];
UniformInfo *builtinUniformInfo[BUILTIN_MAX_ENUM];
// Location values for any generic vertex attribute variables.
GLint builtinAttributes[ATTRIB_MAX_ENUM];
std::map<std::string, GLint> attributes;
// Uniform location buffer map