4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
29 #ifndef __RAS_OPENGLRASTERIZER
30 #define __RAS_OPENGLRASTERIZER
32 #if defined(WIN32) && !defined(FREE_WINDOWS)
33 #pragma warning (disable:4786)
36 #include "MT_CmMatrix4x4.h"
40 #include "RAS_IRasterizer.h"
41 #include "RAS_MaterialBucket.h"
42 #include "RAS_ICanvas.h"
44 #define RAS_MAX_TEXCO 8 // match in BL_Material
45 #define RAS_MAX_ATTRIB 16 // match in BL_BlenderShader
55 * 3D rendering device context.
57 class RAS_OpenGLRasterizer : public RAS_IRasterizer
60 RAS_ICanvas* m_2DCanvas;
80 MT_Matrix4x4 m_viewmatrix;
81 MT_Matrix4x4 m_viewinvmatrix;
85 StereoMode m_stereomode;
87 float m_eyeseparation;
89 bool m_setfocallength;
94 float m_motionblurvalue;
98 TexCoGen m_texco[RAS_MAX_TEXCO];
99 TexCoGen m_attrib[RAS_MAX_ATTRIB];
102 //int m_last_blendmode;
103 bool m_last_frontface;
105 /** Stores the caching information for the last material activated. */
106 RAS_IPolyMaterial::TCachingInfo m_materialCachingInfo;
110 RAS_OpenGLRasterizer(RAS_ICanvas* canv);
111 virtual ~RAS_OpenGLRasterizer();
124 KX_DEPTHMASK_ENABLED =1,
125 KX_DEPTHMASK_DISABLED,
127 virtual void SetDepthMask(DepthMask depthmask);
129 virtual bool SetMaterial(const RAS_IPolyMaterial& mat);
132 virtual bool BeginFrame(int drawingmode, double time);
133 virtual void ClearColorBuffer();
134 virtual void ClearDepthBuffer();
135 virtual void ClearCachingInfo(void);
136 virtual void EndFrame();
137 virtual void SetRenderArea();
139 virtual void SetStereoMode(const StereoMode stereomode);
140 virtual RAS_IRasterizer::StereoMode GetStereoMode();
141 virtual bool Stereo();
142 virtual bool InterlacedStereo();
143 virtual void SetEye(const StereoEye eye);
144 virtual StereoEye GetEye();
145 virtual void SetEyeSeparation(const float eyeseparation);
146 virtual float GetEyeSeparation();
147 virtual void SetFocalLength(const float focallength);
148 virtual float GetFocalLength();
150 virtual void SwapBuffers();
152 virtual void IndexPrimitives(class RAS_MeshSlot& ms);
153 virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms);
154 virtual void IndexPrimitives_3DText(
155 class RAS_MeshSlot& ms,
156 class RAS_IPolyMaterial* polymat,
157 class RAS_IRenderTools* rendertools);
159 void IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi);
161 virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat);
162 virtual void SetProjectionMatrix(const MT_Matrix4x4 & mat);
163 virtual void SetViewMatrix(
164 const MT_Matrix4x4 & mat,
165 const MT_Matrix3x3 & ori,
166 const MT_Point3 & pos,
170 virtual const MT_Point3& GetCameraPosition();
171 virtual bool GetCameraOrtho();
181 virtual void SetFogColor(
187 virtual void SetFogStart(float fogstart);
188 virtual void SetFogEnd(float fogend);
191 virtual void DisplayFog();
192 virtual bool IsFogEnabled();
194 virtual void SetBackColor(
201 virtual void SetDrawingMode(int drawingmode);
202 virtual int GetDrawingMode();
204 virtual void SetCullFace(bool enable);
205 virtual void SetLines(bool enable);
207 virtual MT_Matrix4x4 GetFrustumMatrix(
218 virtual MT_Matrix4x4 GetOrthoMatrix(
227 virtual void SetSpecularity(
234 virtual void SetShinyness(float shiny);
235 virtual void SetDiffuse(
241 virtual void SetEmissive(float eX,
247 virtual void SetAmbientColor(float red, float green, float blue);
248 virtual void SetAmbient(float factor);
250 virtual void SetPolygonOffset(float mult, float add);
252 virtual void FlushDebugLines();
254 virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
259 line.m_color = color;
260 m_debugLines.push_back(line);
263 std::vector <OglDebugLine> m_debugLines;
265 virtual void SetTexCoordNum(int num);
266 virtual void SetAttribNum(int num);
267 virtual void SetTexCoord(TexCoGen coords, int unit);
268 virtual void SetAttrib(TexCoGen coords, int unit);
270 void TexCoord(const RAS_TexVert &tv);
272 const MT_Matrix4x4& GetViewMatrix() const;
273 const MT_Matrix4x4& GetViewInvMatrix() const;
275 virtual void EnableMotionBlur(float motionblurvalue);
276 virtual void DisableMotionBlur();
277 virtual float GetMotionBlurValue(){return m_motionblurvalue;};
278 virtual int GetMotionBlurState(){return m_motionblur;};
279 virtual void SetMotionBlurState(int newstate)
286 m_motionblur = newstate;
289 virtual void SetBlendingMode(int blendmode);
290 virtual void SetFrontFace(bool ccw);
293 #ifdef WITH_CXX_GUARDEDALLOC
295 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_OpenGLRasterizer"); }
296 void operator delete( void *mem ) { MEM_freeN(mem); }
300 #endif //__RAS_OPENGLRASTERIZER