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
54namespace Sword25 {
55
56class Kernel;
57class Image;
58class Panel;
59class Screenshot;
60class 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
84public:
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
122 // Debug methods
123
134 void drawDebugLine(const Vertex &start, const Vertex &end, uint color = BS_RGB(255, 255, 255));
135
144
145 RenderObjectPtr<Panel> getMainPanel();
146
151 if (!_timerActive)
152 return 0;
153 return _lastFrameDuration;
154 }
155
159 float getLastFrameDuration() const {
160 if (!_timerActive)
161 return 0;
162 return static_cast<float>(_lastFrameDuration) / 1000000.0f;
163 }
164
165 void stopMainTimer() {
166 _timerActive = false;
167 }
168
169 void resumeMainTimer() {
170 _timerActive = true;
171 }
172
173 float getSecondaryFrameDuration() const {
174 return static_cast<float>(_lastFrameDuration) / 1000000.0f;
175 }
176
177 // Accessor methods
178
182 int getDisplayWidth() const {
183 return _width;
184 }
185
189 int getDisplayHeight() const {
190 return _height;
191 }
192
197 return _screenRect;
198 }
199
204 return _bitDepth;
205 }
206
212 void setVsync(bool vsync);
213
218 bool getVsync() const;
219
223 bool isWindowed() {
224 return false;
225 }
226
236 bool fill(const Common::Rect *fillRectPtr = 0, uint color = BS_RGB(0, 0, 0));
237
238 Graphics::ManagedSurface _backSurface;
239 Graphics::ManagedSurface *getSurface() { return &_backSurface; }
240
241 Common::SeekableReadStream *_thumbnail;
242 Common::SeekableReadStream *getThumbnail() { return _thumbnail; }
243
244 // Access methods
245
246 // Resource-Managing Methods
247 // --------------------------
248 Resource *loadResource(const Common::String &fileName) override;
249 bool canLoadResource(const Common::String &fileName) override;
250
251 // Persistence Methods
252 // -------------------
253 bool persist(OutputPersistenceBlock &writer) override;
254 bool unpersist(InputPersistenceBlock &reader) override;
255 bool isRTL();
256 static void ARGBColorToLuaColor(lua_State *L, uint color);
257 static uint luaColorToARGBColor(lua_State *L, int stackIndex);
258
259protected:
260
261 // Display Variables
262 // -----------------
263 int _width;
264 int _height;
265 Common::Rect _screenRect;
266 int _bitDepth;
267
272
273private:
274 bool registerScriptBindings();
275 void unregisterScriptBindings();
276
277 // LastFrameDuration Variables
278 // ---------------------------
279 uint _lastTimeStamp;
280 uint _lastFrameDuration;
281 bool _timerActive;
282 Common::Array<uint> _frameTimeSamples;
283 uint _frameTimeSampleSlot;
284
285private:
286 RenderObjectPtr<Panel> _mainPanelPtr;
287
288 Common::ScopedPtr<RenderObjectManager> _renderObjectManagerPtr;
289
290 bool _isRTL;
291
292 struct DebugLine {
293 DebugLine(const Vertex &start, const Vertex &end, uint color) :
294 _start(start),
295 _end(end),
296 _color(color) {}
297 DebugLine() {}
298
299 Vertex _start;
300 Vertex _end;
301 uint _color;
302 };
303
304 Common::Array<DebugLine> _debugLines;
305};
306
307} // End of namespace Sword25
308
309#endif
Definition: ptr.h:572
Definition: stream.h:745
Definition: str.h:59
Definition: managed_surface.h:51
Definition: graphicengine.h:83
bool fill(const Common::Rect *fillRectPtr=0, uint color=(0xFF000000|((0)<< 16)|((0)<< 8)|((0)<< 0)))
bool init(int width=800, int height=600, int bitDepth=16, int backbufferCount=2)
void drawDebugLine(const Vertex &start, const Vertex &end, uint color=(0xFF000000|((255)<< 16)|((255)<< 8)|((255)<< 0)))
int getLastFrameDurationMicro() const
Definition: graphicengine.h:150
bool startFrame(bool updateAll=false)
bool isWindowed()
Definition: graphicengine.h:223
int getBitDepth()
Definition: graphicengine.h:203
bool canLoadResource(const Common::String &fileName) override
float getLastFrameDuration() const
Definition: graphicengine.h:159
bool saveThumbnailScreenshot(const Common::String &filename)
int getDisplayHeight() const
Definition: graphicengine.h:189
int getDisplayWidth() const
Definition: graphicengine.h:182
Common::Rect & getDisplayRect()
Definition: graphicengine.h:196
void setVsync(bool vsync)
Resource * loadResource(const Common::String &fileName) override
Definition: inputpersistenceblock.h:40
Definition: kernel.h:72
Definition: outputpersistenceblock.h:39
Definition: persistable.h:39
Definition: renderobjectptr.h:46
Definition: resource.h:43
Definition: resservice.h:43
Definition: vertex.h:52
Definition: console.h:27
Definition: rect.h:536
Definition: display_client.h:53
Definition: lstate.h:100