ScummVM API documentation
te_renderer.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 TETRAEDGE_TE_TE_RENDERER_H
23 #define TETRAEDGE_TE_TE_RENDERER_H
24 
25 #include "common/ptr.h"
26 #include "tetraedge/te/te_mesh.h"
27 #include "tetraedge/te/te_color.h"
28 #include "tetraedge/te/te_camera.h"
29 #include "tetraedge/te/te_matricies_stack.h"
30 
31 namespace Tetraedge {
32 
33 class TeRenderer {
34 public:
35  TeRenderer();
36  virtual ~TeRenderer() {};
37 
38  enum MatrixMode {
39  MM_GL_PROJECTION = 0,
40  MM_GL_MODELVIEW = 1,
41  MM_GL_TEXTURE = 2
42  };
43 
44  enum ShadowMode {
45  ShadowModeNone = 0,
46  ShadowModeCreating = 1,
47  ShadowModeDrawing = 2
48  };
49 
51  public:
52  TransparentMeshProperties() : _camera(nullptr), _vertexCount(0), _shouldDraw(false),
53  _scissorEnabled(false), _hasColor(false), _glTexEnvMode(0), _zOrder(0.0f),
54  _sourceTransparentMesh(0), _scissorX(0), _scissorY(0),
55  _scissorWidth(0), _scissorHeight(0) {}
56 
57  TeCamera *_camera;
58  int _vertexCount;
59  TeMatrix4x4 _matrix;
60 
61  TeMaterial _material;
62 
63  uint32 _glTexEnvMode;
64  uint _sourceTransparentMesh;
65  bool _hasColor;
66  float _zOrder;
67  bool _scissorEnabled;
68  int _scissorX;
69  int _scissorY;
70  int _scissorWidth;
71  int _scissorHeight;
72  bool _shouldDraw;
73  };
74 
75  enum Buffer {
76  DepthBuffer = 1,
77  ColorBuffer = 2,
78  StencilBuffer = 4,
79  ColorAndDepth = DepthBuffer | ColorBuffer,
80  AllBuffers = DepthBuffer | ColorBuffer | StencilBuffer
81  };
82 
83  void addTransparentMesh(const TeMesh &mesh, uint i1, uint i2, uint i3);
84  void checkError(const Common::String &str) {};
85  virtual void clearBuffer(Buffer buf) = 0;
86  virtual void colorMask(bool r, bool g, bool b, bool a) = 0;
87  void create();
88  TeMatrix4x4 currentMatrix();
89  virtual void disableAllLights() = 0;
90  virtual void disableTexture() = 0;
91  virtual void disableWireFrame() = 0;
92  virtual void disableZBuffer() = 0;
93  virtual void drawLine(const TeVector3f32 &from, const TeVector3f32 &to) = 0;
94  virtual void enableAllLights() = 0;
95  virtual void enableTexture() = 0;
96  virtual void enableWireFrame() = 0;
97  virtual void enableZBuffer() = 0;
98  //void extractFrameBufferToImg(const TeVector2s32 &from, const TeVector2s32 &to, TeImage &output);
99  virtual void init(uint width, uint height) = 0;
100  void loadIdentityMatrix();
101  void loadMatrix(const TeMatrix4x4 &matrix);
102  void loadCurrentMatrixToGL();
103  virtual void loadProjectionMatrix(const TeMatrix4x4 &matrix) = 0;
104  void multiplyMatrix(const TeMatrix4x4 &matrix);
105  void optimiseTransparentMeshProperties();
106  void popMatrix();
107  void pushMatrix();
108  virtual Common::String renderer() = 0;
109  virtual void renderTransparentMeshes() = 0;
110  virtual void reset() = 0;
111  void rotate(const TeQuaternion &rot);
112  void rotate(float angle, float rx, float ry, float rz);
113  void scale(float xs, float ys, float zs);
114  bool scissorEnabled() const { return _scissorEnabled; }
115  int scissorHeight() const { return _scissorHeight; }
116  int scissorWidth() const { return _scissorWidth; }
117  int scissorX() const { return _scissorX; }
118  int scissorY() const { return _scissorY; }
119  void sendModelMatrix(const TeMatrix4x4 &matrix) {}
120  virtual void setClearColor(const TeColor &col) = 0;
121  void setCurrentCamera(TeCamera *camera) {
122  _currentCamera = camera;
123  }
124  virtual void setCurrentColor(const TeColor &col) = 0;
125  virtual void setMatrixMode(enum MatrixMode mode) = 0;
126  void setScissor(int x, int y, int w, int h);
127  void setScissorEnabled(bool val) { _scissorEnabled = val; }
128  virtual void setViewport(int x, int y, int w, int h) = 0;
129  virtual void shadowMode(enum ShadowMode mode) = 0;
130  enum ShadowMode shadowMode() const { return _shadowMode; }
131  void translate(float x, float y, float z);
132  virtual Common::String vendor() = 0;
133 
134  void dumpTransparentMeshProps() const;
135  void dumpTransparentMeshData() const;
136  const TeColor &currentColor() const { return _currentColor; }
137 
138  virtual void updateScreen() = 0;
139  virtual void updateGlobalLight() = 0;
140  virtual void applyMaterial(const TeMaterial &m) = 0;
141 
142  static TeRenderer *makeInstance();
143 
144 protected:
145  TeCamera *_currentCamera;
146  TeColor _currentColor;
147  TeColor _clearColor;
148  bool _textureEnabled;
149 
150  ShadowMode _shadowMode;
151  MatrixMode _matrixMode;
152 
153  bool _scissorEnabled;
154  int _scissorHeight;
155  int _scissorWidth;
156  int _scissorX;
157  int _scissorY;
158 
159  uint _numTransparentMeshes;
160  Common::Array<TeVector3f32> _transparentMeshVertexes;
161  Common::Array<TeVector3f32> _transparentMeshNormals;
162  Common::Array<TeVector2f32> _transparentMeshCoords;
163  Common::Array<TeColor> _transparentMeshColors;
164  Common::Array<unsigned short> _transparentMeshVertexNums;
165 
166  int _pendingTransparentMeshProperties;
167  Common::Array<TransparentMeshProperties> _transparentMeshProps;
168 
169  TeMatriciesStack _matriciesStacks[3]; // one per matrix mode.
170 
171  virtual void loadMatrixToGL(const TeMatrix4x4 &matrix) = 0;
172 };
173 
174 } // end namespace Tetraedge
175 
176 #endif // TETRAEDGE_TE_TE_RENDERER_H
Definition: te_camera.h:38
Definition: str.h:59
Definition: detection.h:27
Definition: te_mesh.h:43
Definition: te_quaternion.h:32
Definition: array.h:52
Definition: te_color.h:30
Definition: te_matricies_stack.h:32
Definition: te_matrix4x4.h:37
Definition: te_renderer.h:33
Definition: te_material.h:35
Definition: te_vector3f32.h:33
Definition: display_client.h:113