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 *****
30 /** \file RAS_IRasterizer.h
34 #ifndef __RAS_IRASTERIZER
35 #define __RAS_IRASTERIZER
37 #if defined(WIN32) && !defined(FREE_WINDOWS)
38 #pragma warning (disable:4786)
41 #include "STR_HashedString.h"
43 #include "MT_CmMatrix4x4.h"
44 #include "MT_Matrix4x4.h"
46 #include "RAS_TexVert.h"
51 #ifdef WITH_CXX_GUARDEDALLOC
52 #include "MEM_guardedalloc.h"
56 class RAS_IPolyMaterial;
58 typedef vector<unsigned short> KX_IndexArray;
59 typedef vector<RAS_TexVert> KX_VertexArray;
60 typedef vector< KX_VertexArray* > vecVertexArray;
61 typedef vector< KX_IndexArray* > vecIndexArrays;
64 * 3D rendering device context interface.
69 RAS_IRasterizer(RAS_ICanvas* canv){};
70 virtual ~RAS_IRasterizer(){};
74 RAS_RENDER_3DPOLYGON_TEXT = 16384 /* TF_BMFONT */
99 * Valid SetDepthMask parameters
102 KX_DEPTHMASK_ENABLED =1,
103 KX_DEPTHMASK_DISABLED
109 KX_TEX = 4, /* TF_TEX */
110 KX_LIGHT = 16, /* TF_LIGHT */
111 KX_TWOSIDE = 512, /* TF_TWOSIDE */
119 RAS_STEREO_NOSTEREO = 1,
120 RAS_STEREO_QUADBUFFERED,
121 RAS_STEREO_ABOVEBELOW,
122 RAS_STEREO_INTERLACED,
124 RAS_STEREO_SIDEBYSIDE,
125 RAS_STEREO_VINTERLACE,
135 RAS_TEXCO_GEN, //< GPU will generate texture coordinates
136 RAS_TEXCO_ORCO, //< Vertex coordinates (object space)
137 RAS_TEXCO_GLOB, //< Vertex coordinates (world space)
138 RAS_TEXCO_UV1, //< UV coordinates
139 RAS_TEXCO_OBJECT, //< Use another object's position as coordinates
140 RAS_TEXCO_LAVECTOR, //< Light vector as coordinates
141 RAS_TEXCO_VIEW, //< View vector as coordinates
142 RAS_TEXCO_STICKY, //< Sticky coordinates
143 RAS_TEXCO_WINDOW, //< Window coordinates
144 RAS_TEXCO_NORM, //< Normal coordinates
147 RAS_TEXCO_VCOL, //< Vertex Color
148 RAS_TEXCO_DISABLE //< Disable this texture unit (cached)
152 * Render pass identifiers for stereo.
155 RAS_STEREO_LEFTEYE = 1,
160 * SetDepthMask enables or disables writing a fragment's depth value
163 virtual void SetDepthMask(DepthMask depthmask)=0;
165 * SetMaterial sets the material settings for subsequent primitives
166 * to be rendered with.
167 * The material will be cached.
169 virtual bool SetMaterial(const RAS_IPolyMaterial& mat)=0;
171 * Init initialises the renderer.
173 virtual bool Init()=0;
175 * Exit cleans up the renderer.
177 virtual void Exit()=0;
179 * BeginFrame is called at the start of each frame.
181 virtual bool BeginFrame(int drawingmode, double time)=0;
183 * ClearColorBuffer clears the color buffer.
185 virtual void ClearColorBuffer()=0;
187 * ClearDepthBuffer clears the depth buffer.
189 virtual void ClearDepthBuffer()=0;
191 * ClearCachingInfo clears the currently cached material.
193 virtual void ClearCachingInfo(void)=0;
195 * EndFrame is called at the end of each frame.
197 virtual void EndFrame()=0;
199 * SetRenderArea sets the render area from the 2d canvas.
200 * Returns true if only of subset of the canvas is used.
202 virtual void SetRenderArea()=0;
206 * SetStereoMode will set the stereo mode
208 virtual void SetStereoMode(const StereoMode stereomode)=0;
210 * Stereo can be used to query if the rasterizer is in stereo mode.
211 * @return true if stereo mode is enabled.
213 virtual bool Stereo()=0;
214 virtual StereoMode GetStereoMode()=0;
215 virtual bool InterlacedStereo()=0;
217 * Sets which eye buffer subsequent primitives will be rendered to.
219 virtual void SetEye(const StereoEye eye)=0;
220 virtual StereoEye GetEye()=0;
222 * Sets the distance between eyes for stereo mode.
224 virtual void SetEyeSeparation(const float eyeseparation)=0;
225 virtual float GetEyeSeparation() = 0;
227 * Sets the focal length for stereo mode.
229 virtual void SetFocalLength(const float focallength)=0;
230 virtual float GetFocalLength() = 0;
232 * SwapBuffers swaps the back buffer with the front buffer.
234 virtual void SwapBuffers()=0;
238 * IndexPrimitives: Renders primitives from mesh slot.
240 virtual void IndexPrimitives(class RAS_MeshSlot& ms)=0;
241 virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms)=0;
244 * IndexPrimitives_3DText will render text into the polygons.
245 * The text to be rendered is from @param rendertools client object's text property.
247 virtual void IndexPrimitives_3DText(class RAS_MeshSlot& ms,
248 class RAS_IPolyMaterial* polymat,
249 class RAS_IRenderTools* rendertools)=0;
251 virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat)=0;
252 /* This one should become our final version, methinks. */
254 * Set the projection matrix for the rasterizer. This projects
255 * from camera coordinates to window coordinates.
256 * @param mat The projection matrix.
258 virtual void SetProjectionMatrix(const MT_Matrix4x4 & mat)=0;
260 * Sets the modelview matrix.
262 virtual void SetViewMatrix(const MT_Matrix4x4 & mat,
263 const MT_Matrix3x3 & ori,
264 const MT_Point3 & pos,
268 virtual const MT_Point3& GetCameraPosition()=0;
269 virtual bool GetCameraOrtho()=0;
273 virtual void SetFog(float start,
279 virtual void SetFogColor(float r,
283 virtual void SetFogStart(float start)=0;
286 virtual void SetFogEnd(float end)=0;
289 virtual void DisplayFog()=0;
292 virtual void DisableFog()=0;
293 virtual bool IsFogEnabled()=0;
295 virtual void SetBackColor(float red,
301 * @param drawingmode = KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
303 virtual void SetDrawingMode(int drawingmode)=0;
305 * @return the current drawing mode: KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
307 virtual int GetDrawingMode()=0;
311 virtual void SetCullFace(bool enable)=0;
313 * Sets wireframe mode.
315 virtual void SetLines(bool enable)=0;
318 virtual double GetTime()=0;
320 * Generates a projection matrix from the specified frustum.
321 * @param left the left clipping plane
322 * @param right the right clipping plane
323 * @param bottom the bottom clipping plane
324 * @param top the top clipping plane
325 * @param frustnear the near clipping plane
326 * @param frustfar the far clipping plane
327 * @return a 4x4 matrix representing the projection transform.
329 virtual MT_Matrix4x4 GetFrustumMatrix(
336 float focallength = 0.0f,
337 bool perspective = true
341 * Generates a orthographic projection matrix from the specified frustum.
342 * @param left the left clipping plane
343 * @param right the right clipping plane
344 * @param bottom the bottom clipping plane
345 * @param top the top clipping plane
346 * @param frustnear the near clipping plane
347 * @param frustfar the far clipping plane
348 * @return a 4x4 matrix representing the projection transform.
350 virtual MT_Matrix4x4 GetOrthoMatrix(
360 * Sets the specular color component of the lighting equation.
362 virtual void SetSpecularity(float specX,
368 * Sets the specular exponent component of the lighting equation.
370 virtual void SetShinyness(float shiny)=0;
372 * Sets the diffuse color component of the lighting equation.
374 virtual void SetDiffuse(float difX,
379 * Sets the emissive color component of the lighting equation.
381 virtual void SetEmissive(float eX,
387 virtual void SetAmbientColor(float red, float green, float blue)=0;
388 virtual void SetAmbient(float factor)=0;
391 * Sets a polygon offset. z depth will be: z1 = mult*z0 + add
393 virtual void SetPolygonOffset(float mult, float add) = 0;
395 virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0;
396 virtual void FlushDebugLines()=0;
400 virtual void SetTexCoordNum(int num) = 0;
401 virtual void SetAttribNum(int num) = 0;
402 virtual void SetTexCoord(TexCoGen coords, int unit) = 0;
403 virtual void SetAttrib(TexCoGen coords, int unit) = 0;
405 virtual const MT_Matrix4x4& GetViewMatrix() const = 0;
406 virtual const MT_Matrix4x4& GetViewInvMatrix() const = 0;
408 virtual bool QueryLists(){return false;}
409 virtual bool QueryArrays(){return false;}
411 virtual void EnableMotionBlur(float motionblurvalue)=0;
412 virtual void DisableMotionBlur()=0;
414 virtual float GetMotionBlurValue()=0;
415 virtual int GetMotionBlurState()=0;
416 virtual void SetMotionBlurState(int newstate)=0;
418 virtual void SetBlendingMode(int blendmode)=0;
419 virtual void SetFrontFace(bool ccw)=0;
422 #ifdef WITH_CXX_GUARDEDALLOC
424 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_IRasterizer"); }
425 void operator delete( void *mem ) { MEM_freeN(mem); }
429 #endif //__RAS_IRASTERIZER