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/renderer.h"
32 
33 #include "engines/grim/material.h"
34 
35 namespace Graphics {
36  struct Surface;
37 }
38 
39 namespace Grim {
40 
41 struct Shadow;
42 struct Light;
43 class Actor;
44 class SaveGame;
45 class BitmapData;
46 class Bitmap;
47 class CMap;
48 class Color;
49 class PrimitiveObject;
50 class Font;
51 class TextObject;
52 class EMIModel;
53 class EMIMeshFace;
54 class ModelNode;
55 class Mesh;
56 class MeshFace;
57 class Sprite;
58 class Texture;
59 class Overlay;
60 
64 enum colorFormat {
65  BM_RGB565 = 1, // Grim Fandango
66  BM_RGB1555 = 2, // EMI-PS2
67  BM_RGBA = 3, // EMI-PC (Also internal Material-format for Grim)
68  BM_BGR888 = 4, // EMI-TGA-materials (888)
69  BM_BGRA = 5 // EMI-TGA-materials with alpha
70 };
71 class GfxBase {
72 public:
73  GfxBase();
74  virtual ~GfxBase() { ; }
75 
82  virtual void setupScreen(int screenW, int screenH) = 0;
83 
89  virtual bool isHardwareAccelerated() = 0;
95  virtual bool supportsShaders() = 0;
96 
97  virtual uint getScreenWidth() { return _screenWidth; }
98  virtual uint getScreenHeight() { return _screenHeight; }
99 
100  virtual void setupCameraFrustum(float fov, float nclip, float fclip) = 0;
101  virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float roll) = 0;
102  virtual void positionCamera(const Math::Vector3d &pos, const Math::Matrix4 &rot) = 0;
103 
104  virtual Math::Matrix4 getModelView() = 0;
105  virtual Math::Matrix4 getProjection() = 0;
106 
107  virtual void clearScreen() = 0;
108  virtual void clearDepthBuffer() = 0;
109 
113  virtual void flipBuffer() = 0;
114 
119  virtual void getScreenBoundingBox(const Mesh *mesh, int *x1, int *y1, int *x2, int *y2) = 0;
120  virtual void getScreenBoundingBox(const EMIModel *mesh, int *x1, int *y1, int *x2, int *y2) = 0;
121  virtual void getActorScreenBBox(const Actor *actor, Common::Point &p1, Common::Point &p2) = 0;
122  virtual void startActorDraw(const Actor *act) = 0;
123  virtual void finishActorDraw() = 0;
124  virtual void setShadow(Shadow *shadow) = 0;
125  virtual void drawShadowPlanes() = 0;
126  virtual void setShadowMode();
127  virtual void clearShadowMode();
128  virtual bool isShadowModeActive();
129  virtual void setShadowColor(byte r, byte g, byte b) = 0;
130  virtual void getShadowColor(byte *r, byte *g, byte *b) = 0;
131  virtual void destroyShadow(Shadow *shadow) {}
132 
133  virtual void set3DMode() = 0;
134 
135  virtual void translateViewpointStart() = 0;
136  virtual void translateViewpoint(const Math::Vector3d &vec) = 0;
137  virtual void rotateViewpoint(const Math::Angle &angle, const Math::Vector3d &axis) = 0;
138  virtual void rotateViewpoint(const Math::Matrix4 &rot) = 0;
139  virtual void translateViewpointFinish() = 0;
140 
141  virtual void drawEMIModelFace(const EMIModel *model, const EMIMeshFace *face) = 0;
142  virtual void drawModelFace(const Mesh *mesh, const MeshFace *face) = 0;
143  virtual void drawSprite(const Sprite *sprite) = 0;
144  virtual void drawMesh(const Mesh *mesh);
145 
146  virtual void drawOverlay(const Overlay *overlay) { };
147 
148  virtual void enableLights() = 0;
149  virtual void disableLights() = 0;
150  virtual void setupLight(Light *light, int lightId) = 0;
151  virtual void turnOffLight(int lightId) = 0;
152 
153  virtual void createTexture(Texture *texture, const uint8 *data, const CMap *cmap, bool clamp) = 0;
154  virtual void selectTexture(const Texture *texture) = 0;
155  virtual void destroyTexture(Texture *texture) = 0;
156 
170  virtual void createBitmap(BitmapData *bitmap) = 0;
171 
180  virtual void drawBitmap(const Bitmap *bitmap, int x, int y, uint32 layer = 0) = 0;
181 
191  virtual void destroyBitmap(BitmapData *bitmap) = 0;
192 
193  virtual void createFont(Font *font) = 0;
194  virtual void destroyFont(Font *font) = 0;
195 
196  virtual void createTextObject(TextObject *text) = 0;
197  virtual void drawTextObject(const TextObject *text) = 0;
198  virtual void destroyTextObject(TextObject *text) = 0;
199 
200  virtual Bitmap *getScreenshot(int w, int h, bool useStored) = 0;
201  virtual void storeDisplay() = 0;
202  virtual void copyStoredToDisplay() = 0;
203 
209  virtual void dimScreen() = 0;
210  virtual void dimRegion(int x, int y, int w, int h, float level) = 0;
211  virtual void setDimLevel(float dimLevel) { _dimLevel = dimLevel; }
212 
221  virtual void irisAroundRegion(int x1, int y1, int x2, int y2) = 0;
222 
223  virtual void drawEmergString(int x, int y, const char *text, const Color &fgColor) = 0;
224  virtual void loadEmergFont() = 0;
225 
226  virtual void drawRectangle(const PrimitiveObject *primitive) = 0;
227  virtual void drawLine(const PrimitiveObject *primitive) = 0;
228  virtual void drawPolygon(const PrimitiveObject *primitive) = 0;
229  virtual void drawDimPlane() {};
230 
241  virtual void prepareMovieFrame(Graphics::Surface *frame) = 0;
242  virtual void drawMovieFrame(int offsetX, int offsetY) = 0;
243 
250  virtual void releaseMovieFrame() = 0;
251 
252  virtual const char *getVideoDeviceName() = 0;
253 
254  virtual void saveState(SaveGame *state);
255  virtual void restoreState(SaveGame *state);
256 
257  virtual void renderBitmaps(bool render);
258  virtual void renderZBitmaps(bool render);
259 
260  virtual void makeScreenTextures();
261 
262  virtual void createMesh(Mesh *mesh) {}
263  virtual void destroyMesh(const Mesh *mesh) {}
264  virtual void createEMIModel(EMIModel *model) {}
265  virtual void updateEMIModel(const EMIModel *model) {}
266  virtual void destroyEMIModel(EMIModel *model) {}
267 
268  virtual void createSpecialtyTexture(uint id, const uint8 *data, int width, int height);
269  virtual void createSpecialtyTextureFromScreen(uint id, uint8 *data, int x, int y, int width, int height) = 0;
270 
272 
273  static Math::Matrix4 makeLookMatrix(const Math::Vector3d& pos, const Math::Vector3d& interest, const Math::Vector3d& up);
274  static Math::Matrix4 makeProjMatrix(float fov, float nclip, float fclip);
275  Texture *getSpecialtyTexturePtr(uint id) { if (id >= _numSpecialtyTextures) return nullptr; return &_specialtyTextures[id]; };
276  Texture *getSpecialtyTexturePtr(Common::String name);
277 
278  virtual void setBlendMode(bool additive) = 0;
279 protected:
280  Bitmap *createScreenshotBitmap(Graphics::Surface *src, int w, int h, bool flipOrientation);
281  static const unsigned int _numSpecialtyTextures = 22;
282  Texture _specialtyTextures[_numSpecialtyTextures];
283  static const int _gameHeight = 480;
284  static const int _gameWidth = 640;
285  static const int _globalHeight = 1080;
286  static const int _globalWidth = 1920;
287  float _scaleW, _scaleH;
288  float _globalScaleW = 1.0f, _globalScaleH = 1.0f;
289  int _screenWidth, _screenHeight;
290  Shadow *_currentShadowArray;
291  unsigned char _shadowColorR;
292  unsigned char _shadowColorG;
293  unsigned char _shadowColorB;
294  bool _renderBitmaps;
295  bool _renderZBitmaps;
296  bool _shadowModeActive;
297  Math::Vector3d _currentPos;
298  Math::Matrix4 _currentRot;
299  float _dimLevel;
300 };
301 
302 // Factory-like functions:
303 
304 GfxBase *CreateGfxOpenGL();
305 GfxBase *CreateGfxOpenGLShader();
306 GfxBase *CreateGfxTinyGL();
307 
308 extern GfxBase *g_driver;
309 
310 } // end of namespace Grim
311 
312 #endif
Definition: set.h:184
Definition: str.h:59
Definition: surface.h:66
RendererType
Definition: renderer.h:45
Definition: actor.h:55
Definition: modelemi.h:82
Definition: overlay.h:33
Definition: savegame.h:33
Definition: actor.h:33
Definition: model.h:92
Definition: sprite.h:38
Definition: model.h:124
Definition: bitmap.h:126
Definition: bitmap.h:50
Definition: textobject.h:84
Definition: gfx_base.h:71
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