From 84c5899faf930af374ee5a2750d31ca70dabd859 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 25 Aug 2014 02:23:26 +0400 Subject: [PATCH] Abstract GSFrameBase class and callback --- Utilities/rPlatform.cpp | 69 --------------------------------- Utilities/rPlatform.h | 31 --------------- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 12 +++++- rpcs3/Emu/RSX/GL/GLGSRender.h | 25 +++++++++++- rpcs3/Gui/GLGSFrame.cpp | 43 +++++++++++++++++++- rpcs3/Gui/GLGSFrame.h | 16 ++++++-- rpcs3/rpcs3.cpp | 7 ++++ 7 files changed, 94 insertions(+), 109 deletions(-) diff --git a/Utilities/rPlatform.cpp b/Utilities/rPlatform.cpp index 2ae7340583..4ba72684ff 100644 --- a/Utilities/rPlatform.cpp +++ b/Utilities/rPlatform.cpp @@ -1,80 +1,11 @@ #include "stdafx.h" -#include -#include "Gui/GLGSFrame.h" - #ifndef _WIN32 #include #endif #include "rPlatform.h" -rCanvas::rCanvas(void *parent) -{ - handle = static_cast(new wxGLCanvas(static_cast(parent),wxID_ANY,NULL)); -} - -rCanvas::~rCanvas() -{ - delete static_cast(handle); -} - -bool rCanvas::SetCurrent(void *ctx) -{ - return static_cast(handle)->SetCurrent(*static_cast(ctx)); -} - - -rGLFrame::rGLFrame() -{ - handle = static_cast(new GLGSFrame()); -} - -rGLFrame::~rGLFrame() -{ - delete static_cast(handle); -} - -void rGLFrame::Close() -{ - static_cast(handle)->Close(); -} - -bool rGLFrame::IsShown() -{ - return static_cast(handle)->IsShown(); -} - -void rGLFrame::Hide() -{ - static_cast(handle)->Hide(); -} - -void rGLFrame::Show() -{ - static_cast(handle)->Show(); -} - - -void *rGLFrame::GetNewContext() -{ - return static_cast(new wxGLContext( - static_cast(handle)->GetCanvas() - )); -} - -void rGLFrame::Flip(void *ctx) -{ - static_cast(handle)->Flip( - static_cast(ctx)); -} - -void rGLFrame::SetCurrent(void *ctx) -{ - static_cast(handle)->GetCanvas()->SetCurrent(*static_cast(ctx)); -} - - rImage::rImage() { handle = static_cast(new wxImage()); diff --git a/Utilities/rPlatform.h b/Utilities/rPlatform.h index 32c6256291..716afd1db2 100644 --- a/Utilities/rPlatform.h +++ b/Utilities/rPlatform.h @@ -2,39 +2,8 @@ #include #include -struct rCanvas -{ - rCanvas(void *parent); - rCanvas(const rCanvas &) = delete; - ~rCanvas(); - /*rGLContext*/void *GetCurrent(); - bool SetCurrent(/*rGLContext &*/ void *ctx); - - void *handle; -}; - -struct rGLFrame -{ - rGLFrame(); - rGLFrame(const rGLFrame &) = delete; - ~rGLFrame(); - - void Close(); - bool IsShown(); - void Hide(); - void Show(); - - void *handle; - - void SetCurrent( void *ctx); - void *GetNewContext(); - void Flip(/*rGLContext*/void *ctx); -}; - struct rPlatform { - rGLFrame *getGLGSFrame(); - static rPlatform &getPlatform(); static std::string getConfigDir(); }; diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 23e72117cc..54549669c3 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -1,10 +1,18 @@ #include "stdafx.h" #include "rpcs3/Ini.h" +#include "Utilities/rPlatform.h" // only for rImage #include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "GLGSRender.h" +GetGSFrameCb GetGSFrame = nullptr; + +void SetGetGSFrameCallback(GetGSFrameCb value) +{ + GetGSFrame = value; +} + #define CMD_DEBUG 0 #define DUMP_VERTEX_DATA 0 @@ -767,13 +775,13 @@ GLGSRender::GLGSRender() , m_vp_buf_num(-1) , m_context(nullptr) { - m_frame = new rGLFrame();// new GLGSFrame(); + m_frame = GetGSFrame(); } GLGSRender::~GLGSRender() { m_frame->Close(); -// delete m_context; // This won't do anything (deleting void* instead of wglContext*) + m_frame->DeleteContext(m_context); } void GLGSRender::Enable(bool enable, const u32 cap) diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.h b/rpcs3/Emu/RSX/GL/GLGSRender.h index 1a26aeaa13..a598404c8a 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.h +++ b/rpcs3/Emu/RSX/GL/GLGSRender.h @@ -1,6 +1,5 @@ #pragma once #include "Emu/RSX/GSRender.h" -#include "Utilities/rPlatform.h" #include "GLBuffers.h" #include "GLProgramBuffer.h" @@ -110,6 +109,28 @@ public: void InitializeLocations(); }; +class GSFrameBase +{ +public: + GSFrameBase() {} + GSFrameBase(const GSFrameBase&) = delete; + virtual void Close() = 0; + + virtual bool IsShown() = 0; + virtual void Hide() = 0; + virtual void Show() = 0; + + virtual void* GetNewContext() = 0; + virtual void SetCurrent(void* ctx) = 0; + virtual void DeleteContext(void* ctx) = 0; + virtual void Flip(void* ctx) = 0; + +}; + +typedef GSFrameBase*(*GetGSFrameCb)(); + +void SetGetGSFrameCallback(GetGSFrameCb value); + class GLGSRender //TODO: find out why this used to inherit from wxWindow : //public wxWindow /*,*/ public GSRender @@ -136,7 +157,7 @@ private: void* m_context; public: - rGLFrame* m_frame; + GSFrameBase* m_frame; u32 m_draw_frames; u32 m_skip_frames; diff --git a/rpcs3/Gui/GLGSFrame.cpp b/rpcs3/Gui/GLGSFrame.cpp index 50c7c8a2db..a52c07be10 100644 --- a/rpcs3/Gui/GLGSFrame.cpp +++ b/rpcs3/Gui/GLGSFrame.cpp @@ -12,10 +12,49 @@ GLGSFrame::GLGSFrame() canvas->Bind(wxEVT_LEFT_DCLICK, &GSFrame::OnLeftDclick, this); } -void GLGSFrame::Flip(wxGLContext *context) +GLGSFrame::~GLGSFrame() +{ +} + +void GLGSFrame::Close() +{ + GSFrame::Close(); +} + +bool GLGSFrame::IsShown() +{ + return GSFrame::IsShown(); +} + +void GLGSFrame::Hide() +{ + GSFrame::Hide(); +} + +void GLGSFrame::Show() +{ + GSFrame::Show(); +} + +void* GLGSFrame::GetNewContext() +{ + return new wxGLContext(GetCanvas()); +} + +void GLGSFrame::SetCurrent(void* ctx) +{ + GetCanvas()->SetCurrent(*(wxGLContext*)ctx); +} + +void GLGSFrame::DeleteContext(void* ctx) +{ + delete (wxGLContext*)ctx; +} + +void GLGSFrame::Flip(void* context) { if (!canvas) return; - canvas->SetCurrent(*context); + canvas->SetCurrent(*(wxGLContext*)context); static Timer fps_t; canvas->SwapBuffers(); diff --git a/rpcs3/Gui/GLGSFrame.h b/rpcs3/Gui/GLGSFrame.h index acbc06cccc..a832453326 100644 --- a/rpcs3/Gui/GLGSFrame.h +++ b/rpcs3/Gui/GLGSFrame.h @@ -1,16 +1,26 @@ #pragma once #include "wx/glcanvas.h" #include "Gui/GSFrame.h" +#include "Emu/RSX/GL/GLGSRender.h" -struct GLGSFrame : public GSFrame +struct GLGSFrame : public GSFrame, public GSFrameBase { wxGLCanvas* canvas; u32 m_frames; GLGSFrame(); - ~GLGSFrame() {} + ~GLGSFrame(); - void Flip(wxGLContext *context); + virtual void Close() override; + + virtual bool IsShown() override; + virtual void Hide() override; + virtual void Show() override; + + virtual void* GetNewContext() override; + virtual void SetCurrent(void* ctx) override; + virtual void DeleteContext(void* ctx) override; + virtual void Flip(void* context) override; wxGLCanvas* GetCanvas() const { return canvas; } diff --git a/rpcs3/rpcs3.cpp b/rpcs3/rpcs3.cpp index cc46d0ef39..a9986ff45a 100644 --- a/rpcs3/rpcs3.cpp +++ b/rpcs3/rpcs3.cpp @@ -17,6 +17,9 @@ #include "Emu/Io/XInput/XInputPadHandler.h" #endif +#include "Emu/RSX/GL/GLGSRender.h" +#include "Gui/GLGSFrame.h" + #ifdef _WIN32 #include #endif @@ -103,6 +106,10 @@ bool Rpcs3App::OnInit() return new NullPadHandler(); } }); + SetGetGSFrameCallback([]() -> GSFrameBase* + { + return new GLGSFrame(); + }); TheApp = this; SetAppName(_PRGNAME_);