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 
32 namespace Myst3 {
33 
34 class Renderer;
35 
36 class Drawable {
37 public:
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 
53 protected:
54  bool _isConstrainedToWindow;
55  bool _is3D;
56  bool _scaled;
57 };
58 
65 class Window : public Drawable {
66 public:
70  virtual Common::Rect getPosition() const = 0;
71 
75  virtual Common::Rect getOriginalPosition() const = 0;
76 
80  Common::Point getCenter() const;
81 
85  Common::Point screenPosToWindowPos(const Common::Point &screen) const;
86 
90  Common::Point scalePoint(const Common::Point &screen) const;
91 };
92 
93 class Texture {
94 public:
95  virtual ~Texture() {}
96 
97  uint width;
98  uint height;
99  Graphics::PixelFormat format;
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 
107 class Renderer {
108 public:
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 
149  void renderWindowOverlay(Window *window);
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 kFrameHeight = 360;
173 
174  void computeScreenViewport();
175 
176 protected:
177  OSystem *_system;
178  Texture *_font;
179 
180  Common::Rect _screenViewport;
181 
182  Math::Matrix4 _projectionMatrix;
183  Math::Matrix4 _modelViewMatrix;
184  Math::Matrix4 _mvpMatrix;
185 
186  Math::Frustum _frustum;
187 
188  static const float cubeVertices[5 * 6 * 4];
189  Math::AABB _cubeFacesAABB[6];
190 
191  Common::Rect getFontCharacterRect(uint8 character);
192 
193  Math::Matrix4 makeProjectionMatrix(float fov) const;
194 };
195 
196 Renderer *CreateGfxOpenGL(OSystem *system);
197 Renderer *CreateGfxOpenGLShader(OSystem *system);
198 Renderer *CreateGfxTinyGL(OSystem *system);
199 Renderer *createRenderer(OSystem *system);
200 
201 } // End of namespace Myst3
202 
203 #endif // GFX_H_
Definition: str.h:59
Definition: surface.h:67
Definition: pixelformat.h:138
Definition: ambient.h:27
Definition: rect.h:144
Definition: gfx.h:107
Definition: gfx.h:93
Definition: gfx.h:65
virtual void flipBuffer()
Definition: gfx.h:118
Definition: rect.h:45
bool is3D() const
Definition: gfx.h:48
Definition: gfx.h:36
Definition: system.h:161
bool isConstrainedToWindow() const
Definition: gfx.h:45
bool isScaled() const
Definition: gfx.h:51