From 52aa26015311c1df779ee236daabfd2cb6e533c0 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Thu, 12 Jan 2017 22:22:53 +0700 Subject: [PATCH] Move GraphicsDrawer and TextDrawer interfaces to OpenGLContext --- projects/msvc12/GLideN64.vcxproj | 4 +- projects/msvc12/GLideN64.vcxproj.filters | 12 +++--- src/Graphics/Context.cpp | 23 ++++++++-- src/Graphics/Context.h | 43 +++++++++++++++++-- src/Graphics/ContextImpl.h | 7 ++- src/Graphics/GraphicsDrawerImpl.h | 42 ------------------ .../OpenGLContext/opengl_ContextImpl.cpp | 29 +++++++++++-- .../OpenGLContext/opengl_ContextImpl.h | 15 ++++++- .../OpenGLContext/opengl_DummyTextDrawer.h | 6 +-- .../OpenGLContext/opengl_GraphicsDrawer.h | 20 +++++++++ .../opengl_TextDrawer.h} | 4 +- .../OpenGLContext/opengl_UnbufferedDrawer.cpp | 4 +- .../OpenGLContext/opengl_UnbufferedDrawer.h | 8 ++-- src/GraphicsDrawer.cpp | 29 ++++++------- src/GraphicsDrawer.h | 3 -- 15 files changed, 153 insertions(+), 96 deletions(-) delete mode 100644 src/Graphics/GraphicsDrawerImpl.h create mode 100644 src/Graphics/OpenGLContext/opengl_GraphicsDrawer.h rename src/Graphics/{TextDrawerImpl.h => OpenGLContext/opengl_TextDrawer.h} (70%) diff --git a/projects/msvc12/GLideN64.vcxproj b/projects/msvc12/GLideN64.vcxproj index 2932b6ce..b8a62217 100644 --- a/projects/msvc12/GLideN64.vcxproj +++ b/projects/msvc12/GLideN64.vcxproj @@ -438,7 +438,6 @@ - @@ -455,6 +454,8 @@ + + @@ -462,7 +463,6 @@ - diff --git a/projects/msvc12/GLideN64.vcxproj.filters b/projects/msvc12/GLideN64.vcxproj.filters index 79c9629d..3e16fae6 100644 --- a/projects/msvc12/GLideN64.vcxproj.filters +++ b/projects/msvc12/GLideN64.vcxproj.filters @@ -634,14 +634,14 @@ Header Files - - Header Files\Graphics - - - Header Files\Graphics - Header Files\Graphics\OpenGL + + Header Files\Graphics\OpenGL + + + Header Files\Graphics\OpenGL + \ No newline at end of file diff --git a/src/Graphics/Context.cpp b/src/Graphics/Context.cpp index 0f289e0d..6c689c49 100644 --- a/src/Graphics/Context.cpp +++ b/src/Graphics/Context.cpp @@ -168,14 +168,29 @@ ShaderProgram * Context::createTexrectCopyShader() return m_impl->createTexrectCopyShader(); } -DrawerImpl * Context::createDrawerImpl() +void Context::drawTriangles(const DrawTriangleParameters & _params) { - return m_impl->createDrawerImpl(); + m_impl->drawTriangles(_params); } -TextDrawer * Context::createTextDrawer() +void Context::drawRects(const DrawRectParameters & _params) { - return m_impl->createTextDrawer(); + m_impl->drawRects(_params); +} + +void Context::drawLine(f32 _width, SPVertex * _vertices) +{ + m_impl->drawLine(_width, _vertices); +} + +void Context::drawText(const char *_pText, float _x, float _y) +{ + m_impl->drawText(_pText, _x, _y); +} + +void Context::getTextSize(const char *_pText, float & _w, float & _h) +{ + m_impl->getTextSize(_pText, _w, _h); } f32 Context::getMaxLineWidth() diff --git a/src/Graphics/Context.h b/src/Graphics/Context.h index 5ada63e9..cd7ab7aa 100644 --- a/src/Graphics/Context.h +++ b/src/Graphics/Context.h @@ -7,8 +7,6 @@ #include "CombinerProgram.h" #include "ShaderProgram.h" #include "PixelBuffer.h" -#include "GraphicsDrawerImpl.h" -#include "TextDrawerImpl.h" #define GRAPHICS_CONTEXT @@ -52,6 +50,8 @@ namespace graphics { void clearDepthBuffer(); + /*---------------Texture-------------*/ + ObjectHandle createTexture(Parameter _target); void deleteTexture(ObjectHandle _name); @@ -103,6 +103,8 @@ namespace graphics { void setTextureParameters(const TexParameters & _parameters); + /*---------------Framebuffer-------------*/ + ObjectHandle createFramebuffer(); void deleteFramebuffer(ObjectHandle _name); @@ -131,6 +133,8 @@ namespace graphics { PixelWriteBuffer * createPixelWriteBuffer(size_t _sizeInBytes); + /*---------------Shaders-------------*/ + CombinerProgram * createCombinerProgram(Combiner & _color, Combiner & _alpha, const CombinerKey & _key); bool saveShadersStorage(const Combiners & _combiners); @@ -147,12 +151,43 @@ namespace graphics { ShaderProgram * createTexrectCopyShader(); - DrawerImpl * createDrawerImpl(); + /*---------------Draw-------------*/ - TextDrawer * createTextDrawer(); + struct DrawTriangleParameters + { + Parameter mode; + Parameter elementsType; + u32 verticesCount = 0; + u32 elementsCount = 0; + bool flatColors = false; + SPVertex * vertices = nullptr; + void * elements = nullptr; + const CombinerProgram * combiner = nullptr; + }; + + void drawTriangles(const DrawTriangleParameters & _params); + + struct DrawRectParameters + { + Parameter mode; + u32 verticesCount = 0; + std::array rectColor; + RectVertex * vertices = nullptr; + const CombinerProgram * combiner = nullptr; + }; + + void drawRects(const DrawRectParameters & _params); + + void drawLine(f32 _width, SPVertex * _vertices); f32 getMaxLineWidth(); + void drawText(const char *_pText, float _x, float _y); + + void getTextSize(const char *_pText, float & _w, float & _h); + + /*---------------Misc-------------*/ + bool isSupported(SpecialFeatures _feature) const; private: diff --git a/src/Graphics/ContextImpl.h b/src/Graphics/ContextImpl.h index 5da75f7c..07c1333d 100644 --- a/src/Graphics/ContextImpl.h +++ b/src/Graphics/ContextImpl.h @@ -41,9 +41,12 @@ namespace graphics { virtual TexDrawerShaderProgram * createTexDrawerDrawShader() = 0; virtual ShaderProgram * createTexDrawerClearShader() = 0; virtual ShaderProgram * createTexrectCopyShader() = 0; - virtual DrawerImpl * createDrawerImpl() = 0; - virtual TextDrawer * createTextDrawer() = 0; + virtual void drawTriangles(const Context::DrawTriangleParameters & _params) = 0; + virtual void drawRects(const Context::DrawRectParameters & _params) = 0; + virtual void drawLine(f32 _width, SPVertex * _vertices) = 0; virtual f32 getMaxLineWidth() = 0; + virtual void drawText(const char *_pText, float _x, float _y) = 0; + virtual void getTextSize(const char *_pText, float & _w, float & _h) = 0; }; } diff --git a/src/Graphics/GraphicsDrawerImpl.h b/src/Graphics/GraphicsDrawerImpl.h deleted file mode 100644 index 078c02e3..00000000 --- a/src/Graphics/GraphicsDrawerImpl.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef GRAPHICS_DRAWERIMPL_H -#define GRAPHICS_DRAWERIMPL_H -#include -#include -#include "Parameter.h" -#include "CombinerProgram.h" - -namespace graphics { - - class DrawerImpl { - public: - virtual ~DrawerImpl() {} - - struct DrawTriangleParameters - { - Parameter mode; - Parameter elementsType; - u32 verticesCount = 0; - u32 elementsCount = 0; - bool flatColors = false; - SPVertex * vertices = nullptr; - void * elements = nullptr; - const CombinerProgram * combiner = nullptr; - }; - virtual void drawTriangles(const DrawTriangleParameters & _params) = 0; - - struct DrawRectParameters - { - Parameter mode; - u32 verticesCount = 0; - std::array rectColor; - RectVertex * vertices = nullptr; - const CombinerProgram * combiner = nullptr; - }; - virtual void drawRects(const DrawRectParameters & _params) = 0; - - virtual void drawLine(f32 _width, SPVertex * vertices) = 0; - }; -} - - -#endif // GRAPHICS_DRAWERIMPL_H \ No newline at end of file diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp index da5dffef..f7285979 100644 --- a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp +++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp @@ -44,6 +44,11 @@ void ContextImpl::init() m_createPixelWriteBuffer.reset(bufferObjectFactory.createPixelWriteBuffer()); } + { + m_graphicsDrawer.reset(new UnbufferedDrawer(m_glInfo, m_cachedFunctions->getCachedVertexAttribArray())); + m_textDrawer.reset(new DummyTextDrawer); + } + m_combinerProgramBuilder.reset(new glsl::CombinerProgramBuilder(m_glInfo)); } @@ -252,19 +257,35 @@ graphics::ShaderProgram * ContextImpl::createTexrectCopyShader() return shadersFactory.createTexrectCopyShader(); } -graphics::DrawerImpl * ContextImpl::createDrawerImpl() +void ContextImpl::drawTriangles(const graphics::Context::DrawTriangleParameters & _params) { - return new UnbufferedDrawer(m_glInfo, m_cachedFunctions->getCachedVertexAttribArray()); + m_graphicsDrawer->drawTriangles(_params); } -graphics::TextDrawer * ContextImpl::createTextDrawer() +void ContextImpl::drawRects(const graphics::Context::DrawRectParameters & _params) { - return new DummyTextDrawer; + m_graphicsDrawer->drawRects(_params); } +void ContextImpl::drawLine(f32 _width, SPVertex * _vertices) +{ + m_graphicsDrawer->drawLine(_width, _vertices); +} + + f32 ContextImpl::getMaxLineWidth() { GLfloat lineWidthRange[2] = { 0.0f, 0.0f }; glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, lineWidthRange); return lineWidthRange[1]; } + +void ContextImpl::drawText(const char *_pText, float _x, float _y) +{ + m_textDrawer->drawText(_pText, _x, _y); +} + +void ContextImpl::getTextSize(const char *_pText, float & _w, float & _h) +{ + m_textDrawer->getTextSize(_pText, _w, _h); +} diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.h b/src/Graphics/OpenGLContext/opengl_ContextImpl.h index 6ffb6444..90101036 100644 --- a/src/Graphics/OpenGLContext/opengl_ContextImpl.h +++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.h @@ -5,6 +5,8 @@ #include "opengl_BufferManipulationObjectFactory.h" #include "opengl_GLInfo.h" #include "opengl_CachedFunctions.h" +#include "opengl_GraphicsDrawer.h" +#include "opengl_TextDrawer.h" namespace glsl { class CombinerProgramBuilder; @@ -80,12 +82,18 @@ namespace opengl { graphics::ShaderProgram * createTexrectCopyShader() override; - graphics::DrawerImpl * createDrawerImpl() override; + void drawTriangles(const graphics::Context::DrawTriangleParameters & _params) override; - graphics::TextDrawer * createTextDrawer() override; + void drawRects(const graphics::Context::DrawRectParameters & _params) override; + + void drawLine(f32 _width, SPVertex * _vertices) override; f32 getMaxLineWidth() override; + void drawText(const char *_pText, float _x, float _y) override; + + void getTextSize(const char *_pText, float & _w, float & _h) override; + private: std::unique_ptr m_cachedFunctions; std::unique_ptr m_createTexture; @@ -99,6 +107,9 @@ namespace opengl { std::unique_ptr m_addFramebufferRenderTarget; std::unique_ptr m_createPixelWriteBuffer; + std::unique_ptr m_graphicsDrawer; + std::unique_ptr m_textDrawer; + std::unique_ptr m_combinerProgramBuilder; GLInfo m_glInfo; }; diff --git a/src/Graphics/OpenGLContext/opengl_DummyTextDrawer.h b/src/Graphics/OpenGLContext/opengl_DummyTextDrawer.h index e9374768..4d84e843 100644 --- a/src/Graphics/OpenGLContext/opengl_DummyTextDrawer.h +++ b/src/Graphics/OpenGLContext/opengl_DummyTextDrawer.h @@ -1,17 +1,17 @@ #ifndef OPENGL_DUMMY_TEXTDRAWER_H #define OPENGL_DUMMY_TEXTDRAWER_H -#include +#include "opengl_TextDrawer.h" namespace opengl { - class DummyTextDrawer : public graphics::TextDrawer + class DummyTextDrawer : public TextDrawer { public: DummyTextDrawer() {} ~DummyTextDrawer() {} - void renderText(const char *_pText, float x, float y) const override {} + void drawText(const char *_pText, float x, float y) const override {} void getTextSize(const char *_pText, float & _w, float & _h) const override {} }; diff --git a/src/Graphics/OpenGLContext/opengl_GraphicsDrawer.h b/src/Graphics/OpenGLContext/opengl_GraphicsDrawer.h new file mode 100644 index 00000000..94b16785 --- /dev/null +++ b/src/Graphics/OpenGLContext/opengl_GraphicsDrawer.h @@ -0,0 +1,20 @@ +#ifndef OPENGL_GRAPHICS_DRAWER_H +#define OPENGL_GRAPHICS_DRAWER_H +#include + +namespace opengl { + + class GraphicsDrawer { + public: + virtual ~GraphicsDrawer() {} + + virtual void drawTriangles(const graphics::Context::DrawTriangleParameters & _params) = 0; + + virtual void drawRects(const graphics::Context::DrawRectParameters & _params) = 0; + + virtual void drawLine(f32 _width, SPVertex * _vertices) = 0; + }; +} + + +#endif // OPENGL_GRAPHICS_DRAWER_H \ No newline at end of file diff --git a/src/Graphics/TextDrawerImpl.h b/src/Graphics/OpenGLContext/opengl_TextDrawer.h similarity index 70% rename from src/Graphics/TextDrawerImpl.h rename to src/Graphics/OpenGLContext/opengl_TextDrawer.h index 75f02773..2be42427 100644 --- a/src/Graphics/TextDrawerImpl.h +++ b/src/Graphics/OpenGLContext/opengl_TextDrawer.h @@ -1,13 +1,13 @@ #ifndef TEXTDRAWERIMPL_H #define TEXTDRAWERIMPL_H -namespace graphics { +namespace opengl { class TextDrawer { public: virtual ~TextDrawer() {} - virtual void renderText(const char *_pText, float x, float y) const = 0; + virtual void drawText(const char *_pText, float x, float y) const = 0; virtual void getTextSize(const char *_pText, float & _w, float & _h) const = 0; }; diff --git a/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp b/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp index 83fce74c..40638b8a 100644 --- a/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp +++ b/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp @@ -37,7 +37,7 @@ bool UnbufferedDrawer::_updateAttribPointer(u32 _index, const void * _ptr) return true; } -void UnbufferedDrawer::drawTriangles(const DrawTriangleParameters & _params) +void UnbufferedDrawer::drawTriangles(const graphics::Context::DrawTriangleParameters & _params) { if (m_glInfo.imageTextures && config.frameBufferEmulation.N64DepthCompare != 0) glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); @@ -94,7 +94,7 @@ void UnbufferedDrawer::drawTriangles(const DrawTriangleParameters & _params) glDrawElements(GLenum(_params.mode), _params.elementsCount, GL_UNSIGNED_BYTE, _params.elements); } -void UnbufferedDrawer::drawRects(const DrawRectParameters & _params) +void UnbufferedDrawer::drawRects(const graphics::Context::DrawRectParameters & _params) { { m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, true); diff --git a/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.h b/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.h index 3ced37d9..c2b7c2cc 100644 --- a/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.h +++ b/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.h @@ -1,20 +1,20 @@ #pragma once #include -#include +#include "opengl_GraphicsDrawer.h" #include "opengl_GLInfo.h" namespace opengl { class CachedVertexAttribArray; - class UnbufferedDrawer : public graphics::DrawerImpl + class UnbufferedDrawer : public GraphicsDrawer { public: UnbufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray * _cachedAttribArray); ~UnbufferedDrawer(); - void drawTriangles(const DrawTriangleParameters & _params) override; + void drawTriangles(const graphics::Context::DrawTriangleParameters & _params) override; - void drawRects(const DrawRectParameters & _params) override; + void drawRects(const graphics::Context::DrawRectParameters & _params) override; void drawLine(f32 _width, SPVertex * _vertices) override; diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index e6196e92..83710e2a 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -10,7 +10,6 @@ #include "DepthBuffer.h" #include "DisplayWindow.h" #include "SoftwareRender.h" -#include "Graphics/GraphicsDrawerImpl.h" #include "GraphicsDrawer.h" #include "Performance.h" @@ -20,8 +19,6 @@ GraphicsDrawer::GraphicsDrawer() : m_modifyVertices(0) , m_bImageTexture(false) , m_bFlatColors(false) -, m_drawerImpl(gfxContext.createDrawerImpl()) -, m_textDrawer(gfxContext.createTextDrawer()) { } @@ -642,7 +639,7 @@ void GraphicsDrawer::drawTriangles() _prepareDrawTriangle(); - DrawerImpl::DrawTriangleParameters triParams; + Context::DrawTriangleParameters triParams; triParams.mode = drawmode::TRIANGLES; triParams.flatColors = m_bFlatColors; triParams.elementsType = datatype::UNSIGNED_BYTE; @@ -651,7 +648,7 @@ void GraphicsDrawer::drawTriangles() triParams.vertices = triangles.vertices.data(); triParams.elements = triangles.elements.data(); triParams.combiner = currentCombiner(); - m_drawerImpl->drawTriangles(triParams); + gfxContext.drawTriangles(triParams); if (config.frameBufferEmulation.enable != 0 && config.frameBufferEmulation.copyDepthToRDRAM == Config::cdSoftwareRender && @@ -681,13 +678,13 @@ void GraphicsDrawer::drawScreenSpaceTriangle(u32 _numVtx) _prepareDrawTriangle(); gfxContext.enable(enable::CULL_FACE, false); - DrawerImpl::DrawTriangleParameters triParams; + Context::DrawTriangleParameters triParams; triParams.mode = drawmode::TRIANGLE_STRIP; triParams.flatColors = m_bFlatColors; triParams.verticesCount = _numVtx; triParams.vertices = m_dmaVertices.data(); triParams.combiner = currentCombiner(); - m_drawerImpl->drawTriangles(triParams); + gfxContext.drawTriangles(triParams); frameBufferList().setBufferChanged(); gSP.changed |= CHANGED_GEOMETRYMODE; @@ -700,13 +697,13 @@ void GraphicsDrawer::drawDMATriangles(u32 _numVtx) _prepareDrawTriangle(); - DrawerImpl::DrawTriangleParameters triParams; + Context::DrawTriangleParameters triParams; triParams.mode = drawmode::TRIANGLES; triParams.flatColors = m_bFlatColors; triParams.verticesCount = _numVtx; triParams.vertices = m_dmaVertices.data(); triParams.combiner = currentCombiner(); - m_drawerImpl->drawTriangles(triParams); + gfxContext.drawTriangles(triParams); if (config.frameBufferEmulation.enable != 0 && config.frameBufferEmulation.copyDepthToRDRAM == Config::cdSoftwareRender && @@ -823,7 +820,7 @@ void GraphicsDrawer::drawLine(int _v0, int _v1, float _width) _updateScreenCoordsViewport(); SPVertex vertexBuf[2] = { triangles.vertices[triangles.elements[_v0]], triangles.vertices[triangles.elements[_v1]] }; - m_drawerImpl->drawLine(lineWidth, vertexBuf); + gfxContext.drawLine(lineWidth, vertexBuf); } void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry, float *_pColor) @@ -875,7 +872,7 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry, float *_pC m_rect[i].x *= scale; } - graphics::DrawerImpl::DrawRectParameters rectParams; + Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLE_STRIP; if (gDP.otherMode.cycleType == G_CYC_FILL) std::copy_n(_pColor, sizeof(_pColor[0]) * 4, rectParams.rectColor.data()); @@ -884,7 +881,7 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry, float *_pC rectParams.verticesCount = 4; rectParams.vertices = m_rect; rectParams.combiner = currentCombiner(); - m_drawerImpl->drawRects(rectParams); + gfxContext.drawRects(rectParams); gSP.changed |= CHANGED_GEOMETRYMODE | CHANGED_VIEWPORT; } @@ -1250,14 +1247,14 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params) else gfxContext.setViewport(0, 0, pCurrentBuffer->m_width*pCurrentBuffer->m_scaleX, pCurrentBuffer->m_height*pCurrentBuffer->m_scaleY); - graphics::DrawerImpl::DrawRectParameters rectParams; + Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLE_STRIP; rectParams.rectColor.fill(0.0f); rectParams.rectColor[3] = alpha; rectParams.verticesCount = 4; rectParams.vertices = m_rect; rectParams.combiner = currentCombiner(); - m_drawerImpl->drawRects(rectParams); + gfxContext.drawRects(rectParams); gSP.changed |= CHANGED_GEOMETRYMODE | CHANGED_VIEWPORT; } @@ -1290,12 +1287,12 @@ void GraphicsDrawer::correctTexturedRectParams(TexturedRectParams & _params) void GraphicsDrawer::drawText(const char *_pText, float x, float y) { m_drawingState = DrawingState::None; - m_textDrawer->renderText(_pText, x, y); + gfxContext.drawText(_pText, x, y); } void GraphicsDrawer::_getTextSize(const char *_pText, float & _w, float & _h) const { - m_textDrawer->getTextSize(_pText, _w, _h); + gfxContext.getTextSize(_pText, _w, _h); } void GraphicsDrawer::_drawOSD(const char *_pText, float _x, float & _y) diff --git a/src/GraphicsDrawer.h b/src/GraphicsDrawer.h index 2ab4823d..90fd9310 100644 --- a/src/GraphicsDrawer.h +++ b/src/GraphicsDrawer.h @@ -174,8 +174,5 @@ private: bool m_bFlatColors; TexrectDrawer m_texrectDrawer; - std::unique_ptr m_drawerImpl; - std::unique_ptr m_textDrawer; - //GLuint m_programCopyTex; };