chore(build): make Thunderbrew zig-buildable

This commit is contained in:
phaneron 2024-07-21 16:41:14 -04:00
parent c6e2947506
commit 20f392cd74
10 changed files with 934 additions and 33 deletions

View file

@ -538,6 +538,8 @@ void CGxDeviceD3d::DeviceWM(EGxWM wm, uintptr_t param1, uintptr_t param2) {
break;
}
default: {
}
}
}
@ -727,6 +729,9 @@ void CGxDeviceD3d::DsSet(EDeviceState state, uint32_t val) {
case Ds_ZFunc: {
this->m_d3dDevice->SetRenderState(D3DRS_ZFUNC, val);
break;
}
default: {
}
}
@ -1915,6 +1920,7 @@ UNLOCK:
}
void CGxDeviceD3d::IXformSetProjection(const C44Matrix& matrix) {
#if defined(_MSC_VER)
DirectX::XMMATRIX projNative;
memcpy(&projNative, &matrix, sizeof(projNative));
@ -1948,6 +1954,41 @@ void CGxDeviceD3d::IXformSetProjection(const C44Matrix& matrix) {
this->m_xforms[GxXform_Projection].m_dirty = 1;
memcpy(&this->m_projNative, &projNative, sizeof(this->m_projNative));
#else
C44Matrix projNative;
memcpy(&projNative, &matrix, sizeof(projNative));
if (NotEqual(projNative.c3, 1.0f, WHOA_EPSILON_1) && NotEqual(projNative.c3, 0.0f, WHOA_EPSILON_1)) {
projNative = projNative * (1.0f / projNative.c3);
}
if (projNative.d3 == 0.0f) {
auto v5 = -(projNative.d2 / (projNative.c2 + 1.0f));
auto v6 = -(projNative.d2 / (projNative.c2 - 1.0f));
projNative.c2 = v6 / (v6 - v5);
projNative.d2 = v6 * v5 / (v5 - v6);
} else {
auto v8 = 1.0f / projNative.c2;
auto v9 = (-1.0f - projNative.d2) * v8;
auto v10 = v8 * (1.0f - projNative.d2);
projNative.c2 = 1.0f / (v10 - v9);
projNative.d2 = v9 / (v9 - v10);
}
if (!this->MasterEnable(GxMasterEnable_NormalProjection) && projNative.d3 != 1.0f) {
C44Matrix shrink = {
0.2f, 0.0f, 0.0f, 0.0f,
0.0f, 0.2f, 0.0f, 0.0f,
0.0f, 0.0f, 0.2f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
projNative = projNative * shrink;
}
this->m_xforms[GxXform_Projection].m_dirty = 1;
memcpy(&this->m_projNative, &projNative, sizeof(this->m_projNative));
#endif
}
void CGxDeviceD3d::IXformSetViewport() {

View file

@ -1,6 +1,6 @@
#ifndef GX_GL_SDL_GL_SDL_CONTEXT_HPP
#include <SDL3/SDL.h>
#include <SDL2/SDL.h>
#include "gx/glsdl/GLSDLWindow.hpp"
#include "gx/glsdl/GLTypes.hpp"

View file

@ -198,6 +198,8 @@ void GLSDLWindow::Create(const char* title, const GLSDLWindowRect& rect, GLTextu
this->m_sdlWindow = SDL_CreateWindow(
title,
0,
0,
static_cast<int>(rect.size.width), static_cast<int>(rect.size.height),
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE
);
@ -229,17 +231,15 @@ GLSDLWindowRect GLSDLWindow::GetRect() {
int origin_x = 0;
int origin_y = 0;
if (SDL_GetWindowPosition(this->m_sdlWindow, &origin_x, &origin_y) == 0) {
rect.origin.x = static_cast<int32_t>(origin_x);
rect.origin.y = static_cast<int32_t>(origin_y);
}
SDL_GetWindowPosition(this->m_sdlWindow, &origin_x, &origin_y);
rect.origin.x = static_cast<int32_t>(origin_x);
rect.origin.y = static_cast<int32_t>(origin_y);
int width = 0;
int height = 0;
if (SDL_GetWindowSize(this->m_sdlWindow, &width, &height) == 0) {
rect.size.width = static_cast<int32_t>(width);
rect.size.height = static_cast<int32_t>(height);
}
SDL_GetWindowSize(this->m_sdlWindow, &width, &height);
rect.size.width = static_cast<int32_t>(width);
rect.size.height = static_cast<int32_t>(height);
return rect;
}
@ -251,10 +251,9 @@ GLSDLWindowRect GLSDLWindow::GetBackingRect() {
// Query backing width/height
int width = 0;
int height = 0;
if (SDL_GetWindowSizeInPixels(this->m_sdlWindow, &width, &height) == 0) {
rect.size.width = static_cast<int32_t>(width);
rect.size.height = static_cast<int32_t>(height);
}
SDL_GetWindowSizeInPixels(this->m_sdlWindow, &width, &height);
rect.size.width = static_cast<int32_t>(width);
rect.size.height = static_cast<int32_t>(height);
return rect;
}
@ -263,8 +262,8 @@ void GLSDLWindow::Resize(const GLSDLWindowRect& rect) {
auto current = this->GetBackingRect();
if (current.size.width != rect.size.width || current.size.height != rect.size.width) {
auto status = SDL_SetWindowSize(this->m_sdlWindow, rect.size.width, rect.size.height);
BLIZZARD_ASSERT(status == 0);
SDL_SetWindowSize(this->m_sdlWindow, rect.size.width, rect.size.height);
// BLIZZARD_ASSERT(status == 0);
}
}
@ -278,24 +277,24 @@ int32_t GLSDLWindow::GetHeight() {
void GLSDLWindow::DispatchSDLEvent(const SDL_Event& event) {
switch (event.type) {
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
case SDL_KEYDOWN:
case SDL_KEYUP:
this->DispatchSDLKeyboardEvent(event);
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
this->DispatchSDLMouseButtonEvent(event);
break;
case SDL_EVENT_MOUSE_MOTION:
case SDL_MOUSEMOTION:
this->DispatchSDLMouseMotionEvent(event);
break;
case SDL_EVENT_TEXT_INPUT:
case SDL_TEXTINPUT:
this->DispatchSDLTextInputEvent(event);
break;
case SDL_EVENT_WINDOW_RESIZED:
case SDL_WINDOWEVENT_RESIZED:
this->DispatchSDLWindowResizedEvent(event);
break;
case SDL_EVENT_QUIT:
case SDL_QUIT:
EventPostClose();
break;
default:
@ -305,7 +304,7 @@ void GLSDLWindow::DispatchSDLEvent(const SDL_Event& event) {
void GLSDLWindow::DispatchSDLKeyboardEvent(const SDL_Event& event) {
// Is this an up or down keypress?
OSINPUT inputclass = event.type == SDL_EVENT_KEY_UP ? OS_INPUT_KEY_UP : OS_INPUT_KEY_DOWN;
OSINPUT inputclass = event.type == SDL_KEYUP ? OS_INPUT_KEY_UP : OS_INPUT_KEY_DOWN;
// What key does this SDL scancode correspond to?
auto lookup = s_keyConversion.find(event.key.keysym.scancode);
@ -329,7 +328,7 @@ void GLSDLWindow::DispatchSDLMouseMotionEvent(const SDL_Event& event) {
void GLSDLWindow::DispatchSDLMouseButtonEvent(const SDL_Event& event) {
// Is this an up or down mouse click?
OSINPUT inputclass = event.type == SDL_EVENT_MOUSE_BUTTON_UP ? OS_INPUT_MOUSE_UP : OS_INPUT_MOUSE_DOWN;
OSINPUT inputclass = event.type == SDL_MOUSEBUTTONUP ? OS_INPUT_MOUSE_UP : OS_INPUT_MOUSE_DOWN;
// XY click coordinates
auto x = static_cast<int32_t>(event.button.x);

View file

@ -2,7 +2,7 @@
#define GX_GL_SDL_GL_SDL_WINDOW_HPP
#include <cstdint>
#include <SDL3/SDL.h>
#include <SDL2/SDL.h>
#include "gx/glsdl/GLTypes.hpp"