citra/src/video_core/video_core.cpp
GPUCode ffc95eb59b
Frontend PR fixes (#6378)
* citra_qt: Check if renderer is null

* core: Fix dynarmic use-after-free error

* bootmanager: Add current context check in DoneCurrent

* Loading a save state would destroy the frame dumper class, which contains a shared context. That context would call DoneCurrent without checking if it was actually bound or not, resulting in crashes when calling opengl functions

* externals: Correct glad readme

* common: Log renderer debug setting

* citra: Make lambda lower case

* Consistency with review comments on the PR

* video_core: Kill more global state

* GetResolutionScaleFactor would be called somewhere in the renderer constructor chain but it relies on the yet unitialized g_renderer, resulting in crashes when the resolution scale is set to auto. Rather than adding a workaround, let's kill this global state to fix this for good
2023-03-30 14:24:49 +03:00

70 lines
2.1 KiB
C++

// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <memory>
#include "common/archives.h"
#include "common/logging/log.h"
#include "common/settings.h"
#include "core/core.h"
#include "video_core/pica.h"
#include "video_core/pica_state.h"
#include "video_core/renderer_base.h"
#include "video_core/renderer_opengl/gl_vars.h"
#include "video_core/renderer_opengl/renderer_opengl.h"
#include "video_core/renderer_software/renderer_software.h"
#include "video_core/video_core.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// Video Core namespace
namespace VideoCore {
std::unique_ptr<RendererBase> g_renderer{}; ///< Renderer plugin
std::atomic<bool> g_shader_jit_enabled;
std::atomic<bool> g_hw_shader_enabled;
std::atomic<bool> g_separable_shader_enabled;
std::atomic<bool> g_hw_shader_accurate_mul;
Memory::MemorySystem* g_memory;
/// Initialize the video core
void Init(Frontend::EmuWindow& emu_window, Frontend::EmuWindow* secondary_window,
Core::System& system) {
g_memory = &system.Memory();
Pica::Init();
const Settings::GraphicsAPI graphics_api = Settings::values.graphics_api.GetValue();
OpenGL::GLES = Settings::values.use_gles.GetValue();
switch (graphics_api) {
case Settings::GraphicsAPI::Software:
g_renderer = std::make_unique<VideoCore::RendererSoftware>(system, emu_window);
break;
case Settings::GraphicsAPI::OpenGL:
g_renderer = std::make_unique<OpenGL::RendererOpenGL>(system, emu_window, secondary_window);
break;
default:
LOG_CRITICAL(Render, "Unknown graphics API {}, using OpenGL", graphics_api);
g_renderer = std::make_unique<OpenGL::RendererOpenGL>(system, emu_window, secondary_window);
}
}
/// Shutdown the video core
void Shutdown() {
Pica::Shutdown();
g_renderer.reset();
LOG_DEBUG(Render, "shutdown OK");
}
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& Pica::g_state;
}
} // namespace VideoCore
SERIALIZE_IMPL(VideoCore)