metaforce/Runtime/CGraphics.hpp

216 lines
5.0 KiB
C++
Raw Normal View History

2016-02-13 09:02:47 +00:00
#ifndef __PSHAG_CGRAPHICS_HPP__
#define __PSHAG_CGRAPHICS_HPP__
2016-02-12 02:36:34 +00:00
#include "RetroTypes.hpp"
2016-02-13 00:57:09 +00:00
#include "CTransform.hpp"
2016-02-14 03:42:36 +00:00
#include "CVector2i.hpp"
2016-02-12 02:36:34 +00:00
2016-02-15 04:00:26 +00:00
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
#include "boo/graphicsdev/IGraphicsCommandQueue.hpp"
2016-02-13 09:02:47 +00:00
namespace pshag
2016-02-12 02:36:34 +00:00
{
enum class ERglLight : u8
{
None = 0,
Zero = 1,
One = 1 << 1,
Two = 1 << 2,
Three = 1 << 3,
Four = 1 << 4,
Five = 1 << 5,
Six = 1 << 6,
Seven = 1 << 7
};
ENABLE_BITWISE_ENUM(ERglLight)
2016-02-13 00:57:09 +00:00
enum class ERglEnum
{
Never = 0,
Less = 1,
Equal = 2,
LEqual = 3,
Greater = 4,
NEqual = 5,
GEqual = 6,
Always = 7
};
enum class ERglBlendMode
{
None = 0,
Blend = 1,
Logic = 2,
Subtract = 3
};
enum class ERglBlendFactor
{
Zero = 0,
One = 1,
SrcColor = 2,
InvSrcColor = 3,
SrcAlpha = 4,
InvSrcAlpha = 5,
DstAlpha = 6,
InvDstAlpha = 7
};
enum class ERglLogicOp
{
Clear = 0,
And = 1,
RevAnd = 2,
Copy = 3,
InvAnd = 4,
NoOp = 5,
Xor = 6,
Or = 7,
Nor = 8,
Equiv = 9,
Inv = 10,
RevOr = 11,
InvCopy = 12,
InvOr = 13,
NAnd = 14,
Set = 15
};
enum class ERglCullMode
{
None = 0,
Front = 1,
Back = 2,
All = 3
};
enum class ERglAlphaFunc
{
Never = 0,
Less = 1,
Equal = 2,
LEqual = 3,
Greater = 4,
NEqual = 5,
GEqual = 6,
Always = 7
};
enum class ERglAlphaOp
{
And = 0,
Or = 1,
Xor = 2,
XNor = 3
};
2016-02-14 03:42:36 +00:00
struct SClipScreenRect
{
bool x0_valid;
2016-02-15 04:00:26 +00:00
int x4_left;
int x8_top;
int xc_width;
int x10_height;
int x14_dstWidth;
2016-02-14 03:42:36 +00:00
float x18_uvXMin;
float x1c_uvXMax;
float x20_uvYMin;
float x24_uvYMax;
};
enum class ETexelFormat
{
2016-02-16 05:50:41 +00:00
I4 = 0,
I8 = 1,
IA4 = 2,
IA8 = 3,
C4 = 4,
C8 = 5,
C14X2 = 6,
RGB565 = 7,
RGB5A3 = 8,
RGBA8 = 9,
CMPR = 10
2016-02-14 03:42:36 +00:00
};
2016-02-12 02:36:34 +00:00
class CGraphics
{
public:
2016-02-14 03:42:36 +00:00
struct CProjectionState
{
bool x0_persp;
float x4_left;
float x8_right;
float xc_top;
float x10_bottom;
float x14_near;
float x18_far;
};
static CProjectionState g_Proj;
2016-02-12 02:36:34 +00:00
static u32 g_NumLightsActive;
static ERglLight g_LightActive;
static ERglLight g_LightsWereOn;
2016-02-14 03:42:36 +00:00
static Zeus::CTransform g_GXModelView;
static Zeus::CTransform g_GXModelMatrix;
2016-02-13 00:57:09 +00:00
static Zeus::CTransform g_ViewMatrix;
2016-02-14 03:42:36 +00:00
static Zeus::CVector3f g_ViewPoint;
static Zeus::CTransform g_GXViewPointMatrix;
static Zeus::CTransform g_CameraMatrix;
static Zeus::CVector2i g_ViewportResolution;
static Zeus::CVector2i g_ViewportResolutionHalf;
2016-02-16 08:52:22 +00:00
static int g_ViewportSamples;
2016-02-14 03:42:36 +00:00
static bool g_IsGXModelMatrixIdentity;
2016-02-15 04:00:26 +00:00
2016-02-12 02:36:34 +00:00
static void DisableAllLights();
static void EnableLight(ERglLight light);
static void SetLightState(ERglLight lightState);
2016-02-14 03:42:36 +00:00
static void SetDepthWriteMode(bool test, ERglEnum comp, bool write);
2016-02-13 00:57:09 +00:00
static void SetBlendMode(ERglBlendMode, ERglBlendFactor, ERglBlendFactor, ERglLogicOp);
static void SetCullMode(ERglCullMode);
static void SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1);
2016-02-14 03:42:36 +00:00
static void SetViewPointMatrix(const Zeus::CTransform& xf);
static void SetViewMatrix();
2016-02-13 00:57:09 +00:00
static void SetModelMatrix(const Zeus::CTransform& xf);
2016-02-14 03:42:36 +00:00
static Zeus::CMatrix4f GetPerspectiveProjectionMatrix();
static const CProjectionState& GetProjectionState();
static void SetProjectionState(const CProjectionState&);
2016-02-16 05:50:41 +00:00
static void SetPerspective(float fovy, float aspect, float near, float far);
2016-02-14 03:42:36 +00:00
static void FlushProjection();
static Zeus::CVector2i ProjectPoint(const Zeus::CVector3f& point);
2016-02-15 04:00:26 +00:00
static SClipScreenRect ClipScreenRectFromMS(const Zeus::CVector3f& p1, const Zeus::CVector3f& p2);
static SClipScreenRect ClipScreenRectFromVS(const Zeus::CVector3f& p1, const Zeus::CVector3f& p2);
static boo::IGraphicsDataFactory* g_BooFactory;
static boo::IGraphicsCommandQueue* g_BooMainCommandQueue;
static boo::ITextureR* g_SpareTexture;
2016-02-16 05:50:41 +00:00
static void InitializeBoo(boo::IGraphicsDataFactory* factory, boo::IGraphicsCommandQueue* cc)
{
g_BooFactory = factory;
g_BooMainCommandQueue = cc;
}
2016-02-15 04:00:26 +00:00
static boo::IGraphicsBufferD* NewDynamicGPUBuffer(boo::BufferUse use, size_t stride, size_t count)
{
return g_BooFactory->newDynamicBuffer(use, stride, count);
}
static boo::GraphicsDataToken CommitResources()
{
return g_BooFactory->commit();
}
static void SetShaderDataBinding(boo::IShaderDataBinding* binding)
{
g_BooMainCommandQueue->setShaderDataBinding(binding);
}
2016-02-16 05:50:41 +00:00
static void DrawInstances(boo::Primitive prim, size_t start, size_t count, size_t instCount)
2016-02-15 04:00:26 +00:00
{
2016-02-16 05:50:41 +00:00
g_BooMainCommandQueue->setDrawPrimitive(prim);
2016-02-15 04:00:26 +00:00
g_BooMainCommandQueue->drawInstances(start, count, instCount);
}
2016-02-12 02:36:34 +00:00
};
}
2016-02-13 09:02:47 +00:00
#endif // __PSHAG_CGRAPHICS_HPP__