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:
|
||||
FrontendSDL();
|
||||
void createOpenGlWindow(const EmulatorConfig& config);
|
||||
void createVulkanWindow(const EmulatorConfig& config);
|
||||
bool loadROM(const std::filesystem::path& path);
|
||||
void run();
|
||||
u32 getMapping(InputMappings::Scancode scancode) { return keyboardMappings.getMapping(scancode); }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "panda_sdl/frontend_sdl.hpp"
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include "panda_sdl/frontend_sdl.hpp"
|
||||
|
||||
FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMappings()) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
|
||||
Helpers::panic("Failed to initialize SDL2");
|
||||
|
@ -23,13 +23,28 @@ FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMapp
|
|||
}
|
||||
|
||||
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) {
|
||||
case RendererType::Software:
|
||||
case RendererType::OpenGL: {
|
||||
createOpenGlWindow(config);
|
||||
break;
|
||||
}
|
||||
case RendererType::Vulkan: {
|
||||
createVulkanWindow(config);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
Helpers::panic("Invalid renderer type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -51,19 +66,21 @@ FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMapp
|
|||
}
|
||||
|
||||
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
|
||||
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());
|
||||
}
|
||||
Helpers::panic("Window creation failed: %s", SDL_GetError());
|
||||
}
|
||||
#else
|
||||
Helpers::panic("Trying to render with vulkan when not enabled");
|
||||
#endif
|
||||
|
||||
emu.initGraphicsContext(window);
|
||||
}
|
||||
|
||||
bool FrontendSDL::loadROM(const std::filesystem::path& path) { return emu.loadROM(path); }
|
||||
|
@ -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) {
|
||||
// Relative motion since last mouse motion event
|
||||
const s32 motionX = event.motion.xrel;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue