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