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 FREESCAPE_GFX_H
23 #define FREESCAPE_GFX_H
24 
25 #include "common/hashmap.h"
26 #include "common/rendermode.h"
27 #include "common/rect.h"
28 
29 #include "graphics/pixelformat.h"
30 #include "graphics/managed_surface.h"
31 #include "graphics/renderer.h"
32 #include "math/frustum.h"
33 #include "math/vector3d.h"
34 
35 namespace Freescape {
36 
37 #define kVertexArraySize 128
38 #define kCoordsArraySize 4
39 
40 typedef Common::Array<byte *> ColorMap;
41 typedef Common::HashMap<int, int> ColorReMap;
42 
43 class Renderer;
44 
45 class Texture {
46 public:
47  Texture(){ _width = 0; _height = 0; };
48  virtual ~Texture(){};
49 
50  uint _width;
51  uint _height;
52  Graphics::PixelFormat _format;
53 
54  virtual void update(const Graphics::Surface *surface) = 0;
55  virtual void updatePartial(const Graphics::Surface *surface, const Common::Rect &rect) = 0;
56 
57  static const Graphics::PixelFormat getRGBAPixelFormat();
58 };
59 
60 class Renderer {
61 public:
62  Renderer(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
63  virtual ~Renderer();
64 
65  Graphics::PixelFormat _currentPixelFormat;
66  Graphics::PixelFormat _palettePixelFormat;
67  Graphics::PixelFormat _texturePixelFormat;
68  bool _isAccelerated;
69  bool _authenticGraphics;
70 
71  virtual void init() = 0;
72  virtual void setViewport(const Common::Rect &rect) = 0;
73 
77  virtual void flipBuffer() {}
78  virtual void useColor(uint8 r, uint8 g, uint8 b) = 0;
79  virtual void depthTesting(bool enabled) {};
80  virtual void polygonOffset(bool enabled) = 0;
81 
82  virtual Texture *createTexture(const Graphics::Surface *surface) = 0;
83  Graphics::Surface *convertImageFormatIfNecessary(Graphics::ManagedSurface *surface);
84 
85  virtual void freeTexture(Texture *texture) = 0;
86  virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) = 0;
87 
88  virtual void renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect viewPort) = 0;
89  virtual void renderPlayerShootBall(byte color, const Common::Point position, int frame, const Common::Rect viewPort) = 0;
90  virtual void renderPlayerShootRay(byte color, const Common::Point position, const Common::Rect viewPort) = 0;
91 
92  virtual void renderCrossair(const Common::Point crossairPosition) = 0;
93 
94  virtual void renderCube(const Math::Vector3d &position, const Math::Vector3d &size, Common::Array<uint8> *colours, Common::Array<uint8> *ecolours, float offset = 0.0);
95  virtual void renderRectangle(const Math::Vector3d &position, const Math::Vector3d &size, Common::Array<uint8> *colours, Common::Array<uint8> *ecolours, float offset = 0.0);
96  virtual void renderPolygon(const Math::Vector3d &origin, const Math::Vector3d &size, const Common::Array<float> *ordinates, Common::Array<uint8> *colours, Common::Array<uint8> *ecolours, float offset = 0.0);
97  virtual void renderPyramid(const Math::Vector3d &origin, const Math::Vector3d &size, const Common::Array<float> *ordinates, Common::Array<uint8> *colours, Common::Array<uint8> *ecolours, int type);
98  virtual void renderFace(const Common::Array<Math::Vector3d> &vertices) = 0;
99 
100  void setColorRemaps(ColorReMap *colorRemaps);
101  virtual void clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport = false) = 0;
102  virtual void drawFloor(uint8 color) = 0;
103  virtual void drawBackground(uint8 color);
104 
105  void drawEclipse(uint8 color1, uint8 color2, float difference);
106  virtual void drawSkybox(Texture *texture, Math::Vector3d camera) {};
107  virtual void drawCelestialBody(Math::Vector3d position, float radius, uint8 color) {};
108 
109  Common::Rect viewport() const;
110  virtual Common::Point nativeResolution() { return Common::Point(_screenW, _screenH); }
111 
112  // palette
113  void readFromPalette(uint8 index, uint8 &r, uint8 &g, uint8 &b);
114  void setPaletteValue(uint8 index, uint8 r, uint8 g, uint8 b);
115  uint8 indexFromColor(uint8 r, uint8 g, uint8 b);
116  uint8 mapEGAColor(uint8 index);
117 
118  bool getRGBAt(uint8 index, uint8 ecolor, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
119  bool getRGBAtC64(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2);
120  bool getRGBAtCGA(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
121  bool getRGBAtCPC(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
122  bool getRGBAtEGA(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2);
123  bool getRGBAtZX(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *&stipple);
124  void extractCPCIndexes(uint8 cm1, uint8 cm2, uint8 &i1, uint8 &i2);
125  void extractC64Indexes(uint8 cm1, uint8 cm2, uint8 &i1, uint8 &i2);
126 
127  void selectColorFromFourColorPalette(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1);
128 
129  virtual void setStippleData(byte *data) {};
130  virtual void useStipple(bool enabled) {};
131  byte *_palette;
132  void setColorMap(ColorMap *colorMap_);
133  ColorMap *_colorMap;
134  ColorReMap *_colorRemaps;
135  void clearColorPairArray();
136  void fillColorPairArray();
137  byte _colorPair[16];
138  int _keyColor;
139  int _inkColor;
140  int _paperColor;
141  int _underFireBackgroundColor;
142  byte _stipples[16][128];
143 
144  int _scale;
145 
152  virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest) = 0;
153  virtual void updateProjectionMatrix(float fov, float yminValue, float ymaxValue, float nearClipPlane, float farClipPlane) = 0;
154 
155  Math::Matrix4 getMvpMatrix() const { return _mvpMatrix; }
156  virtual Graphics::Surface *getScreenshot() = 0;
157  void flipVertical(Graphics::Surface *s);
158 
159  int _screenW;
160  int _screenH;
161  Common::RenderMode _renderMode;
162 
163  bool computeScreenViewport();
164 
165 protected:
166  Common::Rect _screenViewport;
167  Common::Rect _viewport;
168  Common::Rect _unscaledViewport;
169 
170  Math::Matrix4 _projectionMatrix;
171  Math::Matrix4 _modelViewMatrix;
172  Math::Matrix4 _mvpMatrix;
173 
174  Math::Frustum _frustum;
175 
176  Math::Matrix4 makeProjectionMatrix(float fov, float nearClipPlane, float farClipPlane) const;
177 };
178 
179 Graphics::RendererType determinateRenderType();
180 Renderer *CreateGfxOpenGL(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
181 Renderer *CreateGfxOpenGLShader(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
182 Renderer *CreateGfxTinyGL(int screenW, int screenH, Common::RenderMode renderMode);
183 Renderer *createRenderer(int screenW, int screenH, Common::RenderMode renderMode, bool authenticGraphics);
184 
185 } // End of namespace Freescape
186 
187 #endif // FREESCAPE_GFX_H
Definition: managed_surface.h:51
virtual void flipBuffer()
Definition: gfx.h:77
Definition: surface.h:67
RendererType
Definition: renderer.h:45
Definition: area.h:36
Definition: pixelformat.h:138
RenderMode
Definition: rendermode.h:48
Definition: rect.h:144
Definition: gfx.h:60
Definition: rect.h:45
Definition: gfx.h:45