Merge pull request #892 from lioncash/global

video_core: Make global EmuWindow instance part of the base renderer …
merge-requests/60/head
bunnei 2018-08-03 00:31:32 +07:00 committed by GitHub
commit 00ba704a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 54 additions and 64 deletions

@ -84,7 +84,7 @@ System::ResultStatus System::SingleStep() {
return RunLoop(false); return RunLoop(false);
} }
System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& filepath) { System::ResultStatus System::Load(EmuWindow& emu_window, const std::string& filepath) {
app_loader = Loader::GetLoader(std::make_shared<FileSys::RealVfsFile>(filepath)); app_loader = Loader::GetLoader(std::make_shared<FileSys::RealVfsFile>(filepath));
if (!app_loader) { if (!app_loader) {
@ -161,7 +161,7 @@ Cpu& System::CpuCore(size_t core_index) {
return *cpu_cores[core_index]; return *cpu_cores[core_index];
} }
System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { System::ResultStatus System::Init(EmuWindow& emu_window, u32 system_mode) {
LOG_DEBUG(HW_Memory, "initialized OK"); LOG_DEBUG(HW_Memory, "initialized OK");
CoreTiming::Init(); CoreTiming::Init();

@ -81,11 +81,12 @@ public:
/** /**
* Load an executable application. * Load an executable application.
* @param emu_window Pointer to the host-system window used for video output and keyboard input. * @param emu_window Reference to the host-system window used for video output and keyboard
* input.
* @param filepath String path to the executable application to load on the host file system. * @param filepath String path to the executable application to load on the host file system.
* @returns ResultStatus code, indicating if the operation succeeded. * @returns ResultStatus code, indicating if the operation succeeded.
*/ */
ResultStatus Load(EmuWindow* emu_window, const std::string& filepath); ResultStatus Load(EmuWindow& emu_window, const std::string& filepath);
/** /**
* Indicates if the emulated system is powered on (all subsystems initialized and able to run an * Indicates if the emulated system is powered on (all subsystems initialized and able to run an
@ -186,11 +187,12 @@ private:
/** /**
* Initialize the emulated system. * Initialize the emulated system.
* @param emu_window Pointer to the host-system window used for video output and keyboard input. * @param emu_window Reference to the host-system window used for video output and keyboard
* input.
* @param system_mode The system mode. * @param system_mode The system mode.
* @return ResultStatus code, indicating if the operation succeeded. * @return ResultStatus code, indicating if the operation succeeded.
*/ */
ResultStatus Init(EmuWindow* emu_window, u32 system_mode); ResultStatus Init(EmuWindow& emu_window, u32 system_mode);
/// AppLoader used to load the current executing application /// AppLoader used to load the current executing application
std::unique_ptr<Loader::AppLoader> app_loader; std::unique_ptr<Loader::AppLoader> app_loader;

@ -5,10 +5,9 @@
#include "core/gdbstub/gdbstub.h" #include "core/gdbstub/gdbstub.h"
#include "core/hle/service/hid/hid.h" #include "core/hle/service/hid/hid.h"
#include "core/settings.h" #include "core/settings.h"
#include "video_core/renderer_base.h"
#include "video_core/video_core.h" #include "video_core/video_core.h"
#include "core/frontend/emu_window.h"
namespace Settings { namespace Settings {
Values values = {}; Values values = {};
@ -20,9 +19,8 @@ void Apply() {
VideoCore::g_toggle_framelimit_enabled = values.toggle_framelimit; VideoCore::g_toggle_framelimit_enabled = values.toggle_framelimit;
if (VideoCore::g_emu_window) { if (VideoCore::g_renderer) {
auto layout = VideoCore::g_emu_window->GetFramebufferLayout(); VideoCore::g_renderer->UpdateCurrentFramebufferLayout();
VideoCore::g_emu_window->UpdateCurrentFramebufferLayout(layout.width, layout.height);
} }
Service::HID::ReloadInputDevices(); Service::HID::ReloadInputDevices();

@ -2,14 +2,22 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <atomic>
#include <memory> #include <memory>
#include "core/frontend/emu_window.h"
#include "video_core/renderer_base.h" #include "video_core/renderer_base.h"
#include "video_core/renderer_opengl/gl_rasterizer.h" #include "video_core/renderer_opengl/gl_rasterizer.h"
#include "video_core/video_core.h"
RendererBase::RendererBase(EmuWindow& window) : render_window{window} {}
RendererBase::~RendererBase() = default;
void RendererBase::UpdateCurrentFramebufferLayout() {
const Layout::FramebufferLayout& layout = render_window.GetFramebufferLayout();
render_window.UpdateCurrentFramebufferLayout(layout.width, layout.height);
}
void RendererBase::RefreshRasterizerSetting() { void RendererBase::RefreshRasterizerSetting() {
if (rasterizer == nullptr) { if (rasterizer == nullptr) {
rasterizer = std::make_unique<RasterizerOpenGL>(); rasterizer = std::make_unique<RasterizerOpenGL>(render_window);
} }
} }

@ -18,23 +18,21 @@ public:
/// Used to reference a framebuffer /// Used to reference a framebuffer
enum kFramebuffer { kFramebuffer_VirtualXFB = 0, kFramebuffer_EFB, kFramebuffer_Texture }; enum kFramebuffer { kFramebuffer_VirtualXFB = 0, kFramebuffer_EFB, kFramebuffer_Texture };
virtual ~RendererBase() {} explicit RendererBase(EmuWindow& window);
virtual ~RendererBase();
/// Swap buffers (render frame) /// Swap buffers (render frame)
virtual void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) = 0; virtual void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) = 0;
/**
* Set the emulator window to use for renderer
* @param window EmuWindow handle to emulator window to use for rendering
*/
virtual void SetWindow(EmuWindow* window) = 0;
/// Initialize the renderer /// Initialize the renderer
virtual bool Init() = 0; virtual bool Init() = 0;
/// Shutdown the renderer /// Shutdown the renderer
virtual void ShutDown() = 0; virtual void ShutDown() = 0;
/// Updates the framebuffer layout of the contained render window handle.
void UpdateCurrentFramebufferLayout();
// Getter/setter functions: // Getter/setter functions:
// ------------------------ // ------------------------
@ -53,9 +51,8 @@ public:
void RefreshRasterizerSetting(); void RefreshRasterizerSetting();
protected: protected:
EmuWindow& render_window; ///< Reference to the render window handle.
std::unique_ptr<VideoCore::RasterizerInterface> rasterizer; std::unique_ptr<VideoCore::RasterizerInterface> rasterizer;
f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer f32 m_current_fps = 0.0f; ///< Current framerate, should be set by the renderer
int m_current_frame = 0; ///< Current frame, should be set by the renderer int m_current_frame = 0; ///< Current frame, should be set by the renderer
private:
}; };

@ -14,7 +14,6 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/math_util.h" #include "common/math_util.h"
#include "common/microprofile.h" #include "common/microprofile.h"
#include "common/scope_exit.h"
#include "core/core.h" #include "core/core.h"
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
@ -37,7 +36,7 @@ MICROPROFILE_DEFINE(OpenGL_Drawing, "OpenGL", "Drawing", MP_RGB(128, 128, 192));
MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255)); MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255));
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100)); MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
RasterizerOpenGL::RasterizerOpenGL() { RasterizerOpenGL::RasterizerOpenGL(EmuWindow& window) : emu_window{window} {
// Create sampler objects // Create sampler objects
for (size_t i = 0; i < texture_samplers.size(); ++i) { for (size_t i = 0; i < texture_samplers.size(); ++i) {
texture_samplers[i].Create(); texture_samplers[i].Create();
@ -395,7 +394,7 @@ void RasterizerOpenGL::Clear() {
if (clear_mask == 0) if (clear_mask == 0)
return; return;
ScopeAcquireGLContext acquire_context; ScopeAcquireGLContext acquire_context{emu_window};
auto [dirty_color_surface, dirty_depth_surface] = auto [dirty_color_surface, dirty_depth_surface] =
ConfigureFramebuffers(use_color_fb, use_depth_fb); ConfigureFramebuffers(use_color_fb, use_depth_fb);
@ -425,7 +424,7 @@ void RasterizerOpenGL::DrawArrays() {
MICROPROFILE_SCOPE(OpenGL_Drawing); MICROPROFILE_SCOPE(OpenGL_Drawing);
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
ScopeAcquireGLContext acquire_context; ScopeAcquireGLContext acquire_context{emu_window};
auto [dirty_color_surface, dirty_depth_surface] = auto [dirty_color_surface, dirty_depth_surface] =
ConfigureFramebuffers(true, regs.zeta.Address() != 0 && regs.zeta_enable != 0); ConfigureFramebuffers(true, regs.zeta.Address() != 0 && regs.zeta_enable != 0);

@ -21,11 +21,12 @@
#include "video_core/renderer_opengl/gl_state.h" #include "video_core/renderer_opengl/gl_state.h"
#include "video_core/renderer_opengl/gl_stream_buffer.h" #include "video_core/renderer_opengl/gl_stream_buffer.h"
class EmuWindow;
struct ScreenInfo; struct ScreenInfo;
class RasterizerOpenGL : public VideoCore::RasterizerInterface { class RasterizerOpenGL : public VideoCore::RasterizerInterface {
public: public:
RasterizerOpenGL(); explicit RasterizerOpenGL(EmuWindow& renderer);
~RasterizerOpenGL() override; ~RasterizerOpenGL() override;
void DrawArrays() override; void DrawArrays() override;
@ -144,6 +145,8 @@ private:
RasterizerCacheOpenGL res_cache; RasterizerCacheOpenGL res_cache;
EmuWindow& emu_window;
std::unique_ptr<GLShader::ProgramManager> shader_program_manager; std::unique_ptr<GLShader::ProgramManager> shader_program_manager;
OGLVertexArray sw_vao; OGLVertexArray sw_vao;
OGLVertexArray hw_vao; OGLVertexArray hw_vao;

@ -92,23 +92,23 @@ static std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(const float width, cons
return matrix; return matrix;
} }
ScopeAcquireGLContext::ScopeAcquireGLContext() { ScopeAcquireGLContext::ScopeAcquireGLContext(EmuWindow& emu_window_) : emu_window{emu_window_} {
if (Settings::values.use_multi_core) { if (Settings::values.use_multi_core) {
VideoCore::g_emu_window->MakeCurrent(); emu_window.MakeCurrent();
} }
} }
ScopeAcquireGLContext::~ScopeAcquireGLContext() { ScopeAcquireGLContext::~ScopeAcquireGLContext() {
if (Settings::values.use_multi_core) { if (Settings::values.use_multi_core) {
VideoCore::g_emu_window->DoneCurrent(); emu_window.DoneCurrent();
} }
} }
RendererOpenGL::RendererOpenGL() = default; RendererOpenGL::RendererOpenGL(EmuWindow& window) : RendererBase{window} {}
RendererOpenGL::~RendererOpenGL() = default; RendererOpenGL::~RendererOpenGL() = default;
/// Swap buffers (render frame) /// Swap buffers (render frame)
void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) { void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) {
ScopeAcquireGLContext acquire_context; ScopeAcquireGLContext acquire_context{render_window};
Core::System::GetInstance().perf_stats.EndSystemFrame(); Core::System::GetInstance().perf_stats.EndSystemFrame();
@ -130,10 +130,10 @@ void RendererOpenGL::SwapBuffers(boost::optional<const Tegra::FramebufferConfig&
// Load the framebuffer from memory, draw it to the screen, and swap buffers // Load the framebuffer from memory, draw it to the screen, and swap buffers
LoadFBToScreenInfo(*framebuffer, screen_info); LoadFBToScreenInfo(*framebuffer, screen_info);
DrawScreen(); DrawScreen();
render_window->SwapBuffers(); render_window.SwapBuffers();
} }
render_window->PollEvents(); render_window.PollEvents();
Core::System::GetInstance().frame_limiter.DoFrameLimiting(CoreTiming::GetGlobalTimeUs()); Core::System::GetInstance().frame_limiter.DoFrameLimiting(CoreTiming::GetGlobalTimeUs());
Core::System::GetInstance().perf_stats.BeginSystemFrame(); Core::System::GetInstance().perf_stats.BeginSystemFrame();
@ -356,7 +356,7 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
* Draws the emulated screens to the emulator window. * Draws the emulated screens to the emulator window.
*/ */
void RendererOpenGL::DrawScreen() { void RendererOpenGL::DrawScreen() {
const auto& layout = render_window->GetFramebufferLayout(); const auto& layout = render_window.GetFramebufferLayout();
const auto& screen = layout.screen; const auto& screen = layout.screen;
glViewport(0, 0, layout.width, layout.height); glViewport(0, 0, layout.width, layout.height);
@ -380,14 +380,6 @@ void RendererOpenGL::DrawScreen() {
/// Updates the framerate /// Updates the framerate
void RendererOpenGL::UpdateFramerate() {} 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) { static const char* GetSource(GLenum source) {
#define RET(s) \ #define RET(s) \
case GL_DEBUG_SOURCE_##s: \ case GL_DEBUG_SOURCE_##s: \
@ -445,7 +437,7 @@ static void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum
/// Initialize the renderer /// Initialize the renderer
bool RendererOpenGL::Init() { bool RendererOpenGL::Init() {
ScopeAcquireGLContext acquire_context; ScopeAcquireGLContext acquire_context{render_window};
if (GLAD_GL_KHR_debug) { if (GLAD_GL_KHR_debug) {
glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT);

@ -34,24 +34,21 @@ struct ScreenInfo {
/// Helper class to acquire/release OpenGL context within a given scope /// Helper class to acquire/release OpenGL context within a given scope
class ScopeAcquireGLContext : NonCopyable { class ScopeAcquireGLContext : NonCopyable {
public: public:
ScopeAcquireGLContext(); explicit ScopeAcquireGLContext(EmuWindow& window);
~ScopeAcquireGLContext(); ~ScopeAcquireGLContext();
private:
EmuWindow& emu_window;
}; };
class RendererOpenGL : public RendererBase { class RendererOpenGL : public RendererBase {
public: public:
RendererOpenGL(); explicit RendererOpenGL(EmuWindow& window);
~RendererOpenGL() override; ~RendererOpenGL() override;
/// Swap buffers (render frame) /// Swap buffers (render frame)
void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) override; void SwapBuffers(boost::optional<const Tegra::FramebufferConfig&> framebuffer) 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 /// Initialize the renderer
bool Init() override; bool Init() override;
@ -72,8 +69,6 @@ private:
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a, void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
const TextureInfo& texture); const TextureInfo& texture);
EmuWindow* render_window; ///< Handle to render window
OpenGLState state; OpenGLState state;
// OpenGL object IDs // OpenGL object IDs

@ -13,16 +13,13 @@
namespace VideoCore { namespace VideoCore {
EmuWindow* g_emu_window = nullptr; ///< Frontend emulator window
std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin
std::atomic<bool> g_toggle_framelimit_enabled; std::atomic<bool> g_toggle_framelimit_enabled;
/// Initialize the video core /// Initialize the video core
bool Init(EmuWindow* emu_window) { bool Init(EmuWindow& emu_window) {
g_emu_window = emu_window; g_renderer = std::make_unique<RendererOpenGL>(emu_window);
g_renderer = std::make_unique<RendererOpenGL>();
g_renderer->SetWindow(g_emu_window);
if (g_renderer->Init()) { if (g_renderer->Init()) {
LOG_DEBUG(Render, "initialized OK"); LOG_DEBUG(Render, "initialized OK");
} else { } else {

@ -18,7 +18,6 @@ namespace VideoCore {
enum class Renderer { Software, OpenGL }; enum class Renderer { Software, OpenGL };
extern std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin extern std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin
extern EmuWindow* g_emu_window; ///< Emu window
// TODO: Wrap these in a user settings struct along with any other graphics settings (often set from // TODO: Wrap these in a user settings struct along with any other graphics settings (often set from
// qt ui) // qt ui)
@ -28,7 +27,7 @@ extern std::atomic<bool> g_toggle_framelimit_enabled;
void Start(); void Start();
/// Initialize the video core /// Initialize the video core
bool Init(EmuWindow* emu_window); bool Init(EmuWindow& emu_window);
/// Shutdown the video core /// Shutdown the video core
void Shutdown(); void Shutdown();

@ -402,7 +402,7 @@ bool GMainWindow::LoadROM(const QString& filename) {
system.SetGPUDebugContext(debug_context); system.SetGPUDebugContext(debug_context);
const Core::System::ResultStatus result{system.Load(render_window, filename.toStdString())}; const Core::System::ResultStatus result{system.Load(*render_window, filename.toStdString())};
render_window->DoneCurrent(); render_window->DoneCurrent();

@ -162,7 +162,7 @@ int main(int argc, char** argv) {
SCOPE_EXIT({ system.Shutdown(); }); SCOPE_EXIT({ system.Shutdown(); });
const Core::System::ResultStatus load_result{system.Load(emu_window.get(), filepath)}; const Core::System::ResultStatus load_result{system.Load(*emu_window, filepath)};
switch (load_result) { switch (load_result) {
case Core::System::ResultStatus::ErrorGetLoader: case Core::System::ResultStatus::ErrorGetLoader: