some fixes with the stencil states and implemented stencil func/stencilop/stencilmask to renderstate

This commit is contained in:
Tleety
2016-02-04 11:13:26 +01:00
parent bc01e147c2
commit 379d211832
5 changed files with 93 additions and 17 deletions
+3 -1
View File
@@ -19,7 +19,9 @@ public:
bool BindFramebuffer(GLint framebuffer); bool BindFramebuffer(GLint framebuffer);
bool BlendEquation(GLenum mode); bool BlendEquation(GLenum mode);
bool BlendFunc(GLenum sfactor, GLenum dfactor); bool BlendFunc(GLenum sfactor, GLenum dfactor);
bool StencilFunc(GLenum sfail, GLenum dpfail, GLenum dppass); bool StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
bool StencilFunc(GLenum func, GLint ref, GLuint mask);
bool StencilMask(GLuint mask);
bool DepthMask(GLboolean flag); bool DepthMask(GLboolean flag);
private: private:
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>Models/Core/Unithexagon.mesh</Resource>
</c:Model>
<c:Shield/>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="dl">
<Components>
<c:DirectionalLight/>
<c:Transform>
<Orientation X="0" Y="2.61800003" Z="0.756000042"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="sl">
<Components>
<c:SceneLight>
<Gamma>2.2000000476837158</Gamma>
</c:SceneLight>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+8 -6
View File
@@ -73,22 +73,23 @@ void DrawFinalPass::Draw(RenderScene& scene)
if (scene.ClearDepth) { if (scene.ClearDepth) {
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
} }
//might need to clear stencil here //TODO: Do we need check for this or will it be per scene always?
glClear(GL_STENCIL_BUFFER_BIT);
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene); DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene);
GLERROR("OpaqueObjects"); GLERROR("OpaqueObjects");
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene); DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects"); GLERROR("TransparentObjects");
delete state;
DrawStencilState* stencilState = new DrawStencilState(m_FinalPassFrameBuffer.GetHandle()); //DrawStencilState* stencilState = new DrawStencilState(m_FinalPassFrameBuffer.GetHandle());
glClear(GL_STENCIL_BUFFER_BIT);
//Draw shields to stencil pass //Draw shields to stencil pass
state->StencilFunc(GL_ALWAYS, 1, 0xFF);
state->StencilMask(0xFF);
DrawShieldToStencilBuffer(scene.Jobs.ShieldObjects, scene); DrawShieldToStencilBuffer(scene.Jobs.ShieldObjects, scene);
GLERROR("StencilPass"); GLERROR("StencilPass");
//Draw Opaque shielded objects //Draw Opaque shielded objects
DrawShieldedModelRenderQueue(scene.Jobs.OpaqueShieldedObjects, scene); //DrawShieldedModelRenderQueue(scene.Jobs.OpaqueShieldedObjects, scene);
GLERROR("Shielded Opaque object"); GLERROR("Shielded Opaque object");
//Draw Transparen Shielded objects //Draw Transparen Shielded objects
@@ -96,7 +97,8 @@ void DrawFinalPass::Draw(RenderScene& scene)
GLERROR("Shielded Transparent objects"); GLERROR("Shielded Transparent objects");
GLERROR("END"); GLERROR("END");
delete stencilState; delete state;
//delete stencilState;
} }
+7 -1
View File
@@ -9,6 +9,10 @@ DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer)
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Enable(GL_DEPTH_TEST); Enable(GL_DEPTH_TEST);
Enable(GL_CULL_FACE); Enable(GL_CULL_FACE);
Enable(GL_STENCIL_TEST);
StencilFunc(GL_NOTEQUAL, 1, 0xFF);
StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
StencilMask(0x00);
ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f)); ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f));
} }
@@ -21,7 +25,9 @@ DrawStencilState::DrawStencilState(GLuint frameBuffer)
{ {
BindFramebuffer(frameBuffer); BindFramebuffer(frameBuffer);
Enable(GL_STENCIL_TEST); Enable(GL_STENCIL_TEST);
StencilFunc(GL_KEEP, GL_KEEP, GL_REPLACE); StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
StencilFunc(GL_ALWAYS, 1, 0xFF);
StencilMask(0xFF);
Enable(GL_DEPTH_TEST); Enable(GL_DEPTH_TEST);
ClearColor(glm::vec4(0.f)); ClearColor(glm::vec4(0.f));
} }
+36 -9
View File
@@ -6,9 +6,10 @@ bool RenderState::Enable(GLenum cap)
//LOG_WARNING("Trying to enable somthing that is already enabled."); //LOG_WARNING("Trying to enable somthing that is already enabled.");
return false; return false;
} }
m_ResetFunctions.push_back(std::bind(glDisable, cap)); m_ResetFunctions.push_back(std::bind(glDisable, cap));
glEnable(cap); glEnable(cap);
return !GLERROR("RenderState::Enable"); return !GLERROR("Enable");
} }
bool RenderState::Disable(GLenum cap) bool RenderState::Disable(GLenum cap)
@@ -16,9 +17,10 @@ bool RenderState::Disable(GLenum cap)
if (!glIsEnabled(cap)) { if (!glIsEnabled(cap)) {
return false; return false;
} }
m_ResetFunctions.push_back(std::bind(glEnable, cap)); m_ResetFunctions.push_back(std::bind(glEnable, cap));
glDisable(cap); glDisable(cap);
return !GLERROR("RenderState::Disable"); return !GLERROR("Disable");
} }
bool RenderState::CullFace(GLenum mode) bool RenderState::CullFace(GLenum mode)
@@ -32,7 +34,7 @@ bool RenderState::CullFace(GLenum mode)
glGetIntegerv(GL_CULL_FACE_MODE, &original); glGetIntegerv(GL_CULL_FACE_MODE, &original);
m_ResetFunctions.push_back(std::bind(glCullFace, original)); m_ResetFunctions.push_back(std::bind(glCullFace, original));
glCullFace(mode); glCullFace(mode);
return !GLERROR("RenderState::CullFace"); return !GLERROR("CullFace");
} }
bool RenderState::ClearColor(glm::vec4 color) bool RenderState::ClearColor(glm::vec4 color)
@@ -41,7 +43,7 @@ bool RenderState::ClearColor(glm::vec4 color)
glGetFloatv(GL_COLOR_CLEAR_VALUE, &original[0]); glGetFloatv(GL_COLOR_CLEAR_VALUE, &original[0]);
m_ResetFunctions.push_back(std::bind(glClearColor, original[0], original[1], original[2], original[3])); m_ResetFunctions.push_back(std::bind(glClearColor, original[0], original[1], original[2], original[3]));
glClearColor(color.r, color.g, color.b, color.a); glClearColor(color.r, color.g, color.b, color.a);
return !GLERROR("RenderState::ClearColor"); return !GLERROR("ClearColor");
} }
bool RenderState::BindFramebuffer(GLint framebuffer) bool RenderState::BindFramebuffer(GLint framebuffer)
@@ -55,7 +57,7 @@ bool RenderState::BindFramebuffer(GLint framebuffer)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, originalDraw); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, originalDraw);
}); });
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
return !GLERROR("RenderState::BindBuffer"); return !GLERROR("BindBuffer");
} }
@@ -67,7 +69,7 @@ bool RenderState::BlendEquation(GLenum mode)
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &originalAlpha); glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &originalAlpha);
m_ResetFunctions.push_back(std::bind(glBlendEquationSeparate, originalRGB, originalAlpha)); m_ResetFunctions.push_back(std::bind(glBlendEquationSeparate, originalRGB, originalAlpha));
glBlendEquation(mode); glBlendEquation(mode);
return !GLERROR("RenderState::BlendEquation"); return !GLERROR("BlendEquation");
} }
bool RenderState::BlendFunc(GLenum sfactor, GLenum dfactor) bool RenderState::BlendFunc(GLenum sfactor, GLenum dfactor)
@@ -82,11 +84,11 @@ bool RenderState::BlendFunc(GLenum sfactor, GLenum dfactor)
glGetIntegerv(GL_BLEND_DST_ALPHA, &originalDestAlpha); glGetIntegerv(GL_BLEND_DST_ALPHA, &originalDestAlpha);
m_ResetFunctions.push_back(std::bind(glBlendFuncSeparate, originalSrcRGB, originalSrcAlpha, originalDestRGB, originalDestAlpha)); m_ResetFunctions.push_back(std::bind(glBlendFuncSeparate, originalSrcRGB, originalSrcAlpha, originalDestRGB, originalDestAlpha));
glBlendFunc(sfactor, dfactor); glBlendFunc(sfactor, dfactor);
return !GLERROR("RenderState::BlendFunc"); return !GLERROR("BlendFunc");
} }
bool RenderState::StencilFunc(GLenum sfail, GLenum dpfail, GLenum dppass) bool RenderState::StencilOp(GLenum sfail, GLenum dpfail, GLenum dppass)
{ {
GLint originalSFail; GLint originalSFail;
glGetIntegerv(GL_STENCIL_FAIL, &originalSFail); glGetIntegerv(GL_STENCIL_FAIL, &originalSFail);
@@ -96,16 +98,41 @@ bool RenderState::StencilFunc(GLenum sfail, GLenum dpfail, GLenum dppass)
glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &originalDPPass); glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &originalDPPass);
m_ResetFunctions.push_back(std::bind(glStencilOp, originalSFail, originalDPFail, originalDPPass)); m_ResetFunctions.push_back(std::bind(glStencilOp, originalSFail, originalDPFail, originalDPPass));
glStencilOp(sfail, dpfail, dppass); glStencilOp(sfail, dpfail, dppass);
return !GLERROR("StencilOp");
}
bool RenderState::StencilFunc(GLenum func, GLint ref, GLuint mask)
{
GLint originalFunc;
glGetIntegerv(GL_STENCIL_FUNC, &originalFunc);
GLint originalRef;
glGetIntegerv(GL_STENCIL_REF, &originalRef);
GLint originalMask;
glGetIntegerv(GL_STENCIL_VALUE_MASK, &originalMask);
m_ResetFunctions.push_back(std::bind(glStencilFunc, originalFunc, originalRef, originalMask));
glStencilFunc(func, ref, mask);
return !GLERROR("StencilFunc"); return !GLERROR("StencilFunc");
} }
bool RenderState::StencilMask(GLuint mask)
{
GLint originalMask;
glGetIntegerv(GL_STENCIL_WRITEMASK, &originalMask);
m_ResetFunctions.push_back(std::bind(glStencilMask, mask));
glStencilMask(mask);
return !GLERROR("StencilMask");
}
bool RenderState::DepthMask(GLboolean flag) bool RenderState::DepthMask(GLboolean flag)
{ {
GLboolean original; GLboolean original;
glGetBooleanv(GL_DEPTH_WRITEMASK, &original); glGetBooleanv(GL_DEPTH_WRITEMASK, &original);
m_ResetFunctions.push_back(std::bind(glDepthMask, original)); m_ResetFunctions.push_back(std::bind(glDepthMask, original));
glDepthMask(flag); glDepthMask(flag);
return !GLERROR("RenderState::DepthMask"); return !GLERROR("DepthMask");
} }
RenderState::~RenderState() RenderState::~RenderState()