From 809987b5158699aa70c7904fbf6d3b1b1cf79663 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sat, 14 Jan 2017 21:24:48 +0700 Subject: [PATCH] Implement GraphicsDrawer::_initStates() --- src/Graphics/Context.cpp | 5 +++ src/Graphics/Context.h | 2 ++ src/Graphics/ContextImpl.h | 1 + .../OpenGLContext/opengl_ContextImpl.cpp | 5 +++ .../OpenGLContext/opengl_ContextImpl.h | 2 ++ src/GraphicsDrawer.cpp | 31 +++++++++++++++++++ src/GraphicsDrawer.h | 1 - 7 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Graphics/Context.cpp b/src/Graphics/Context.cpp index 2a0cdc93..eb276f42 100644 --- a/src/Graphics/Context.cpp +++ b/src/Graphics/Context.cpp @@ -74,6 +74,11 @@ void Context::clearDepthBuffer() m_impl->clearDepthBuffer(); } +void Context::setPolygonOffset(f32 _factor, f32 _units) +{ + m_impl->setPolygonOffset(_factor, _units); +} + ObjectHandle Context::createTexture(Parameter _target) { return m_impl->createTexture(_target); diff --git a/src/Graphics/Context.h b/src/Graphics/Context.h index e620deff..bb834e16 100644 --- a/src/Graphics/Context.h +++ b/src/Graphics/Context.h @@ -51,6 +51,8 @@ namespace graphics { void clearDepthBuffer(); + void setPolygonOffset(f32 _factor, f32 _units); + /*---------------Texture-------------*/ ObjectHandle createTexture(Parameter _target); diff --git a/src/Graphics/ContextImpl.h b/src/Graphics/ContextImpl.h index 21e0f77d..b54dcf97 100644 --- a/src/Graphics/ContextImpl.h +++ b/src/Graphics/ContextImpl.h @@ -22,6 +22,7 @@ namespace graphics { virtual void setBlendColor(f32 _red, f32 _green, f32 _blue, f32 _alpha) = 0; virtual void clearColorBuffer(f32 _red, f32 _green, f32 _blue, f32 _alpha) = 0; virtual void clearDepthBuffer() = 0; + virtual void setPolygonOffset(f32 _factor, f32 _units) = 0; virtual ObjectHandle createTexture(Parameter _target) = 0; virtual void deleteTexture(ObjectHandle _name) = 0; virtual void init2DTexture(const Context::InitTextureParams & _params) = 0; diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp index cbfcdf7e..b721837b 100644 --- a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp +++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp @@ -138,6 +138,11 @@ void ContextImpl::clearDepthBuffer() enableScissor->enable(true); } +void ContextImpl::setPolygonOffset(f32 _factor, f32 _units) +{ + glPolygonOffset(_factor, _units); +} + /*---------------Texture-------------*/ graphics::ObjectHandle ContextImpl::createTexture(graphics::Parameter _target) diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.h b/src/Graphics/OpenGLContext/opengl_ContextImpl.h index 896da6bc..0595edf1 100644 --- a/src/Graphics/OpenGLContext/opengl_ContextImpl.h +++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.h @@ -44,6 +44,8 @@ namespace opengl { void clearDepthBuffer() override; + void setPolygonOffset(f32 _factor, f32 _units) override; + /*---------------Texture-------------*/ graphics::ObjectHandle createTexture(graphics::Parameter _target) override; diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index 9533fb7f..5e94252e 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -1494,3 +1494,34 @@ void GraphicsDrawer::blitOrCopyTexturedRect(const BlitOrCopyRectParams & _params copyTexturedRect(_params); } + +void GraphicsDrawer::_initStates() +{ + gfxContext.enable(enable::CULL_FACE, false); + gfxContext.enable(enable::SCISSOR_TEST, true); + gfxContext.enableDepthWrite(false); + gfxContext.setDepthCompare(compare::ALWAYS); + + if (config.frameBufferEmulation.N64DepthCompare != 0) { + gfxContext.enable(enable::DEPTH_TEST, false); + gfxContext.enable(enable::POLYGON_OFFSET_FILL, false); + } + else { + gfxContext.enable(enable::DEPTH_TEST, true); +#ifdef ANDROID + if (config.generalEmulation.forcePolygonOffset != 0) + gfxContext.setPolygonOffset(config.generalEmulation.polygonOffsetFactor, config.generalEmulation.polygonOffsetUnits); + else +#endif + gfxContext.setPolygonOffset(-3.0f, -3.0f); + } + + DisplayWindow & wnd = DisplayWindow::get(); + glViewport(0, wnd.getHeightOffset(), wnd.getScreenWidth(), wnd.getScreenHeight()); + + gfxContext.clearColorBuffer(0.0f, 0.0f, 0.0f, 0.0f); + + srand(time(nullptr)); + + wnd.swapBuffers(); +} diff --git a/src/GraphicsDrawer.h b/src/GraphicsDrawer.h index 8dc1cfa3..be72ca97 100644 --- a/src/GraphicsDrawer.h +++ b/src/GraphicsDrawer.h @@ -141,7 +141,6 @@ public: private: GraphicsDrawer(const GraphicsDrawer &); - void _initExtensions(); void _initStates(); void _initData(); void _destroyData();