ScummVM API documentation
graphicengine.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on Broken Sword 2.5 engine
24  *
25  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
26  *
27  * Licensed under GNU GPL v2
28  *
29  */
30 
31 /*
32  * GraphicEngine
33  * ----------------
34  * This the graphics engine interface.
35  *
36  * Autor: Malte Thiesen
37  */
38 
39 #ifndef SWORD25_GRAPHICENGINE_H
40 #define SWORD25_GRAPHICENGINE_H
41 
42 // Includes
43 #include "common/array.h"
44 #include "common/rect.h"
45 #include "common/ptr.h"
46 #include "common/str.h"
47 #include "graphics/managed_surface.h"
48 #include "sword25/kernel/common.h"
49 #include "sword25/kernel/resservice.h"
50 #include "sword25/kernel/persistable.h"
51 #include "sword25/gfx/renderobjectptr.h"
52 #include "sword25/math/vertex.h"
53 
54 namespace Sword25 {
55 
56 class Kernel;
57 class Image;
58 class Panel;
59 class Screenshot;
60 class RenderObjectManager;
61 
62 #define BS_ASHIFT 24
63 #define BS_RSHIFT 16
64 #define BS_GSHIFT 8
65 #define BS_BSHIFT 0
66 
67 #define BS_AMASK 0xFF000000
68 #define BS_RMASK 0x00FF0000
69 #define BS_GMASK 0x0000FF00
70 #define BS_BMASK 0x000000FF
71 
72 #define BS_RGBMASK (BS_RMASK | BS_GMASK | BS_BMASK)
73 #define BS_ARGBMASK (BS_AMASK | BS_RMASK | BS_GMASK | BS_BMASK)
74 
75 #define BS_RGB(R,G,B) (BS_AMASK | ((R) << BS_RSHIFT) | ((G) << BS_GSHIFT) | ((B) << BS_BSHIFT))
76 #define BS_ARGB(A,R,G,B) (((A) << BS_ASHIFT) | ((R) << BS_RSHIFT) | ((G) << BS_GSHIFT) | ((B) << BS_BSHIFT))
77 
83 class GraphicEngine : public ResourceService, public Persistable {
84 public:
85  // Constructor
86  // -----------
87  GraphicEngine(Kernel *pKernel);
88  ~GraphicEngine() override;
89 
90  // Interface
91  // ---------
92 
103  bool init(int width = 800, int height = 600, int bitDepth = 16, int backbufferCount = 2);
104 
112  bool startFrame(bool updateAll = false);
113 
120  bool endFrame();
121 
129  bool saveThumbnailScreenshot(const Common::String &filename);
130 
131  RenderObjectPtr<Panel> getMainPanel();
132 
137  if (!_timerActive)
138  return 0;
139  return _lastFrameDuration;
140  }
141 
145  float getLastFrameDuration() const {
146  if (!_timerActive)
147  return 0;
148  return static_cast<float>(_lastFrameDuration) / 1000000.0f;
149  }
150 
151  void stopMainTimer() {
152  _timerActive = false;
153  }
154 
155  void resumeMainTimer() {
156  _timerActive = true;
157  }
158 
159  float getSecondaryFrameDuration() const {
160  return static_cast<float>(_lastFrameDuration) / 1000000.0f;
161  }
162 
163  // Accessor methods
164 
168  int getDisplayWidth() const {
169  return _width;
170  }
171 
175  int getDisplayHeight() const {
176  return _height;
177  }
178 
183  return _screenRect;
184  }
185 
189  int getBitDepth() {
190  return _bitDepth;
191  }
192 
198  void setVsync(bool vsync);
199 
204  bool getVsync() const;
205 
215  bool fill(const Common::Rect *fillRectPtr = 0, uint color = BS_RGB(0, 0, 0));
216 
217  Graphics::ManagedSurface _backSurface;
218  Graphics::ManagedSurface *getSurface() { return &_backSurface; }
219 
220  Common::SeekableReadStream *_thumbnail;
221  Common::SeekableReadStream *getThumbnail() { return _thumbnail; }
222 
223  // Access methods
224 
225  // Resource-Managing Methods
226  // --------------------------
227  Resource *loadResource(const Common::String &fileName) override;
228  bool canLoadResource(const Common::String &fileName) override;
229 
230  // Persistence Methods
231  // -------------------
232  bool persist(OutputPersistenceBlock &writer) override;
233  bool unpersist(InputPersistenceBlock &reader) override;
234  bool isRTL();
235  static void ARGBColorToLuaColor(lua_State *L, uint color);
236  static uint luaColorToARGBColor(lua_State *L, int stackIndex);
237 
238 protected:
239 
240  // Display Variables
241  // -----------------
242  int _width;
243  int _height;
244  Common::Rect _screenRect;
245  int _bitDepth;
246 
251 
252 private:
253  bool registerScriptBindings();
254  void unregisterScriptBindings();
255 
256  // LastFrameDuration Variables
257  // ---------------------------
258  uint _lastTimeStamp;
259  uint _lastFrameDuration;
260  bool _timerActive;
261  Common::Array<uint> _frameTimeSamples;
262  uint _frameTimeSampleSlot;
263 
264 private:
265  RenderObjectPtr<Panel> _mainPanelPtr;
266 
267  Common::ScopedPtr<RenderObjectManager> _renderObjectManagerPtr;
268 
269  bool _isRTL;
270 
271  struct DebugLine {
272  DebugLine(const Vertex &start, const Vertex &end, uint color) :
273  _start(start),
274  _end(end),
275  _color(color) {}
276  DebugLine() {}
277 
278  Vertex _start;
279  Vertex _end;
280  uint _color;
281  };
282 
283 };
284 
285 } // End of namespace Sword25
286 
287 #endif
Definition: managed_surface.h:51
bool init(int width=800, int height=600, int bitDepth=16, int backbufferCount=2)
Definition: str.h:59
int getDisplayWidth() const
Definition: graphicengine.h:168
Definition: renderobjectptr.h:46
bool startFrame(bool updateAll=false)
Definition: rect.h:144
Common::Rect & getDisplayRect()
Definition: graphicengine.h:182
bool saveThumbnailScreenshot(const Common::String &filename)
Definition: lstate.h:100
Definition: stream.h:745
Definition: resource.h:43
void setVsync(bool vsync)
Definition: ptr.h:572
Definition: persistable.h:39
Definition: console.h:27
Definition: kernel.h:72
int getDisplayHeight() const
Definition: graphicengine.h:175
Definition: resservice.h:43
Resource * loadResource(const Common::String &fileName) override
float getLastFrameDuration() const
Definition: graphicengine.h:145
Definition: inputpersistenceblock.h:40
int getBitDepth()
Definition: graphicengine.h:189
bool fill(const Common::Rect *fillRectPtr=0, uint color=(0xFF000000|((0)<< 16)|((0)<< 8)|((0)<< 0)))
int getLastFrameDurationMicro() const
Definition: graphicengine.h:136
bool canLoadResource(const Common::String &fileName) override
Definition: movie_decoder.h:32
Definition: outputpersistenceblock.h:39
Definition: vertex.h:52
Definition: graphicengine.h:83