ScummVM API documentation
gfx.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#ifndef GFX_H_
23#define GFX_H_
24
25#include "common/rect.h"
26#include "common/system.h"
27
28#include "math/frustum.h"
29#include "math/matrix4.h"
30#include "math/vector3d.h"
31
32namespace Myst3 {
33
34class Renderer;
35
36class Drawable {
37public:
38 Drawable();
39 virtual ~Drawable() {}
40
41 virtual void draw() {}
42 virtual void drawOverlay() {}
43
45 bool isConstrainedToWindow() const { return _isConstrainedToWindow; }
46
48 bool is3D() const { return _is3D; }
49
51 bool isScaled() const { return _scaled; }
52
53protected:
54 bool _isConstrainedToWindow;
55 bool _is3D;
56 bool _scaled;
57};
58
65class Window : public Drawable {
66public:
70 virtual Common::Rect getPosition() const = 0;
71
75 virtual Common::Rect getOriginalPosition() const = 0;
76
81
86
91};
92
93class Texture {
94public:
95 virtual ~Texture() {}
96
97 uint width;
98 uint height;
100
101 virtual void update(const Graphics::Surface *surface) = 0;
102 virtual void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) = 0;
103
104 static const Graphics::PixelFormat getRGBAPixelFormat();
105};
106
107class Renderer {
108public:
109 Renderer(OSystem *system);
110 virtual ~Renderer();
111
112 virtual void init() = 0;
113 virtual void clear() = 0;
114
118 virtual void flipBuffer() { }
119
120 virtual void initFont(const Graphics::Surface *surface);
121 virtual void freeFont();
122
123 virtual Texture *createTexture3D(const Graphics::Surface *surface) = 0;
124 virtual Texture *createTexture2D(const Graphics::Surface *surface) { return createTexture3D(surface); }
125
126 virtual void drawRect2D(const Common::Rect &rect, uint8 a, uint8 r, uint8 g, uint8 b) = 0;
127 virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture,
128 float transparency = -1.0, bool additiveBlending = false) = 0;
129 virtual void drawTexturedRect3D(const Math::Vector3d &topLeft, const Math::Vector3d &bottomLeft,
130 const Math::Vector3d &topRight, const Math::Vector3d &bottomRight,
131 Texture *texture) = 0;
132
133 virtual void drawCube(Texture **textures) = 0;
134 virtual void draw2DText(const Common::String &text, const Common::Point &position) = 0;
135
136 virtual Graphics::Surface *getScreenshot() = 0;
137 virtual Texture *copyScreenshotToTexture();
138
140 void renderDrawable(Drawable *drawable, Window *window);
141
143 void renderDrawableOverlay(Drawable *drawable, Window *window);
144
146 void renderWindow(Window *window);
147
150
151 Common::Rect viewport() const;
152
158 virtual void selectTargetWindow(Window *window, bool is3D, bool scaled) = 0;
159
160 void setupCameraPerspective(float pitch, float heading, float fov);
161
162 bool isCubeFaceVisible(uint face);
163
164 Math::Matrix4 getMvpMatrix() const { return _mvpMatrix; }
165
166 void flipVertical(Graphics::Surface *s);
167
168 static const int kOriginalWidth = 640;
169 static const int kOriginalHeight = 480;
170 static const int kTopBorderHeight = 30;
171 static const int kBottomBorderHeight = 90;
172 static const int kBottomBorderHeightForSubsInWideScreen = 60;
173 static const int kBottomTriggerForInventoryInWideScreen = 35;
174 static const int kFrameHeight = 360;
175
176 void computeScreenViewport();
177
178protected:
179 OSystem *_system;
180 Texture *_font;
181
182 Common::Rect _screenViewport;
183
184 Math::Matrix4 _projectionMatrix;
185 Math::Matrix4 _modelViewMatrix;
186 Math::Matrix4 _mvpMatrix;
187
188 Math::Frustum _frustum;
189
190 static const float cubeVertices[5 * 6 * 4];
191 Math::AABB _cubeFacesAABB[6];
192
193 Common::Rect getFontCharacterRect(uint8 character);
194
195 Math::Matrix4 makeProjectionMatrix(float fov) const;
196};
197
198Renderer *CreateGfxOpenGL(OSystem *system);
199Renderer *CreateGfxOpenGLShader(OSystem *system);
200Renderer *CreateGfxTinyGL(OSystem *system);
201Renderer *createRenderer(OSystem *system);
202
203} // End of namespace Myst3
204
205#endif // GFX_H_
Definition: str.h:59
Definition: gfx.h:36
bool isScaled() const
Definition: gfx.h:51
bool isConstrainedToWindow() const
Definition: gfx.h:45
bool is3D() const
Definition: gfx.h:48
Definition: gfx.h:107
void renderDrawableOverlay(Drawable *drawable, Window *window)
void renderWindow(Window *window)
virtual void selectTargetWindow(Window *window, bool is3D, bool scaled)=0
void renderWindowOverlay(Window *window)
void renderDrawable(Drawable *drawable, Window *window)
virtual void flipBuffer()
Definition: gfx.h:118
Definition: gfx.h:93
Definition: gfx.h:65
virtual Common::Rect getOriginalPosition() const =0
Common::Point scalePoint(const Common::Point &screen) const
Common::Point screenPosToWindowPos(const Common::Point &screen) const
virtual Common::Rect getPosition() const =0
Common::Point getCenter() const
Definition: system.h:166
Definition: rect.h:144
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67