diff --git a/Source/Core/VideoBackends/Null/NullBackend.cpp b/Source/Core/VideoBackends/Null/NullBackend.cpp index b90363818e..900a911699 100644 --- a/Source/Core/VideoBackends/Null/NullBackend.cpp +++ b/Source/Core/VideoBackends/Null/NullBackend.cpp @@ -71,14 +71,9 @@ void VideoBackend::InitBackendInfo() bool VideoBackend::Initialize(const WindowSystemInfo& wsi) { - g_gfx = std::make_unique(); - g_renderer = std::make_unique(); - g_bounding_box = std::make_unique(); - g_vertex_manager = std::make_unique(); - g_perf_query = std::make_unique(); - - InitializeShared(); - return true; + return InitializeShared(std::make_unique(), std::make_unique(), + std::make_unique(), std::make_unique(), + std::make_unique(), std::make_unique()); } void VideoBackend::Shutdown() diff --git a/Source/Core/VideoBackends/OGL/OGLMain.cpp b/Source/Core/VideoBackends/OGL/OGLMain.cpp index a36d9f99a4..c47b94ceb8 100644 --- a/Source/Core/VideoBackends/OGL/OGLMain.cpp +++ b/Source/Core/VideoBackends/OGL/OGLMain.cpp @@ -187,17 +187,16 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi) if (!InitializeGLExtensions(main_gl_context.get()) || !FillBackendInfo()) return false; - g_gfx = std::make_unique(std::move(main_gl_context), wsi.render_surface_scale); + auto gfx = std::make_unique(std::move(main_gl_context), wsi.render_surface_scale); ProgramShaderCache::Init(); - - g_vertex_manager = std::make_unique(); - g_perf_query = GetPerfQuery(); g_sampler_cache = std::make_unique(); - g_bounding_box = std::make_unique(); - InitializeShared(); + auto vertex_manager = std::make_unique(); + auto perf_query = GetPerfQuery(gfx->IsGLES()); + auto bounding_box = std::make_unique(); - return true; + return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query), + std::move(bounding_box)); } void VideoBackend::Shutdown() diff --git a/Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp b/Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp index 00816b679d..cae5f71297 100644 --- a/Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp +++ b/Source/Core/VideoBackends/OGL/OGLPerfQuery.cpp @@ -15,9 +15,8 @@ namespace OGL { -std::unique_ptr GetPerfQuery() +std::unique_ptr GetPerfQuery(bool is_gles) { - const bool is_gles = static_cast(g_gfx.get())->IsGLES(); if (is_gles && GLExtensions::Supports("GL_NV_occlusion_query_samples")) return std::make_unique(); else if (is_gles) diff --git a/Source/Core/VideoBackends/OGL/OGLPerfQuery.h b/Source/Core/VideoBackends/OGL/OGLPerfQuery.h index 8ca2bd4334..f593ab5447 100644 --- a/Source/Core/VideoBackends/OGL/OGLPerfQuery.h +++ b/Source/Core/VideoBackends/OGL/OGLPerfQuery.h @@ -12,7 +12,7 @@ namespace OGL { -std::unique_ptr GetPerfQuery(); +std::unique_ptr GetPerfQuery(bool is_gles); class PerfQuery : public PerfQueryBase { diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp index 46101afe77..8703ea4b4d 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -106,14 +106,10 @@ bool VideoSoftware::Initialize(const WindowSystemInfo& wsi) Clipper::Init(); Rasterizer::Init(); - g_gfx = std::make_unique(std::move(window)); - g_bounding_box = std::make_unique(); - g_vertex_manager = std::make_unique(); - g_perf_query = std::make_unique(); - - InitializeShared(); - - return true; + return InitializeShared(std::make_unique(std::move(window)), + std::make_unique(), std::make_unique(), + std::make_unique(), std::make_unique(), + std::make_unique()); } void VideoSoftware::Shutdown() diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp index 1ced44e3ae..2f930ceac2 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.cpp +++ b/Source/Core/VideoCommon/VideoBackendBase.cpp @@ -317,7 +317,25 @@ void VideoBackendBase::DoState(PointerWrap& p) system.GetFifo().GpuMaySleep(); } -void VideoBackendBase::InitializeShared() +bool VideoBackendBase::InitializeShared(std::unique_ptr gfx, + std::unique_ptr vertex_manager, + std::unique_ptr perf_query, + std::unique_ptr bounding_box) +{ + // All hardware backends use the default RendererBase and TextureCacheBase. + // Only Null and Software backends override them + + return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query), + std::move(bounding_box), std::make_unique(), + std::make_unique()); +} + +bool VideoBackendBase::InitializeShared(std::unique_ptr gfx, + std::unique_ptr vertex_manager, + std::unique_ptr perf_query, + std::unique_ptr bounding_box, + std::unique_ptr renderer, + std::unique_ptr texture_cache) { memset(reinterpret_cast(&g_main_cp_state), 0, sizeof(g_main_cp_state)); memset(reinterpret_cast(&g_preprocess_cp_state), 0, sizeof(g_preprocess_cp_state)); @@ -326,14 +344,17 @@ void VideoBackendBase::InitializeShared() // do not initialize again for the config window m_initialized = true; - if (!g_renderer) - { - // Null and Software Backends supply their own Renderer - g_renderer = std::make_unique(); - } + g_gfx = std::move(gfx); + g_vertex_manager = std::move(vertex_manager); + g_perf_query = std::move(perf_query); + g_bounding_box = std::move(bounding_box); + + // Null and Software Backends supply their own derived Renderer and Texture Cache + g_texture_cache = std::move(texture_cache); + g_renderer = std::move(renderer); + g_presenter = std::make_unique(); g_frame_dumper = std::make_unique(); - g_texture_cache = std::make_unique(); g_framebuffer_manager = std::make_unique(); g_shader_cache = std::make_unique(); @@ -355,13 +376,15 @@ void VideoBackendBase::InitializeShared() { PanicAlertFmtT("Failed to initialize renderer classes"); Shutdown(); - return; + return false; } g_Config.VerifyValidity(); UpdateActiveConfig(); g_shader_cache->InitializeShaderCache(); + + return true; } void VideoBackendBase::ShutdownShared() diff --git a/Source/Core/VideoCommon/VideoBackendBase.h b/Source/Core/VideoCommon/VideoBackendBase.h index 8238bc2067..2ce235f8f8 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.h +++ b/Source/Core/VideoCommon/VideoBackendBase.h @@ -18,6 +18,12 @@ class Mapping; } class PointerWrap; +class AbstractGfx; +class BoundingBox; +class Renderer; +class TextureCacheBase; +class VertexManagerBase; + enum class FieldType { Odd, @@ -71,7 +77,19 @@ public: void DoState(PointerWrap& p); protected: - void InitializeShared(); + // For hardware backends + bool InitializeShared(std::unique_ptr gfx, + std::unique_ptr vertex_manager, + std::unique_ptr perf_query, + std::unique_ptr bounding_box); + + // For software and null backends. Allows overriding the default Renderer and Texture Cache + bool InitializeShared(std::unique_ptr gfx, + std::unique_ptr vertex_manager, + std::unique_ptr perf_query, + std::unique_ptr bounding_box, + std::unique_ptr renderer, + std::unique_ptr texture_cache); void ShutdownShared(); bool m_initialized = false;