Renderer: Add a base Initialize() method to match Shutdown()

This commit is contained in:
Stenzek 2018-02-09 20:52:25 +10:00
parent 38479dd783
commit 1adcd47dcb
10 changed files with 51 additions and 28 deletions

View file

@ -161,7 +161,8 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
D3D::InitUtils();
BBox::Init();
return true;
return g_renderer->Initialize();
}
void VideoBackend::Shutdown()

View file

@ -64,7 +64,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
g_framebuffer_manager = std::make_unique<FramebufferManagerBase>();
g_texture_cache = std::make_unique<TextureCache>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
return g_shader_cache->Initialize();
return g_renderer->Initialize() && g_shader_cache->Initialize();
}
void VideoBackend::Shutdown()

View file

@ -811,6 +811,23 @@ bool Renderer::IsHeadless() const
return m_main_gl_context->IsHeadless();
}
bool Renderer::Initialize()
{
if (!::Renderer::Initialize())
return false;
// Initialize the FramebufferManager
g_framebuffer_manager = std::make_unique<FramebufferManager>(
m_target_width, m_target_height, s_MSAASamples, BoundingBox::NeedsStencilBuffer());
m_current_framebuffer_width = m_target_width;
m_current_framebuffer_height = m_target_height;
m_post_processor = std::make_unique<OpenGLPostProcessing>();
s_raster_font = std::make_unique<RasterFont>();
return true;
}
void Renderer::Shutdown()
{
::Renderer::Shutdown();
@ -822,18 +839,6 @@ void Renderer::Shutdown()
m_post_processor.reset();
}
void Renderer::Init()
{
// Initialize the FramebufferManager
g_framebuffer_manager = std::make_unique<FramebufferManager>(
m_target_width, m_target_height, s_MSAASamples, BoundingBox::NeedsStencilBuffer());
m_current_framebuffer_width = m_target_width;
m_current_framebuffer_height = m_target_height;
m_post_processor = std::make_unique<OpenGLPostProcessing>();
s_raster_font = std::make_unique<RasterFont>();
}
std::unique_ptr<AbstractTexture> Renderer::CreateTexture(const TextureConfig& config)
{
return std::make_unique<OGLTexture>(config);

View file

@ -88,7 +88,7 @@ public:
bool IsHeadless() const override;
void Init();
bool Initialize() override;
void Shutdown() override;
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;

View file

@ -179,7 +179,8 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
g_texture_cache = std::make_unique<TextureCache>();
g_sampler_cache = std::make_unique<SamplerCache>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
static_cast<Renderer*>(g_renderer.get())->Init();
if (!g_renderer->Initialize())
return false;
TextureConverter::Init();
BoundingBox::Init(g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight());
return g_shader_cache->Initialize();

View file

@ -95,7 +95,7 @@ bool VideoSoftware::Initialize(const WindowSystemInfo& wsi)
g_perf_query = std::make_unique<PerfQuery>();
g_texture_cache = std::make_unique<TextureCache>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
return g_shader_cache->Initialize();
return g_renderer->Initialize() && g_shader_cache->Initialize();
}
void VideoSoftware::Shutdown()

View file

@ -57,13 +57,7 @@ Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain)
m_sampler_states[i].hex = RenderState::GetPointSamplerState().hex;
}
Renderer::~Renderer()
{
UpdateActiveConfig();
DestroyShaders();
DestroySemaphores();
}
Renderer::~Renderer() = default;
Renderer* Renderer::GetInstance()
{
@ -77,6 +71,9 @@ bool Renderer::IsHeadless() const
bool Renderer::Initialize()
{
if (!::Renderer::Initialize())
return false;
BindEFBToStateTracker();
if (!CreateSemaphores())
@ -131,6 +128,18 @@ bool Renderer::Initialize()
return true;
}
void Renderer::Shutdown()
{
::Renderer::Shutdown();
// Submit the current command buffer, in case there's a partial frame.
StateTracker::GetInstance()->EndRenderPass();
g_command_buffer_mgr->ExecuteCommandBuffer(false, true);
DestroyShaders();
DestroySemaphores();
}
bool Renderer::CreateSemaphores()
{
// Create two semaphores, one that is triggered when the swapchain buffer is ready, another after

View file

@ -37,6 +37,9 @@ public:
bool IsHeadless() const override;
bool Initialize() override;
void Shutdown() override;
std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) override;
std::unique_ptr<AbstractStagingTexture>
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override;
@ -52,8 +55,6 @@ public:
SwapChain* GetSwapChain() const { return m_swap_chain.get(); }
BoundingBox* GetBoundingBox() const { return m_bounding_box.get(); }
bool Initialize();
void RenderText(const std::string& pstr, int left, int top, u32 color) override;
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override;

View file

@ -93,6 +93,11 @@ Renderer::Renderer(int backbuffer_width, int backbuffer_height)
Renderer::~Renderer() = default;
bool Renderer::Initialize()
{
return true;
}
void Renderer::Shutdown()
{
// First stop any framedumping, which might need to dump the last xfb frame. This process

View file

@ -79,6 +79,9 @@ public:
virtual bool IsHeadless() const = 0;
virtual bool Initialize();
virtual void Shutdown();
virtual void SetPipeline(const AbstractPipeline* pipeline) {}
virtual void SetScissorRect(const MathUtil::Rectangle<int>& rc) {}
virtual void SetTexture(u32 index, const AbstractTexture* texture) {}
@ -188,8 +191,6 @@ public:
virtual std::unique_ptr<VideoCommon::AsyncShaderCompiler> CreateAsyncShaderCompiler();
virtual void Shutdown();
// Drawing utility shaders.
virtual void DrawUtilityPipeline(const void* uniforms, u32 uniforms_size, const void* vertices,
u32 vertex_stride, u32 num_vertices)