ScummVM API documentation
gfx_tinygl.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_TINYGL_H
23 #define FREESCAPE_GFX_TINYGL_H
24 
25 #include "math/vector3d.h"
26 #include "common/hashmap.h"
27 
28 #include "freescape/gfx.h"
29 #include "freescape/gfx_tinygl_texture.h"
30 
31 namespace Freescape {
32 
33 class TinyGLRenderer : public Renderer {
34 public:
35  TinyGLRenderer(int screenW, int screenH, Common::RenderMode renderMode);
36  virtual ~TinyGLRenderer();
37 
38  struct Vertex {
39  TGLfloat x;
40  TGLfloat y;
41  TGLfloat z;
42  };
43 
44  Vertex *_verts;
45  void copyToVertexArray(uint idx, const Math::Vector3d &src) {
46  assert(idx < kVertexArraySize);
47  _verts[idx].x = src.x();
48  _verts[idx].y = src.y();
49  _verts[idx].z = src.z();
50  }
51 
52  struct Coord {
53  TGLfloat x;
54  TGLfloat y;
55  };
56 
57  Coord *_texCoord;
58 
59  void copyToTexCoordArray(uint idx, float x, float y) {
60  assert(idx < kVertexArraySize);
61  _texCoord[idx].x = x;
62  _texCoord[idx].y = y;
63  }
64 
65  bool _stippleEnabled;
66  TinyGL3DTexture *_stippleTexture;
67  Common::HashMap<uint64, TinyGL3DTexture *> _stippleTextureCache;
68  uint32 _lastColorSet0;
69  uint32 _lastColorSet1;
70 
71  virtual void init() override;
72  virtual void clear(uint8 r, uint8 g, uint8 b, bool ignoreViewport = false) override;
73  virtual void setViewport(const Common::Rect &rect) override;
74  virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle = 0.0f) override;
75  virtual void updateProjectionMatrix(float fov, float aspectRatio, float nearClipPlane, float farClipPlane) override;
76 
77  virtual void useColor(uint8 r, uint8 g, uint8 b) override;
78  virtual void polygonOffset(bool enabled) override;
79  virtual void enableCulling(bool enabled) override;
80  virtual void setStippleData(byte *data) override;
81  virtual void useStipple(bool enabled) override;
82 
83  Texture *createTexture(const Graphics::Surface *surface, bool is3D = false) override;
84  void freeTexture(Texture *texture) override;
85  virtual void drawTexturedRect2D(const Common::Rect &screenRect, const Common::Rect &textureRect, Texture *texture) override;
86  void drawSkybox(Texture *texture, Math::Vector3d camera) override;
87  void drawThunder(Texture *texture, Math::Vector3d camera, float size) override;
88 
89  virtual void renderSensorShoot(byte color, const Math::Vector3d sensor, const Math::Vector3d player, const Common::Rect &viewPort) override;
90  virtual void renderPlayerShootBall(byte color, const Common::Point &position, int frame, const Common::Rect &viewPort) override;
91  virtual void renderPlayerShootRay(byte color, const Common::Point &position, const Common::Rect &viewPort) override;
92  virtual void renderCrossair(const Common::Point &crossairPosition) override;
93 
94  virtual void renderFace(const Common::Array<Math::Vector3d> &vertices) override;
95 
96  void drawCelestialBody(Math::Vector3d position, float radius, byte color) override;
97 
98  virtual void flipBuffer() override;
99  virtual void drawFloor(uint8 color) override;
100  virtual void fillViewportStippled(uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2, byte *stipple) override;
101  virtual Graphics::Surface *getScreenshot() override;
102 
103  byte _defaultStippleArray[128] = {
104  0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
105  0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
106  0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
107  0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
108  0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
109  0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
110  0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
111  0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
112  0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
113  0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
114  0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
115  0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
116  0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
117  0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
118  0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
119  0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
120  };
121 
122 };
123 
124 } // End of namespace Freescape
125 
126 #endif // FREESCAPE_GFX_TINYGL_H
Definition: surface.h:67
Definition: area.h:36
virtual void flipBuffer() override
Definition: gfx_tinygl.h:38
RenderMode
Definition: rendermode.h:48
Definition: rect.h:536
Definition: gfx.h:63
Definition: hashmap.h:85
Definition: rect.h:144
Definition: gfx_tinygl_texture.h:49
virtual void positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float rollAngle=0.0f) override
Definition: gfx_tinygl.h:33
Definition: gfx_tinygl.h:52
Definition: gfx.h:50