metaforce/Runtime/Graphics/CGraphics.cpp

539 lines
18 KiB
C++
Raw Normal View History

2016-03-04 15:04:53 -08:00
#include "Graphics/CGraphics.hpp"
2016-03-14 21:55:57 -07:00
#include "Graphics/CLight.hpp"
2016-03-04 15:04:53 -08:00
#include "zeus/Math.hpp"
2016-03-30 23:18:56 -07:00
#include "CTimeProvider.hpp"
2017-01-28 19:58:16 -08:00
#include "Shaders/CTextSupportShader.hpp"
2017-01-29 20:16:20 -08:00
#include "GuiSys/CGuiSys.hpp"
2017-04-22 14:46:18 -07:00
#include "CLineRenderer.hpp"
2016-02-11 18:36:34 -08:00
2016-03-04 15:04:53 -08:00
namespace urde
2016-02-11 18:36:34 -08:00
{
2016-02-13 19:42:36 -08:00
CGraphics::CProjectionState CGraphics::g_Proj;
2016-08-07 21:48:18 -07:00
CGraphics::CFogState CGraphics::g_Fog;
2017-04-13 12:28:31 -07:00
zeus::CColor CGraphics::g_ColorRegs[3] = {};
float CGraphics::g_ProjAspect = 1.f;
2016-02-11 18:36:34 -08:00
u32 CGraphics::g_NumLightsActive = 0;
2016-03-06 19:12:32 -08:00
u32 CGraphics::g_NumBreakpointsWaiting = 0;
u32 CGraphics::g_FlippingState;
bool CGraphics::g_LastFrameUsedAbove = false;
bool CGraphics::g_InterruptLastFrameUsedAbove = false;
2016-03-14 21:55:57 -07:00
ERglLightBits CGraphics::g_LightActive = ERglLightBits::None;
ERglLightBits CGraphics::g_LightsWereOn = ERglLightBits::None;
2016-03-04 15:04:53 -08:00
zeus::CTransform CGraphics::g_GXModelView;
2016-03-30 23:18:56 -07:00
zeus::CTransform CGraphics::g_GXModelViewInvXpose;
2016-07-08 12:57:51 -07:00
zeus::CTransform CGraphics::g_GXModelMatrix = zeus::CTransform::Identity();
2016-03-04 15:04:53 -08:00
zeus::CTransform CGraphics::g_ViewMatrix;
zeus::CVector3f CGraphics::g_ViewPoint;
zeus::CTransform CGraphics::g_GXViewPointMatrix;
zeus::CTransform CGraphics::g_CameraMatrix;
SClipScreenRect CGraphics::g_CroppedViewport;
2016-07-08 12:57:51 -07:00
bool CGraphics::g_IsGXModelMatrixIdentity = true;
SViewport g_Viewport = {0, 0, 640, 480, 640 / 2.f, 480 / 2.f};
u32 CGraphics::g_FrameCounter = 0;
2016-02-11 18:36:34 -08:00
void CGraphics::DisableAllLights()
{
g_NumLightsActive = 0;
2016-03-14 21:55:57 -07:00
g_LightActive = ERglLightBits::None;
2016-02-11 18:36:34 -08:00
// TODO: turn lights off for real
}
2016-03-14 21:55:57 -07:00
void CGraphics::LoadLight(ERglLight light, const CLight& info)
{
// TODO: load light for real
}
2016-02-11 18:36:34 -08:00
void CGraphics::EnableLight(ERglLight light)
{
2016-03-14 21:55:57 -07:00
ERglLightBits lightBit = ERglLightBits(1 << int(light));
if ((lightBit & g_LightActive) == ERglLightBits::None)
2016-02-11 18:36:34 -08:00
{
2016-03-14 21:55:57 -07:00
g_LightActive |= lightBit;
2016-02-11 18:36:34 -08:00
++g_NumLightsActive;
// TODO: turn light on for real
}
g_LightsWereOn = g_LightActive;
}
2016-03-14 21:55:57 -07:00
void CGraphics::SetLightState(ERglLightBits lightState)
2016-02-11 18:36:34 -08:00
{
// TODO: set state for real
g_LightActive = lightState;
2016-03-04 15:04:53 -08:00
g_NumLightsActive = zeus::PopCount(lightState);
2016-02-11 18:36:34 -08:00
}
2016-03-14 21:55:57 -07:00
void CGraphics::SetAmbientColor(const zeus::CColor& col)
{
// TODO: set for real
}
2016-08-07 21:48:18 -07:00
void CGraphics::SetFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color)
{
2018-05-26 21:22:38 -07:00
g_Fog.m_mode = mode > ERglFogMode::PerspRevExp2 ? ERglFogMode(int(mode) - 8) : mode;
switch (g_Fog.m_mode)
{
case ERglFogMode::None:
2016-08-07 21:48:18 -07:00
{
2016-08-08 11:23:12 -07:00
g_Fog.m_start = 4096.f;
2017-11-24 18:50:24 -08:00
g_Fog.m_rangeScale = 0.f;
2018-05-26 21:22:38 -07:00
break;
2016-08-07 21:48:18 -07:00
}
2018-05-26 21:22:38 -07:00
case ERglFogMode::PerspRevExp:
case ERglFogMode::PerspRevExp2:
{
float userRange = endz - startz;
g_Fog.m_color = color;
g_Fog.m_start = endz;
g_Fog.m_rangeScale = 1.f / userRange;
break;
}
default:
2016-08-07 21:48:18 -07:00
{
float userRange = endz - startz;
g_Fog.m_color = color;
2016-08-08 11:23:12 -07:00
g_Fog.m_start = startz;
g_Fog.m_rangeScale = 1.f / userRange;
2018-05-26 21:22:38 -07:00
break;
}
2016-08-07 21:48:18 -07:00
}
}
2016-02-13 19:42:36 -08:00
void CGraphics::SetDepthWriteMode(bool test, ERglEnum comp, bool write)
2016-02-12 16:57:09 -08:00
{
}
void CGraphics::SetBlendMode(ERglBlendMode, ERglBlendFactor, ERglBlendFactor, ERglLogicOp)
{
}
void CGraphics::SetCullMode(ERglCullMode)
{
}
2016-07-29 10:38:44 -07:00
void CGraphics::BeginScene()
{
}
2016-03-06 19:12:32 -08:00
void CGraphics::EndScene()
{
/* Spinwait until g_NumBreakpointsWaiting is 0 */
/* ++g_NumBreakpointsWaiting; */
/* GXCopyDisp to g_CurrenFrameBuf with clear enabled */
/* Register next breakpoint with GP FIFO */
2017-04-22 14:46:18 -07:00
/* Yup, GX effectively had fences long before D3D12 and Vulkan
* (same functionality implemented in boo's execute method) */
/* This usually comes from VI register during interrupt;
* we don't care in the era of progressive-scan dominance,
* so simulate field-flipping with XOR instead */
g_InterruptLastFrameUsedAbove ^= 1;
g_LastFrameUsedAbove = g_InterruptLastFrameUsedAbove;
2017-01-28 19:58:16 -08:00
/* Flush text instance buffers just before GPU command list submission */
CTextSupportShader::UpdateBuffers();
2017-04-22 14:46:18 -07:00
/* Same with line renderer */
CLineRenderer::UpdateBuffers();
++g_FrameCounter;
2016-03-06 19:12:32 -08:00
}
2016-02-12 16:57:09 -08:00
void CGraphics::SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1)
{
}
2016-03-04 15:04:53 -08:00
void CGraphics::SetViewPointMatrix(const zeus::CTransform& xf)
2016-02-13 19:42:36 -08:00
{
g_ViewMatrix = xf;
2016-04-29 03:08:46 -07:00
g_ViewPoint = xf.origin;
zeus::CMatrix3f tmp(xf.basis[0], xf.basis[2], -xf.basis[1]);
2016-03-04 15:04:53 -08:00
g_GXViewPointMatrix = zeus::CTransform(tmp.transposed());
2016-02-13 19:42:36 -08:00
SetViewMatrix();
}
void CGraphics::SetViewMatrix()
{
2016-03-04 15:04:53 -08:00
g_CameraMatrix = g_GXViewPointMatrix * zeus::CTransform::Translate(-g_ViewPoint);
2016-02-13 19:42:36 -08:00
if (g_IsGXModelMatrixIdentity)
g_GXModelView = g_CameraMatrix;
else
g_GXModelView = g_CameraMatrix * g_GXModelMatrix;
/* Load position matrix */
/* Inverse-transpose */
2016-03-30 23:18:56 -07:00
g_GXModelViewInvXpose = g_GXModelView.inverse();
2016-04-29 03:08:46 -07:00
g_GXModelViewInvXpose.origin.zeroOut();
g_GXModelViewInvXpose.basis.transpose();
2016-02-13 19:42:36 -08:00
/* Load normal matrix */
}
2016-03-04 15:04:53 -08:00
void CGraphics::SetModelMatrix(const zeus::CTransform& xf)
2016-02-12 16:57:09 -08:00
{
2016-02-13 19:42:36 -08:00
g_IsGXModelMatrixIdentity = false;
g_GXModelMatrix = xf;
SetViewMatrix();
}
static const zeus::CMatrix4f PlusOneZ(1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 1.f,
0.f, 0.f, 0.f, 1.f);
static const zeus::CMatrix4f VulkanCorrect(1.f, 0.f, 0.f, 0.f,
0.f, -1.f, 0.f, 0.f,
0.f, 0.f, 0.5f, 0.5f + FLT_EPSILON,
0.f, 0.f, 0.f, 1.f);
2016-07-07 17:07:11 -07:00
2016-03-15 20:37:51 -07:00
zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect,
2016-09-10 18:25:59 -07:00
float znear, float zfar,
2016-04-02 22:25:34 -07:00
bool forRenderer)
2016-03-15 20:37:51 -07:00
{
CProjectionState st;
float tfov = std::tan(zeus::degToRad(fovy * 0.5f));
2016-09-10 18:25:59 -07:00
st.x14_near = znear;
st.x18_far = zfar;
st.xc_top = znear * tfov;
2016-03-15 20:37:51 -07:00
st.x10_bottom = -st.xc_top;
2016-09-10 18:25:59 -07:00
st.x8_right = aspect * znear * tfov;
2016-03-15 20:37:51 -07:00
st.x4_left = -st.x8_right;
float rml = st.x8_right - st.x4_left;
float rpl = st.x8_right + st.x4_left;
float tmb = st.xc_top - st.x10_bottom;
float tpb = st.xc_top + st.x10_bottom;
float fpn = st.x18_far + st.x14_near;
2016-04-02 22:25:34 -07:00
float fmn = st.x18_far - st.x14_near;
if (!forRenderer)
{
return zeus::CMatrix4f(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f,
0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn,
0.f, 0.f, -1.f, 0.f);
}
switch (g_BooPlatform)
{
2016-08-23 21:35:35 -07:00
case boo::IGraphicsDataFactory::Platform::OpenGL:
2016-04-02 22:25:34 -07:00
default:
{
return zeus::CMatrix4f(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f,
0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn,
0.f, 0.f, -1.f, 0.f);
}
case boo::IGraphicsDataFactory::Platform::D3D11:
2016-04-02 23:19:33 -07:00
case boo::IGraphicsDataFactory::Platform::Metal:
2016-04-02 22:25:34 -07:00
{
zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f,
0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, st.x18_far / fmn, st.x14_near * st.x18_far / fmn,
0.f, 0.f, -1.f, 0.f);
return PlusOneZ * mat2;
}
2016-07-07 17:07:11 -07:00
case boo::IGraphicsDataFactory::Platform::Vulkan:
{
zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f,
0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f,
2016-07-26 23:14:05 -07:00
0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn,
2016-07-07 17:07:11 -07:00
0.f, 0.f, -1.f, 0.f);
return VulkanCorrect * mat2;
2016-07-07 17:07:11 -07:00
}
2016-04-02 22:25:34 -07:00
}
2016-03-15 20:37:51 -07:00
}
2016-04-02 22:25:34 -07:00
zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer)
2016-02-13 19:42:36 -08:00
{
2017-01-28 19:58:16 -08:00
if (g_Proj.x0_persp)
2016-04-02 22:25:34 -07:00
{
2017-01-28 19:58:16 -08:00
float rml = g_Proj.x8_right - g_Proj.x4_left;
float rpl = g_Proj.x8_right + g_Proj.x4_left;
float tmb = g_Proj.xc_top - g_Proj.x10_bottom;
float tpb = g_Proj.xc_top + g_Proj.x10_bottom;
float fpn = g_Proj.x18_far + g_Proj.x14_near;
float fmn = g_Proj.x18_far - g_Proj.x14_near;
if (!forRenderer)
{
return zeus::CMatrix4f(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f,
0.f, 2.f * g_Proj.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn,
0.f, 0.f, -1.f, 0.f);
}
switch (g_BooPlatform)
{
case boo::IGraphicsDataFactory::Platform::OpenGL:
default:
{
return zeus::CMatrix4f(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f,
0.f, 2.f * g_Proj.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn,
0.f, 0.f, -1.f, 0.f);
}
case boo::IGraphicsDataFactory::Platform::D3D11:
case boo::IGraphicsDataFactory::Platform::Metal:
{
zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f,
0.f, 2.f * g_Proj.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, g_Proj.x18_far / fmn, g_Proj.x14_near * g_Proj.x18_far / fmn,
0.f, 0.f, -1.f, 0.f);
return PlusOneZ * mat2;
}
case boo::IGraphicsDataFactory::Platform::Vulkan:
{
zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f,
0.f, 2.f * g_Proj.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn,
0.f, 0.f, -1.f, 0.f);
return VulkanCorrect * mat2;
2017-01-28 19:58:16 -08:00
}
}
2016-04-02 22:25:34 -07:00
}
2017-01-28 19:58:16 -08:00
else
2016-07-07 17:07:11 -07:00
{
2017-01-28 19:58:16 -08:00
float rml = g_Proj.x8_right - g_Proj.x4_left;
float rpl = g_Proj.x8_right + g_Proj.x4_left;
float tmb = g_Proj.xc_top - g_Proj.x10_bottom;
float tpb = g_Proj.xc_top + g_Proj.x10_bottom;
float fpn = g_Proj.x18_far + g_Proj.x14_near;
float fmn = g_Proj.x18_far - g_Proj.x14_near;
if (!forRenderer)
{
return zeus::CMatrix4f(2.f / rml, 0.f, 0.f, -rpl / rml,
0.f, 2.f / tmb, 0.f, -tpb / tmb,
0.f, 0.f, -2.f / fmn, -fpn / fmn,
0.f, 0.f, 0.f, 1.f);
}
switch (g_BooPlatform)
{
case boo::IGraphicsDataFactory::Platform::OpenGL:
default:
{
return zeus::CMatrix4f(2.f / rml, 0.f, 0.f, -rpl / rml,
0.f, 2.f / tmb, 0.f, -tpb / tmb,
0.f, 0.f, -2.f / fmn, -fpn / fmn,
0.f, 0.f, 0.f, 1.f);
}
case boo::IGraphicsDataFactory::Platform::D3D11:
case boo::IGraphicsDataFactory::Platform::Metal:
{
zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml,
0.f, 2.f / tmb, 0.f, -tpb / tmb,
0.f, 0.f, 1.f / fmn, g_Proj.x14_near / fmn,
2017-01-28 19:58:16 -08:00
0.f, 0.f, 0.f, 1.f);
return PlusOneZ * mat2;
}
case boo::IGraphicsDataFactory::Platform::Vulkan:
{
zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml,
0.f, 2.f / tmb, 0.f, -tpb / tmb,
0.f, 0.f, -2.f / fmn, -fpn / fmn,
2017-01-28 19:58:16 -08:00
0.f, 0.f, 0.f, 1.f);
return VulkanCorrect * mat2;
2017-01-28 19:58:16 -08:00
}
}
2016-04-02 22:25:34 -07:00
}
2016-02-13 19:42:36 -08:00
}
const CGraphics::CProjectionState& CGraphics::GetProjectionState()
{
return g_Proj;
}
void CGraphics::SetProjectionState(const CGraphics::CProjectionState& proj)
{
g_Proj = proj;
FlushProjection();
}
2016-09-10 18:25:59 -07:00
void CGraphics::SetPerspective(float fovy, float aspect, float znear, float zfar)
2016-02-13 19:42:36 -08:00
{
g_ProjAspect = aspect;
2016-03-04 15:04:53 -08:00
float tfov = std::tan(zeus::degToRad(fovy * 0.5f));
2016-02-13 19:42:36 -08:00
g_Proj.x0_persp = true;
2016-09-10 18:25:59 -07:00
g_Proj.x14_near = znear;
g_Proj.x18_far = zfar;
g_Proj.xc_top = znear * tfov;
2016-02-13 19:42:36 -08:00
g_Proj.x10_bottom = -g_Proj.xc_top;
2016-09-10 18:25:59 -07:00
g_Proj.x8_right = aspect * znear * tfov;
2016-02-13 19:42:36 -08:00
g_Proj.x4_left = -g_Proj.x8_right;
2016-03-15 20:37:51 -07:00
FlushProjection();
}
void CGraphics::SetOrtho(float left, float right,
float top, float bottom,
float znear, float zfar)
{
g_Proj.x0_persp = false;
g_Proj.x4_left = left;
g_Proj.x8_right = right;
g_Proj.xc_top = top;
g_Proj.x10_bottom = bottom;
g_Proj.x14_near = znear;
g_Proj.x18_far = zfar;
FlushProjection();
2016-02-13 19:42:36 -08:00
}
void CGraphics::FlushProjection()
{
if (g_Proj.x0_persp)
{
// Convert and load persp
}
else
{
// Convert and load ortho
}
}
2016-03-04 15:04:53 -08:00
zeus::CVector2i CGraphics::ProjectPoint(const zeus::CVector3f& point)
2016-02-13 19:42:36 -08:00
{
2016-04-02 22:25:34 -07:00
zeus::CVector3f projPt = GetPerspectiveProjectionMatrix(false).multiplyOneOverW(point);
2018-12-07 17:49:15 -08:00
return {int(projPt.x() * g_Viewport.x10_halfWidth) + int(g_Viewport.x10_halfWidth),
int(g_Viewport.xc_height) - (int(projPt.y() * g_Viewport.x14_halfHeight) +
2017-03-03 20:58:33 -08:00
int(g_Viewport.x14_halfHeight))};
2016-02-13 19:42:36 -08:00
}
2016-03-04 15:04:53 -08:00
SClipScreenRect CGraphics::ClipScreenRectFromMS(const zeus::CVector3f& p1,
const zeus::CVector3f& p2)
2016-02-13 19:42:36 -08:00
{
2016-03-04 15:04:53 -08:00
zeus::CVector3f xf1 = g_GXModelView * p1;
zeus::CVector3f xf2 = g_GXModelView * p2;
return ClipScreenRectFromVS(xf1, xf2);
2016-02-13 19:42:36 -08:00
}
2016-03-04 15:04:53 -08:00
SClipScreenRect CGraphics::ClipScreenRectFromVS(const zeus::CVector3f& p1,
const zeus::CVector3f& p2)
2016-02-13 19:42:36 -08:00
{
2018-12-07 17:49:15 -08:00
if (p1.x() == 0.f && p1.y() == 0.f && p1.z() == 0.f)
2016-02-13 19:42:36 -08:00
return {};
2018-12-07 17:49:15 -08:00
if (p2.x() == 0.f && p2.y() == 0.f && p2.z() == 0.f)
2016-02-13 19:42:36 -08:00
return {};
2018-12-07 17:49:15 -08:00
if (-p1.z() < GetProjectionState().x14_near || -p2.z() < GetProjectionState().x14_near)
2016-02-13 19:42:36 -08:00
return {};
2018-12-07 17:49:15 -08:00
if (-p1.z() > GetProjectionState().x18_far || -p2.z() > GetProjectionState().x18_far)
2016-02-13 19:42:36 -08:00
return {};
2016-03-04 15:04:53 -08:00
zeus::CVector2i sp1 = ProjectPoint(p1);
zeus::CVector2i sp2 = ProjectPoint(p2);
2016-02-14 20:00:26 -08:00
int minX = std::min(sp2.x, sp1.x);
2016-02-13 19:42:36 -08:00
int minX2 = minX & 0xfffffffe;
2016-02-14 20:00:26 -08:00
int minY = std::min(sp2.y, sp1.y);
2016-02-13 19:42:36 -08:00
int minY2 = minY & 0xfffffffe;
if (minX2 >= g_Viewport.x8_width)
2016-02-13 19:42:36 -08:00
return {};
2016-02-14 20:00:26 -08:00
int maxX = abs(sp1.x - sp2.x) + minX;
int maxX2 = (maxX + 2) & 0xfffffffe;
if (maxX2 <= 0 /* ViewportX origin */)
2016-02-13 19:42:36 -08:00
return {};
//int finalMinX = std::max(minX, 0 /* ViewportX origin */);
//int finalMaxX = std::min(maxX, int(g_Viewport.x8_width));
2016-02-13 19:42:36 -08:00
if (minY2 >= g_Viewport.xc_height)
2016-02-13 19:42:36 -08:00
return {};
2016-02-14 20:00:26 -08:00
int maxY = abs(sp1.y - sp2.y) + minY;
int maxY2 = (maxY + 2) & 0xfffffffe;
if (maxY2 <= 0 /* ViewportY origin */)
2016-02-13 19:42:36 -08:00
return {};
//int finalMinY = std::max(minY, 0 /* ViewportY origin */);
//int finalMaxY = std::min(maxY, int(g_Viewport.xc_height));
2016-02-13 19:42:36 -08:00
2016-02-14 20:00:26 -08:00
int width = maxX2 - minX2;
int height = maxY2 - minY2;
return {true, minX2, minY2, width, height, width,
minX2 / float(g_Viewport.x8_width), maxX2 / float(g_Viewport.x8_width),
1.f - maxY2 / float(g_Viewport.xc_height), 1.f - minY2 / float(g_Viewport.xc_height)};
2016-02-13 19:42:36 -08:00
2016-02-12 16:57:09 -08:00
}
2016-03-04 15:04:53 -08:00
zeus::CVector3f CGraphics::ProjectModelPointToViewportSpace(const zeus::CVector3f& point)
{
2016-03-04 15:04:53 -08:00
zeus::CVector3f pt = g_GXModelView * point;
return GetPerspectiveProjectionMatrix(true).multiplyOneOverW(pt);
}
zeus::CVector3f CGraphics::ProjectModelPointToViewportSpace(const zeus::CVector3f& point, float& wOut)
{
zeus::CVector3f pt = g_GXModelView * point;
return GetPerspectiveProjectionMatrix(true).multiplyOneOverW(pt, wOut);
}
2016-03-04 15:04:53 -08:00
void CGraphics::SetViewportResolution(const zeus::CVector2i& res)
{
g_Viewport.x8_width = res.x;
g_Viewport.xc_height = res.y;
g_CroppedViewport = SClipScreenRect();
g_CroppedViewport.xc_width = res.x;
g_CroppedViewport.x10_height = res.y;
g_Viewport.x10_halfWidth = res.x / 2.f;
g_Viewport.x14_halfHeight = res.y / 2.f;
2017-01-29 20:16:20 -08:00
if (g_GuiSys)
g_GuiSys->OnViewportResize();
}
static boo::SWindowRect CachedVP;
2017-03-04 23:57:12 -08:00
zeus::CVector2f CGraphics::g_CachedDepthRange = {0.f, 1.f};
void CGraphics::SetViewport(int leftOff, int bottomOff, int width, int height)
{
CachedVP.location[0] = leftOff;
CachedVP.location[1] = bottomOff;
CachedVP.size[0] = width;
CachedVP.size[1] = height;
2017-03-04 23:57:12 -08:00
g_BooMainCommandQueue->setViewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]);
}
void CGraphics::SetScissor(int leftOff, int bottomOff, int width, int height)
{
boo::SWindowRect rect(leftOff, bottomOff, width, height);
g_BooMainCommandQueue->setScissor(rect);
}
void CGraphics::SetDepthRange(float znear, float zfar)
{
2017-03-04 23:57:12 -08:00
g_CachedDepthRange[0] = znear;
g_CachedDepthRange[1] = zfar;
g_BooMainCommandQueue->setViewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]);
}
2016-03-30 23:18:56 -07:00
CTimeProvider* CGraphics::g_ExternalTimeProvider = nullptr;
2016-04-23 03:51:53 -07:00
float CGraphics::g_DefaultSeconds = 0.f;
u32 CGraphics::g_RenderTimings = 0;
2016-03-30 23:18:56 -07:00
float CGraphics::GetSecondsMod900()
{
if (!g_ExternalTimeProvider)
return g_DefaultSeconds;
return g_ExternalTimeProvider->x0_currentTime;
}
2016-04-23 03:51:53 -07:00
void CGraphics::TickRenderTimings()
{
g_RenderTimings = (g_RenderTimings + 1) % u32(900*60);
g_DefaultSeconds = g_RenderTimings / 60.f;
2016-04-23 03:51:53 -07:00
}
2016-04-02 22:25:34 -07:00
boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null;
2016-02-14 20:00:26 -08:00
boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr;
boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr;
boo::ObjToken<boo::ITextureR> CGraphics::g_SpareTexture;
const boo::SystemChar* CGraphics::g_BooPlatformName = nullptr;
2016-02-14 20:00:26 -08:00
2016-02-11 18:36:34 -08:00
}