ScummVM API documentation
gfx_base.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 GRIM_GFX_BASE_H
23 #define GRIM_GFX_BASE_H
24 
25 #include "math/vector3d.h"
26 #include "math/quat.h"
27 
28 #include "common/str.h"
29 #include "common/rect.h"
30 
31 #include "graphics/pixelformat.h"
32 #include "graphics/renderer.h"
33 
34 #include "engines/grim/material.h"
35 
36 namespace Graphics {
37  struct Surface;
38 }
39 
40 namespace Grim {
41 
42 struct Shadow;
43 struct Light;
44 class Actor;
45 class SaveGame;
46 class BitmapData;
47 class Bitmap;
48 class CMap;
49 class Color;
50 class PrimitiveObject;
51 class Font;
52 class TextObject;
53 class EMIModel;
54 class EMIMeshFace;
55 class ModelNode;
56 class Mesh;
57 class MeshFace;
58 class Sprite;
59 class Texture;
60 class Overlay;
61 
62 class GfxBase {
63 public:
64  GfxBase();
65  virtual ~GfxBase() { ; }
66 
73  virtual void setupScreen(int screenW, int screenH) = 0;
74 
80  virtual bool isHardwareAccelerated() = 0;
86  virtual bool supportsShaders() = 0;
87 
88  virtual uint getScreenWidth() { return _screenWidth; }
89  virtual uint getScreenHeight() { return _screenHeight; }
90 
91  virtual void setupCameraFrustum(float fov, float nclip, float fclip) = 0;
92  virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float roll) = 0;
93  virtual void positionCamera(const Math::Vector3d &pos, const Math::Matrix4 &rot) = 0;
94 
95  virtual Math::Matrix4 getModelView() = 0;
96  virtual Math::Matrix4 getProjection() = 0;
97 
98  virtual void clearScreen() = 0;
99  virtual void clearDepthBuffer() = 0;
100 
106  virtual void flipBuffer(bool opportunistic = false) = 0;
107 
112  virtual void getScreenBoundingBox(const Mesh *mesh, int *x1, int *y1, int *x2, int *y2) = 0;
113  virtual void getScreenBoundingBox(const EMIModel *mesh, int *x1, int *y1, int *x2, int *y2) = 0;
114  virtual void getActorScreenBBox(const Actor *actor, Common::Point &p1, Common::Point &p2) = 0;
115  virtual void startActorDraw(const Actor *act) = 0;
116  virtual void finishActorDraw() = 0;
117  virtual void setShadow(Shadow *shadow) = 0;
118  virtual void drawShadowPlanes() = 0;
119  virtual void setShadowMode();
120  virtual void clearShadowMode();
121  virtual bool isShadowModeActive();
122  virtual void setShadowColor(byte r, byte g, byte b) = 0;
123  virtual void getShadowColor(byte *r, byte *g, byte *b) = 0;
124  virtual void destroyShadow(Shadow *shadow) {}
125 
126  virtual void set3DMode() = 0;
127 
128  virtual void translateViewpointStart() = 0;
129  virtual void translateViewpoint(const Math::Vector3d &vec) = 0;
130  virtual void rotateViewpoint(const Math::Angle &angle, const Math::Vector3d &axis) = 0;
131  virtual void rotateViewpoint(const Math::Matrix4 &rot) = 0;
132  virtual void translateViewpointFinish() = 0;
133 
134  virtual void drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face) = 0;
135  virtual void drawModelFace(const Mesh *mesh, const MeshFace *face) = 0;
136  virtual void drawSprite(const Sprite *sprite) = 0;
137  virtual void drawMesh(const Mesh *mesh);
138 
139  virtual void drawOverlay(const Overlay *overlay) { };
140 
141  virtual void enableLights() = 0;
142  virtual void disableLights() = 0;
143  virtual void setupLight(Light *light, int lightId) = 0;
144  virtual void turnOffLight(int lightId) = 0;
145 
146  virtual void createTexture(Texture *texture, const uint8 *data, const CMap *cmap, bool clamp) = 0;
147  virtual void selectTexture(const Texture *texture) = 0;
148  virtual void destroyTexture(Texture *texture) = 0;
149 
163  virtual void createBitmap(BitmapData *bitmap) = 0;
164 
173  virtual void drawBitmap(const Bitmap *bitmap, int x, int y, uint32 layer = 0) = 0;
174 
184  virtual void destroyBitmap(BitmapData *bitmap) = 0;
185 
186  virtual void createFont(Font *font) = 0;
187  virtual void destroyFont(Font *font) = 0;
188 
189  virtual void createTextObject(TextObject *text) = 0;
190  virtual void drawTextObject(const TextObject *text) = 0;
191  virtual void destroyTextObject(TextObject *text) = 0;
192 
193  virtual Bitmap *getScreenshot(int w, int h, bool useStored) = 0;
194  virtual void storeDisplay() = 0;
195  virtual void copyStoredToDisplay() = 0;
196 
202  virtual void dimScreen() = 0;
203  virtual void dimRegion(int x, int y, int w, int h, float level) = 0;
204  virtual void setDimLevel(float dimLevel) { _dimLevel = dimLevel; }
205 
214  virtual void irisAroundRegion(int x1, int y1, int x2, int y2) = 0;
215 
216  virtual void drawEmergString(int x, int y, const char *text, const Color &fgColor) = 0;
217  virtual void loadEmergFont() = 0;
218 
219  virtual void drawRectangle(const PrimitiveObject *primitive) = 0;
220  virtual void drawLine(const PrimitiveObject *primitive) = 0;
221  virtual void drawPolygon(const PrimitiveObject *primitive) = 0;
222  virtual void drawDimPlane() {};
223 
224  virtual const Graphics::PixelFormat getMovieFormat() const = 0;
225 
236  virtual void prepareMovieFrame(Graphics::Surface *frame) = 0;
237  virtual void prepareMovieFrame(Graphics::Surface *frame, const byte *palette);
238  virtual void drawMovieFrame(int offsetX, int offsetY) = 0;
239 
246  virtual void releaseMovieFrame() = 0;
247 
248  virtual const char *getVideoDeviceName() = 0;
249 
250  virtual void saveState(SaveGame *state);
251  virtual void restoreState(SaveGame *state);
252 
253  virtual void renderBitmaps(bool render);
254  virtual void renderZBitmaps(bool render);
255 
256  virtual void makeScreenTextures();
257 
258  virtual void createMesh(Mesh *mesh) {}
259  virtual void destroyMesh(const Mesh *mesh) {}
260  virtual void createEMIModel(EMIModel *model) {}
261  virtual void updateEMIModel(const EMIModel *model) {}
262  virtual void destroyEMIModel(EMIModel *model) {}
263 
264  virtual void createSpecialtyTexture(uint id, const uint8 *data, int width, int height);
265  virtual void createSpecialtyTextureFromScreen(uint id, uint8 *data, int x, int y, int width, int height) = 0;
266 
268 
269  static Math::Matrix4 makeLookMatrix(const Math::Vector3d& pos, const Math::Vector3d& interest, const Math::Vector3d& up);
270  static Math::Matrix4 makeProjMatrix(float fov, float nclip, float fclip);
271  Texture *getSpecialtyTexturePtr(uint id) { if (id >= _numSpecialtyTextures) return nullptr; return &_specialtyTextures[id]; };
272  Texture *getSpecialtyTexturePtr(Common::String name);
273 
274  virtual void setBlendMode(bool additive) = 0;
275 protected:
276  Bitmap *createScreenshotBitmap(Graphics::Surface *src, int w, int h, bool flipOrientation);
277  static const unsigned int _numSpecialtyTextures = 22;
278  Texture _specialtyTextures[_numSpecialtyTextures];
279  static const int _gameHeight = 480;
280  static const int _gameWidth = 640;
281  static const int _globalHeight = 1080;
282  static const int _globalWidth = 1920;
283  float _scaleW, _scaleH;
284  float _globalScaleW = 1.0f, _globalScaleH = 1.0f;
285  int _screenWidth, _screenHeight;
286  Shadow *_currentShadowArray;
287  unsigned char _shadowColorR;
288  unsigned char _shadowColorG;
289  unsigned char _shadowColorB;
290  bool _renderBitmaps;
291  bool _renderZBitmaps;
292  bool _shadowModeActive;
293  Math::Vector3d _currentPos;
294  Math::Matrix4 _currentRot;
295  float _dimLevel;
296 };
297 
298 // Factory-like functions:
299 
300 GfxBase *CreateGfxOpenGL();
301 GfxBase *CreateGfxOpenGLShader();
302 GfxBase *CreateGfxTinyGL();
303 
304 extern GfxBase *g_driver;
305 
306 } // end of namespace Grim
307 
308 #endif
Definition: set.h:184
Definition: str.h:59
Definition: surface.h:67
RendererType
Definition: renderer.h:45
Definition: actor.h:55
Definition: modelemi.h:82
Definition: overlay.h:33
Definition: pixelformat.h:138
Definition: savegame.h:33
Definition: actor.h:33
Definition: model.h:92
Definition: sprite.h:38
Definition: model.h:124
Definition: bitmap.h:125
Definition: bitmap.h:50
Definition: textobject.h:84
Definition: gfx_base.h:62
Definition: formatinfo.h:28
Definition: modelemi.h:55
Definition: colormap.h:35
Definition: rect.h:45
Definition: primitives.h:34
Definition: default_display_client.h:65
Definition: font.h:38
Actor represents a 3D character on screen.
Definition: actor.h:72
Definition: material.h:31
Definition: color.h:29