diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index c3c6207f2c..cb1ea4298d 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -3,6 +3,13 @@ #include #include +GetGSFrameCb2 GetGSFrame = nullptr; + +void SetGetD3DGSFrameCallback(GetGSFrameCb2 value) +{ + GetGSFrame = value; +} + static void check(HRESULT hr) { if (hr != 0) @@ -30,6 +37,9 @@ D3D12GSRender::D3D12GSRender() graphicQueueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT; check(m_device->CreateCommandQueue(©QueueDesc, IID_PPV_ARGS(&m_commandQueueCopy))); check(m_device->CreateCommandQueue(&graphicQueueDesc, IID_PPV_ARGS(&m_commandQueueGraphic))); + + GSFrameBase2 *tmp = GetGSFrame(); + tmp->Show(); } D3D12GSRender::~D3D12GSRender() @@ -47,15 +57,15 @@ void D3D12GSRender::Close() void D3D12GSRender::InitDrawBuffers() { - // if (!m_fbo.IsCreated() || RSXThread::m_width != last_width || RSXThread::m_height != last_height || last_depth_format != m_surface_depth_format) + if (!m_fbo.IsCreated() || RSXThread::m_width != m_lastWidth || RSXThread::m_height != m_lastHeight || m_lastDepth != m_surface_depth_format) { - /* + LOG_WARNING(RSX, "New FBO (%dx%d)", RSXThread::m_width, RSXThread::m_height); - last_width = RSXThread::m_width; - last_height = RSXThread::m_height; - last_depth_format = m_surface_depth_format; + m_lastWidth = RSXThread::m_width; + m_lastHeight = RSXThread::m_height; + m_lastDepth = m_surface_depth_format; - m_fbo.Create(); +/* m_fbo.Create(); checkForGlError("m_fbo.Create"); m_fbo.Bind(); diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index a8c1c43d67..4439ed8f47 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -16,6 +16,28 @@ #pragma comment (lib, "dxgi.lib") #pragma comment (lib, "d3dcompiler.lib") +class GSFrameBase2 +{ +public: + GSFrameBase2() {} + GSFrameBase2(const GSFrameBase2&) = 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 GSFrameBase2*(*GetGSFrameCb2)(); + +void SetGetD3DGSFrameCallback(GetGSFrameCb2 value); + class D3D12GSRender //TODO: find out why this used to inherit from wxWindow : //public wxWindow @@ -44,6 +66,8 @@ private: ID3D12CommandQueue *m_commandQueueCopy; ID3D12CommandQueue *m_commandQueueGraphic; + size_t m_lastWidth, m_lastHeight, m_lastDepth; + void* m_context; public: diff --git a/rpcs3/Gui/D3DGSFrame.cpp b/rpcs3/Gui/D3DGSFrame.cpp new file mode 100644 index 0000000000..6d38812a8e --- /dev/null +++ b/rpcs3/Gui/D3DGSFrame.cpp @@ -0,0 +1,95 @@ +#include "stdafx_gui.h" +#include "Emu/Memory/Memory.h" +#include "Emu/System.h" +#include "D3DGSFrame.h" +#include "Utilities/Timer.h" + +D3DGSFrame::D3DGSFrame() + : GSFrame(nullptr, "GSFrame[OpenGL]") + , m_frames(0) +{ + canvas = new wxWindow(this, wxID_ANY); + canvas->SetSize(GetClientSize()); + + canvas->Bind(wxEVT_LEFT_DCLICK, &GSFrame::OnLeftDclick, this); +} + +D3DGSFrame::~D3DGSFrame() +{ +} + +void D3DGSFrame::Close() +{ + GSFrame::Close(); +} + +bool D3DGSFrame::IsShown() +{ + return GSFrame::IsShown(); +} + +void D3DGSFrame::Hide() +{ + GSFrame::Hide(); +} + +void D3DGSFrame::Show() +{ + GSFrame::Show(); +} + +void* D3DGSFrame::GetNewContext() +{ + return nullptr;//new wxGLContext(GetCanvas()); +} + +void D3DGSFrame::SetCurrent(void* ctx) +{ +// GetCanvas()->SetCurrent(*(wxGLContext*)ctx); +} + +void D3DGSFrame::DeleteContext(void* ctx) +{ +// delete (wxGLContext*)ctx; +} + +void D3DGSFrame::Flip(void* context) +{ + if (!canvas) return; +// canvas->SetCurrent(*(wxGLContext*)context); + + static Timer fps_t; +// canvas->SwapBuffers(); + m_frames++; + + const std::string sub_title = Emu.GetTitle() + (Emu.GetTitleID().length() ? " [" + Emu.GetTitleID() + "] | " : " | "); + + if (fps_t.GetElapsedTimeInSec() >= 0.5) + { + // can freeze on exit + SetTitle(wxString(sub_title.c_str(), wxConvUTF8) + wxString::Format("FPS: %.2f", (double)m_frames / fps_t.GetElapsedTimeInSec())); + m_frames = 0; + fps_t.Start(); + } +} + +void D3DGSFrame::OnSize(wxSizeEvent& event) +{ + if (canvas) canvas->SetSize(GetClientSize()); + event.Skip(); +} + +void D3DGSFrame::SetViewport(int x, int y, u32 w, u32 h) +{ + /* + //ConLog.Warning("SetViewport(x=%d, y=%d, w=%d, h=%d)", x, y, w, h); + + const wxSize client = GetClientSize(); + const wxSize viewport = AspectRatio(client, wxSize(w, h)); + + const int vx = (client.GetX() - viewport.GetX()) / 2; + const int vy = (client.GetY() - viewport.GetY()) / 2; + + glViewport(vx + x, vy + y, viewport.GetWidth(), viewport.GetHeight()); + */ +} \ No newline at end of file diff --git a/rpcs3/Gui/D3DGSFrame.h b/rpcs3/Gui/D3DGSFrame.h new file mode 100644 index 0000000000..4925eeb7fa --- /dev/null +++ b/rpcs3/Gui/D3DGSFrame.h @@ -0,0 +1,31 @@ +#pragma once +#include "Emu/RSX/D3D12/D3D12GSRender.h" +#include "Gui/GSFrame.h" +#include "wx/window.h" + +struct D3DGSFrame : public GSFrame, public GSFrameBase2 +{ + wxWindow* canvas; + u32 m_frames; + + D3DGSFrame(); + ~D3DGSFrame(); + + 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; + + wxWindow* GetCanvas() const { return canvas; } + + virtual void SetViewport(int x, int y, u32 w, u32 h); + +private: + virtual void OnSize(wxSizeEvent& event); +}; \ No newline at end of file diff --git a/rpcs3/Gui/GLGSFrame.cpp b/rpcs3/Gui/GLGSFrame.cpp index 899b2de32d..a5419f5c3f 100644 --- a/rpcs3/Gui/GLGSFrame.cpp +++ b/rpcs3/Gui/GLGSFrame.cpp @@ -3,6 +3,7 @@ #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "GLGSFrame.h" +#include "D3DGSFrame.h" #include "Utilities/Timer.h" GLGSFrame::GLGSFrame() diff --git a/rpcs3/rpcs3.cpp b/rpcs3/rpcs3.cpp index 20a5c9d01f..69757d3786 100644 --- a/rpcs3/rpcs3.cpp +++ b/rpcs3/rpcs3.cpp @@ -26,6 +26,7 @@ #include "Gui/SaveDataDialog.h" #include "Gui/GLGSFrame.h" +#include "Gui/D3DGSFrame.h" #include #ifdef _WIN32 @@ -137,6 +138,11 @@ bool Rpcs3App::OnInit() return new GLGSFrame(); }); + SetGetD3DGSFrameCallback([]() ->GSFrameBase2* + { + return new D3DGSFrame(); + }); + g_msg_dialog.reset(new MsgDialogFrame); g_savedata_dialog.reset(new SaveDataDialogFrame); diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index f2e3fd3df3..648a0d7e93 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -177,6 +177,7 @@ + @@ -218,6 +219,7 @@ + diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index f1b37ef93a..a5efe10e7e 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -102,6 +102,9 @@ Gui + + Gui + @@ -207,6 +210,9 @@ Gui + + Gui +