11#pragma once
22#include < QWidget>
33#include < functional>
4- #include < memory>
54
65#include " gl/context.h"
76#include " screen_layout.hpp"
87#include " window_info.h"
98
10- // OpenGL widget for drawing the 3DS screen
9+ // Abstract screen widget for drawing the 3DS screen. We've got a child class for each graphics API (ScreenWidgetGL, ScreenWidgetMTL, ...)
1110class ScreenWidget : public QWidget {
1211 Q_OBJECT
1312
1413 public:
1514 using ResizeCallback = std::function<void (u32 , u32 )>;
1615
17- ScreenWidget (ResizeCallback resizeCallback, QWidget* parent = nullptr );
16+ enum class API { OpenGL, Metal, Vulkan };
17+
18+ ScreenWidget (API api, ResizeCallback resizeCallback, QWidget* parent = nullptr );
19+ virtual ~ScreenWidget () {}
20+
1821 void resizeEvent (QResizeEvent* event) override ;
19- // Called by the emulator thread for resizing the actual GL surface, since the emulator thread owns the GL context
20- void resizeSurface (u32 width, u32 height);
2122
22- GL::Context* getGLContext () { return glContext.get (); }
23+ virtual GL::Context* getGLContext () { return nullptr ; }
24+ virtual void * getMTKLayer () { return nullptr ; }
2325
2426 // Dimensions of our output surface
2527 u32 surfaceWidth = 0 ;
@@ -30,25 +32,33 @@ class ScreenWidget : public QWidget {
3032 u32 previousWidth = 0 ;
3133 u32 previousHeight = 0 ;
3234
33- // Coordinates (x/y/width/height) for the two screens in window space, used for properly handling touchscreen regardless
34- // of layout or resizing
35+ API api = API::OpenGL;
36+
37+ // Coordinates (x/y/width/height) for the two screens in window space, used for properly handling touchscreen
3538 ScreenLayout::WindowCoordinates screenCoordinates;
3639 // Screen layouts and sizes
3740 ScreenLayout::Layout screenLayout = ScreenLayout::Layout::Default;
3841 float topScreenSize = 0 .5f ;
3942
4043 void reloadScreenLayout (ScreenLayout::Layout newLayout, float newTopScreenSize);
4144
42- private:
43- std::unique_ptr<GL::Context> glContext = nullptr ;
45+ // Creates a screen widget depending on the graphics API we're using
46+ static ScreenWidget* getWidget (API api, ResizeCallback resizeCallback, QWidget* parent = nullptr );
47+
48+ // Called by the emulator thread on OpenGL for resizing the actual GL surface, since the emulator thread owns the GL context
49+ virtual void resizeSurface (u32 width, u32 height) {};
50+
51+ protected:
4452 ResizeCallback resizeCallback;
4553
46- bool createGLContext ();
54+ virtual bool createContext () = 0;
55+ virtual void resizeDisplay () = 0;
56+ std::optional<WindowInfo> getWindowInfo ();
4757
58+ private:
4859 qreal devicePixelRatioFromScreen () const ;
4960 int scaledWindowWidth () const ;
5061 int scaledWindowHeight () const ;
51- std::optional<WindowInfo> getWindowInfo ();
5262
5363 void reloadScreenCoordinates ();
5464};
0 commit comments