Add Os Bridge into test framework

This commit is contained in:
2026-03-21 14:43:16 +01:00
parent a86c13b9a3
commit baad2ce15c
10 changed files with 357 additions and 242 deletions
+92
View File
@@ -0,0 +1,92 @@
#include <os/desktopos.hpp>
#if !defined(__SWITCH__) && !defined(__3DS__)
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <pdsystem>
namespace PD {
struct DesktopOS::Impl {
GLFWwindow* win = nullptr;
};
void DesktopOS::Init() {
if (impl) return;
impl = new Impl();
std::string winname = "gfx_test";
glfwInit();
if (pDriver == Driver::OpenGL2) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
PD::Gfx::UseDriver<PD::GfxOpenGL2>();
winname += " (OpenGL2)";
} else if (pDriver == Driver::OpenGL3) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 1);
#endif
PD::Gfx::UseDriver<PD::GfxOpenGL3>();
winname += " (OpenGL3)";
} else if (pDriver == Driver::DirectX9) {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
winname += " (DirectX9)";
}
#ifdef __APPLE__
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, 0);
#endif
impl->win = glfwCreateWindow(1280, 720, winname.c_str(), nullptr, nullptr);
glfwMakeContextCurrent(impl->win);
if (pDriver == Driver::OpenGL2 || pDriver == Driver::OpenGL3) {
gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress));
}
#ifdef _WIN32
if (pDriver == Driver::DirectX9) {
d3d = Direct3DCreate9(D3D_SDK_VERSION);
auto hwnd = glfwGetWin32Window(impl->win);
D3DPRESENT_PARAMETERS d3dpp = {};
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp,
&dx9_device);
if (FAILED(hr)) {
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
std::abort();
}
PD::Gfx::UseDriver<PD::GfxDirectX9>(dx9_device);
}
#endif
glfwSwapInterval(1);
}
void DesktopOS::Deinit() {
glfwTerminate();
if (impl) {
delete impl;
impl = nullptr;
}
}
bool DesktopOS::Mainloop() {
glfwPollEvents();
glfwGetFramebufferSize(impl->win, &pViewPort.x, &pViewPort.y);
return !glfwWindowShouldClose(impl->win);
}
void DesktopOS::ClearViewPort() {
PD::Gfx::SetViewPort(pViewPort);
glClearColor(0.1, 0.1, 0.1, 0.1);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, pViewPort.x, pViewPort.y);
}
void DesktopOS::SwapBuffers() { glfwSwapBuffers(impl->win); }
} // namespace PD
#endif
+64
View File
@@ -0,0 +1,64 @@
#include <os/horizon-ctr.hpp>
#if defined(__3DS__)
#include <3ds.h>
#include <citro3d.h>
const u32 DisplayTransferFlags =
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
#include <pdsystem>
namespace PD {
struct HorizonCtr::Impl {
C3D_RenderTarget* Top = nullptr;
C3D_RenderTarget* Bottom = nullptr;
};
void HorizonCtr::Init() {
if (impl) return;
impl = new Impl();
romfsInit();
gfxInitDefault();
consoleInit(GFX_BOTTOM, nullptr);
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
impl->Top =
C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
impl->Bottom =
C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(impl->Top, GFX_TOP, GFX_LEFT, DisplayTransferFlags);
C3D_RenderTargetSetOutput(impl->Bottom, GFX_BOTTOM, GFX_LEFT,
DisplayTransferFlags);
PD::Gfx::UseDriver<PD::GfxCitro3D>();
}
void HorizonCtr::Deinit() {
if (impl) {
C3D_RenderTargetDelete(impl->Top);
C3D_RenderTargetDelete(impl->Bottom);
C3D_Fini();
gfxExit();
romfsExit();
delete impl;
impl = nullptr;
}
}
bool HorizonCtr::Mainloop() {
pViewPort = ivec2(400, 240);
return aptMainLoop();
}
void HorizonCtr::ClearViewPort() {
PD::Gfx::SetViewPort(pViewPort);
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C3D_FrameDrawOn(impl->Top);
C3D_RenderTargetClear(impl->Top, C3D_CLEAR_ALL, PD::Color(25, 25, 25, 25), 0);
}
void HorizonCtr::SwapBuffers() { C3D_FrameEnd(0); }
} // namespace PD
#endif
+62
View File
@@ -0,0 +1,62 @@
#include <os/horizon-nx.hpp>
#if defined(__SWITCH__)
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include <switch.h>
#include <pdsystem>
namespace PD {
struct HorizonNX::Impl {
GLFWwindow* win = nullptr;
};
void HorizonNX::Init() {
if (impl) return;
impl = new Impl();
romfsInit();
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
impl->win =
glfwCreateWindow(1280, 720, "gfx_test (OpenGL3)", nullptr, nullptr);
glfwMakeContextCurrent(impl->win);
gladLoadGL();
glfwSwapInterval(1);
PD::Gfx::UseDriver<PD::GfxOpenGL3>();
}
void HorizonNX::Deinit() {
glfwTerminate();
if (impl) {
delete impl;
impl = nullptr;
}
}
bool HorizonNX::Mainloop() {
glfwPollEvents();
GLFWgamepadstate _gs;
if (glfwGetGamepadState(GLFW_JOYSTICK_1, &_gs)) {
if (_gs.buttons[GLFW_GAMEPAD_BUTTON_START] == GLFW_PRESS) {
glfwSetWindowShouldClose(impl->win, GLFW_TRUE);
}
}
glfwGetFramebufferSize(impl->win, &pViewPort.x, &pViewPort.y);
return !glfwWindowShouldClose(impl->win);
}
void HorizonNX::ClearViewPort() {
PD::Gfx::SetViewPort(pViewPort);
glClearColor(0.1, 0.1, 0.1, 0.1);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, pViewPort.x, pViewPort.y);
}
void HorizonNX::SwapBuffers() { glfwSwapBuffers(impl->win); }
} // namespace PD
#endif