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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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_IRASTERIZER
30 #define __RAS_IRASTERIZER
33 #pragma warning (disable:4786)
36 #include "STR_HashedString.h"
38 #include "MT_CmMatrix4x4.h"
39 #include "MT_Matrix4x4.h"
41 #include "RAS_TexVert.h"
47 class RAS_IPolyMaterial;
49 typedef vector<unsigned short> KX_IndexArray;
50 typedef vector<RAS_TexVert> KX_VertexArray;
51 typedef vector< KX_VertexArray* > vecVertexArray;
52 typedef vector< KX_IndexArray* > vecIndexArrays;
55 * 3D rendering device context interface.
61 RAS_IRasterizer(RAS_ICanvas* canv){};
62 virtual ~RAS_IRasterizer(){};
66 RAS_RENDER_3DPOLYGON_TEXT = 16384
91 * Valid SetDepthMask parameters
94 KX_DEPTHMASK_ENABLED =1,
109 RAS_STEREO_NOSTEREO = 1,
110 RAS_STEREO_QUADBUFFERED,
111 RAS_STEREO_ABOVEBELOW,
112 RAS_STEREO_INTERLACED,
114 RAS_STEREO_SIDEBYSIDE,
115 RAS_STEREO_VINTERLACE,
124 RAS_TEXCO_GEN, //< GPU will generate texture coordinates
125 RAS_TEXCO_ORCO, //< Vertex coordinates (object space)
126 RAS_TEXCO_GLOB, //< Vertex coordinates (world space)
127 RAS_TEXCO_UV1, //< UV coordinates
128 RAS_TEXCO_OBJECT, //< Use another object's position as coordinates
129 RAS_TEXCO_LAVECTOR, //< Light vector as coordinates
130 RAS_TEXCO_VIEW, //< View vector as coordinates
131 RAS_TEXCO_STICKY, //< Sticky coordinates
132 RAS_TEXCO_WINDOW, //< Window coordinates
133 RAS_TEXCO_NORM, //< Normal coordinates
136 RAS_TEXCO_VCOL, //< Vertex Color
137 RAS_TEXCO_DISABLE //< Disable this texture unit (cached)
141 * Render pass identifiers for stereo.
144 RAS_STEREO_LEFTEYE = 1,
149 * SetDepthMask enables or disables writing a fragment's depth value
152 virtual void SetDepthMask(DepthMask depthmask)=0;
154 * SetMaterial sets the material settings for subsequent primitives
155 * to be rendered with.
156 * The material will be cached.
158 virtual bool SetMaterial(const RAS_IPolyMaterial& mat)=0;
160 * Init initialises the renderer.
162 virtual bool Init()=0;
164 * Exit cleans up the renderer.
166 virtual void Exit()=0;
168 * BeginFrame is called at the start of each frame.
170 virtual bool BeginFrame(int drawingmode, double time)=0;
172 * ClearColorBuffer clears the color buffer.
174 virtual void ClearColorBuffer()=0;
176 * ClearDepthBuffer clears the depth buffer.
178 virtual void ClearDepthBuffer()=0;
180 * ClearCachingInfo clears the currently cached material.
182 virtual void ClearCachingInfo(void)=0;
184 * EndFrame is called at the end of each frame.
186 virtual void EndFrame()=0;
188 * SetRenderArea sets the render area from the 2d canvas.
189 * Returns true if only of subset of the canvas is used.
191 virtual void SetRenderArea()=0;
195 * SetStereoMode will set the stereo mode
197 virtual void SetStereoMode(const StereoMode stereomode)=0;
199 * Stereo can be used to query if the rasterizer is in stereo mode.
200 * @return true if stereo mode is enabled.
202 virtual bool Stereo()=0;
203 virtual StereoMode GetStereoMode()=0;
204 virtual bool InterlacedStereo()=0;
206 * Sets which eye buffer subsequent primitives will be rendered to.
208 virtual void SetEye(const StereoEye eye)=0;
209 virtual StereoEye GetEye()=0;
211 * Sets the distance between eyes for stereo mode.
213 virtual void SetEyeSeparation(const float eyeseparation)=0;
214 virtual float GetEyeSeparation() = 0;
216 * Sets the focal length for stereo mode.
218 virtual void SetFocalLength(const float focallength)=0;
219 virtual float GetFocalLength() = 0;
221 * SwapBuffers swaps the back buffer with the front buffer.
223 virtual void SwapBuffers()=0;
227 * IndexPrimitives: Renders primitives from mesh slot.
229 virtual void IndexPrimitives(class RAS_MeshSlot& ms)=0;
230 virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms)=0;
233 * IndexPrimitives_3DText will render text into the polygons.
234 * The text to be rendered is from @param rendertools client object's text property.
236 virtual void IndexPrimitives_3DText(class RAS_MeshSlot& ms,
237 class RAS_IPolyMaterial* polymat,
238 class RAS_IRenderTools* rendertools)=0;
240 virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat)=0;
241 /* This one should become our final version, methinks. */
243 * Set the projection matrix for the rasterizer. This projects
244 * from camera coordinates to window coordinates.
245 * @param mat The projection matrix.
247 virtual void SetProjectionMatrix(const MT_Matrix4x4 & mat)=0;
249 * Sets the modelview matrix.
251 virtual void SetViewMatrix(const MT_Matrix4x4 & mat,
252 const MT_Vector3& campos,
253 const MT_Point3 &camLoc,
254 const MT_Quaternion &camOrientQuat)=0;
257 virtual const MT_Point3& GetCameraPosition()=0;
258 virtual bool GetCameraOrtho()=0;
262 virtual void SetFog(float start,
268 virtual void SetFogColor(float r,
272 virtual void SetFogStart(float start)=0;
275 virtual void SetFogEnd(float end)=0;
278 virtual void DisplayFog()=0;
281 virtual void DisableFog()=0;
283 virtual void SetBackColor(float red,
289 * @param drawingmode = KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
291 virtual void SetDrawingMode(int drawingmode)=0;
293 * @return the current drawing mode: KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
295 virtual int GetDrawingMode()=0;
299 virtual void SetCullFace(bool enable)=0;
301 * Sets wireframe mode.
303 virtual void SetLines(bool enable)=0;
306 virtual double GetTime()=0;
308 * Generates a projection matrix from the specified frustum.
309 * @param left the left clipping plane
310 * @param right the right clipping plane
311 * @param bottom the bottom clipping plane
312 * @param top the top clipping plane
313 * @param frustnear the near clipping plane
314 * @param frustfar the far clipping plane
315 * @return a 4x4 matrix representing the projection transform.
317 virtual MT_Matrix4x4 GetFrustumMatrix(
324 float focallength = 0.0f,
325 bool perspective = true
328 * Sets the specular color component of the lighting equation.
330 virtual void SetSpecularity(float specX,
336 * Sets the specular exponent component of the lighting equation.
338 virtual void SetShinyness(float shiny)=0;
340 * Sets the diffuse color component of the lighting equation.
342 virtual void SetDiffuse(float difX,
347 * Sets the emissive color component of the lighting equation.
349 virtual void SetEmissive(float eX,
355 virtual void SetAmbientColor(float red, float green, float blue)=0;
356 virtual void SetAmbient(float factor)=0;
359 * Sets a polygon offset. z depth will be: z1 = mult*z0 + add
361 virtual void SetPolygonOffset(float mult, float add) = 0;
363 virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0;
364 virtual void FlushDebugLines()=0;
368 virtual void SetTexCoordNum(int num) = 0;
369 virtual void SetAttribNum(int num) = 0;
370 virtual void SetTexCoord(TexCoGen coords, int unit) = 0;
371 virtual void SetAttrib(TexCoGen coords, int unit) = 0;
373 virtual const MT_Matrix4x4& GetViewMatrix() const = 0;
374 virtual const MT_Matrix4x4& GetViewInvMatrix() const = 0;
376 virtual bool QueryLists(){return false;}
377 virtual bool QueryArrays(){return false;}
379 virtual void EnableMotionBlur(float motionblurvalue)=0;
380 virtual void DisableMotionBlur()=0;
382 virtual float GetMotionBlurValue()=0;
383 virtual int GetMotionBlurState()=0;
384 virtual void SetMotionBlurState(int newstate)=0;
386 virtual void SetBlendingMode(int blendmode)=0;
387 virtual void SetFrontFace(bool ccw)=0;
390 #endif //__RAS_IRASTERIZER