Abstract GSFrameBase class and callback

This commit is contained in:
Nekotekina 2014-08-25 02:23:26 +04:00
parent 50b5d72bb2
commit 84c5899faf
7 changed files with 94 additions and 109 deletions

View file

@ -1,80 +1,11 @@
#include "stdafx.h"
#include <wx/glcanvas.h>
#include "Gui/GLGSFrame.h"
#ifndef _WIN32
#include <dirent.h>
#endif
#include "rPlatform.h"
rCanvas::rCanvas(void *parent)
{
handle = static_cast<void*>(new wxGLCanvas(static_cast<wxWindow *>(parent),wxID_ANY,NULL));
}
rCanvas::~rCanvas()
{
delete static_cast<wxGLCanvas*>(handle);
}
bool rCanvas::SetCurrent(void *ctx)
{
return static_cast<wxGLCanvas*>(handle)->SetCurrent(*static_cast<wxGLContext *>(ctx));
}
rGLFrame::rGLFrame()
{
handle = static_cast<void*>(new GLGSFrame());
}
rGLFrame::~rGLFrame()
{
delete static_cast<GLGSFrame*>(handle);
}
void rGLFrame::Close()
{
static_cast<GLGSFrame*>(handle)->Close();
}
bool rGLFrame::IsShown()
{
return static_cast<GLGSFrame*>(handle)->IsShown();
}
void rGLFrame::Hide()
{
static_cast<GLGSFrame*>(handle)->Hide();
}
void rGLFrame::Show()
{
static_cast<GLGSFrame*>(handle)->Show();
}
void *rGLFrame::GetNewContext()
{
return static_cast<void *>(new wxGLContext(
static_cast<GLGSFrame*>(handle)->GetCanvas()
));
}
void rGLFrame::Flip(void *ctx)
{
static_cast<GLGSFrame*>(handle)->Flip(
static_cast<wxGLContext*>(ctx));
}
void rGLFrame::SetCurrent(void *ctx)
{
static_cast<GLGSFrame*>(handle)->GetCanvas()->SetCurrent(*static_cast<wxGLContext*>(ctx));
}
rImage::rImage()
{
handle = static_cast<void*>(new wxImage());

View file

@ -2,39 +2,8 @@
#include <vector>
#include <string>
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();
};

View file

@ -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)

View file

@ -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;

View file

@ -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();

View file

@ -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; }

View file

@ -17,6 +17,9 @@
#include "Emu/Io/XInput/XInputPadHandler.h"
#endif
#include "Emu/RSX/GL/GLGSRender.h"
#include "Gui/GLGSFrame.h"
#ifdef _WIN32
#include <wx/msw/wrapwin.h>
#endif
@ -103,6 +106,10 @@ bool Rpcs3App::OnInit()
return new NullPadHandler();
}
});
SetGetGSFrameCallback([]() -> GSFrameBase*
{
return new GLGSFrame();
});
TheApp = this;
SetAppName(_PRGNAME_);