forked from moonpower/azahar-UWP
* externals: Update dynarmic * settings: Introduce GraphicsAPI enum * For now it's OpenGL only but will be expanded upon later * citra_qt: Introduce backend agnostic context management * Mostly a direct port from yuzu * core: Simplify context acquire * settings: Add option to create debug contexts * renderer_opengl: Abstract initialization to Driver * This commit also updates glad and adds some useful extensions which we will use in part 2 * Rasterizer construction is moved to the specific renderer instead of RendererBase. Software rendering has been disable to achieve this but will be brought back in the next commit. * video_core: Remove Init/Shutdown methods from renderer * The constructor and destructor can do the same job * In addition move opengl function loading to Qt since SDL already does this. Also remove ErrorVideoCore which is never reached * citra_qt: Decouple software renderer from opengl part 1 * citra: Decouple software renderer from opengl part 2 * android: Decouple software renderer from opengl part 3 * swrasterizer: Decouple software renderer from opengl part 4 * This commit simply enforces the renderer naming conventions in the software renderer * video_core: Move RendererBase to VideoCore * video_core: De-globalize screenshot state * video_core: Pass system to the renderers * video_core: Commonize shader uniform data * video_core: Abstract backend agnostic rasterizer operations * bootmanager: Remove references to OpenGL for macOS OpenGL macOS headers definitions clash heavily with each other * citra_qt: Proper title for api settings * video_core: Reduce boost usage * bootmanager: Fix hide mouse option Remove event handlers from RenderWidget for events that are already handled by the parent GRenderWindow. Also enable mouse tracking on the RenderWidget. * android: Remove software from graphics api list * code: Address review comments * citra: Port per-game settings read * Having to update the default value for all backends is a pain so lets centralize it * android: Rename to OpenGLES --------- Co-authored-by: MerryMage <MerryMage@users.noreply.github.com> Co-authored-by: Vitor Kiguchi <vitor-kiguchi@hotmail.com>
153 lines
4.9 KiB
C++
153 lines
4.9 KiB
C++
// Copyright 2023 Citra Emulator Project
|
|
// Licensed under GPLv2 or any later version
|
|
// Refer to the license.txt file included.
|
|
|
|
#include <algorithm>
|
|
#include <cstdlib>
|
|
#include <string>
|
|
#define SDL_MAIN_HANDLED
|
|
#include <SDL.h>
|
|
#include <glad/glad.h>
|
|
#include "citra/emu_window/emu_window_sdl2_gl.h"
|
|
#include "common/scm_rev.h"
|
|
#include "video_core/renderer_base.h"
|
|
#include "video_core/video_core.h"
|
|
|
|
class SDLGLContext : public Frontend::GraphicsContext {
|
|
public:
|
|
using SDL_GLContext = void*;
|
|
|
|
SDLGLContext() {
|
|
window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0,
|
|
SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
|
context = SDL_GL_CreateContext(window);
|
|
}
|
|
|
|
~SDLGLContext() override {
|
|
SDL_GL_DeleteContext(context);
|
|
SDL_DestroyWindow(window);
|
|
}
|
|
|
|
void MakeCurrent() override {
|
|
SDL_GL_MakeCurrent(window, context);
|
|
}
|
|
|
|
void DoneCurrent() override {
|
|
SDL_GL_MakeCurrent(window, nullptr);
|
|
}
|
|
|
|
private:
|
|
SDL_Window* window;
|
|
SDL_GLContext context;
|
|
};
|
|
|
|
EmuWindow_SDL2_GL::EmuWindow_SDL2_GL(bool fullscreen, bool is_secondary)
|
|
: EmuWindow_SDL2{is_secondary} {
|
|
// Initialize the window
|
|
if (Settings::values.use_gles) {
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
} else {
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
}
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
|
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
|
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
|
|
// Enable context sharing for the shared context
|
|
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
|
|
// Enable vsync
|
|
SDL_GL_SetSwapInterval(1);
|
|
// Enable debug context
|
|
if (Settings::values.renderer_debug) {
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
|
|
}
|
|
|
|
std::string window_title = fmt::format("Citra {} | {}-{}", Common::g_build_fullname,
|
|
Common::g_scm_branch, Common::g_scm_desc);
|
|
render_window =
|
|
SDL_CreateWindow(window_title.c_str(),
|
|
SDL_WINDOWPOS_UNDEFINED, // x position
|
|
SDL_WINDOWPOS_UNDEFINED, // y position
|
|
Core::kScreenTopWidth, Core::kScreenTopHeight + Core::kScreenBottomHeight,
|
|
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
|
|
|
if (render_window == nullptr) {
|
|
LOG_CRITICAL(Frontend, "Failed to create SDL2 window: {}", SDL_GetError());
|
|
exit(1);
|
|
}
|
|
|
|
dummy_window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0,
|
|
SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
|
|
|
if (fullscreen) {
|
|
Fullscreen();
|
|
}
|
|
|
|
window_context = SDL_GL_CreateContext(render_window);
|
|
core_context = CreateSharedContext();
|
|
last_saved_context = nullptr;
|
|
|
|
if (window_context == nullptr) {
|
|
LOG_CRITICAL(Frontend, "Failed to create SDL2 GL context: {}", SDL_GetError());
|
|
exit(1);
|
|
}
|
|
if (core_context == nullptr) {
|
|
LOG_CRITICAL(Frontend, "Failed to create shared SDL2 GL context: {}", SDL_GetError());
|
|
exit(1);
|
|
}
|
|
|
|
render_window_id = SDL_GetWindowID(render_window);
|
|
auto gl_load_func = Settings::values.use_gles ? gladLoadGLES2Loader : gladLoadGLLoader;
|
|
|
|
if (!gl_load_func(static_cast<GLADloadproc>(SDL_GL_GetProcAddress))) {
|
|
LOG_CRITICAL(Frontend, "Failed to initialize GL functions: {}", SDL_GetError());
|
|
exit(1);
|
|
}
|
|
|
|
OnResize();
|
|
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
|
|
SDL_PumpEvents();
|
|
}
|
|
|
|
EmuWindow_SDL2_GL::~EmuWindow_SDL2_GL() {
|
|
core_context.reset();
|
|
SDL_DestroyWindow(render_window);
|
|
SDL_GL_DeleteContext(window_context);
|
|
}
|
|
|
|
std::unique_ptr<Frontend::GraphicsContext> EmuWindow_SDL2_GL::CreateSharedContext() const {
|
|
return std::make_unique<SDLGLContext>();
|
|
}
|
|
|
|
void EmuWindow_SDL2_GL::MakeCurrent() {
|
|
core_context->MakeCurrent();
|
|
}
|
|
|
|
void EmuWindow_SDL2_GL::DoneCurrent() {
|
|
core_context->DoneCurrent();
|
|
}
|
|
|
|
void EmuWindow_SDL2_GL::SaveContext() {
|
|
last_saved_context = SDL_GL_GetCurrentContext();
|
|
}
|
|
|
|
void EmuWindow_SDL2_GL::RestoreContext() {
|
|
SDL_GL_MakeCurrent(render_window, last_saved_context);
|
|
}
|
|
|
|
void EmuWindow_SDL2_GL::Present() {
|
|
SDL_GL_MakeCurrent(render_window, window_context);
|
|
SDL_GL_SetSwapInterval(1);
|
|
while (IsOpen()) {
|
|
VideoCore::g_renderer->TryPresent(100, is_secondary);
|
|
SDL_GL_SwapWindow(render_window);
|
|
}
|
|
SDL_GL_MakeCurrent(render_window, nullptr);
|
|
}
|