comparison Framework/Viewport/SdlViewport.h @ 905:88bf49aebc13

introduced ICompositor and allow SdlViewport to work with a CairoCompositor (to run on machines without OpenGL drivers)
author Alain Mazy <alain@mazy.be>
date Wed, 17 Jul 2019 16:56:53 +0200
parents 0c5201499af8
children 722ee73e6ba2
comparison
equal deleted inserted replaced
904:ecdb2ceaa925 905:88bf49aebc13
36 # error Support for OpenGL is disabled 36 # error Support for OpenGL is disabled
37 #endif 37 #endif
38 38
39 #include "../../Applications/Sdl/SdlOpenGLContext.h" 39 #include "../../Applications/Sdl/SdlOpenGLContext.h"
40 #include "../Scene2D/OpenGLCompositor.h" 40 #include "../Scene2D/OpenGLCompositor.h"
41 #include "../Scene2D/CairoCompositor.h"
41 #include "ViewportBase.h" 42 #include "ViewportBase.h"
42 43
43 namespace OrthancStone 44 namespace OrthancStone
44 { 45 {
45 class SdlViewport : public ViewportBase 46 class SdlViewport : public ViewportBase
46 { 47 {
48 public:
49 SdlViewport(const std::string& identifier)
50 : ViewportBase(identifier)
51 {}
52
53 SdlViewport(const std::string& identifier,
54 boost::shared_ptr<Scene2D>& scene)
55 : ViewportBase(identifier, scene)
56 {
57
58 }
59
60
61 virtual SdlWindow& GetWindow() = 0;
62 };
63
64 class SdlOpenGLViewport : public SdlViewport
65 {
47 private: 66 private:
48 SdlOpenGLContext context_; 67 SdlOpenGLContext context_;
49 OpenGLCompositor compositor_; 68 OpenGLCompositor compositor_;
50 69
51 public: 70 public:
52 SdlViewport(const char* title, 71 SdlOpenGLViewport(const char* title,
53 unsigned int width, 72 unsigned int width,
54 unsigned int height, 73 unsigned int height,
55 bool allowDpiScaling = true); 74 bool allowDpiScaling = true);
56 75
57 SdlViewport(const char* title, 76 SdlOpenGLViewport(const char* title,
58 unsigned int width, 77 unsigned int width,
59 unsigned int height, 78 unsigned int height,
60 boost::shared_ptr<Scene2D>& scene, 79 boost::shared_ptr<Scene2D>& scene,
61 bool allowDpiScaling = true); 80 bool allowDpiScaling = true);
62 81
63 virtual void Refresh()
64 {
65 compositor_.Refresh();
66 }
67 82
68 virtual unsigned int GetCanvasWidth() const 83 virtual ICompositor& GetCompositor()
69 {
70 return compositor_.GetCanvasWidth();
71 }
72
73 virtual unsigned int GetCanvasHeight() const
74 {
75 return compositor_.GetCanvasHeight();
76 }
77
78 OpenGLCompositor& GetCompositor()
79 { 84 {
80 return compositor_; 85 return compositor_;
81 } 86 }
82 87
83 SdlOpenGLContext& GetContext() 88 virtual SdlWindow& GetWindow()
84 { 89 {
85 return context_; 90 return context_.GetWindow();
86 } 91 }
92 // SdlOpenGLContext& GetContext()
93 // {
94 // return context_;
95 // }
96 };
97
98
99 class SdlCairoViewport : public SdlViewport
100 {
101 private:
102 SdlWindow window_;
103 CairoCompositor compositor_;
104 SDL_Surface* sdlSurface_;
105
106 public:
107 SdlCairoViewport(const char* title,
108 unsigned int width,
109 unsigned int height,
110 bool allowDpiScaling = true);
111
112 SdlCairoViewport(const char* title,
113 unsigned int width,
114 unsigned int height,
115 boost::shared_ptr<Scene2D>& scene,
116 bool allowDpiScaling = true);
117
118 ~SdlCairoViewport();
119
120 virtual ICompositor& GetCompositor()
121 {
122 return compositor_;
123 }
124
125 virtual SdlWindow& GetWindow()
126 {
127 return window_;
128 }
129
130 virtual void Refresh();
131
87 }; 132 };
88 } 133 }