+ mask |= GL_STENCIL_BUFFER_BIT;
+ }
+ }
+
+ SetScissorTestEnabled(true);
+ gl.Scissor(renderPassBegin.renderArea.x, renderPassBegin.renderArea.y, renderPassBegin.renderArea.width, renderPassBegin.renderArea.height);
+ ClearBuffer(mask, true);
+ SetScissorTestEnabled(false);
+
+ mImpl->mCurrentRenderPass = &renderPass;
+ mImpl->mCurrentRenderTarget = &renderTarget;
+}
+
+void Context::EndRenderPass()
+{
+ if(mImpl->mCurrentRenderTarget)
+ {
+ if(mImpl->mCurrentRenderTarget->GetFramebuffer())
+ {
+ auto& gl = *mImpl->mController.GetGL();
+ gl.Flush();
+ }
+ }
+}
+
+void Context::ClearState()
+{
+ mImpl->mCurrentTextureBindings.clear();
+}
+
+void Context::ColorMask(bool enabled)
+{
+ if(enabled != mImpl->mGlStateCache.mColorMask)
+ {
+ mImpl->mGlStateCache.mColorMask = enabled;
+
+ auto& gl = *mImpl->mController.GetGL();
+ gl.ColorMask(enabled, enabled, enabled, enabled);
+ }
+}
+
+void Context::ClearStencilBuffer()
+{
+ ClearBuffer(GL_STENCIL_BUFFER_BIT, false);
+}
+
+void Context::ClearDepthBuffer()
+{
+ ClearBuffer(GL_DEPTH_BUFFER_BIT, false);
+}
+
+void Context::ClearBuffer(uint32_t mask, bool forceClear)
+{
+ mask = mImpl->mGlStateCache.mFrameBufferStateCache.GetClearMask(mask, forceClear, mImpl->mGlStateCache.mScissorTestEnabled);
+ if(mask > 0)
+ {
+ auto& gl = *mImpl->mController.GetGL();
+ gl.Clear(mask);
+ }
+}
+
+void Context::InvalidateDepthStencilBuffers()
+{
+ auto& gl = *mImpl->mController.GetGL();
+
+ GLenum attachments[] = {GL_DEPTH, GL_STENCIL};
+ gl.InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
+}
+
+void Context::SetScissorTestEnabled(bool scissorEnabled)
+{
+ if(mImpl->mGlStateCache.mScissorTestEnabled != scissorEnabled)
+ {
+ mImpl->mGlStateCache.mScissorTestEnabled = scissorEnabled;
+
+ auto& gl = *mImpl->mController.GetGL();
+ if(scissorEnabled)
+ {
+ gl.Enable(GL_SCISSOR_TEST);
+ }
+ else
+ {
+ gl.Disable(GL_SCISSOR_TEST);
+ }
+ }
+}
+
+void Context::SetStencilTestEnable(bool stencilEnable)
+{
+ if(stencilEnable != mImpl->mGlStateCache.mStencilBufferEnabled)
+ {
+ mImpl->mGlStateCache.mStencilBufferEnabled = stencilEnable;
+
+ auto& gl = *mImpl->mController.GetGL();
+ if(stencilEnable)
+ {
+ gl.Enable(GL_STENCIL_TEST);
+ }
+ else
+ {
+ gl.Disable(GL_STENCIL_TEST);
+ }
+ }
+}
+
+void Context::StencilMask(uint32_t writeMask)
+{
+ if(writeMask != mImpl->mGlStateCache.mStencilMask)
+ {
+ mImpl->mGlStateCache.mStencilMask = writeMask;
+
+ auto& gl = *mImpl->mController.GetGL();
+ gl.StencilMask(writeMask);
+ }
+}
+
+void Context::StencilFunc(Graphics::CompareOp compareOp,
+ uint32_t reference,
+ uint32_t compareMask)
+{
+ if(compareOp != mImpl->mGlStateCache.mStencilFunc ||
+ reference != mImpl->mGlStateCache.mStencilFuncRef ||
+ compareMask != mImpl->mGlStateCache.mStencilFuncMask)
+ {
+ mImpl->mGlStateCache.mStencilFunc = compareOp;
+ mImpl->mGlStateCache.mStencilFuncRef = reference;
+ mImpl->mGlStateCache.mStencilFuncMask = compareMask;
+
+ auto& gl = *mImpl->mController.GetGL();
+ gl.StencilFunc(GLCompareOp(compareOp).op, reference, compareMask);
+ }
+}
+
+void Context::StencilOp(Graphics::StencilOp failOp,
+ Graphics::StencilOp depthFailOp,
+ Graphics::StencilOp passOp)
+{
+ if(failOp != mImpl->mGlStateCache.mStencilOpFail ||
+ depthFailOp != mImpl->mGlStateCache.mStencilOpDepthFail ||
+ passOp != mImpl->mGlStateCache.mStencilOpDepthPass)
+ {
+ mImpl->mGlStateCache.mStencilOpFail = failOp;
+ mImpl->mGlStateCache.mStencilOpDepthFail = depthFailOp;
+ mImpl->mGlStateCache.mStencilOpDepthPass = passOp;
+
+ auto& gl = *mImpl->mController.GetGL();
+ gl.StencilOp(GLStencilOp(failOp).op, GLStencilOp(depthFailOp).op, GLStencilOp(passOp).op);
+ }
+}
+
+void Context::SetDepthCompareOp(Graphics::CompareOp compareOp)
+{
+ if(compareOp != mImpl->mGlStateCache.mDepthFunction)
+ {
+ mImpl->mGlStateCache.mDepthFunction = compareOp;
+ auto& gl = *mImpl->mController.GetGL();
+ gl.DepthFunc(GLCompareOp(compareOp).op);
+ }
+}
+
+void Context::SetDepthTestEnable(bool depthTestEnable)
+{
+ if(depthTestEnable != mImpl->mGlStateCache.mDepthBufferEnabled)
+ {
+ mImpl->mGlStateCache.mDepthBufferEnabled = depthTestEnable;
+
+ auto& gl = *mImpl->mController.GetGL();
+ if(depthTestEnable)
+ {
+ gl.Enable(GL_DEPTH_TEST);