2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-13 20:06:10 +00:00

Start wiring up wgpu+winit

This commit is contained in:
2022-01-31 19:06:54 -05:00
parent 5491fd75cf
commit e48435f11e
209 changed files with 24234 additions and 8085 deletions

View File

@@ -37,7 +37,7 @@ u32 CGraphics::g_FrameCounter = 0;
u32 CGraphics::g_Framerate = 0;
u32 CGraphics::g_FramesPast = 0;
frame_clock::time_point CGraphics::g_FrameStartTime = frame_clock::now();
bool CGraphics::g_commitAsLazy = false;
//bool CGraphics::g_commitAsLazy = false;
const std::array<zeus::CMatrix3f, 6> CGraphics::skCubeBasisMats{{
/* Right */
@@ -127,7 +127,7 @@ void CGraphics::EndScene() {
CTextSupportShader::UpdateBuffers();
/* Same with line renderer */
CLineRenderer::UpdateBuffers();
// CLineRenderer::UpdateBuffers();
++g_FrameCounter;
@@ -156,6 +156,7 @@ void CGraphics::SetViewMatrix() {
g_GXModelViewInvXpose.origin.zeroOut();
g_GXModelViewInvXpose.basis.transpose();
/* Load normal matrix */
aurora::shaders::update_model_view(g_GXModelView.toMatrix4f(), g_GXModelViewInvXpose.toMatrix4f());
}
void CGraphics::SetModelMatrix(const zeus::CTransform& xf) {
@@ -192,24 +193,24 @@ zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect,
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) {
case boo::IGraphicsDataFactory::Platform::OpenGL:
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:
case boo::IGraphicsDataFactory::Platform::Metal: {
// switch (g_BooPlatform) {
// case boo::IGraphicsDataFactory::Platform::OpenGL:
// 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:
// case boo::IGraphicsDataFactory::Platform::Metal: {
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;
}
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,
0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f);
return VulkanCorrect * mat2;
}
}
// }
// 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,
// 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f);
// return VulkanCorrect * mat2;
// }
// }
}
zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) {
@@ -227,27 +228,27 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) {
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: {
// 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;
}
}
// }
// 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;
// }
// }
} else {
float rml = g_Proj.x8_right - g_Proj.x4_left;
float rpl = g_Proj.x8_right + g_Proj.x4_left;
@@ -261,24 +262,24 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) {
-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: {
// 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, 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, 0.f, 0.f, 0.f, 1.f);
return VulkanCorrect * 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, 0.f, 0.f, 0.f, 1.f);
// return VulkanCorrect * mat2;
// }
// }
}
}
@@ -322,6 +323,7 @@ void CGraphics::FlushProjection() {
} else {
// Convert and load ortho
}
aurora::shaders::update_projection(GetPerspectiveProjectionMatrix(true));
}
zeus::CVector2i CGraphics::ProjectPoint(const zeus::CVector3f& point) {
@@ -413,26 +415,25 @@ void CGraphics::SetViewportResolution(const zeus::CVector2i& res) {
g_GuiSys->OnViewportResize();
}
static boo::SWindowRect CachedVP;
static zeus::CRectangle CachedVP;
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.position[0] = leftOff;
CachedVP.position[1] = bottomOff;
CachedVP.size[0] = width;
CachedVP.size[1] = height;
g_BooMainCommandQueue->setViewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]);
aurora::shaders::set_viewport(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);
aurora::shaders::set_scissor(leftOff, bottomOff, width, height);
}
void CGraphics::SetDepthRange(float znear, float zfar) {
g_CachedDepthRange[0] = znear;
g_CachedDepthRange[1] = zfar;
g_BooMainCommandQueue->setViewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]);
aurora::shaders::set_viewport(CachedVP, g_CachedDepthRange[0], g_CachedDepthRange[1]);
}
CTimeProvider* CGraphics::g_ExternalTimeProvider = nullptr;
@@ -463,11 +464,11 @@ void CGraphics::UpdateFPSCounter() {
}
}
boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null;
boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr;
boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr;
boo::ObjToken<boo::ITextureR> CGraphics::g_SpareTexture;
const char* CGraphics::g_BooPlatformName = nullptr;
//boo::IGraphicsDataFactory::Platform CGraphics::g_BooPlatform = boo::IGraphicsDataFactory::Platform::Null;
//boo::IGraphicsDataFactory* CGraphics::g_BooFactory = nullptr;
//boo::IGraphicsCommandQueue* CGraphics::g_BooMainCommandQueue = nullptr;
//boo::ObjToken<boo::ITextureR> CGraphics::g_SpareTexture;
//const char* CGraphics::g_BooPlatformName = nullptr;
const CTevCombiners::CTevPass CGraphics::sTevPass805a564c({GX::TevColorArg::CC_ZERO, GX::TevColorArg::CC_ZERO,
GX::TevColorArg::CC_ZERO, GX::TevColorArg::CC_RASC},