1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef STARK_GFX_DRIVER_H
24 #define STARK_GFX_DRIVER_H
25 
26 #include "common/rect.h"
27 #include "graphics/pixelformat.h"
28 
29 namespace Graphics {
30 struct Surface;
31 }
32 
33 namespace Stark {
34 
35 class VisualActor;
36 class VisualProp;
37 
38 namespace Gfx {
39 
40 class SurfaceRenderer;
41 class FadeRenderer;
42 class Texture;
43 
44 class Driver {
45 public:
46 	static Driver *create();
47 
~Driver()48 	virtual ~Driver() {}
49 
50 	virtual void init() = 0;
51 
52 	/**
53 	 * Toggle between windowed mode and fullscreen when spported by the backend.
54 	 */
55 	void toggleFullscreen() const;
56 
57 	void computeScreenViewport();
58 	virtual void setScreenViewport(bool noScaling) = 0; // deprecated
59 
60 	virtual void setViewport(Common::Rect rect, bool noScaling) = 0;
61 
62 	/** Get the screen viewport in actual resolution */
getScreenViewport()63 	Common::Rect getScreenViewport() { return _screenViewport; }
64 
65 	Common::Rect gameViewport() const;
66 
67 	virtual void clearScreen() = 0;
68 	virtual void flipBuffer() = 0;
69 
70 	/**
71 	 * Create a new texture
72 	 *
73 	 * The caller is responsible for freeing it.
74 	 *
75 	 */
76 	virtual Texture *createTexture(const Graphics::Surface *surface = nullptr, const byte *palette = nullptr) = 0;
77 
78 	/**
79 	 * Create a new actor renderer
80 	 *
81 	 * The caller is responsible for freeing it.
82 	 */
83 	virtual VisualActor *createActorRenderer() = 0;
84 
85 	/**
86 	 * Create a new prop renderer
87 	 *
88 	 * The caller is responsible for freeing it.
89 	 */
90 	virtual VisualProp *createPropRenderer() = 0;
91 
92 	/**
93 	 * Create a new surface renderer
94 	 *
95 	 * The caller is responsible for freeing it.
96 	 */
97 	virtual SurfaceRenderer *createSurfaceRenderer() = 0;
98 
99 	/**
100 	 * Create a new fade renderer
101 	 *
102 	 * The caller is responsible for freeing it.
103 	 */
104 	virtual FadeRenderer *createFadeRenderer() = 0;
105 
106 	/** Bound a screen coordinate coord within the actual game area */
107 	Common::Point getScreenPosBounded(const Common::Point &point) const;
108 
109 	/** Convert a coordinate from current to original resolution */
110 	Common::Point convertCoordinateCurrentToOriginal(const Common::Point &point) const;
111 
112 	/** Scale a width value from original resolution to current resolution */
113 	uint scaleWidthOriginalToCurrent(uint width) const;
114 
115 	/** Scale a height value from original resolution to current resolution */
116 	uint scaleHeightOriginalToCurrent(uint height) const;
117 
118 	/**
119 	 * Textures are expected to be in the RGBA byte order
120 	 *
121 	 * That is to say bitmaps sent to OpenGL need to have the following layout:
122 	 * R G B A R G B A, ...
123 	 *
124 	 * This method can be used to retrieve what that means in terms
125 	 * of pixel format according to the current platform's endianness.
126 	 */
127 	static const Graphics::PixelFormat getRGBAPixelFormat();
128 
129 	/** Grab a screenshot of the currently active viewport as defined by setViewport */
130 	virtual Graphics::Surface *getViewportScreenshot() const = 0;
131 
132 	virtual void set3DMode() = 0;
133 
134 	static const int32 kOriginalWidth = 640;
135 	static const int32 kOriginalHeight = 480;
136 
137 	static const int32 kTopBorderHeight = 36;
138 	static const int32 kGameViewportHeight = 365;
139 	static const int32 kBottomBorderHeight = 79;
140 
141 	static const int32 kGameViewportWidth = 640;
142 
143 protected:
144 	static void flipVertical(Graphics::Surface *s);
145 
146 	Common::Rect _screenViewport;
147 };
148 
149 } // End of namespace Gfx
150 } // End of namespace Stark
151 
152 #endif // STARK_GFX_DRIVER_H
153