2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file RAS_IRasterizer.h
32 #ifndef __RAS_IRASTERIZER_H__
33 #define __RAS_IRASTERIZER_H__
36 # pragma warning (disable:4786)
39 #include "STR_HashedString.h"
41 #include "MT_CmMatrix4x4.h"
42 #include "MT_Matrix4x4.h"
44 #include "RAS_TexVert.h"
49 #ifdef WITH_CXX_GUARDEDALLOC
50 #include "MEM_guardedalloc.h"
54 class RAS_IPolyMaterial;
56 class RAS_ILightObject;
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 enum RAS_TEXT_RENDER_MODE {
70 RAS_TEXT_RENDER_NODEF = 0,
76 RAS_IRasterizer(RAS_ICanvas* canv) {};
77 virtual ~RAS_IRasterizer() {};
102 * Valid SetDepthMask parameters
105 KX_DEPTHMASK_ENABLED = 1,
106 KX_DEPTHMASK_DISABLED,
112 RAS_RENDER_3DPOLYGON_TEXT = 64, /* GEMAT_TEXT */
113 KX_BACKCULL = 16, /* GEMAT_BACKCULL */
114 KX_TEX = 4096, /* GEMAT_TEX */
122 RAS_STEREO_NOSTEREO = 1,
123 RAS_STEREO_QUADBUFFERED,
124 RAS_STEREO_ABOVEBELOW,
125 RAS_STEREO_INTERLACED,
127 RAS_STEREO_SIDEBYSIDE,
128 RAS_STEREO_VINTERLACE,
130 RAS_STEREO_3DTVTOPBOTTOM,
139 RAS_TEXCO_GEN, /* < GPU will generate texture coordinates */
140 RAS_TEXCO_ORCO, /* < Vertex coordinates (object space) */
141 RAS_TEXCO_GLOB, /* < Vertex coordinates (world space) */
142 RAS_TEXCO_UV, /* < UV coordinates */
143 RAS_TEXCO_OBJECT, /* < Use another object's position as coordinates */
144 RAS_TEXCO_LAVECTOR, /* < Light vector as coordinates */
145 RAS_TEXCO_VIEW, /* < View vector as coordinates */
146 RAS_TEXCO_STICKY, /* < Sticky coordinates */
147 RAS_TEXCO_WINDOW, /* < Window coordinates */
148 RAS_TEXCO_NORM, /* < Normal coordinates */
149 RAS_TEXTANGENT, /* < */
150 RAS_TEXCO_VCOL, /* < Vertex Color */
151 RAS_TEXCO_DISABLE, /* < Disable this texture unit (cached) */
155 * Render pass identifiers for stereo.
158 RAS_STEREO_LEFTEYE = 1,
170 RAS_MIPMAP_MAX, /* Should always be last */
174 * SetDepthMask enables or disables writing a fragment's depth value
177 virtual void SetDepthMask(DepthMask depthmask) = 0;
180 * SetMaterial sets the material settings for subsequent primitives
181 * to be rendered with.
182 * The material will be cached.
184 virtual bool SetMaterial(const RAS_IPolyMaterial &mat) = 0;
187 * Init initializes the renderer.
189 virtual bool Init() = 0;
192 * Exit cleans up the renderer.
194 virtual void Exit() = 0;
197 * BeginFrame is called at the start of each frame.
199 virtual bool BeginFrame(double time) = 0;
202 * ClearColorBuffer clears the color buffer.
204 virtual void ClearColorBuffer() = 0;
207 * ClearDepthBuffer clears the depth buffer.
209 virtual void ClearDepthBuffer() = 0;
212 * ClearCachingInfo clears the currently cached material.
214 virtual void ClearCachingInfo(void) = 0;
217 * EndFrame is called at the end of each frame.
219 virtual void EndFrame() = 0;
222 * SetRenderArea sets the render area from the 2d canvas.
223 * Returns true if only of subset of the canvas is used.
225 virtual void SetRenderArea() = 0;
229 * SetStereoMode will set the stereo mode
231 virtual void SetStereoMode(const StereoMode stereomode) = 0;
234 * Stereo can be used to query if the rasterizer is in stereo mode.
235 * \return true if stereo mode is enabled.
237 virtual bool Stereo() = 0;
238 virtual StereoMode GetStereoMode() = 0;
239 virtual bool InterlacedStereo() = 0;
242 * Sets which eye buffer subsequent primitives will be rendered to.
244 virtual void SetEye(const StereoEye eye) = 0;
245 virtual StereoEye GetEye() = 0;
248 * Sets the distance between eyes for stereo mode.
250 virtual void SetEyeSeparation(const float eyeseparation) = 0;
251 virtual float GetEyeSeparation() = 0;
254 * Sets the focal length for stereo mode.
256 virtual void SetFocalLength(const float focallength) = 0;
257 virtual float GetFocalLength() = 0;
260 * SwapBuffers swaps the back buffer with the front buffer.
262 virtual void SwapBuffers() = 0;
266 * IndexPrimitives: Renders primitives from mesh slot.
268 virtual void IndexPrimitives(class RAS_MeshSlot &ms) = 0;
269 virtual void IndexPrimitivesMulti(class RAS_MeshSlot &ms) = 0;
272 * IndexPrimitives_3DText will render text into the polygons.
274 virtual void IndexPrimitives_3DText(class RAS_MeshSlot &ms, class RAS_IPolyMaterial *polymat) = 0;
276 virtual void SetProjectionMatrix(MT_CmMatrix4x4 &mat) = 0;
278 /* This one should become our final version, methinks. */
280 * Set the projection matrix for the rasterizer. This projects
281 * from camera coordinates to window coordinates.
282 * \param mat The projection matrix.
284 virtual void SetProjectionMatrix(const MT_Matrix4x4 &mat) = 0;
287 * Sets the modelview matrix.
289 virtual void SetViewMatrix(const MT_Matrix4x4 &mat, const MT_Matrix3x3 &ori,
290 const MT_Point3 &pos, bool perspective) = 0;
294 virtual const MT_Point3& GetCameraPosition() = 0;
295 virtual bool GetCameraOrtho() = 0;
300 virtual void SetFog(float start, float dist, float r, float g, float b) = 0;
301 virtual void SetFogColor(float r, float g,float b) = 0;
302 virtual void SetFogStart(float start) = 0;
303 virtual void SetFogEnd(float end) = 0;
304 virtual void DisplayFog() = 0;
305 virtual void EnableFog(bool enable) = 0;
306 virtual bool IsFogEnabled() = 0;
308 virtual void SetBackColor(float red, float green, float blue, float alpha) = 0;
311 * \param drawingmode = KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
313 virtual void SetDrawingMode(int drawingmode) = 0;
316 * \return the current drawing mode: KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
318 virtual int GetDrawingMode() = 0;
323 virtual void SetCullFace(bool enable) = 0;
326 * Sets wireframe mode.
328 virtual void SetLines(bool enable) = 0;
332 virtual double GetTime() = 0;
335 * Generates a projection matrix from the specified frustum.
336 * \param left the left clipping plane
337 * \param right the right clipping plane
338 * \param bottom the bottom clipping plane
339 * \param top the top clipping plane
340 * \param frustnear the near clipping plane
341 * \param frustfar the far clipping plane
342 * \return a 4x4 matrix representing the projection transform.
344 virtual MT_Matrix4x4 GetFrustumMatrix(
345 float left, float right, float bottom, float top,
346 float frustnear, float frustfar,
347 float focallength = 0.0f, bool perspective = true) = 0;
350 * Generates a orthographic projection matrix from the specified frustum.
351 * \param left the left clipping plane
352 * \param right the right clipping plane
353 * \param bottom the bottom clipping plane
354 * \param top the top clipping plane
355 * \param frustnear the near clipping plane
356 * \param frustfar the far clipping plane
357 * \return a 4x4 matrix representing the projection transform.
359 virtual MT_Matrix4x4 GetOrthoMatrix(
360 float left, float right, float bottom, float top,
361 float frustnear, float frustfar) = 0;
364 * Sets the specular color component of the lighting equation.
366 virtual void SetSpecularity(float specX, float specY, float specZ, float specval) = 0;
369 * Sets the specular exponent component of the lighting equation.
371 virtual void SetShinyness(float shiny) = 0;
374 * Sets the diffuse color component of the lighting equation.
376 virtual void SetDiffuse(float difX,float difY, float difZ, float diffuse) = 0;
379 * Sets the emissive color component of the lighting equation.
381 virtual void SetEmissive(float eX, float eY, float eZ, float e) = 0;
383 virtual void SetAmbientColor(float red, float green, float blue) = 0;
384 virtual void SetAmbient(float factor) = 0;
387 * Sets a polygon offset. z depth will be: z1 = mult*z0 + add
389 virtual void SetPolygonOffset(float mult, float add) = 0;
391 virtual void DrawDebugLine(const MT_Vector3 &from, const MT_Vector3 &to, const MT_Vector3& color) = 0;
392 virtual void DrawDebugCircle(const MT_Vector3 ¢er, const MT_Scalar radius, const MT_Vector3 &color,
393 const MT_Vector3 &normal, int nsector) = 0;
394 virtual void FlushDebugShapes() = 0;
396 virtual void SetTexCoordNum(int num) = 0;
397 virtual void SetAttribNum(int num) = 0;
398 virtual void SetTexCoord(TexCoGen coords, int unit) = 0;
399 virtual void SetAttrib(TexCoGen coords, int unit, int layer = 0) = 0;
401 virtual const MT_Matrix4x4 &GetViewMatrix() const = 0;
402 virtual const MT_Matrix4x4 &GetViewInvMatrix() const = 0;
404 virtual bool QueryLists() { return false; }
405 virtual bool QueryArrays() { return false; }
407 virtual void EnableMotionBlur(float motionblurvalue) = 0;
408 virtual void DisableMotionBlur() = 0;
410 virtual float GetMotionBlurValue() = 0;
411 virtual int GetMotionBlurState() = 0;
412 virtual void SetMotionBlurState(int newstate) = 0;
414 virtual void SetAlphaBlend(int alphablend) = 0;
415 virtual void SetFrontFace(bool ccw) = 0;
417 virtual void SetAnisotropicFiltering(short level) = 0;
418 virtual short GetAnisotropicFiltering() = 0;
420 virtual void SetMipmapping(MipmapOption val) = 0;
421 virtual MipmapOption GetMipmapping() = 0;
423 virtual void SetUsingOverrideShader(bool val) = 0;
424 virtual bool GetUsingOverrideShader() = 0;
429 virtual void applyTransform(double *oglmatrix, int drawingmode) = 0;
433 * \param xco Position on the screen (origin in lower left corner).
434 * \param yco Position on the screen (origin in lower left corner).
435 * \param width Width of the canvas to draw to.
436 * \param height Height of the canvas to draw to.
437 * \param percentage Percentage of bar.
439 virtual void RenderBox2D(int xco, int yco, int width, int height, float percentage) = 0;
442 * Renders 3D text string using BFL.
443 * \param fontid The id of the font.
444 * \param text The string to render.
445 * \param size The size of the text.
446 * \param dpi The resolution of the text.
447 * \param color The color of the object.
448 * \param mat The Matrix of the text object.
449 * \param aspect A scaling factor to compensate for the size.
451 virtual void RenderText3D(
452 int fontid, const char *text, int size, int dpi,
453 const float color[4], const double mat[16], float aspect) = 0;
456 * Renders 2D text string.
457 * \param mode The type of text
458 * \param text The string to render.
459 * \param xco Position on the screen (origin in lower left corner).
460 * \param yco Position on the screen (origin in lower left corner).
461 * \param width Width of the canvas to draw to.
462 * \param height Height of the canvas to draw to.
464 virtual void RenderText2D(
465 RAS_TEXT_RENDER_MODE mode, const char *text,
466 int xco, int yco, int width, int height) = 0;
468 virtual void ProcessLighting(bool uselights, const MT_Transform &trans) = 0;
470 virtual void PushMatrix() = 0;
472 virtual void PopMatrix() = 0;
474 virtual RAS_ILightObject *CreateLight() = 0;
476 virtual void AddLight(RAS_ILightObject *lightobject) = 0;
478 virtual void RemoveLight(RAS_ILightObject *lightobject) = 0;
480 virtual void MotionBlur() = 0;
482 virtual void SetClientObject(void *obj) = 0;
484 virtual void SetAuxilaryClientInfo(void *inf) = 0;
486 #ifdef WITH_CXX_GUARDEDALLOC
487 MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_IRasterizer")
491 #endif /* __RAS_IRASTERIZER_H__ */