Emulator: Conditional OpenGL compilation

This commit is contained in:
Wunkolo 2023-07-10 08:30:23 -07:00
parent 0009b0817d
commit d664d5caf0
2 changed files with 19 additions and 3 deletions

View file

@ -1,19 +1,22 @@
#pragma once
#include <SDL.h>
#include <glad/gl.h>
#include <filesystem>
#include <fstream>
#include <optional>
#include "PICA/gpu.hpp"
#include "cpu.hpp"
#include "config.hpp"
#include "cpu.hpp"
#include "crypto/aes_engine.hpp"
#include "io_file.hpp"
#include "memory.hpp"
#if ENABLE_OPENGL
#include "gl_state.hpp"
#endif
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
#include "httpserver.hpp"
#endif
@ -27,10 +30,14 @@ class Emulator {
Kernel kernel;
Crypto::AESEngine aesEngine;
GLStateManager gl;
EmulatorConfig config;
SDL_Window* window;
#if ENABLE_OPENGL
SDL_GLContext glContext;
GLStateManager gl;
#endif
SDL_GameController* gameController = nullptr;
int gameControllerID;

View file

@ -2,6 +2,10 @@
#include <stb_image_write.h>
#if ENABLE_OPENGL
#include <glad/gl.h>
#endif
#ifdef _WIN32
#include <windows.h>
@ -23,6 +27,7 @@ Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory
Helpers::warn("Failed to initialize SDL2 GameController: %s", SDL_GetError());
}
#if ENABLE_OPENGL
// Request OpenGL 4.1 Core (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);
@ -42,6 +47,7 @@ Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory
if (!gladLoadGL(reinterpret_cast<GLADloadfunc>(SDL_GL_GetProcAddress))) {
Helpers::panic("OpenGL init failed: %s", SDL_GetError());
}
#endif
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER)) {
gameController = SDL_GameControllerOpen(0);
@ -428,13 +434,16 @@ bool Emulator::loadELF(std::ifstream& file) {
// Reset our graphics context and initialize the GPU's graphics context
void Emulator::initGraphicsContext() {
#if ENABLE_OPENGL
gl.reset(); // TODO (For when we have multiple backends): Only do this if we are using OpenGL
#endif
gpu.initGraphicsContext();
}
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
void Emulator::pollHttpServer() {
std::scoped_lock lock(httpServer.actionMutex);
ServiceManager& srv = kernel.getServiceManager();
if (httpServer.pendingAction) {