video_core: Make global EmuWindow instance part of the base renderer …
…class Makes the global a member of the RendererBase class. We also change this to be a reference. Passing any form of null pointer to these functions is incorrect entirely, especially given the code itself assumes that the pointer would always be in a valid state. This also makes it easier to follow the lifecycle of instances being used, as we explicitly interact the renderer with the rasterizer, rather than it just operating on a global pointer.
This commit is contained in:
parent
b49d042200
commit
f61c9c3eb7
14 changed files with 49 additions and 54 deletions
|
@ -40,12 +40,12 @@ static bool IsVendorAmd() {
|
|||
return gpu_vendor == "ATI Technologies Inc." || gpu_vendor == "Advanced Micro Devices, Inc.";
|
||||
}
|
||||
|
||||
RasterizerOpenGL::RasterizerOpenGL()
|
||||
RasterizerOpenGL::RasterizerOpenGL(EmuWindow& window)
|
||||
: is_amd(IsVendorAmd()), shader_dirty(true),
|
||||
vertex_buffer(GL_ARRAY_BUFFER, VERTEX_BUFFER_SIZE, is_amd),
|
||||
uniform_buffer(GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE, false),
|
||||
index_buffer(GL_ELEMENT_ARRAY_BUFFER, INDEX_BUFFER_SIZE, false),
|
||||
texture_buffer(GL_TEXTURE_BUFFER, TEXTURE_BUFFER_SIZE, false) {
|
||||
texture_buffer(GL_TEXTURE_BUFFER, TEXTURE_BUFFER_SIZE, false), emu_window{window} {
|
||||
|
||||
allow_shadow = GLAD_GL_ARB_shader_image_load_store && GLAD_GL_ARB_shader_image_size &&
|
||||
GLAD_GL_ARB_framebuffer_no_attachments;
|
||||
|
|
|
@ -29,12 +29,13 @@
|
|||
#include "video_core/renderer_opengl/pica_to_gl.h"
|
||||
#include "video_core/shader/shader.h"
|
||||
|
||||
class EmuWindow;
|
||||
struct ScreenInfo;
|
||||
class ShaderProgramManager;
|
||||
|
||||
class RasterizerOpenGL : public VideoCore::RasterizerInterface {
|
||||
public:
|
||||
RasterizerOpenGL();
|
||||
explicit RasterizerOpenGL(EmuWindow& renderer);
|
||||
~RasterizerOpenGL() override;
|
||||
|
||||
void AddTriangle(const Pica::Shader::OutputVertex& v0, const Pica::Shader::OutputVertex& v1,
|
||||
|
@ -249,6 +250,8 @@ private:
|
|||
|
||||
RasterizerCacheOpenGL res_cache;
|
||||
|
||||
EmuWindow& emu_window;
|
||||
|
||||
std::vector<HardwareVertex> vertex_batch;
|
||||
|
||||
bool shader_dirty;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "core/memory.h"
|
||||
#include "core/settings.h"
|
||||
#include "video_core/pica_state.h"
|
||||
#include "video_core/renderer_base.h"
|
||||
#include "video_core/renderer_opengl/gl_rasterizer_cache.h"
|
||||
#include "video_core/renderer_opengl/gl_state.h"
|
||||
#include "video_core/utils.h"
|
||||
|
@ -77,7 +78,7 @@ constexpr auto RangeFromInterval(Map& map, const Interval& interval) {
|
|||
|
||||
static u16 GetResolutionScaleFactor() {
|
||||
return !Settings::values.resolution_factor
|
||||
? VideoCore::g_emu_window->GetFramebufferLayout().GetScalingRatio()
|
||||
? VideoCore::g_renderer->GetRenderWindow().GetFramebufferLayout().GetScalingRatio()
|
||||
: Settings::values.resolution_factor;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ static std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(const float width, cons
|
|||
return matrix;
|
||||
}
|
||||
|
||||
RendererOpenGL::RendererOpenGL() = default;
|
||||
RendererOpenGL::RendererOpenGL(EmuWindow& window) : RendererBase{window} {}
|
||||
RendererOpenGL::~RendererOpenGL() = default;
|
||||
|
||||
/// Swap buffers (render frame)
|
||||
|
@ -143,8 +143,8 @@ void RendererOpenGL::SwapBuffers() {
|
|||
Core::System::GetInstance().perf_stats.EndSystemFrame();
|
||||
|
||||
// Swap buffers
|
||||
render_window->PollEvents();
|
||||
render_window->SwapBuffers();
|
||||
render_window.PollEvents();
|
||||
render_window.SwapBuffers();
|
||||
|
||||
Core::System::GetInstance().frame_limiter.DoFrameLimiting(CoreTiming::GetGlobalTimeUs());
|
||||
Core::System::GetInstance().perf_stats.BeginSystemFrame();
|
||||
|
@ -390,7 +390,7 @@ void RendererOpenGL::DrawScreens() {
|
|||
0.0f);
|
||||
}
|
||||
|
||||
auto layout = render_window->GetFramebufferLayout();
|
||||
auto layout = render_window.GetFramebufferLayout();
|
||||
const auto& top_screen = layout.top_screen;
|
||||
const auto& bottom_screen = layout.bottom_screen;
|
||||
|
||||
|
@ -442,14 +442,6 @@ void RendererOpenGL::DrawScreens() {
|
|||
/// Updates the framerate
|
||||
void RendererOpenGL::UpdateFramerate() {}
|
||||
|
||||
/**
|
||||
* Set the emulator window to use for renderer
|
||||
* @param window EmuWindow handle to emulator window to use for rendering
|
||||
*/
|
||||
void RendererOpenGL::SetWindow(EmuWindow* window) {
|
||||
render_window = window;
|
||||
}
|
||||
|
||||
static const char* GetSource(GLenum source) {
|
||||
#define RET(s) \
|
||||
case GL_DEBUG_SOURCE_##s: \
|
||||
|
@ -506,7 +498,7 @@ static void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum
|
|||
|
||||
/// Initialize the renderer
|
||||
Core::System::ResultStatus RendererOpenGL::Init() {
|
||||
render_window->MakeCurrent();
|
||||
render_window.MakeCurrent();
|
||||
|
||||
if (GLAD_GL_KHR_debug) {
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
|
|
|
@ -34,18 +34,12 @@ struct ScreenInfo {
|
|||
|
||||
class RendererOpenGL : public RendererBase {
|
||||
public:
|
||||
RendererOpenGL();
|
||||
explicit RendererOpenGL(EmuWindow& window);
|
||||
~RendererOpenGL() override;
|
||||
|
||||
/// Swap buffers (render frame)
|
||||
void SwapBuffers() override;
|
||||
|
||||
/**
|
||||
* Set the emulator window to use for renderer
|
||||
* @param window EmuWindow handle to emulator window to use for rendering
|
||||
*/
|
||||
void SetWindow(EmuWindow* window) override;
|
||||
|
||||
/// Initialize the renderer
|
||||
Core::System::ResultStatus Init() override;
|
||||
|
||||
|
@ -66,8 +60,6 @@ private:
|
|||
// Fills active OpenGL texture with the given RGB color.
|
||||
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, const TextureInfo& texture);
|
||||
|
||||
EmuWindow* render_window; ///< Handle to render window
|
||||
|
||||
OpenGLState state;
|
||||
|
||||
// OpenGL object IDs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue