feat(gx): add work for console hardware detection

This commit is contained in:
superp00t 2025-04-01 15:18:36 -04:00
parent 12b405a4dd
commit c67ca6fba9
6 changed files with 105 additions and 5 deletions

View File

@ -4,6 +4,7 @@
#include "gx/Buffer.hpp"
#include "gx/CGxCaps.hpp"
#include "gx/CGxFormat.hpp"
#include "gx/CGxMonitorMode.hpp"
#include "gx/CGxMatrixStack.hpp"
#include "gx/CGxStateBom.hpp"
#include "gx/Types.hpp"
@ -51,10 +52,13 @@ class CGxDevice {
static CGxShader* s_uiPixelShader;
// Static functions
static bool AdapterMonitorModes(TSGrowableArray<CGxMonitorMode>& modes);
static void ICursorUpdate(EGxTexCommand, uint32_t, uint32_t, uint32_t, uint32_t, void*, uint32_t&, const void*&);
static void LogOpen();
static void LogClose();
static void Log(const char* format, ...);
static void Log(const CGxFormat& format);
static void LogClose();
static uint32_t PrimCalcCount(EGxPrim primType, uint32_t count);
#if defined(WHOA_SYSTEM_WIN)
static CGxDevice* NewD3d();
static CGxDevice* NewD3d9Ex();
@ -66,8 +70,6 @@ class CGxDevice {
static CGxDevice* NewGLSDL();
#endif
static CGxDevice* NewOpenGl();
static uint32_t PrimCalcCount(EGxPrim primType, uint32_t count);
static void ICursorUpdate(EGxTexCommand, uint32_t, uint32_t, uint32_t, uint32_t, void*, uint32_t&, const void*&);
// Member variables
TSGrowableArray<CGxPushedRenderState> m_pushedStates;
@ -84,7 +86,7 @@ class CGxDevice {
int32_t intF5C = 0;
int32_t m_windowVisible = 0;
int32_t intF64 = 0;
int32_t intF6C = 1;
int32_t m_needsReset = 1;
CBoundingBox m_viewport;
C44Matrix m_projection;
C44Matrix m_projNative;

View File

@ -0,0 +1,8 @@
#include "gx/CGxMonitorMode.hpp"
int32_t CGxMonitorModeSort(const void* a, const void* b) {
auto i = static_cast<const CGxMonitorMode*>(a);
auto j = static_cast<const CGxMonitorMode*>(b);
return (i->size.x * i->size.y) - (j->size.x * j->size.y);
}

16
src/gx/CGxMonitorMode.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef GX_C_GX_MONITOR_MODE_HPP
#define GX_C_GX_MONITOR_MODE_HPP
#include <cstdint>
#include <tempest/Vector.hpp>
class CGxMonitorMode {
public:
C2iVector size;
uint32_t bpp;
uint32_t refreshRate;
};
int32_t CGxMonitorModeSort(const void* i, const void* j);
#endif

View File

@ -5,6 +5,22 @@
CGxDevice* g_theGxDevicePtr = nullptr;
// NOTE: this is a backport from later versions
// bitmask listing supported gxapis
uint32_t g_supportedApis = 0
#if defined(WHOA_SYSTEM_WIN)
| (1 << GxApi_D3d9)
#endif
#if defined(WHOA_SYSTEM_MAC)
| (1 << GxApi_GLL)
#endif
#if defined(WHOA_BUILD_GLSDL)
| (1 << GxApi_GLSDL)
#endif
;
CGxDevice* GxDevCreate(EGxApi api, int32_t (*windowProc)(void* window, uint32_t message, uintptr_t wparam, intptr_t lparam), const CGxFormat& format) {
CGxDevice* device = nullptr;
@ -55,13 +71,18 @@ CGxDevice* GxDevCreate(EGxApi api, int32_t (*windowProc)(void* window, uint32_t
return g_theGxDevicePtr;
} else {
if (g_theGxDevicePtr) {
delete g_theGxDevicePtr;
DEL(g_theGxDevicePtr);
}
return nullptr;
}
}
int32_t GxDevExists() {
return g_theGxDevicePtr != nullptr;
}
EGxApi GxDevApi() {
return g_theGxDevicePtr->m_api;
}
@ -73,3 +94,29 @@ void* GxDevWindow() {
int32_t GxMasterEnable(EGxMasterEnables state) {
return g_theGxDevicePtr->MasterEnable(state);
}
EGxApi GxApiDefault() {
#if defined(WHOA_SYSTEM_WIN)
return GxApi_D3d9;
#endif
#if defined(WHOA_SYSTEM_MAC)
return GxApi_GLL;
#endif
#if defined(WHOA_SYSTEM_LINUX)
return GxApi_GLSDL;
#endif
}
bool GxApiSupported(EGxApi api) {
return (g_supportedApis & static_cast<uint32_t>(api)) != 0;
}
bool GxAdapterMonitorModes(TSGrowableArray<CGxMonitorMode>& modes) {
return CGxDevice::AdapterMonitorModes(modes);
}
void GxLogOpen() {
CGxDevice::LogOpen();
}

View File

@ -34,6 +34,9 @@ const char** g_gxShaderProfileNames[GxShTargets_Last] = {
csProfileNames
};
static uint32_t s_maxFPS;
static uint32_t s_maxFPSBk;
const CGxCaps& GxCaps() {
return g_theGxDevicePtr->Caps();
}
@ -71,3 +74,19 @@ void GxLogClose() {
void GxLog(const char* format, ...) {
// TODO
}
void GxSetMaxFPS(uint32_t maxFPS) {
s_maxFPS = maxFPS;
}
void GxSetMaxFPSBk(uint32_t maxFPSBk) {
s_maxFPSBk = maxFPSBk;
}
uint32_t GxGetMaxFPS() {
return s_maxFPS;
}
uint32_t GxGetMaxFPSBk() {
return s_maxFPSBk;
}

View File

@ -24,4 +24,12 @@ void GxLogClose();
void GxLog(const char* format, ...);
void GxSetMaxFPS(uint32_t maxFPS);
void GxSetMaxFPSBk(uint32_t maxFPSBk);
uint32_t GxGetMaxFPS();
uint32_t GxGetMaxFPSBk();
#endif