some fixes with the stencil states and implemented stencil func/stencilop/stencilmask to renderstate
This commit is contained in:
@@ -19,7 +19,9 @@ public:
|
||||
bool BindFramebuffer(GLint framebuffer);
|
||||
bool BlendEquation(GLenum mode);
|
||||
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);
|
||||
|
||||
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>
|
||||
@@ -73,22 +73,23 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
||||
if (scene.ClearDepth) {
|
||||
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);
|
||||
GLERROR("OpaqueObjects");
|
||||
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
|
||||
GLERROR("TransparentObjects");
|
||||
delete state;
|
||||
|
||||
DrawStencilState* stencilState = new DrawStencilState(m_FinalPassFrameBuffer.GetHandle());
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
//DrawStencilState* stencilState = new DrawStencilState(m_FinalPassFrameBuffer.GetHandle());
|
||||
//Draw shields to stencil pass
|
||||
state->StencilFunc(GL_ALWAYS, 1, 0xFF);
|
||||
state->StencilMask(0xFF);
|
||||
DrawShieldToStencilBuffer(scene.Jobs.ShieldObjects, scene);
|
||||
GLERROR("StencilPass");
|
||||
|
||||
//Draw Opaque shielded objects
|
||||
DrawShieldedModelRenderQueue(scene.Jobs.OpaqueShieldedObjects, scene);
|
||||
//DrawShieldedModelRenderQueue(scene.Jobs.OpaqueShieldedObjects, scene);
|
||||
GLERROR("Shielded Opaque object");
|
||||
|
||||
//Draw Transparen Shielded objects
|
||||
@@ -96,7 +97,8 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
||||
GLERROR("Shielded Transparent objects");
|
||||
|
||||
GLERROR("END");
|
||||
delete stencilState;
|
||||
delete state;
|
||||
//delete stencilState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer)
|
||||
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Enable(GL_DEPTH_TEST);
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -21,7 +25,9 @@ DrawStencilState::DrawStencilState(GLuint frameBuffer)
|
||||
{
|
||||
BindFramebuffer(frameBuffer);
|
||||
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);
|
||||
ClearColor(glm::vec4(0.f));
|
||||
}
|
||||
|
||||
@@ -6,9 +6,10 @@ bool RenderState::Enable(GLenum cap)
|
||||
//LOG_WARNING("Trying to enable somthing that is already enabled.");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ResetFunctions.push_back(std::bind(glDisable, cap));
|
||||
glEnable(cap);
|
||||
return !GLERROR("RenderState::Enable");
|
||||
return !GLERROR("Enable");
|
||||
}
|
||||
|
||||
bool RenderState::Disable(GLenum cap)
|
||||
@@ -16,9 +17,10 @@ bool RenderState::Disable(GLenum cap)
|
||||
if (!glIsEnabled(cap)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ResetFunctions.push_back(std::bind(glEnable, cap));
|
||||
glDisable(cap);
|
||||
return !GLERROR("RenderState::Disable");
|
||||
return !GLERROR("Disable");
|
||||
}
|
||||
|
||||
bool RenderState::CullFace(GLenum mode)
|
||||
@@ -32,7 +34,7 @@ bool RenderState::CullFace(GLenum mode)
|
||||
glGetIntegerv(GL_CULL_FACE_MODE, &original);
|
||||
m_ResetFunctions.push_back(std::bind(glCullFace, original));
|
||||
glCullFace(mode);
|
||||
return !GLERROR("RenderState::CullFace");
|
||||
return !GLERROR("CullFace");
|
||||
}
|
||||
|
||||
bool RenderState::ClearColor(glm::vec4 color)
|
||||
@@ -41,7 +43,7 @@ bool RenderState::ClearColor(glm::vec4 color)
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, &original[0]);
|
||||
m_ResetFunctions.push_back(std::bind(glClearColor, original[0], original[1], original[2], original[3]));
|
||||
glClearColor(color.r, color.g, color.b, color.a);
|
||||
return !GLERROR("RenderState::ClearColor");
|
||||
return !GLERROR("ClearColor");
|
||||
}
|
||||
|
||||
bool RenderState::BindFramebuffer(GLint framebuffer)
|
||||
@@ -55,7 +57,7 @@ bool RenderState::BindFramebuffer(GLint framebuffer)
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, originalDraw);
|
||||
});
|
||||
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);
|
||||
m_ResetFunctions.push_back(std::bind(glBlendEquationSeparate, originalRGB, originalAlpha));
|
||||
glBlendEquation(mode);
|
||||
return !GLERROR("RenderState::BlendEquation");
|
||||
return !GLERROR("BlendEquation");
|
||||
}
|
||||
|
||||
bool RenderState::BlendFunc(GLenum sfactor, GLenum dfactor)
|
||||
@@ -82,11 +84,11 @@ bool RenderState::BlendFunc(GLenum sfactor, GLenum dfactor)
|
||||
glGetIntegerv(GL_BLEND_DST_ALPHA, &originalDestAlpha);
|
||||
m_ResetFunctions.push_back(std::bind(glBlendFuncSeparate, originalSrcRGB, originalSrcAlpha, originalDestRGB, originalDestAlpha));
|
||||
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;
|
||||
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);
|
||||
m_ResetFunctions.push_back(std::bind(glStencilOp, originalSFail, originalDPFail, originalDPPass));
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
GLboolean original;
|
||||
glGetBooleanv(GL_DEPTH_WRITEMASK, &original);
|
||||
m_ResetFunctions.push_back(std::bind(glDepthMask, original));
|
||||
glDepthMask(flag);
|
||||
return !GLERROR("RenderState::DepthMask");
|
||||
return !GLERROR("DepthMask");
|
||||
}
|
||||
|
||||
RenderState::~RenderState()
|
||||
|
||||
Reference in New Issue
Block a user