1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Move GraphicsDrawer and TextDrawer interfaces to OpenGLContext

This commit is contained in:
Sergey Lipskiy 2017-01-12 22:22:53 +07:00
parent a39bdd2ad3
commit 52aa260153
15 changed files with 153 additions and 96 deletions

View File

@ -438,7 +438,6 @@
<ClInclude Include="..\..\src\Graphics\CombinerProgram.h" />
<ClInclude Include="..\..\src\Graphics\Context.h" />
<ClInclude Include="..\..\src\Graphics\ContextImpl.h" />
<ClInclude Include="..\..\src\Graphics\GraphicsDrawerImpl.h" />
<ClInclude Include="..\..\src\Graphics\ObjectHandle.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLFunctions.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerInputs.h" />
@ -455,6 +454,8 @@
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_ContextImpl.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GLInfo.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_DummyTextDrawer.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GraphicsDrawer.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_TextDrawer.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_TextureManipulationObjectFactory.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_UnbufferedDrawer.h" />
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_Utils.h" />
@ -462,7 +463,6 @@
<ClInclude Include="..\..\src\Graphics\Parameters.h" />
<ClInclude Include="..\..\src\Graphics\PixelBuffer.h" />
<ClInclude Include="..\..\src\Graphics\ShaderProgram.h" />
<ClInclude Include="..\..\src\Graphics\TextDrawerImpl.h" />
<ClInclude Include="..\..\src\gSP.h" />
<ClInclude Include="..\..\src\inc\glext.h" />
<ClInclude Include="..\..\src\Keys.h" />

View File

@ -634,14 +634,14 @@
<ClInclude Include="..\..\src\GraphicsDrawer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Graphics\GraphicsDrawerImpl.h">
<Filter>Header Files\Graphics</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Graphics\TextDrawerImpl.h">
<Filter>Header Files\Graphics</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_DummyTextDrawer.h">
<Filter>Header Files\Graphics\OpenGL</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_TextDrawer.h">
<Filter>Header Files\Graphics\OpenGL</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Graphics\OpenGLContext\opengl_GraphicsDrawer.h">
<Filter>Header Files\Graphics\OpenGL</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -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()

View File

@ -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<f32, 4> 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:

View File

@ -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;
};
}

View File

@ -1,42 +0,0 @@
#ifndef GRAPHICS_DRAWERIMPL_H
#define GRAPHICS_DRAWERIMPL_H
#include <array>
#include <GraphicsDrawer.h>
#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<f32, 4> 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

View File

@ -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);
}

View File

@ -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<CachedFunctions> m_cachedFunctions;
std::unique_ptr<Create2DTexture> m_createTexture;
@ -99,6 +107,9 @@ namespace opengl {
std::unique_ptr<AddFramebufferRenderTarget> m_addFramebufferRenderTarget;
std::unique_ptr<CreatePixelWriteBuffer> m_createPixelWriteBuffer;
std::unique_ptr<GraphicsDrawer> m_graphicsDrawer;
std::unique_ptr<TextDrawer> m_textDrawer;
std::unique_ptr<glsl::CombinerProgramBuilder> m_combinerProgramBuilder;
GLInfo m_glInfo;
};

View File

@ -1,17 +1,17 @@
#ifndef OPENGL_DUMMY_TEXTDRAWER_H
#define OPENGL_DUMMY_TEXTDRAWER_H
#include <Graphics/TextDrawerImpl.h>
#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 {}
};

View File

@ -0,0 +1,20 @@
#ifndef OPENGL_GRAPHICS_DRAWER_H
#define OPENGL_GRAPHICS_DRAWER_H
#include <Graphics/Context.h>
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

View File

@ -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;
};

View File

@ -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);

View File

@ -1,20 +1,20 @@
#pragma once
#include <array>
#include <Graphics/GraphicsDrawerImpl.h>
#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;

View File

@ -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)

View File

@ -174,8 +174,5 @@ private:
bool m_bFlatColors;
TexrectDrawer m_texrectDrawer;
std::unique_ptr<graphics::DrawerImpl> m_drawerImpl;
std::unique_ptr<graphics::TextDrawer> m_textDrawer;
//GLuint m_programCopyTex;
};