mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-18 03:31:31 +12:00
Allow compilation with opengl=off
This commit is contained in:
parent
428401870b
commit
1c63f61ad7
2 changed files with 58 additions and 38 deletions
|
@ -15,6 +15,8 @@ class FrontendSDL {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FrontendSDL();
|
FrontendSDL();
|
||||||
|
void createOpenGlWindow(const EmulatorConfig& config);
|
||||||
|
void createVulkanWindow(const EmulatorConfig& config);
|
||||||
bool loadROM(const std::filesystem::path& path);
|
bool loadROM(const std::filesystem::path& path);
|
||||||
void run();
|
void run();
|
||||||
u32 getMapping(InputMappings::Scancode scancode) { return keyboardMappings.getMapping(scancode); }
|
u32 getMapping(InputMappings::Scancode scancode) { return keyboardMappings.getMapping(scancode); }
|
||||||
|
@ -25,7 +27,7 @@ class FrontendSDL {
|
||||||
|
|
||||||
int gameControllerID;
|
int gameControllerID;
|
||||||
bool programRunning = true;
|
bool programRunning = true;
|
||||||
|
|
||||||
// For tracking whether to update gyroscope
|
// For tracking whether to update gyroscope
|
||||||
// We bind gyro to right click + mouse movement
|
// We bind gyro to right click + mouse movement
|
||||||
bool holdingRightClick = false;
|
bool holdingRightClick = false;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "panda_sdl/frontend_sdl.hpp"
|
|
||||||
|
|
||||||
#include <glad/gl.h>
|
#include <glad/gl.h>
|
||||||
|
|
||||||
|
#include "panda_sdl/frontend_sdl.hpp"
|
||||||
|
|
||||||
FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMappings()) {
|
FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMappings()) {
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
|
||||||
Helpers::panic("Failed to initialize SDL2");
|
Helpers::panic("Failed to initialize SDL2");
|
||||||
|
@ -23,49 +23,66 @@ FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMapp
|
||||||
}
|
}
|
||||||
|
|
||||||
const EmulatorConfig& config = emu.getConfig();
|
const EmulatorConfig& config = emu.getConfig();
|
||||||
// We need OpenGL for software rendering or for OpenGL if it's enabled
|
|
||||||
bool needOpenGL = config.rendererType == RendererType::Software;
|
|
||||||
#ifdef PANDA3DS_ENABLE_OPENGL
|
|
||||||
needOpenGL = needOpenGL || (config.rendererType == RendererType::OpenGL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (needOpenGL) {
|
switch (config.rendererType) {
|
||||||
// Demand 3.3 core for software renderer, or 4.1 core for OpenGL renderer (max available on MacOS)
|
case RendererType::Software:
|
||||||
// MacOS gets mad if we don't explicitly demand a core profile
|
case RendererType::OpenGL: {
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
createOpenGlWindow(config);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, config.rendererType == RendererType::Software ? 3 : 4);
|
break;
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, config.rendererType == RendererType::Software ? 3 : 1);
|
|
||||||
window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_OPENGL);
|
|
||||||
|
|
||||||
if (window == nullptr) {
|
|
||||||
Helpers::panic("Window creation failed: %s", SDL_GetError());
|
|
||||||
}
|
}
|
||||||
|
case RendererType::Vulkan: {
|
||||||
glContext = SDL_GL_CreateContext(window);
|
createVulkanWindow(config);
|
||||||
if (glContext == nullptr) {
|
break;
|
||||||
Helpers::panic("OpenGL context creation failed: %s", SDL_GetError());
|
|
||||||
}
|
}
|
||||||
|
default: {
|
||||||
if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(SDL_GL_GetProcAddress))) {
|
Helpers::panic("Invalid renderer type");
|
||||||
Helpers::panic("OpenGL init failed");
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
SDL_GL_SetSwapInterval(config.vsyncEnabled ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef PANDA3DS_ENABLE_VULKAN
|
|
||||||
if (config.rendererType == RendererType::Vulkan) {
|
|
||||||
window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_VULKAN);
|
|
||||||
|
|
||||||
if (window == nullptr) {
|
|
||||||
Helpers::warn("Window creation failed: %s", SDL_GetError());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
emu.initGraphicsContext(window);
|
emu.initGraphicsContext(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrontendSDL::createOpenGlWindow(const EmulatorConfig& config) {
|
||||||
|
#ifdef PANDA3DS_ENABLE_OPENGL
|
||||||
|
// Demand 3.3 core for software renderer, or 4.1 core for OpenGL renderer (max available on MacOS)
|
||||||
|
// MacOS gets mad if we don't explicitly demand a core profile
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, config.rendererType == RendererType::Software ? 3 : 4);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, config.rendererType == RendererType::Software ? 3 : 1);
|
||||||
|
window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_OPENGL);
|
||||||
|
|
||||||
|
if (window == nullptr) {
|
||||||
|
Helpers::panic("Window creation failed: %s", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
glContext = SDL_GL_CreateContext(window);
|
||||||
|
if (glContext == nullptr) {
|
||||||
|
Helpers::panic("OpenGL context creation failed: %s", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(SDL_GL_GetProcAddress))) {
|
||||||
|
Helpers::panic("OpenGL init failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_GL_SetSwapInterval(config.vsyncEnabled ? 1 : 0);
|
||||||
|
#else
|
||||||
|
Helpers::panic("Trying to render with opengl when not enabled");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void FrontendSDL::createVulkanWindow(const EmulatorConfig& config) {
|
||||||
|
#ifdef PANDA3DS_ENABLE_VULKAN
|
||||||
|
window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_VULKAN);
|
||||||
|
|
||||||
|
if (window == nullptr) {
|
||||||
|
Helpers::panic("Window creation failed: %s", SDL_GetError());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Helpers::panic("Trying to render with vulkan when not enabled");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool FrontendSDL::loadROM(const std::filesystem::path& path) { return emu.loadROM(path); }
|
bool FrontendSDL::loadROM(const std::filesystem::path& path) { return emu.loadROM(path); }
|
||||||
|
|
||||||
void FrontendSDL::run() {
|
void FrontendSDL::run() {
|
||||||
|
@ -255,7 +272,8 @@ void FrontendSDL::run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use right click to indicate we want to rotate the console. If right click is not held, then this is not a gyroscope rotation
|
// We use right click to indicate we want to rotate the console. If right click is not held, then this is not a gyroscope
|
||||||
|
// rotation
|
||||||
if (holdingRightClick) {
|
if (holdingRightClick) {
|
||||||
// Relative motion since last mouse motion event
|
// Relative motion since last mouse motion event
|
||||||
const s32 motionX = event.motion.xrel;
|
const s32 motionX = event.motion.xrel;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue