2016-04-13 06:07:23 +00:00
|
|
|
#ifndef __URDE_CGRAPHICS_HPP__
|
|
|
|
#define __URDE_CGRAPHICS_HPP__
|
2016-02-12 02:36:34 +00:00
|
|
|
|
2016-08-17 20:05:23 +00:00
|
|
|
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
|
|
|
|
#include "boo/graphicsdev/IGraphicsCommandQueue.hpp"
|
|
|
|
|
2016-02-12 02:36:34 +00:00
|
|
|
#include "RetroTypes.hpp"
|
2016-03-04 23:04:53 +00:00
|
|
|
#include "zeus/CTransform.hpp"
|
|
|
|
#include "zeus/CVector2i.hpp"
|
2016-08-08 04:48:18 +00:00
|
|
|
#include "zeus/CColor.hpp"
|
2016-02-12 02:36:34 +00:00
|
|
|
|
2016-03-31 02:44:43 +00:00
|
|
|
#include "hecl/Runtime.hpp"
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2016-02-12 02:36:34 +00:00
|
|
|
{
|
2016-03-15 04:55:57 +00:00
|
|
|
class CLight;
|
2016-03-31 06:18:56 +00:00
|
|
|
class CTimeProvider;
|
2016-02-12 02:36:34 +00:00
|
|
|
|
|
|
|
enum class ERglLight : u8
|
2016-03-15 04:55:57 +00:00
|
|
|
{
|
|
|
|
Zero = 0,
|
|
|
|
One,
|
|
|
|
Two,
|
|
|
|
Three,
|
|
|
|
Four,
|
|
|
|
Five,
|
|
|
|
Six,
|
|
|
|
Seven
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class ERglLightBits : u8
|
2016-02-12 02:36:34 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
};
|
2016-03-15 04:55:57 +00:00
|
|
|
ENABLE_BITWISE_ENUM(ERglLightBits)
|
2016-02-12 02:36:34 +00:00
|
|
|
|
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-08-08 04:48:18 +00:00
|
|
|
enum class ERglFogMode
|
|
|
|
{
|
|
|
|
None = 0x00,
|
|
|
|
|
|
|
|
PerspLin = 0x02,
|
|
|
|
PerspExp = 0x04,
|
|
|
|
PerspExp2 = 0x05,
|
|
|
|
PerspRevExp = 0x06,
|
|
|
|
PerspRevExp2 = 0x07,
|
|
|
|
|
|
|
|
OrthoLin = 0x0A,
|
|
|
|
OrthoExp = 0x0C,
|
|
|
|
OrthoExp2 = 0x0D,
|
|
|
|
OrthoRevExp = 0x0E,
|
|
|
|
OrthoRevExp2 = 0x0F
|
|
|
|
};
|
|
|
|
|
2016-10-31 22:56:44 +00:00
|
|
|
struct SViewport
|
|
|
|
{
|
|
|
|
u32 x0_left;
|
|
|
|
u32 x4_top;
|
|
|
|
u32 x8_width;
|
|
|
|
u32 xc_height;
|
|
|
|
float x10_halfWidth;
|
|
|
|
float x14_halfHeight;
|
|
|
|
};
|
|
|
|
|
2017-03-03 07:18:12 +00:00
|
|
|
extern SViewport g_Viewport;
|
2016-10-31 22:56:44 +00:00
|
|
|
|
2016-02-14 03:42:36 +00:00
|
|
|
struct SClipScreenRect
|
|
|
|
{
|
2016-09-02 23:37:02 +00:00
|
|
|
bool x0_valid = false;
|
|
|
|
int x4_left = 0;
|
|
|
|
int x8_top = 0;
|
|
|
|
int xc_width = 0;
|
|
|
|
int x10_height = 0;
|
|
|
|
int x14_dstWidth = 0;
|
|
|
|
float x18_uvXMin = 0.f;
|
|
|
|
float x1c_uvXMax = 0.f;
|
|
|
|
float x20_uvYMin = 0.f;
|
|
|
|
float x24_uvYMax = 0.f;
|
|
|
|
|
|
|
|
SClipScreenRect() = default;
|
|
|
|
SClipScreenRect(bool valid, int left, int top, int width, int height, int dstWidth,
|
|
|
|
float uvXMin, float uvXMax, float uvYMin, float uvYMax)
|
|
|
|
: x0_valid(valid), x4_left(left), x8_top(top), xc_width(width), x10_height(height), x14_dstWidth(dstWidth),
|
|
|
|
x18_uvXMin(uvXMin), x1c_uvXMax(uvXMax), x20_uvYMin(uvYMin), x24_uvYMax(uvYMax) {}
|
|
|
|
|
|
|
|
SClipScreenRect(const boo::SWindowRect& rect)
|
|
|
|
{
|
|
|
|
x4_left = rect.location[0];
|
|
|
|
x8_top = rect.location[1];
|
|
|
|
xc_width = rect.size[0];
|
|
|
|
x10_height = rect.size[1];
|
|
|
|
x14_dstWidth = rect.size[0];
|
|
|
|
}
|
2016-02-14 03:42:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class ETexelFormat
|
|
|
|
{
|
2016-03-31 21:06: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-07-27 19:07:46 +00:00
|
|
|
RGBA8PC = 16,
|
|
|
|
C8PC = 17
|
2016-02-14 03:42:36 +00:00
|
|
|
};
|
|
|
|
|
2016-02-12 02:36:34 +00:00
|
|
|
class CGraphics
|
|
|
|
{
|
|
|
|
public:
|
2016-04-23 10:51:53 +00:00
|
|
|
|
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;
|
|
|
|
};
|
2016-08-08 04:48:18 +00:00
|
|
|
|
|
|
|
struct CFogState
|
|
|
|
{
|
|
|
|
zeus::CColor m_color;
|
2016-08-08 18:23:12 +00:00
|
|
|
float m_rangeScale = 1.f;
|
|
|
|
float m_start = 4096.f;
|
2016-08-08 04:48:18 +00:00
|
|
|
};
|
|
|
|
|
2016-02-14 03:42:36 +00:00
|
|
|
static CProjectionState g_Proj;
|
2017-03-05 07:57:12 +00:00
|
|
|
static zeus::CVector2f g_CachedDepthRange;
|
2016-08-08 04:48:18 +00:00
|
|
|
static CFogState g_Fog;
|
2016-02-18 02:42:32 +00:00
|
|
|
static float g_ProjAspect;
|
2016-02-12 02:36:34 +00:00
|
|
|
static u32 g_NumLightsActive;
|
2016-03-07 03:12:32 +00:00
|
|
|
static u32 g_NumBreakpointsWaiting;
|
|
|
|
static u32 g_FlippingState;
|
|
|
|
static bool g_LastFrameUsedAbove;
|
|
|
|
static bool g_InterruptLastFrameUsedAbove;
|
2016-03-15 04:55:57 +00:00
|
|
|
static ERglLightBits g_LightActive;
|
|
|
|
static ERglLightBits g_LightsWereOn;
|
2016-03-04 23:04:53 +00:00
|
|
|
static zeus::CTransform g_GXModelView;
|
2016-03-31 06:18:56 +00:00
|
|
|
static zeus::CTransform g_GXModelViewInvXpose;
|
2016-03-04 23:04:53 +00:00
|
|
|
static zeus::CTransform g_GXModelMatrix;
|
|
|
|
static zeus::CTransform g_ViewMatrix;
|
|
|
|
static zeus::CVector3f g_ViewPoint;
|
|
|
|
static zeus::CTransform g_GXViewPointMatrix;
|
|
|
|
static zeus::CTransform g_CameraMatrix;
|
2016-09-02 23:37:02 +00:00
|
|
|
static SClipScreenRect g_CroppedViewport;
|
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();
|
2016-03-15 04:55:57 +00:00
|
|
|
static void LoadLight(ERglLight light, const CLight& info);
|
2016-02-12 02:36:34 +00:00
|
|
|
static void EnableLight(ERglLight light);
|
2016-03-15 04:55:57 +00:00
|
|
|
static void SetLightState(ERglLightBits lightState);
|
|
|
|
static void SetAmbientColor(const zeus::CColor& col);
|
2016-08-08 04:48:18 +00:00
|
|
|
static void SetFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color);
|
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);
|
2016-04-23 10:51:53 +00:00
|
|
|
static void BeginScene();
|
2016-03-07 03:12:32 +00:00
|
|
|
static void EndScene();
|
2016-02-13 00:57:09 +00:00
|
|
|
static void SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1);
|
2016-03-04 23:04:53 +00:00
|
|
|
static void SetViewPointMatrix(const zeus::CTransform& xf);
|
2016-02-14 03:42:36 +00:00
|
|
|
static void SetViewMatrix();
|
2016-03-04 23:04:53 +00:00
|
|
|
static void SetModelMatrix(const zeus::CTransform& xf);
|
2016-03-16 03:37:51 +00:00
|
|
|
static zeus::CMatrix4f CalculatePerspectiveMatrix(float fovy, float aspect,
|
2016-04-03 05:25:34 +00:00
|
|
|
float znear, float zfar,
|
|
|
|
bool forRenderer);
|
|
|
|
static zeus::CMatrix4f GetPerspectiveProjectionMatrix(bool forRenderer);
|
2016-02-14 03:42:36 +00:00
|
|
|
static const CProjectionState& GetProjectionState();
|
|
|
|
static void SetProjectionState(const CProjectionState&);
|
2016-04-03 05:25:34 +00:00
|
|
|
static void SetPerspective(float fovy, float aspect, float znear, float zfar);
|
2016-03-16 03:37:51 +00:00
|
|
|
static void SetOrtho(float left, float right,
|
|
|
|
float top, float bottom,
|
|
|
|
float znear, float zfar);
|
2016-02-14 03:42:36 +00:00
|
|
|
static void FlushProjection();
|
2016-03-04 23:04:53 +00:00
|
|
|
static zeus::CVector2i ProjectPoint(const zeus::CVector3f& point);
|
|
|
|
static SClipScreenRect ClipScreenRectFromMS(const zeus::CVector3f& p1, const zeus::CVector3f& p2);
|
|
|
|
static SClipScreenRect ClipScreenRectFromVS(const zeus::CVector3f& p1, const zeus::CVector3f& p2);
|
|
|
|
static zeus::CVector3f ProjectModelPointToViewportSpace(const zeus::CVector3f& point);
|
2016-04-05 01:51:25 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
static void SetViewportResolution(const zeus::CVector2i& res);
|
2016-04-05 01:51:25 +00:00
|
|
|
static void SetViewport(int leftOff, int bottomOff, int width, int height);
|
|
|
|
static void SetScissor(int leftOff, int bottomOff, int width, int height);
|
|
|
|
static void SetDepthRange(float near, float far);
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2016-03-31 06:18:56 +00:00
|
|
|
static CTimeProvider* g_ExternalTimeProvider;
|
|
|
|
static float g_DefaultSeconds;
|
2016-04-23 10:51:53 +00:00
|
|
|
static u32 g_RenderTimings;
|
2016-03-31 06:18:56 +00:00
|
|
|
static void SetExternalTimeProvider(CTimeProvider* provider)
|
|
|
|
{g_ExternalTimeProvider = provider;}
|
|
|
|
static float GetSecondsMod900();
|
2016-04-23 10:51:53 +00:00
|
|
|
static void TickRenderTimings();
|
2017-03-10 03:40:24 +00:00
|
|
|
static u32 g_FrameCounter;
|
|
|
|
static u32 GetFrameCounter() { return g_FrameCounter; }
|
2016-03-31 06:18:56 +00:00
|
|
|
|
2016-04-03 05:25:34 +00:00
|
|
|
static boo::IGraphicsDataFactory::Platform g_BooPlatform;
|
2016-08-05 03:21:19 +00:00
|
|
|
static const boo::SystemChar* g_BooPlatformName;
|
2016-02-15 04:00:26 +00:00
|
|
|
static boo::IGraphicsDataFactory* g_BooFactory;
|
|
|
|
static boo::IGraphicsCommandQueue* g_BooMainCommandQueue;
|
|
|
|
static boo::ITextureR* g_SpareTexture;
|
|
|
|
|
2016-02-25 02:55:38 +00:00
|
|
|
static void InitializeBoo(boo::IGraphicsDataFactory* factory,
|
|
|
|
boo::IGraphicsCommandQueue* cc,
|
2016-04-04 02:32:57 +00:00
|
|
|
boo::ITextureR* spareTex)
|
2016-02-16 05:50:41 +00:00
|
|
|
{
|
2016-04-03 05:25:34 +00:00
|
|
|
g_BooPlatform = factory->platform();
|
2016-08-05 03:21:19 +00:00
|
|
|
g_BooPlatformName = factory->platformName();
|
2016-02-16 05:50:41 +00:00
|
|
|
g_BooFactory = factory;
|
|
|
|
g_BooMainCommandQueue = cc;
|
2016-02-25 02:55:38 +00:00
|
|
|
g_SpareTexture = spareTex;
|
2016-02-16 05:50:41 +00:00
|
|
|
}
|
2016-08-05 03:21:19 +00:00
|
|
|
|
|
|
|
const boo::SystemChar* PlatformName()
|
|
|
|
{
|
|
|
|
return g_BooPlatformName;
|
|
|
|
}
|
2016-02-16 05:50:41 +00:00
|
|
|
|
2016-03-30 19:16:01 +00:00
|
|
|
static boo::GraphicsDataToken CommitResources(const boo::FactoryCommitFunc& commitFunc)
|
2016-02-15 04:00:26 +00:00
|
|
|
{
|
2016-03-30 19:16:01 +00:00
|
|
|
return g_BooFactory->commitTransaction(commitFunc);
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
|
|
|
static void SetShaderDataBinding(boo::IShaderDataBinding* binding)
|
|
|
|
{
|
|
|
|
g_BooMainCommandQueue->setShaderDataBinding(binding);
|
|
|
|
}
|
2017-03-14 07:03:58 +00:00
|
|
|
static void ResolveSpareTexture(const SClipScreenRect& rect, int bindIdx=0)
|
2016-02-25 02:55:38 +00:00
|
|
|
{
|
|
|
|
boo::SWindowRect wrect = {rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height};
|
2017-03-14 07:03:58 +00:00
|
|
|
g_BooMainCommandQueue->resolveBindTexture(g_SpareTexture, wrect, true, bindIdx, true, false);
|
|
|
|
}
|
|
|
|
static void ResolveSpareDepth(const SClipScreenRect& rect, int bindIdx=0)
|
|
|
|
{
|
|
|
|
boo::SWindowRect wrect = {rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height};
|
|
|
|
g_BooMainCommandQueue->resolveBindTexture(g_SpareTexture, wrect, true, bindIdx, false, true);
|
2016-02-25 02:55:38 +00:00
|
|
|
}
|
2016-02-23 02:34:16 +00:00
|
|
|
static void DrawInstances(size_t start, size_t count, size_t instCount)
|
2016-02-15 04:00:26 +00:00
|
|
|
{
|
|
|
|
g_BooMainCommandQueue->drawInstances(start, count, instCount);
|
|
|
|
}
|
2016-02-23 02:34:16 +00:00
|
|
|
static void DrawArray(size_t start, size_t count)
|
2016-02-18 02:42:32 +00:00
|
|
|
{
|
|
|
|
g_BooMainCommandQueue->draw(start, count);
|
|
|
|
}
|
2016-03-31 02:44:43 +00:00
|
|
|
static void DrawArrayIndexed(size_t start, size_t count)
|
|
|
|
{
|
|
|
|
g_BooMainCommandQueue->drawIndexed(start, count);
|
|
|
|
}
|
2016-02-12 02:36:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-13 06:07:23 +00:00
|
|
|
#endif // __URDE_CGRAPHICS_HPP__
|