From 43f6d1f3cdb33276b2e4c60de91fb8f3d33e5ec0 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 8 Apr 2023 23:03:09 -0500 Subject: [PATCH 01/22] fix(gx): set remaining values in ortho proj matrix --- src/gx/Transform.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gx/Transform.cpp b/src/gx/Transform.cpp index ca94049..6ee7b3e 100644 --- a/src/gx/Transform.cpp +++ b/src/gx/Transform.cpp @@ -141,9 +141,9 @@ void GxuXformCreateOrtho(float minX, float maxX, float minY, float maxY, float m dst.c2 = 2.0 / v12; dst.c3 = 0.0f; - dst.d0 = 0.0f; - dst.d1 = 0.0f; - dst.d2 = 0.0f; + dst.d0 = -((minX + maxX) / v10); + dst.d1 = -((minY + maxY) / v11); + dst.d2 = -((minZ + maxZ) / v12); dst.d3 = 1.0f; } From 134d85bce6bc8e36beacae1628defccf0ff6eb1f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 8 Apr 2023 23:10:53 -0500 Subject: [PATCH 02/22] feat(console): add background drawing for console --- src/console/Screen.cpp | 60 +++++++++++++++++++++++++++++++++++++++++- src/console/Types.hpp | 17 ++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/console/Types.hpp diff --git a/src/console/Screen.cpp b/src/console/Screen.cpp index dd93622..31fe6aa 100644 --- a/src/console/Screen.cpp +++ b/src/console/Screen.cpp @@ -1,7 +1,12 @@ #include "console/Screen.hpp" +#include "console/Types.hpp" +#include "gx/Buffer.hpp" #include "gx/Coordinate.hpp" +#include "gx/Device.hpp" +#include "gx/Draw.hpp" #include "gx/Font.hpp" #include "gx/Gx.hpp" +#include "gx/RenderState.hpp" #include "gx/Screen.hpp" #include #include @@ -11,15 +16,68 @@ static float s_caretpixwidth; static float s_caretpixheight; static float s_fontHeight = 0.02f; static char s_fontName[STORM_MAX_PATH]; +static int32_t s_highlightState; static HLAYER s_layerBackground; static HLAYER s_layerText; static RECTF s_rect = { 0.0f, 1.0f, 1.0f, 1.0f }; static HTEXTFONT s_textFont; -void PaintBackground(void* param, const RECTF* rect, const RECTF* visible, float elapsedSec) { +static CImVector s_colorArray[] = { + { 0xFF, 0xFF, 0xFF, 0xFF }, // DEFAULT_COLOR + { 0xFF, 0xFF, 0xFF, 0xFF }, // INPUT_COLOR + { 0x80, 0x80, 0x80, 0xFF }, // ECHO_COLOR + { 0x00, 0x00, 0xFF, 0xFF }, // ERROR_COLOR + { 0x00, 0xFF, 0xFF, 0xFF }, // WARNING_COLOR + { 0xFF, 0xFF, 0xFF, 0xFF }, // GLOBAL_COLOR + { 0xFF, 0xFF, 0xFF, 0xFF }, // ADMIN_COLOR + { 0xFF, 0xFF, 0xFF, 0x80 }, // HIGHLIGHT_COLOR + { 0x00, 0x00, 0x00, 0x80 }, // BACKGROUND_COLOR +}; + +void DrawBackground() { + uint16_t indices[] = { + 0, 1, 2, 3 + }; + + C3Vector position[] = { + { s_rect.left, s_rect.bottom, 0.0f }, + { s_rect.right, s_rect.bottom, 0.0f }, + { s_rect.left, s_rect.top, 0.0f }, + { s_rect.right, s_rect.top, 0.0f } + }; + + GxRsPush(); + + GxRsSet(GxRs_Lighting, 0); + GxRsSet(GxRs_Fog, 0); + GxRsSet(GxRs_DepthTest, 0); + GxRsSet(GxRs_DepthWrite, 0); + GxRsSet(GxRs_Culling, 0); + GxRsSet(GxRs_PolygonOffset, 0.0f); + GxRsSet(GxRs_BlendingMode, GxBlend_Alpha); + GxRsSet(GxRs_AlphaRef, CGxDevice::s_alphaRef[GxBlend_Alpha]); + + GxPrimLockVertexPtrs(4, position, sizeof(C3Vector), nullptr, 0, &s_colorArray[BACKGROUND_COLOR], 0, nullptr, 0, nullptr, 0, nullptr, 0); + GxDrawLockedElements(GxPrim_TriangleStrip, 4, indices); + GxPrimUnlockVertexPtrs(); + + GxRsPop(); +} + +void DrawHighLight() { // TODO } +void PaintBackground(void* param, const RECTF* rect, const RECTF* visible, float elapsedSec) { + if (s_rect.bottom < 1.0f) { + DrawBackground(); + + if (s_highlightState) { + DrawHighLight(); + } + } +} + void PaintText(void* param, const RECTF* rect, const RECTF* visible, float elapsedSec) { // TODO } diff --git a/src/console/Types.hpp b/src/console/Types.hpp new file mode 100644 index 0000000..0099be2 --- /dev/null +++ b/src/console/Types.hpp @@ -0,0 +1,17 @@ +#ifndef CONSOLE_TYPES_HPP +#define CONSOLE_TYPES_HPP + +enum COLOR_T { + DEFAULT_COLOR, + INPUT_COLOR, + ECHO_COLOR, + ERROR_COLOR, + WARNING_COLOR, + GLOBAL_COLOR, + ADMIN_COLOR, + HIGHLIGHT_COLOR, + BACKGROUND_COLOR, + NUM_COLORTYPES, +}; + +#endif From cfd7aff5360889bb12b68e8238761d5ed3390834 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sun, 9 Apr 2023 12:58:43 -0500 Subject: [PATCH 03/22] fix(console): correct alpha value for console background --- src/console/Screen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/console/Screen.cpp b/src/console/Screen.cpp index 31fe6aa..caacd49 100644 --- a/src/console/Screen.cpp +++ b/src/console/Screen.cpp @@ -31,7 +31,7 @@ static CImVector s_colorArray[] = { { 0xFF, 0xFF, 0xFF, 0xFF }, // GLOBAL_COLOR { 0xFF, 0xFF, 0xFF, 0xFF }, // ADMIN_COLOR { 0xFF, 0xFF, 0xFF, 0x80 }, // HIGHLIGHT_COLOR - { 0x00, 0x00, 0x00, 0x80 }, // BACKGROUND_COLOR + { 0x00, 0x00, 0x00, 0xC0 }, // BACKGROUND_COLOR }; void DrawBackground() { From ecf0c43e70c54a9ccd0c98d0f15600eb8856818f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sun, 9 Apr 2023 22:40:32 -0500 Subject: [PATCH 04/22] feat(console): register event handlers for console --- src/console/Handlers.cpp | 58 ++++++++++++++++++++++++++++++++++++++++ src/console/Handlers.hpp | 6 +++++ src/console/Screen.cpp | 5 +--- 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/console/Handlers.cpp create mode 100644 src/console/Handlers.hpp diff --git a/src/console/Handlers.cpp b/src/console/Handlers.cpp new file mode 100644 index 0000000..4f5a3bc --- /dev/null +++ b/src/console/Handlers.cpp @@ -0,0 +1,58 @@ +#include "console/Handlers.hpp" +#include "event/Event.hpp" +#include + +namespace { + +int32_t OnChar(const EVENT_DATA_CHAR* data, void* param) { + // TODO + return 1; +} + +int32_t OnIdle(const EVENT_DATA_IDLE* data, void* param) { + // TODO + return 1; +} + +int32_t OnKeyDown(const EVENT_DATA_KEY* data, void* param) { + // TODO + return 1; +} + +int32_t OnKeyDownRepeat(const EVENT_DATA_KEY* data, void* param) { + // TODO + return 1; +} + +int32_t OnKeyUp(const EVENT_DATA_KEY* data, void* param) { + // TODO + return 1; +} + +int32_t OnMouseDown(const EVENT_DATA_MOUSE* data, void* param) { + // TODO + return 1; +} + +int32_t OnMouseMove(const EVENT_DATA_MOUSE* data, void* param) { + // TODO + return 1; +} + +int32_t OnMouseUp(const EVENT_DATA_MOUSE* data, void* param) { + // TODO + return 1; +} + +} + +void RegisterHandlers() { + EventRegisterEx(EVENT_ID_CHAR, reinterpret_cast(OnChar), nullptr, 7.0f); + EventRegisterEx(EVENT_ID_IDLE, reinterpret_cast(OnIdle), nullptr, 7.0f); + EventRegisterEx(EVENT_ID_KEYDOWN, reinterpret_cast(OnKeyDown), nullptr, 7.0f); + EventRegisterEx(EVENT_ID_KEYUP, reinterpret_cast(OnKeyUp), nullptr, 7.0f); + EventRegisterEx(EVENT_ID_KEYDOWN_REPEATING, reinterpret_cast(OnKeyDownRepeat), nullptr, 7.0f); + EventRegisterEx(EVENT_ID_MOUSEDOWN, reinterpret_cast(OnMouseDown), nullptr, 7.0f); + EventRegisterEx(EVENT_ID_MOUSEUP, reinterpret_cast(OnMouseUp), nullptr, 7.0f); + EventRegisterEx(EVENT_ID_MOUSEMOVE, reinterpret_cast(OnMouseMove), nullptr, 7.0f); +} diff --git a/src/console/Handlers.hpp b/src/console/Handlers.hpp new file mode 100644 index 0000000..092cec4 --- /dev/null +++ b/src/console/Handlers.hpp @@ -0,0 +1,6 @@ +#ifndef CONSOLE_HANDLERS_HPP +#define CONSOLE_HANDLERS_HPP + +void RegisterHandlers(); + +#endif diff --git a/src/console/Screen.cpp b/src/console/Screen.cpp index caacd49..2e2844c 100644 --- a/src/console/Screen.cpp +++ b/src/console/Screen.cpp @@ -1,4 +1,5 @@ #include "console/Screen.hpp" +#include "console/Handlers.hpp" #include "console/Types.hpp" #include "gx/Buffer.hpp" #include "gx/Coordinate.hpp" @@ -82,10 +83,6 @@ void PaintText(void* param, const RECTF* rect, const RECTF* visible, float elaps // TODO } -void RegisterHandlers() { - // TODO -} - void ConsoleScreenInitialize(const char* title) { CRect windowSize; GxCapsWindowSize(windowSize); From 30964bf827839445c32c2d53c126e34b354dd6d1 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sun, 9 Apr 2023 22:40:17 -0500 Subject: [PATCH 05/22] fix(gx): walk dirty states backward when syncing --- src/gx/CGxDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gx/CGxDevice.cpp b/src/gx/CGxDevice.cpp index 1a354b7..d96376e 100644 --- a/src/gx/CGxDevice.cpp +++ b/src/gx/CGxDevice.cpp @@ -432,7 +432,7 @@ void CGxDevice::IRsSync(int32_t force) { this->IRsForceUpdate(); } - for (int32_t i = 0; i < this->m_dirtyStates.Count(); i++) { + for (int32_t i = this->m_dirtyStates.Count() - 1; i >= 0; i--) { auto ds = this->m_dirtyStates[i]; auto rs = &this->m_appRenderStates[ds]; auto hs = &this->m_hwRenderStates[ds]; From dfb7fb02700492ac4a3ea612b345796f0186bf3b Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 11 Apr 2023 00:23:06 -0500 Subject: [PATCH 06/22] feat(gx): add FFP support for vertex arrays in GLL --- src/gx/gll/GLVertexArray.cpp | 127 +++++++++++++++++++++++++++++++++-- 1 file changed, 121 insertions(+), 6 deletions(-) diff --git a/src/gx/gll/GLVertexArray.cpp b/src/gx/gll/GLVertexArray.cpp index e4cc825..ba721c2 100644 --- a/src/gx/gll/GLVertexArray.cpp +++ b/src/gx/gll/GLVertexArray.cpp @@ -124,7 +124,7 @@ void GLVertexArray::ApplyVertexFormat(GLDevice* device) { auto vertexBuffer = this->GetProperties().m_VertexBuffer[attrib.stream]; - if (useVertexShader || attrib.slot - 1 > 1) { + if (useVertexShader || static_cast(attrib.slot - 1) > 1) { if (this->m_GLStates.buffers[0] != vertexBuffer->m_BufferID) { glBindBuffer(vertexBuffer->m_Type, vertexBuffer->m_BufferID); this->m_GLStates.buffers[0] = vertexBuffer->m_BufferID; @@ -147,38 +147,153 @@ void GLVertexArray::ApplyVertexFormat(GLDevice* device) { reinterpret_cast(offset) ); } else { - // TODO + switch (attrib.slot) { + case 0: { + glVertexPointer( + k_VertexTypeInfo[attrib.type].m_Size, + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + + case 3: { + glNormalPointer( + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + + case 4: { + glColorPointer( + k_VertexTypeInfo[attrib.type].m_Size, + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + + case 5: { + glSecondaryColorPointer( + k_VertexTypeInfo[attrib.type].m_Size, + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: { + auto tmu = attrib.slot - 6; + auto texCoordIndex = device->m_States.fixedFunc.texCoordIndex[tmu]; + glClientActiveTextureARB(GL_TEXTURE0 + texCoordIndex); + glTexCoordPointer( + k_VertexTypeInfo[attrib.type].m_Size, + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + } } } } for (int32_t s = 0; s < 16; s++) { bool* prevAttribEnable; + GLenum glArray; if (useVertexShader) { prevAttribEnable = &this->m_GLStates.vertexAttribs[s].enable; } else { - // TODO + switch (s) { + case 0: { + prevAttribEnable = &this->m_GLStates.position.enable; + glArray = GL_VERTEX_ARRAY; + + break; + } + + case 3: { + prevAttribEnable = &this->m_GLStates.normal.enable; + glArray = GL_NORMAL_ARRAY; + + break; + } + + case 4: { + prevAttribEnable = &this->m_GLStates.color0.enable; + glArray = GL_COLOR_ARRAY; + + break; + } + + case 5: { + prevAttribEnable = &this->m_GLStates.color1.enable; + glArray = GL_SECONDARY_COLOR_ARRAY; + + break; + } + + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: { + auto tmu = s - 6; + auto texCoordIndex = device->m_States.fixedFunc.texCoordIndex[tmu]; + prevAttribEnable = &this->m_GLStates.texCoord[texCoordIndex].enable; + glArray = GL_TEXTURE_COORD_ARRAY; + + glClientActiveTextureARB(GL_TEXTURE0 + texCoordIndex); + + break; + } + } } if (*prevAttribEnable != attribEnable[s]) { if (attribEnable[s]) { if (useVertexShader) { - glEnableVertexAttribArrayARB(s); + glEnableVertexAttribArrayARB(s); } else { - // TODO + glEnableClientState(glArray); } } else { if (useVertexShader) { glDisableVertexAttribArrayARB(s); } else { - // TODO + glDisableClientState(glArray); } } *prevAttribEnable = attribEnable[s]; } } + + if (!useVertexShader) { + // TODO device->SetColorMaterial(this->m_GLStates.color0.enable); + } } GLVertexArray::Properties& GLVertexArray::GetProperties() { From eddc6f7f4a63c02839e3f51160978179713b6bca Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 11 Apr 2023 00:24:59 -0500 Subject: [PATCH 07/22] fix(gx): correct off-by-one error when popping render states --- src/gx/CGxDevice.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gx/CGxDevice.cpp b/src/gx/CGxDevice.cpp index d96376e..31b30b6 100644 --- a/src/gx/CGxDevice.cpp +++ b/src/gx/CGxDevice.cpp @@ -734,8 +734,11 @@ void CGxDevice::RsPop() { auto topOfStack = this->m_stackOffsets[this->m_stackOffsets.Count() - 1]; if (this->m_pushedStates.Count() > topOfStack) { - for (int32_t i = this->m_pushedStates.Count() - 1; i > topOfStack; i--) { - auto ps = &this->m_pushedStates[i]; + auto bottomOfStack = this->m_pushedStates.Count() - 1; + auto stackSize = this->m_pushedStates.Count() - topOfStack; + + for (uint32_t stackOffset = 0; stackOffset < stackSize; stackOffset++) { + auto ps = &this->m_pushedStates[bottomOfStack - stackOffset]; auto rs = &this->m_appRenderStates[ps->m_which]; if (!rs->m_dirty) { From eb706077505c73b569a794d02c58b38515d9c3ef Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 14 Apr 2023 07:45:19 -0500 Subject: [PATCH 08/22] fix(gx): only change vertex array FFP state for used attrib slots --- src/gx/gll/GLVertexArray.cpp | 51 ++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/gx/gll/GLVertexArray.cpp b/src/gx/gll/GLVertexArray.cpp index ba721c2..d3af1b0 100644 --- a/src/gx/gll/GLVertexArray.cpp +++ b/src/gx/gll/GLVertexArray.cpp @@ -217,12 +217,25 @@ void GLVertexArray::ApplyVertexFormat(GLDevice* device) { } for (int32_t s = 0; s < 16; s++) { - bool* prevAttribEnable; - GLenum glArray; - + // Shader if (useVertexShader) { - prevAttribEnable = &this->m_GLStates.vertexAttribs[s].enable; + auto prevAttribEnable = &this->m_GLStates.vertexAttribs[s].enable; + + if (*prevAttribEnable != attribEnable[s]) { + if (attribEnable[s]) { + glEnableVertexAttribArrayARB(s); + } else { + glDisableVertexAttribArrayARB(s); + } + } + + *prevAttribEnable = attribEnable[s]; + + // FFP } else { + bool* prevAttribEnable = nullptr; + GLenum glArray = GL_NONE; + switch (s) { case 0: { prevAttribEnable = &this->m_GLStates.position.enable; @@ -262,6 +275,7 @@ void GLVertexArray::ApplyVertexFormat(GLDevice* device) { case 13: { auto tmu = s - 6; auto texCoordIndex = device->m_States.fixedFunc.texCoordIndex[tmu]; + prevAttribEnable = &this->m_GLStates.texCoord[texCoordIndex].enable; glArray = GL_TEXTURE_COORD_ARRAY; @@ -269,25 +283,22 @@ void GLVertexArray::ApplyVertexFormat(GLDevice* device) { break; } - } - } - if (*prevAttribEnable != attribEnable[s]) { - if (attribEnable[s]) { - if (useVertexShader) { - glEnableVertexAttribArrayARB(s); - } else { - glEnableClientState(glArray); - } - } else { - if (useVertexShader) { - glDisableVertexAttribArrayARB(s); - } else { - glDisableClientState(glArray); - } + default: + break; } - *prevAttribEnable = attribEnable[s]; + if (prevAttribEnable) { + if (*prevAttribEnable != attribEnable[s]) { + if (attribEnable[s]) { + glEnableClientState(glArray); + } else { + glDisableClientState(glArray); + } + } + + *prevAttribEnable = attribEnable[s]; + } } } From 317d94cd1a21d5e713431d6d59fea6d495ae1ce8 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 14 Apr 2023 08:02:40 -0500 Subject: [PATCH 09/22] feat(gx): handle projection and view matrices in GLL backend --- src/gx/gll/GLDevice.cpp | 164 +++++++++++++++++++++++++++++++++++++--- src/gx/gll/GLDevice.h | 1 + src/gx/gll/GLTypes.cpp | 53 +++++++++++++ src/gx/gll/GLTypes.h | 5 ++ 4 files changed, 214 insertions(+), 9 deletions(-) diff --git a/src/gx/gll/GLDevice.cpp b/src/gx/gll/GLDevice.cpp index 3a74e0c..8489cc4 100644 --- a/src/gx/gll/GLDevice.cpp +++ b/src/gx/gll/GLDevice.cpp @@ -628,8 +628,59 @@ void GLDevice::ApplyGLStates(const GLStates& states, bool force) { { glMatrixMode(GL_PROJECTION); - // TODO - // - some interesting logic to manipulate the projection matrix before loading + GLTransform projection = { + true, + { + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, + }, + true + }; + + if (!states.fixedFunc.transforms.projection.isIdentity) { + projection.isIdentity = false; + + memcpy(projection.m, states.fixedFunc.transforms.projection.m, sizeof(projection.m)); + projection.isDirty = true; + } + + if (projection.isIdentity) { + projection.SetIdentity(); + } + + projection.a1 *= -1.0f; + projection.b1 *= -1.0f; + projection.c1 *= -1.0f; + projection.d1 *= -1.0f; + + auto isIdentity = projection.a0 == 1.0f + && projection.a1 == 0.0f + && projection.a2 == 0.0f + && projection.a3 == 0.0f + && projection.b0 == 0.0f + && projection.b1 == 1.0f + && projection.b2 == 0.0f + && projection.b3 == 0.0f + && projection.c0 == 0.0f + && projection.c1 == 0.0f + && projection.c2 == 1.0f + && projection.c3 == 0.0f + && projection.d0 == 0.0f + && projection.d1 == 0.0f + && projection.d2 == 0.0f + && projection.d3 == 1.0f; + + projection.isDirty = true; + + if (isIdentity) { + glLoadIdentity(); + } else { + glLoadMatrixf(projection.m); + } + + projection.isDirty = false; } glMatrixMode(states.fixedFunc.transforms.matrixMode); @@ -892,7 +943,53 @@ void GLDevice::ApplyShaderConstants() { } void GLDevice::ApplyTransforms() { - // TODO + this->SetModelView(GL_MODELVIEW); + + auto& projection = this->m_States.fixedFunc.transforms.projection; + if (projection.isDirty) { + if (projection.isIdentity) { + projection.SetIdentity(); + } + + projection.a1 *= -1.0f; + projection.b1 *= -1.0f; + projection.c1 *= -1.0f; + projection.d1 *= -1.0f; + + projection.isIdentity = projection.a0 == 1.0f + && projection.a1 == 0.0f + && projection.a2 == 0.0f + && projection.a3 == 0.0f + && projection.b0 == 0.0f + && projection.b1 == 1.0f + && projection.b2 == 0.0f + && projection.b3 == 0.0f + && projection.c0 == 0.0f + && projection.c1 == 0.0f + && projection.c2 == 1.0f + && projection.c3 == 0.0f + && projection.d0 == 0.0f + && projection.d1 == 0.0f + && projection.d2 == 0.0f + && projection.d3 == 1.0f; + + projection.isDirty = true; + + if (this->m_States.fixedFunc.transforms.matrixMode != GL_PROJECTION) { + glMatrixMode(GL_PROJECTION); + this->m_States.fixedFunc.transforms.matrixMode = GL_PROJECTION; + } + + if (projection.isIdentity) { + glLoadIdentity(); + } else { + glLoadMatrixf(projection.m); + } + + projection.isDirty = false; + } + + // TODO texture transforms } void GLDevice::BindBuffer(GLBuffer* buffer, GLEnum target) { @@ -2315,6 +2412,57 @@ void GLDevice::SetLightingEnable(bool enable) { } } +void GLDevice::SetModelView(GLEnum transform) { + if (transform == 'VIEW') { + // TODO + return; + } + + if (transform == 'WRLD') { + // TODO + return; + } + + if (transform != GL_MODELVIEW) { + BLIZZARD_ASSERT(false); + } + + auto& world = this->m_States.fixedFunc.transforms.world; + auto& view = this->m_States.fixedFunc.transforms.view; + auto& modelView = this->m_States.fixedFunc.transforms.modelView; + + if (this->m_States.fixedFunc.transforms.modelviewStatus != transform || modelView.isDirty) { + if (world.isIdentity && view.isIdentity) { + modelView.isIdentity = true; + modelView.isDirty = true; + } else if (world.isIdentity) { + modelView = view; + modelView.isIdentity = false; + modelView.isDirty = true; + } else if (view.isIdentity) { + modelView = world; + modelView.isIdentity = false; + modelView.isDirty = true; + } else { + // TODO assign model * view to modelView + BLIZZARD_ASSERT(!"Unimplemented"); + } + + if (this->m_States.fixedFunc.transforms.matrixMode != GL_MODELVIEW) { + glMatrixMode(GL_MODELVIEW); + this->m_States.fixedFunc.transforms.matrixMode = GL_MODELVIEW; + } + + if (modelView.isIdentity) { + glLoadIdentity(); + } else { + glLoadMatrixf(modelView.m); + } + + this->m_States.fixedFunc.transforms.modelviewStatus = transform; + } +} + void GLDevice::SetScissor(bool a2, const GLRect& a3) { // TODO } @@ -2469,15 +2617,13 @@ void GLDevice::SetTransform(GLEnum transform, const float* a3) { BLIZZARD_ASSERT(false); } - // TODO - // int32_t needsUpdate = !(t == a3); // GLTransform::operator==() - // if (needsUpdate) { - // t.Set(a3); - // } + if (*t != a3) { + t->Set(a3); + } if (t->isDirty) { if (transform == 'VIEW' || transform == 'WRLD') { - this->m_States.fixedFunc.transforms.modelView.isDirty = 1; + this->m_States.fixedFunc.transforms.modelView.isDirty = true; } } } diff --git a/src/gx/gll/GLDevice.h b/src/gx/gll/GLDevice.h index df09376..c3f8e98 100644 --- a/src/gx/gll/GLDevice.h +++ b/src/gx/gll/GLDevice.h @@ -172,6 +172,7 @@ class GLDevice { void SetFogParam(GLEnum param, float value); void SetIndexBuffer(GLBuffer*); void SetLightingEnable(bool enable); + void SetModelView(GLEnum view); void SetScissor(bool, const GLRect&); void SetShader(GLShader::ShaderType, GLShader*); void SetShaderConstants(GLShader::ShaderType, uint32_t, const float*, uint32_t); diff --git a/src/gx/gll/GLTypes.cpp b/src/gx/gll/GLTypes.cpp index 6875344..226ae4f 100644 --- a/src/gx/gll/GLTypes.cpp +++ b/src/gx/gll/GLTypes.cpp @@ -1,5 +1,58 @@ #include "gx/gll/GLTypes.h" +#include GLColor4f GLColor4f::ZERO = { 0.0, 0.0, 0.0, 0.0 }; GLColor4f GLColor4f::WHITE = { 1.0, 1.0, 1.0, 1.0 }; GLColor4f GLColor4f::BLACK = { 0.0, 0.0, 0.0, 1.0 }; + +bool GLTransform::operator==(const float m[16]) const { + return this->m[0] == m[0] + && this->m[1] == m[1] + && this->m[2] == m[2] + && this->m[3] == m[3] + && this->m[4] == m[4] + && this->m[5] == m[5] + && this->m[6] == m[6] + && this->m[7] == m[7] + && this->m[8] == m[8] + && this->m[9] == m[9] + && this->m[10] == m[10] + && this->m[11] == m[11] + && this->m[12] == m[12] + && this->m[13] == m[13] + && this->m[14] == m[14] + && this->m[15] == m[15]; +} + +bool GLTransform::operator!=(const float m[16]) const { + return !(*this == m); +} + +void GLTransform::Set(const float m[16]) { + memcpy(this->m, m, sizeof(this->m)); + this->isDirty = true; + this->isIdentity = this->a0 == 1.0f + && this->a1 == 0.0f + && this->a2 == 0.0f + && this->a3 == 0.0f + && this->b0 == 0.0f + && this->b1 == 1.0f + && this->b2 == 0.0f + && this->b3 == 0.0f + && this->c0 == 0.0f + && this->c1 == 0.0f + && this->c2 == 1.0f + && this->c3 == 0.0f + && this->d0 == 0.0f + && this->d1 == 0.0f + && this->d2 == 0.0f + && this->d3 == 1.0f; +} + +void GLTransform::SetIdentity() { + memset(this->m, 0, sizeof(this->m)); + this->a0 = 1.0f; + this->b1 = 1.0f; + this->c2 = 1.0f; + this->d3 = 1.0f; +} diff --git a/src/gx/gll/GLTypes.h b/src/gx/gll/GLTypes.h index 6b01706..9c147fb 100644 --- a/src/gx/gll/GLTypes.h +++ b/src/gx/gll/GLTypes.h @@ -138,6 +138,11 @@ struct GLTransform { }; bool isIdentity; + + bool operator==(const float m[16]) const; + bool operator!=(const float m[16]) const; + void Set(const float m[16]); + void SetIdentity(); }; struct GLStates { From 36fa30eba8531524dd9f9578d2d45b983d0a6ce7 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 09:16:06 -0500 Subject: [PATCH 10/22] feat(gx): add equality operator to CGxStateBom --- src/gx/CGxStateBom.cpp | 34 ++++++++++++++++++++++++++++------ src/gx/CGxStateBom.hpp | 6 ++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/gx/CGxStateBom.cpp b/src/gx/CGxStateBom.cpp index fc9d4cf..0527190 100644 --- a/src/gx/CGxStateBom.cpp +++ b/src/gx/CGxStateBom.cpp @@ -33,20 +33,42 @@ const CGxStateBom& CGxStateBom::operator=(C3Vector& value) { return *this; } -bool CGxStateBom::operator!=(int32_t value) { - return this->m_data.i[0] != value; +bool CGxStateBom::operator==(float value) { + return this->m_data.f[0] == value; } -bool CGxStateBom::operator!=(uint32_t value) { - return this->m_data.i[0] != value; +bool CGxStateBom::operator==(int32_t value) { + return this->m_data.i[0] == value; +} + +bool CGxStateBom::operator==(uint32_t value) { + return this->m_data.u[0] == value; +} + +bool CGxStateBom::operator==(void* value) { + return this->m_data.p == value; +} + +bool CGxStateBom::operator==(C3Vector& value) { + return this->m_data.f[0] == value.x + || this->m_data.f[1] == value.y + || this->m_data.f[2] == value.z; } bool CGxStateBom::operator!=(float value) { - return this->m_data.f[0] != value; + return !(*this == value); +} + +bool CGxStateBom::operator!=(int32_t value) { + return !(*this == value); +} + +bool CGxStateBom::operator!=(uint32_t value) { + return !(*this == value); } bool CGxStateBom::operator!=(void* value) { - return this->m_data.p != value; + return !(*this == value); } bool CGxStateBom::operator!=(C3Vector& value) { diff --git a/src/gx/CGxStateBom.hpp b/src/gx/CGxStateBom.hpp index bff7163..4a3d749 100644 --- a/src/gx/CGxStateBom.hpp +++ b/src/gx/CGxStateBom.hpp @@ -11,6 +11,7 @@ class CGxStateBom { // Member variables union { int32_t i[3]; + uint32_t u[3]; float f[3]; void* p; } m_data; @@ -23,6 +24,11 @@ class CGxStateBom { const CGxStateBom& operator=(uint32_t); const CGxStateBom& operator=(void*); const CGxStateBom& operator=(C3Vector&); + bool operator==(float); + bool operator==(int32_t); + bool operator==(uint32_t); + bool operator==(void*); + bool operator==(C3Vector&); bool operator!=(float); bool operator!=(int32_t); bool operator!=(uint32_t); From 4a1101bd7df1253f9e865a7d3929107b36d72144 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 10:04:29 -0500 Subject: [PATCH 11/22] feat(gx): stub ffp state syncing in d3d backend --- src/gx/d3d/CGxDeviceD3d.cpp | 18 +++++++++++++++++- src/gx/d3d/CGxDeviceD3d.hpp | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/gx/d3d/CGxDeviceD3d.cpp b/src/gx/d3d/CGxDeviceD3d.cpp index d0fb4ed..1a8b1f5 100644 --- a/src/gx/d3d/CGxDeviceD3d.cpp +++ b/src/gx/d3d/CGxDeviceD3d.cpp @@ -1580,7 +1580,11 @@ void CGxDeviceD3d::IStateSync() { this->IShaderConstantsFlush(); this->IRsSync(0); - // TODO ffp if vertex shader is disabled + if (this->m_hwRenderStates[GxRs_VertexShader] == nullptr && this->m_appRenderStates[GxRs_VertexShader].m_value == nullptr) { + this->IStateSyncLights(); + this->IStateSyncMaterial(); + this->IStateSyncXforms(); + } this->IStateSyncEnables(); @@ -1611,6 +1615,14 @@ void CGxDeviceD3d::IStateSyncIndexPtr() { } } +void CGxDeviceD3d::IStateSyncLights() { + // TODO +} + +void CGxDeviceD3d::IStateSyncMaterial() { + // TODO +} + void CGxDeviceD3d::IStateSyncVertexPtrs() { if (this->m_primVertexFormat < GxVertexBufferFormats_Last && this->m_d3dVertexDecl[this->m_primVertexFormat]) { auto d3dVertexDecl = this->m_d3dVertexDecl[this->m_primVertexFormat]; @@ -1691,6 +1703,10 @@ void CGxDeviceD3d::IStateSyncVertexPtrs() { } } +void CGxDeviceD3d::IStateSyncXforms() { + // TODO +} + void CGxDeviceD3d::ITexCreate(CGxTex* texId) { uint32_t width, height, startLevel, endLevel; this->ITexWHDStartEnd(texId, width, height, startLevel, endLevel); diff --git a/src/gx/d3d/CGxDeviceD3d.hpp b/src/gx/d3d/CGxDeviceD3d.hpp index 18437d9..456a36f 100644 --- a/src/gx/d3d/CGxDeviceD3d.hpp +++ b/src/gx/d3d/CGxDeviceD3d.hpp @@ -294,7 +294,10 @@ class CGxDeviceD3d : public CGxDevice { void IStateSync(); void IStateSyncEnables(); void IStateSyncIndexPtr(); + void IStateSyncLights(); + void IStateSyncMaterial(); void IStateSyncVertexPtrs(); + void IStateSyncXforms(); void ITexCreate(CGxTex* texId); void ITexUpload(CGxTex* texId); void IXformSetProjection(const C44Matrix& matrix); From c0e623d02b0c10afd21f22f9f5d6ec697a68b2f7 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 10:32:07 -0500 Subject: [PATCH 12/22] feat(gx): add const getter for top of matrix stack --- src/gx/CGxMatrixStack.cpp | 4 ++++ src/gx/CGxMatrixStack.hpp | 1 + 2 files changed, 5 insertions(+) diff --git a/src/gx/CGxMatrixStack.cpp b/src/gx/CGxMatrixStack.cpp index 804bf1e..d284464 100644 --- a/src/gx/CGxMatrixStack.cpp +++ b/src/gx/CGxMatrixStack.cpp @@ -28,3 +28,7 @@ C44Matrix& CGxMatrixStack::Top() { this->m_flags[this->m_level] &= 0xFFFFFFFE; return this->m_mtx[this->m_level]; } + +const C44Matrix& CGxMatrixStack::TopConst() { + return this->m_mtx[this->m_level]; +} diff --git a/src/gx/CGxMatrixStack.hpp b/src/gx/CGxMatrixStack.hpp index a0eef62..7bb2381 100644 --- a/src/gx/CGxMatrixStack.hpp +++ b/src/gx/CGxMatrixStack.hpp @@ -17,6 +17,7 @@ class CGxMatrixStack { void Pop(void); void Push(void); C44Matrix& Top(void); + const C44Matrix& TopConst(); }; #endif From 5174970b2486971e3191238ced53cf6a274c90a0 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 12:14:33 -0500 Subject: [PATCH 13/22] feat(gx): sync projection and view xforms in d3d backend --- src/gx/d3d/CGxDeviceD3d.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gx/d3d/CGxDeviceD3d.cpp b/src/gx/d3d/CGxDeviceD3d.cpp index 1a8b1f5..99b7f0a 100644 --- a/src/gx/d3d/CGxDeviceD3d.cpp +++ b/src/gx/d3d/CGxDeviceD3d.cpp @@ -1704,7 +1704,19 @@ void CGxDeviceD3d::IStateSyncVertexPtrs() { } void CGxDeviceD3d::IStateSyncXforms() { - // TODO + if (this->m_xforms[GxXform_Projection].m_dirty) { + this->m_d3dDevice->SetTransform(D3DTS_PROJECTION, reinterpret_cast(&this->m_projNative)); + this->m_xforms[GxXform_Projection].m_dirty = 0; + } + + if (this->m_xforms[GxXform_View].m_dirty) { + this->m_d3dDevice->SetTransform(D3DTS_VIEW, reinterpret_cast(&this->m_xforms[GxXform_View].TopConst())); + this->m_xforms[GxXform_View].m_dirty = 0; + } + + // TODO world + + // TODO tex } void CGxDeviceD3d::ITexCreate(CGxTex* texId) { From 37996fa79c30d654002e0c85ff2f154b27d3e5ad Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 12:36:57 -0500 Subject: [PATCH 14/22] feat(gx): set marker when viewport changes --- src/gx/CGxDevice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gx/CGxDevice.cpp b/src/gx/CGxDevice.cpp index 31b30b6..16387a9 100644 --- a/src/gx/CGxDevice.cpp +++ b/src/gx/CGxDevice.cpp @@ -1052,8 +1052,7 @@ void CGxDevice::XformSetViewport(float minX, float maxX, float minY, float maxY, return; } - // TODO - // this->unk4[4] = 1; + this->intF6C = 1; this->m_viewport.x.l = minX; this->m_viewport.x.h = maxX; From d67e13087abb612f76d12482d648b9d623c0f5e4 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 13:56:49 -0500 Subject: [PATCH 15/22] feat(gx): sync viewport in d3d backend --- src/gx/d3d/CGxDeviceD3d.cpp | 30 +++++++++++++++++++++++++++++- src/gx/d3d/CGxDeviceD3d.hpp | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/gx/d3d/CGxDeviceD3d.cpp b/src/gx/d3d/CGxDeviceD3d.cpp index 99b7f0a..58b103e 100644 --- a/src/gx/d3d/CGxDeviceD3d.cpp +++ b/src/gx/d3d/CGxDeviceD3d.cpp @@ -1594,6 +1594,10 @@ void CGxDeviceD3d::IStateSync() { this->IStateSyncIndexPtr(); // TODO + + if (this->intF6C) { + this->IXformSetViewport(); + } } void CGxDeviceD3d::IStateSyncEnables() { @@ -1946,6 +1950,30 @@ void CGxDeviceD3d::IXformSetProjection(const C44Matrix& matrix) { memcpy(&this->m_projNative, &projNative, sizeof(this->m_projNative)); } +void CGxDeviceD3d::IXformSetViewport() { + const auto& gxViewport = this->m_viewport; + auto windowRect = this->DeviceCurWindow(); + + D3DVIEWPORT9 d3dViewport; + + d3dViewport.X = (gxViewport.x.l * windowRect.maxX) + 0.5; + d3dViewport.Y = ((1.0 - gxViewport.y.h) * windowRect.maxY) + 0.5; + + // TODO account for negative X value + + d3dViewport.Width = (gxViewport.x.h * windowRect.maxX) - d3dViewport.X + 0.5; + d3dViewport.Height = ((1.0 - gxViewport.y.l) * windowRect.maxY) - d3dViewport.Y + 0.5; + + d3dViewport.MinZ = gxViewport.z.l; + d3dViewport.MaxZ = gxViewport.z.h; + + // TODO conditionally adjust Y value + + this->m_d3dDevice->SetViewport(&d3dViewport); + + this->intF6C = 0; +} + void CGxDeviceD3d::PoolSizeSet(CGxPool* pool, uint32_t size) { // TODO } @@ -1966,7 +1994,7 @@ void CGxDeviceD3d::SceneClear(uint32_t mask, CImVector color) { } if (this->intF6C) { - // TODO + this->IXformSetViewport(); } D3DCOLOR d3dColor = color.b | (color.g | (color.r << 8) << 8); diff --git a/src/gx/d3d/CGxDeviceD3d.hpp b/src/gx/d3d/CGxDeviceD3d.hpp index 456a36f..9823083 100644 --- a/src/gx/d3d/CGxDeviceD3d.hpp +++ b/src/gx/d3d/CGxDeviceD3d.hpp @@ -301,6 +301,7 @@ class CGxDeviceD3d : public CGxDevice { void ITexCreate(CGxTex* texId); void ITexUpload(CGxTex* texId); void IXformSetProjection(const C44Matrix& matrix); + void IXformSetViewport(); }; #endif From 092ba0f88105bde402b1b9023caf2fe6bdcc2e9e Mon Sep 17 00:00:00 2001 From: Tristan 'Natrist' Cormier Date: Sat, 15 Apr 2023 15:40:07 -0400 Subject: [PATCH 16/22] feat(console): add helpers for console active state --- src/console/Console.cpp | 11 +++++++++++ src/console/Console.hpp | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/console/Console.cpp create mode 100644 src/console/Console.hpp diff --git a/src/console/Console.cpp b/src/console/Console.cpp new file mode 100644 index 0000000..ecd10ce --- /dev/null +++ b/src/console/Console.cpp @@ -0,0 +1,11 @@ +#include "console/Console.hpp" + +static int32_t s_active; + +int32_t ConsoleGetActive() { + return s_active; +} + +void ConsoleSetActive(int32_t active) { + s_active = active; +} diff --git a/src/console/Console.hpp b/src/console/Console.hpp new file mode 100644 index 0000000..0be2004 --- /dev/null +++ b/src/console/Console.hpp @@ -0,0 +1,10 @@ +#ifndef CONSOLE_CONSOLE_HPP +#define CONSOLE_CONSOLE_HPP + +#include + +int32_t ConsoleGetActive(); + +void ConsoleSetActive(int32_t active); + +#endif // ifndef CONSOLE_CONSOLE_HPP From ef71ddc46ede47e5eaf734097a4f56d526234ffd Mon Sep 17 00:00:00 2001 From: Tristan 'Natrist' Cormier Date: Sat, 15 Apr 2023 17:03:58 -0400 Subject: [PATCH 17/22] feat(console): add helpers for console access enabled state --- src/console/Console.cpp | 9 +++++++++ src/console/Console.hpp | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/console/Console.cpp b/src/console/Console.cpp index ecd10ce..2e7a225 100644 --- a/src/console/Console.cpp +++ b/src/console/Console.cpp @@ -1,6 +1,15 @@ #include "console/Console.hpp" static int32_t s_active; +static int32_t s_consoleAccessEnabled; + +int32_t ConsoleAccessGetEnabled() { + return s_consoleAccessEnabled; +} + +void ConsoleAccessSetEnabled(int32_t enable) { + s_consoleAccessEnabled = enable; +} int32_t ConsoleGetActive() { return s_active; diff --git a/src/console/Console.hpp b/src/console/Console.hpp index 0be2004..6bac5b8 100644 --- a/src/console/Console.hpp +++ b/src/console/Console.hpp @@ -3,6 +3,10 @@ #include +int32_t ConsoleAccessGetEnabled(); + +void ConsoleAccessSetEnabled(int32_t enable); + int32_t ConsoleGetActive(); void ConsoleSetActive(int32_t active); From 309ba8085c912a3921f90d5111ad15c90489c940 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 16:14:15 -0500 Subject: [PATCH 18/22] feat(console): enable console access when initializing device --- src/console/Device.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/console/Device.cpp b/src/console/Device.cpp index 7d59bc3..ebb169a 100644 --- a/src/console/Device.cpp +++ b/src/console/Device.cpp @@ -1,5 +1,6 @@ #include "console/Device.hpp" #include "client/Gui.hpp" +#include "console/Console.hpp" #include "console/CVar.hpp" #include "event/Input.hpp" #include "gx/Device.hpp" @@ -147,6 +148,9 @@ void ConsoleDeviceInitialize(const char* title) { // TODO proper logic s_hwDetect = true; + // TODO ConsoleAccessSetEnabled(CmdLineGetBool(35)); + ConsoleAccessSetEnabled(1); + // TODO RegisterGxCVars(); From 3549abd87fa96142243404f26e7924b70c893afd Mon Sep 17 00:00:00 2001 From: Tristan 'Natrist' Cormier Date: Sat, 15 Apr 2023 17:33:17 -0400 Subject: [PATCH 19/22] feat(console): add helpers for console hotkey --- src/console/Console.cpp | 9 +++++++++ src/console/Console.hpp | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/console/Console.cpp b/src/console/Console.cpp index 2e7a225..1609c64 100644 --- a/src/console/Console.cpp +++ b/src/console/Console.cpp @@ -2,6 +2,7 @@ static int32_t s_active; static int32_t s_consoleAccessEnabled; +static KEY s_consoleKey = KEY_TILDE; int32_t ConsoleAccessGetEnabled() { return s_consoleAccessEnabled; @@ -15,6 +16,14 @@ int32_t ConsoleGetActive() { return s_active; } +KEY ConsoleGetHotKey() { + return s_consoleKey; +} + void ConsoleSetActive(int32_t active) { s_active = active; } + +void ConsoleSetHotKey(KEY hotkey) { + s_consoleKey = hotkey; +} diff --git a/src/console/Console.hpp b/src/console/Console.hpp index 6bac5b8..e9bfac8 100644 --- a/src/console/Console.hpp +++ b/src/console/Console.hpp @@ -1,6 +1,7 @@ #ifndef CONSOLE_CONSOLE_HPP #define CONSOLE_CONSOLE_HPP +#include "event/Types.hpp" #include int32_t ConsoleAccessGetEnabled(); @@ -9,6 +10,10 @@ void ConsoleAccessSetEnabled(int32_t enable); int32_t ConsoleGetActive(); +KEY ConsoleGetHotKey(); + void ConsoleSetActive(int32_t active); +void ConsoleSetHotKey(KEY hotkey); + #endif // ifndef CONSOLE_CONSOLE_HPP From 912d643e9c4eefee7f9562b16c3ea31adb2d82ee Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 21:21:27 -0500 Subject: [PATCH 20/22] chore(gx): add flag enum to CGxMatrixStack --- src/gx/CGxMatrixStack.cpp | 4 ++-- src/gx/CGxMatrixStack.hpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gx/CGxMatrixStack.cpp b/src/gx/CGxMatrixStack.cpp index d284464..1efb83b 100644 --- a/src/gx/CGxMatrixStack.cpp +++ b/src/gx/CGxMatrixStack.cpp @@ -1,7 +1,7 @@ #include "gx/CGxMatrixStack.hpp" CGxMatrixStack::CGxMatrixStack() { - this->m_flags[0] = 0x1; + this->m_flags[0] = F_Identity; } void CGxMatrixStack::Pop() { @@ -25,7 +25,7 @@ void CGxMatrixStack::Push() { C44Matrix& CGxMatrixStack::Top() { this->m_dirty = 1; - this->m_flags[this->m_level] &= 0xFFFFFFFE; + this->m_flags[this->m_level] &= ~F_Identity; return this->m_mtx[this->m_level]; } diff --git a/src/gx/CGxMatrixStack.hpp b/src/gx/CGxMatrixStack.hpp index 7bb2381..80ce9cc 100644 --- a/src/gx/CGxMatrixStack.hpp +++ b/src/gx/CGxMatrixStack.hpp @@ -6,6 +6,11 @@ class CGxMatrixStack { public: + // Types + enum EMatrixFlags { + F_Identity = 0x1, + }; + // Member variables uint32_t m_level = 0; int8_t m_dirty = 0; From 01ca76788c1b55e3a03c9ce41b8daffc8ef25bc9 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 15 Apr 2023 21:23:03 -0500 Subject: [PATCH 21/22] chore(gx): clean up member function declarations in CGxMatrixStack --- src/gx/CGxMatrixStack.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gx/CGxMatrixStack.hpp b/src/gx/CGxMatrixStack.hpp index 80ce9cc..fd54109 100644 --- a/src/gx/CGxMatrixStack.hpp +++ b/src/gx/CGxMatrixStack.hpp @@ -19,9 +19,9 @@ class CGxMatrixStack { // Member functions CGxMatrixStack(); - void Pop(void); - void Push(void); - C44Matrix& Top(void); + void Pop(); + void Push(); + C44Matrix& Top(); const C44Matrix& TopConst(); }; From 58272f1212e0f4d7d5d0122a79e1b6d6fd09790e Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 17 Apr 2023 12:16:38 -0500 Subject: [PATCH 22/22] chore(gx): clean up function declarations in GLDevice --- src/gx/gll/GLDevice.cpp | 30 +++++----- src/gx/gll/GLDevice.h | 126 ++++++++++++++++++++-------------------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/gx/gll/GLDevice.cpp b/src/gx/gll/GLDevice.cpp index 8489cc4..facc73c 100644 --- a/src/gx/gll/GLDevice.cpp +++ b/src/gx/gll/GLDevice.cpp @@ -2200,29 +2200,29 @@ void GLDevice::SetAlphaTestEnable(bool enable) { } } -void GLDevice::SetClearColor(const GLColor4f& a2) { +void GLDevice::SetClearColor(const GLColor4f& clearColor) { if ( - this->m_States.clear.clearColor.r != a2.r - || this->m_States.clear.clearColor.g != a2.g - || this->m_States.clear.clearColor.b != a2.b - || this->m_States.clear.clearColor.a != a2.a + this->m_States.clear.clearColor.r != clearColor.r + || this->m_States.clear.clearColor.g != clearColor.g + || this->m_States.clear.clearColor.b != clearColor.b + || this->m_States.clear.clearColor.a != clearColor.a ) { - glClearColor(a2.r, a2.g, a2.b, a2.a); - this->m_States.clear.clearColor = { a2.r, a2.g, a2.b, a2.a }; + glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); + this->m_States.clear.clearColor = { clearColor.r, clearColor.g, clearColor.b, clearColor.a }; } } -void GLDevice::SetClearDepth(double depth) { - if (this->m_States.clear.clearDepth != depth) { - glClearDepth(depth); - this->m_States.clear.clearDepth = depth; +void GLDevice::SetClearDepth(double clearDepth) { + if (this->m_States.clear.clearDepth != clearDepth) { + glClearDepth(clearDepth); + this->m_States.clear.clearDepth = clearDepth; } } -void GLDevice::SetClearStencil(int32_t s) { - if (this->m_States.clear.clearStencil != s) { - glClearStencil(s); - this->m_States.clear.clearStencil = s; +void GLDevice::SetClearStencil(int32_t clearStencil) { + if (this->m_States.clear.clearStencil != clearStencil) { + glClearStencil(clearStencil); + this->m_States.clear.clearStencil = clearStencil; } } diff --git a/src/gx/gll/GLDevice.h b/src/gx/gll/GLDevice.h index c3f8e98..d755acc 100644 --- a/src/gx/gll/GLDevice.h +++ b/src/gx/gll/GLDevice.h @@ -63,13 +63,13 @@ class GLDevice { static GLFramebuffer* m_F8330C; // Static functions - static GLDevice* Get(void); - static void Set(GLDevice*); - static void InitPools(void); - static RendererInfo GetRendererInfo(void); - static void InitRendererInfo(void); - static void SetOption(GLDeviceOption, bool); - static void StaticInit(void); + static GLDevice* Get(); + static void Set(GLDevice* device); + static void InitPools(); + static RendererInfo GetRendererInfo(); + static void InitRendererInfo(); + static void SetOption(GLDeviceOption option, bool enable); + static void StaticInit(); // Member variables std::basic_string, std::allocator> m_DebugName; @@ -121,72 +121,72 @@ class GLDevice { // Member functions GLDevice(); - void ApplyGLBindings(const GLStates&, bool); - void ApplyGLStates(const GLStates&, bool); - void ApplyShaderConstants(void); - void ApplyTransforms(void); - void BindBuffer(GLBuffer*, GLEnum); - void BindFramebuffer(GLFramebuffer*); - void BindGLSLProgram(GLGLSLProgram*); - void BindShader(GLShader*); - void BindTexture(GLEnum, GLTexture*); - void BindVertexArray(GLVertexArray*); - void BlitFramebuffer(GLMipmap*, const GLRect*, GLMipmap*, const GLRect*, GLEnum, GLEnum); - void CheckDepthTarget(void); - void Clear(uint32_t, const GLColor4f&, double, int32_t); - void CopyTex(uint32_t, uint32_t, GLMipmap*, const GLRect*); - GLBuffer* CreateBuffer(GLEnum, uint32_t, const void*, GLEnum, GLEnum); - GLShader* CreateShader(GLShader::ShaderType, const void*, int32_t, const char*); - GLTexture* CreateTexture2D(uint32_t, uint32_t, uint32_t, GLTextureFormat, uint32_t); - GLTexture* CreateTextureCubeMap(uint32_t, uint32_t, GLTextureFormat, uint32_t); - void Draw(GLEnum, uint32_t, uint32_t); - void DrawIndexed(GLEnum, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); - void DrawRect(void); - GLFramebuffer* GetCurrentTarget(void); // invented name - uint32_t GetID(void); - GLShader* GetShader(GLShader::ShaderType); + void ApplyGLBindings(const GLStates& states, bool a3); + void ApplyGLStates(const GLStates& states, bool force); + void ApplyShaderConstants(); + void ApplyTransforms(); + void BindBuffer(GLBuffer* buffer, GLEnum target); + void BindFramebuffer(GLFramebuffer* framebuffer); + void BindGLSLProgram(GLGLSLProgram* a2); + void BindShader(GLShader* shader); + void BindTexture(GLEnum textureType, GLTexture* texture); + void BindVertexArray(GLVertexArray* a2); + void BlitFramebuffer(GLMipmap* src, const GLRect* srcRect, GLMipmap* dst, const GLRect* dstRect, GLEnum mask, GLEnum filter); + void CheckDepthTarget(); + void Clear(uint32_t clearMask, const GLColor4f& clearColor, double clearDepth, int32_t clearStencil); + void CopyTex(uint32_t a2, uint32_t a3, GLMipmap* dst, const GLRect* framebufferRect); + GLBuffer* CreateBuffer(GLEnum type, uint32_t a3, const void* a4, GLEnum usage, GLEnum format); + GLShader* CreateShader(GLShader::ShaderType type, const void* buf, int32_t codeLen, const char* name); + GLTexture* CreateTexture2D(uint32_t width, uint32_t height, uint32_t numMipMap, GLTextureFormat format, uint32_t flags); + GLTexture* CreateTextureCubeMap(uint32_t size, uint32_t numMipMap, GLTextureFormat format, uint32_t flags); + void Draw(GLEnum primitive, uint32_t a3, uint32_t a4); + void DrawIndexed(GLEnum primitive, uint32_t a3, uint32_t a4, uint32_t a5, uint32_t a6, uint32_t count); + void DrawRect(); + GLFramebuffer* GetCurrentTarget(); // invented name + uint32_t GetID(); + GLShader* GetShader(GLShader::ShaderType shaderType); const GLStates::VertexArrayObject& GetVertexArrayStates(); - void GLLDraw(GLEnum, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); - void Init(GLAbstractWindow*, const char*, uint32_t, GLTextureFormat); - void LoadDefaultStates(void); + void GLLDraw(GLEnum mode, uint32_t start, uint32_t end, uint32_t a5, uint32_t a6, uint32_t count); + void Init(GLAbstractWindow* a2, const char* a3, uint32_t a4, GLTextureFormat a5); + void LoadDefaultStates(); void ResetBackbuffer(uint32_t width, uint32_t height, GLTextureFormat colorFormat, GLTextureFormat depthFormat, uint32_t sampleCount); void Resize(uint32_t width, uint32_t height); - void RestoreTextures(void); - void SetActiveTexture(uint32_t); - void SetAlphaBlend(GLEnum, GLEnum, GLEnum); - void SetAlphaBlendEnable(bool); - void SetAlphaTest(GLEnum, float); - void SetAlphaTestEnable(bool); - void SetClearColor(const GLColor4f&); - void SetClearDepth(double); - void SetClearStencil(int32_t); + void RestoreTextures(); + void SetActiveTexture(uint32_t a2); + void SetAlphaBlend(GLEnum srcBlend, GLEnum dstBlend, GLEnum blendOp); + void SetAlphaBlendEnable(bool enable); + void SetAlphaTest(GLEnum func, float ref); + void SetAlphaTestEnable(bool enable); + void SetClearColor(const GLColor4f& clearColor); + void SetClearDepth(double clearDepth); + void SetClearStencil(int32_t clearStencil); void SetColorWriteMask(bool red, bool green, bool blue, bool alpha, uint32_t index); - void SetCullMode(GLEnum); + void SetCullMode(GLEnum cullMode); void SetDepthBias(float constantBias, float slopeScaledBias); - void SetDepthTestEnable(bool); - void SetDepthTestFunc(GLEnum); - void SetDepthWriteMask(bool); - void SetDisplay(uint32_t, uint32_t, GLTextureFormat, GLTextureFormat, uint32_t, bool, bool, uint32_t); + void SetDepthTestEnable(bool enable); + void SetDepthTestFunc(GLEnum func); + void SetDepthWriteMask(bool enable); + void SetDisplay(uint32_t width, uint32_t height, GLTextureFormat a4, GLTextureFormat a5, uint32_t a6, bool a7, bool a8, uint32_t a9); void SetFogColor(float r, float g, float b, float a); void SetFogEnable(bool enable); void SetFogParam(GLEnum param, float value); - void SetIndexBuffer(GLBuffer*); + void SetIndexBuffer(GLBuffer* buffer); void SetLightingEnable(bool enable); - void SetModelView(GLEnum view); - void SetScissor(bool, const GLRect&); - void SetShader(GLShader::ShaderType, GLShader*); - void SetShaderConstants(GLShader::ShaderType, uint32_t, const float*, uint32_t); - void SetShaderConstantsInternal(GLShader::ShaderType, uint32_t, const float*, uint32_t); - void SetTexture(uint32_t, GLTexture*); - void SetTransform(GLEnum, const float*); - void SetUnpackClientStorage(bool); - void SetVertexBuffer(uint32_t, GLBuffer*, uint32_t, uint32_t); - void SetVertexFormat(GLVertexFormat*); - void SetViewport(const GLRect&, double, double); + void SetModelView(GLEnum transform); + void SetScissor(bool a2, const GLRect& a3); + void SetShader(GLShader::ShaderType shaderType, GLShader* shader); + void SetShaderConstants(GLShader::ShaderType shaderType, uint32_t index, const float* constants, uint32_t count); + void SetShaderConstantsInternal(GLShader::ShaderType shaderType, uint32_t index, const float* constants, uint32_t count); + void SetTexture(uint32_t stage, GLTexture* texture); + void SetTransform(GLEnum transform, const float* a3); + void SetUnpackClientStorage(bool enable); + void SetVertexBuffer(uint32_t index, GLBuffer* buffer, uint32_t offset, uint32_t stride); + void SetVertexFormat(GLVertexFormat* format); + void SetViewport(const GLRect& viewport, double zNear, double zFar); void Sub34BB0(GLEnum a2, GLMipmap* a3, uint32_t index); - void Sub38460(bool); - void Swap(void); - void UpdateFFPTexturing(void); + void Sub38460(bool a2); + void Swap(); + void UpdateFFPTexturing(); }; #endif