Improved OpenGL Shader Language support for game engine. The python interface is...
[blender.git] / source / gameengine / Rasterizer / RAS_OpenGLRasterizer / RAS_OpenGLRasterizer.h
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32 #ifndef __RAS_OPENGLRASTERIZER
33 #define __RAS_OPENGLRASTERIZER
34
35 #ifdef WIN32
36 #pragma warning (disable:4786)
37 #endif
38
39 #include "MT_CmMatrix4x4.h"
40 #include <vector>
41 using namespace std;
42
43 #include "RAS_IRasterizer.h"
44 #include "RAS_MaterialBucket.h"
45 #include "RAS_ICanvas.h"
46
47 #define RAS_MAX 3// match in BL_Material
48
49 struct  OglDebugLine
50 {
51         MT_Vector3      m_from;
52         MT_Vector3      m_to;
53         MT_Vector3      m_color;
54 };
55
56 /**
57  * 3D rendering device context.
58  */
59 class RAS_OpenGLRasterizer : public RAS_IRasterizer
60 {
61
62         RAS_ICanvas*    m_2DCanvas;
63         
64         // fogging vars
65         bool                    m_fogenabled;
66         float                   m_fogstart;
67         float                   m_fogdist;
68         float                   m_fogr;
69         float                   m_fogg;
70         float                   m_fogb;
71         
72         float                   m_redback;
73         float                   m_greenback;
74         float                   m_blueback;
75         float                   m_alphaback;
76         
77         float                   m_ambr;
78         float                   m_ambg;
79         float                   m_ambb;
80
81         double                  m_time;
82         MT_CmMatrix4x4  m_viewmatrix;
83         MT_Point3               m_campos;
84
85         StereoMode              m_stereomode;
86         StereoEye               m_curreye;
87         float                   m_eyeseparation;
88         bool                    m_seteyesep;
89         float                   m_focallength;
90         bool                    m_setfocallength;
91         int                             m_noOfScanlines;
92         TexCoGen                m_texco[RAS_MAX];
93         bool                    m_useTang;
94         
95         bool                    InterlacedStereo() const;
96
97 protected:
98         int                             m_drawingmode;
99         /** Stores the caching information for the last material activated. */
100         RAS_IPolyMaterial::TCachingInfo m_materialCachingInfo;
101
102 public:
103         double GetTime();
104         RAS_OpenGLRasterizer(RAS_ICanvas* canv);
105         virtual ~RAS_OpenGLRasterizer();
106
107         /*enum DrawType
108         {
109                         KX_BOUNDINGBOX = 1,
110                         KX_WIREFRAME,
111                         KX_SOLID,
112                         KX_SHADED,
113                         KX_TEXTURED
114         };
115
116         enum DepthMask
117         {
118                         KX_DEPTHMASK_ENABLED =1,
119                         KX_DEPTHMASK_DISABLED,
120         };*/
121         virtual void    SetDepthMask(DepthMask depthmask);
122
123         virtual bool    SetMaterial(const RAS_IPolyMaterial& mat);
124         virtual bool    Init();
125         virtual void    Exit();
126         virtual bool    BeginFrame(int drawingmode, double time);
127         virtual void    ClearDepthBuffer();
128         virtual void    ClearCachingInfo(void);
129         virtual void    EndFrame();
130         virtual void    SetRenderArea();
131
132         virtual void    SetStereoMode(const StereoMode stereomode);
133         virtual bool    Stereo();
134         virtual void    SetEye(const StereoEye eye);
135         virtual StereoEye       GetEye();
136         virtual void    SetEyeSeparation(const float eyeseparation);
137         virtual float   GetEyeSeparation();
138         virtual void    SetFocalLength(const float focallength);
139         virtual float   GetFocalLength();
140
141         virtual void    SetAlphaTest(bool enable);
142
143         virtual void    SwapBuffers();
144         virtual void    IndexPrimitives(
145                                                 const vecVertexArray& vertexarrays,
146                                                 const vecIndexArrays & indexarrays,
147                                                 int mode,
148                                                 class RAS_IPolyMaterial* polymat,
149                                                 class RAS_IRenderTools* rendertools,
150                                                 bool useObjectColor,
151                                                 const MT_Vector4& rgbacolor
152                                         );
153
154         virtual void    IndexPrimitives_Ex(
155                                                 const vecVertexArray& vertexarrays,
156                                                 const vecIndexArrays & indexarrays,
157                                                 int mode,
158                                                 class RAS_IPolyMaterial* polymat,
159                                                 class RAS_IRenderTools* rendertools,
160                                                 bool useObjectColor,
161                                                 const MT_Vector4& rgbacolor
162                                         );
163
164         virtual void    IndexPrimitives_3DText(
165                                                 const vecVertexArray& vertexarrays,
166                                                 const vecIndexArrays & indexarrays,
167                                                 int mode,
168                                                 class RAS_IPolyMaterial* polymat,
169                                                 class RAS_IRenderTools* rendertools,
170                                                 bool useObjectColor,
171                                                 const MT_Vector4& rgbacolor
172                                         );
173
174         virtual void IndexPrimitivesMulti( 
175                                                 const vecVertexArray& vertexarrays,
176                                                 const vecIndexArrays & indexarrays,
177                                                 int mode,
178                                                 class RAS_IPolyMaterial* polymat,
179                                                 class RAS_IRenderTools* rendertools,
180                                                 bool useObjectColor,
181                                                 const MT_Vector4& rgbacolor);
182
183         virtual void IndexPrimitivesMulti_Ex( 
184                                                 const vecVertexArray& vertexarrays,
185                                                 const vecIndexArrays & indexarrays,
186                                                 int mode,
187                                                 class RAS_IPolyMaterial* polymat,
188                                                 class RAS_IRenderTools* rendertools,
189                                                 bool useObjectColor,
190                                                 const MT_Vector4& rgbacolor);
191
192
193         virtual void    SetProjectionMatrix(MT_CmMatrix4x4 & mat);
194         virtual void    SetProjectionMatrix(const MT_Matrix4x4 & mat);
195         virtual void    SetViewMatrix(
196                                                 const MT_Matrix4x4 & mat,
197                                                 const MT_Vector3& campos,
198                                                 const MT_Point3 &camLoc,
199                                                 const MT_Quaternion &camOrientQuat
200                                         );
201
202         virtual const   MT_Point3& GetCameraPosition();
203         virtual void    LoadViewMatrix();
204         
205         virtual void    SetFog(
206                                                 float start,
207                                                 float dist,
208                                                 float r,
209                                                 float g,
210                                                 float b
211                                         );
212
213         virtual void    SetFogColor(
214                                                 float r,
215                                                 float g,
216                                                 float b
217                                         );
218
219         virtual void    SetFogStart(float fogstart);
220         virtual void    SetFogEnd(float fogend);
221
222         void                    DisableFog();
223         virtual void    DisplayFog();
224
225         virtual void    SetBackColor(
226                                                 float red,
227                                                 float green,
228                                                 float blue,
229                                                 float alpha
230                                         );
231         
232         virtual void    SetDrawingMode(int drawingmode);
233         virtual int             GetDrawingMode();
234
235         virtual void    EnableTextures(bool enable);
236         virtual void    SetCullFace(bool enable);
237         virtual void    SetLines(bool enable);
238
239         virtual MT_Matrix4x4 GetFrustumMatrix(
240                                                         float left,
241                                                         float right,
242                                                         float bottom,
243                                                         float top,
244                                                         float frustnear,
245                                                         float frustfar,
246                                                         bool perspective
247                                                 );
248
249         virtual void    SetSpecularity(
250                                                 float specX,
251                                                 float specY,
252                                                 float specZ,
253                                                 float specval
254                                         );
255
256         virtual void    SetShinyness(float shiny);
257         virtual void    SetDiffuse(
258                                                 float difX,
259                                                 float difY,
260                                                 float difZ,
261                                                 float diffuse
262                                         );
263         virtual void    SetEmissive(float eX,
264                                                                 float eY,
265                                                                 float eZ,
266                                                                 float e
267                                                            );
268
269         virtual void    SetAmbientColor(float red, float green, float blue);
270         virtual void    SetAmbient(float factor);
271
272         virtual void    SetPolygonOffset(float mult, float add);
273
274         virtual void    DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
275         {
276                 OglDebugLine line;
277                 line.m_from = from;
278                 line.m_to = to;
279                 line.m_color = color;
280                 m_debugLines.push_back(line);
281         }
282
283         std::vector <OglDebugLine>      m_debugLines;
284
285         virtual void    SetTexCoords(TexCoGen coords,int enabled);
286         void                    TexCoord(const RAS_TexVert &tv, int unit);
287         virtual void    SetAttrib(int type);
288         virtual void    GetViewMatrix(MT_Matrix4x4 &mat) const;
289
290 };
291
292 #endif //__RAS_OPENGLRASTERIZER
293