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

197 lines
4.4 KiB
C
Raw Normal View History

#pragma once
2017-01-10 14:58:09 +00:00
#include <memory>
#include <array>
#include <vector>
#include "gSP.h"
2017-01-14 10:08:02 +00:00
#include "Graphics/ObjectHandle.h"
#include "Graphics/Parameter.h"
2017-01-10 14:58:09 +00:00
namespace graphics {
class DrawerImpl;
2017-01-11 10:07:20 +00:00
class TextDrawer;
2017-01-10 14:58:09 +00:00
}
struct CachedTexture;
struct FrameBuffer;
#define VERTBUFF_SIZE 256U
#define ELEMBUFF_SIZE 1024U
enum class DrawingState
{
None = 0,
Line = 1,
Triangle = 2,
Rect = 3,
TexRect = 4,
};
2017-01-10 14:58:09 +00:00
struct RectVertex
{
float x, y, z, w;
float s0, t0, s1, t1;
};
2017-01-11 06:08:05 +00:00
class GraphicsDrawer
{
public:
2017-01-11 06:08:05 +00:00
GraphicsDrawer();
2017-01-10 14:58:09 +00:00
void addTriangle(int _v0, int _v1, int _v2);
void drawTriangles();
void drawScreenSpaceTriangle(u32 _numVtx);
void drawDMATriangles(u32 _numVtx);
void drawLine(int _v0, int _v1, float _width);
void drawRect(int _ulx, int _uly, int _lrx, int _lry, float * _pColor);
struct TexturedRectParams
{
float ulx, uly, lrx, lry;
float uls, ult, lrs, lrt;
float dsdx, dtdy;
bool flip, forceAjustScale, texrectCmd;
const FrameBuffer * pBuffer;
TexturedRectParams(float _ulx, float _uly, float _lrx, float _lry,
float _uls, float _ult, float _lrs, float _lrt,
float _dsdx, float _dtdy,
bool _flip, bool _forceAjustScale, bool _texrectCmd,
const FrameBuffer * _pBuffer
) :
ulx(_ulx), uly(_uly), lrx(_lrx), lry(_lry),
uls(_uls), ult(_ult), lrs(_lrs), lrt(_lrt),
dsdx(_dsdx), dtdy(_dtdy),
flip(_flip), forceAjustScale(_forceAjustScale), texrectCmd(_texrectCmd),
pBuffer(_pBuffer)
{}
private:
2017-01-11 06:08:05 +00:00
friend class GraphicsDrawer;
TexturedRectParams() :
ulx(0), uly(0), lrx(0), lry(0)
{};
};
void correctTexturedRectParams(TexturedRectParams & _params);
void drawTexturedRect(const TexturedRectParams & _params);
struct CopyRectParams
{
s32 srcX0 = 0;
s32 srcY0 = 0;
s32 srcX1;
s32 srcY1;
u32 srcWidth;
u32 srcHeight;
s32 dstX0 = 0;
s32 dstY0 = 0;
s32 dstX1;
s32 dstY1;
u32 dstWidth;
u32 dstHeight;
std::array<CachedTexture *, 2> tex{ { nullptr, nullptr } };
graphics::CombinerProgram * combiner = nullptr;
graphics::Parameter filter;
};
void copyTexturedRect(const CopyRectParams & _params);
2017-01-14 10:08:02 +00:00
struct BlitOrCopyRectParams : public CopyRectParams
{
graphics::ObjectHandle readBuffer;
graphics::ObjectHandle drawBuffer;
graphics::Parameter mask;
};
void blitOrCopyTexturedRect(const BlitOrCopyRectParams & _params);
void drawText(const char *_pText, float x, float y);
void drawOSD();
void clearDepthBuffer(u32 _ulx, u32 _uly, u32 _lrx, u32 _lry);
void clearColorBuffer(float * _pColor);
int getTrianglesCount() const { return triangles.num; }
bool isClipped(s32 _v0, s32 _v1, s32 _v2) const
{
return (triangles.vertices[_v0].clip & triangles.vertices[_v1].clip & triangles.vertices[_v2].clip) != 0;
}
bool isImageTexturesSupported() const { return m_bImageTexture; }
SPVertex & getVertex(u32 _v) { return triangles.vertices[_v]; }
void setDMAVerticesSize(u32 _size) { if (m_dmaVertices.size() < _size) m_dmaVertices.resize(_size); }
SPVertex * getDMAVerticesData() { return m_dmaVertices.data(); }
void updateScissor(FrameBuffer * _pBuffer) const;
DrawingState getDrawingState() const { return m_drawingState; }
void dropRenderState() { m_drawingState = DrawingState::None; }
private:
2017-01-11 06:08:05 +00:00
GraphicsDrawer(const GraphicsDrawer &);
void _initStates();
void _initData();
void _destroyData();
void _setSpecialTexrect() const;
void _setBlendMode() const;
void _legacySetBlendMode() const;
void _updateCullFace() const;
void _updateViewport() const;
void _updateScreenCoordsViewport() const;
void _updateDepthUpdate() const;
void _updateDepthCompare() const;
void _updateTextures() const;
void _updateStates(DrawingState _drawingState) const;
2017-01-11 10:07:20 +00:00
void _prepareDrawTriangle();
bool _canDraw() const;
void _drawThickLine(int _v0, int _v1, float _width);
void _drawOSD(const char *_pText, float _x, float & _y);
DrawingState m_drawingState;
TexturedRectParams m_texrectParams;
2017-01-11 10:07:20 +00:00
// Dummy TexrectDrawer
class TexrectDrawer
{
public:
TexrectDrawer() {}
void init() {}
void destroy() {}
void add() {}
bool draw() { return false; }
bool isEmpty() { return true; }
};
struct {
std::array<SPVertex, VERTBUFF_SIZE> vertices;
std::array<u8, ELEMBUFF_SIZE> elements;
u32 num;
int maxElement;
} triangles;
std::vector<SPVertex> m_dmaVertices;
RectVertex m_rect[4];
u32 m_modifyVertices;
f32 m_maxLineWidth;
bool m_bImageTexture;
bool m_bFlatColors;
2017-01-11 10:07:20 +00:00
TexrectDrawer m_texrectDrawer;
};