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,
125 RAS_TEXCO_GEN, //< GPU will generate texture coordinates
126 RAS_TEXCO_ORCO, //< Vertex coordinates (object space)
127 RAS_TEXCO_GLOB, //< Vertex coordinates (world space)
128 RAS_TEXCO_UV1, //< UV coordinates
129 RAS_TEXCO_OBJECT, //< Use another object's position as coordinates
130 RAS_TEXCO_LAVECTOR, //< Light vector as coordinates
131 RAS_TEXCO_VIEW, //< View vector as coordinates
132 RAS_TEXCO_STICKY, //< Sticky coordinates
133 RAS_TEXCO_WINDOW, //< Window coordinates
134 RAS_TEXCO_NORM, //< Normal coordinates
137 RAS_TEXCO_VCOL, //< Vertex Color
138 RAS_TEXCO_DISABLE //< Disable this texture unit (cached)
142 * Render pass identifiers for stereo.
145 RAS_STEREO_LEFTEYE = 1,
150 * SetDepthMask enables or disables writing a fragment's depth value
153 virtual void SetDepthMask(DepthMask depthmask)=0;
155 * SetMaterial sets the material settings for subsequent primitives
156 * to be rendered with.
157 * The material will be cached.
159 virtual bool SetMaterial(const RAS_IPolyMaterial& mat)=0;
161 * Init initialises the renderer.
163 virtual bool Init()=0;
165 * Exit cleans up the renderer.
167 virtual void Exit()=0;
169 * BeginFrame is called at the start of each frame.
171 virtual bool BeginFrame(int drawingmode, double time)=0;
173 * ClearColorBuffer clears the color buffer.
175 virtual void ClearColorBuffer()=0;
177 * ClearDepthBuffer clears the depth buffer.
179 virtual void ClearDepthBuffer()=0;
181 * ClearCachingInfo clears the currently cached material.
183 virtual void ClearCachingInfo(void)=0;
185 * EndFrame is called at the end of each frame.
187 virtual void EndFrame()=0;
189 * SetRenderArea sets the render area from the 2d canvas.
190 * Returns true if only of subset of the canvas is used.
192 virtual void SetRenderArea()=0;
196 * SetStereoMode will set the stereo mode
198 virtual void SetStereoMode(const StereoMode stereomode)=0;
200 * Stereo can be used to query if the rasterizer is in stereo mode.
201 * @return true if stereo mode is enabled.
203 virtual bool Stereo()=0;
204 virtual StereoMode GetStereoMode()=0;
205 virtual bool InterlacedStereo()=0;
207 * Sets which eye buffer subsequent primitives will be rendered to.
209 virtual void SetEye(const StereoEye eye)=0;
210 virtual StereoEye GetEye()=0;
212 * Sets the distance between eyes for stereo mode.
214 virtual void SetEyeSeparation(const float eyeseparation)=0;
215 virtual float GetEyeSeparation() = 0;
217 * Sets the focal length for stereo mode.
219 virtual void SetFocalLength(const float focallength)=0;
220 virtual float GetFocalLength() = 0;
222 * SwapBuffers swaps the back buffer with the front buffer.
224 virtual void SwapBuffers()=0;
228 * IndexPrimitives: Renders primitives from mesh slot.
230 virtual void IndexPrimitives(class RAS_MeshSlot& ms)=0;
231 virtual void IndexPrimitivesMulti(class RAS_MeshSlot& ms)=0;
234 * IndexPrimitives_3DText will render text into the polygons.
235 * The text to be rendered is from @param rendertools client object's text property.
237 virtual void IndexPrimitives_3DText(class RAS_MeshSlot& ms,
238 class RAS_IPolyMaterial* polymat,
239 class RAS_IRenderTools* rendertools)=0;
241 virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat)=0;
242 /* This one should become our final version, methinks. */
244 * Set the projection matrix for the rasterizer. This projects
245 * from camera coordinates to window coordinates.
246 * @param mat The projection matrix.
248 virtual void SetProjectionMatrix(const MT_Matrix4x4 & mat)=0;
250 * Sets the modelview matrix.
252 virtual void SetViewMatrix(const MT_Matrix4x4 & mat,
253 const MT_Vector3& campos,
254 const MT_Point3 &camLoc,
255 const MT_Quaternion &camOrientQuat)=0;
258 virtual const MT_Point3& GetCameraPosition()=0;
259 virtual bool GetCameraOrtho()=0;
263 virtual void SetFog(float start,
269 virtual void SetFogColor(float r,
273 virtual void SetFogStart(float start)=0;
276 virtual void SetFogEnd(float end)=0;
279 virtual void DisplayFog()=0;
282 virtual void DisableFog()=0;
284 virtual void SetBackColor(float red,
290 * @param drawingmode = KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
292 virtual void SetDrawingMode(int drawingmode)=0;
294 * @return the current drawing mode: KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
296 virtual int GetDrawingMode()=0;
300 virtual void SetCullFace(bool enable)=0;
302 * Sets wireframe mode.
304 virtual void SetLines(bool enable)=0;
307 virtual double GetTime()=0;
309 * Generates a projection matrix from the specified frustum.
310 * @param left the left clipping plane
311 * @param right the right clipping plane
312 * @param bottom the bottom clipping plane
313 * @param top the top clipping plane
314 * @param frustnear the near clipping plane
315 * @param frustfar the far clipping plane
316 * @return a 4x4 matrix representing the projection transform.
318 virtual MT_Matrix4x4 GetFrustumMatrix(
325 float focallength = 0.0f,
326 bool perspective = true
329 * Sets the specular color component of the lighting equation.
331 virtual void SetSpecularity(float specX,
337 * Sets the specular exponent component of the lighting equation.
339 virtual void SetShinyness(float shiny)=0;
341 * Sets the diffuse color component of the lighting equation.
343 virtual void SetDiffuse(float difX,
348 * Sets the emissive color component of the lighting equation.
350 virtual void SetEmissive(float eX,
356 virtual void SetAmbientColor(float red, float green, float blue)=0;
357 virtual void SetAmbient(float factor)=0;
360 * Sets a polygon offset. z depth will be: z1 = mult*z0 + add
362 virtual void SetPolygonOffset(float mult, float add) = 0;
364 virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0;
365 virtual void FlushDebugLines()=0;
369 virtual void SetTexCoordNum(int num) = 0;
370 virtual void SetAttribNum(int num) = 0;
371 virtual void SetTexCoord(TexCoGen coords, int unit) = 0;
372 virtual void SetAttrib(TexCoGen coords, int unit) = 0;
374 virtual const MT_Matrix4x4& GetViewMatrix() const = 0;
375 virtual const MT_Matrix4x4& GetViewInvMatrix() const = 0;
377 virtual bool QueryLists(){return false;}
378 virtual bool QueryArrays(){return false;}
380 virtual void EnableMotionBlur(float motionblurvalue)=0;
381 virtual void DisableMotionBlur()=0;
383 virtual float GetMotionBlurValue()=0;
384 virtual int GetMotionBlurState()=0;
385 virtual void SetMotionBlurState(int newstate)=0;
387 virtual void SetBlendingMode(int blendmode)=0;
388 virtual void SetFrontFace(bool ccw)=0;
391 #endif //__RAS_IRASTERIZER