CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ivideo/graph3d.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 1998-2001 by Jorrit Tyberghein
00003     Written by Jorrit Tyberghein, Dan Ogles, and Gary Clark.
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_IVIDEO_GRAPH3D_H__
00021 #define __CS_IVIDEO_GRAPH3D_H__
00022 
00031 #include "csutil/scf.h"
00032 #include "csgeom/plane3.h"
00033 #include "csgeom/vector2.h"
00034 #include "csgeom/tri.h"
00035 #include "csutil/cscolor.h"
00036 #include "ivideo/rndbuf.h"
00037 
00038 struct csRenderMesh;
00039 class csMatrix3;
00040 class csVector4;
00041 class csVector3;
00042 class csVector2;
00043 class csPlane3;
00044 class csRect;
00045 class csReversibleTransform;
00046 
00047 struct iGraphics2D;
00048 struct iPolygonBuffer;
00049 struct iVertexBuffer;
00050 struct iVertexBufferManager;
00051 struct iTextureManager;
00052 struct iTextureHandle;
00053 struct iMaterialHandle;
00054 struct iMaterial;
00055 struct iClipper2D;
00056 struct iHalo;
00057 struct iRendererLightmap;
00058 struct csRGBpixel;
00059 struct csPixelFormat;
00060 struct csPolyTextureMapping;
00061 struct iRenderBuffer;
00062 struct iRenderBufferManager;
00063 struct iLightingManager;
00064 struct iPolygonRenderer;
00065 struct iShader;
00066 struct iShaderVariableContext;
00067 
00068 
00071 
00072 #define CSDRAW_2DGRAPHICS   0x00000001
00073 
00074 #define CSDRAW_3DGRAPHICS   0x00000002
00075 
00076 #define CSDRAW_CLEARZBUFFER 0x00000010
00077 
00078 #define CSDRAW_CLEARSCREEN  0x00000020
00079 
00086 #define CS_CLIPPER_NONE -1
00087 
00090 #define CS_CLIPPER_OPTIONAL 0
00091 
00094 #define CS_CLIPPER_TOPLEVEL 1
00095 
00098 #define CS_CLIPPER_REQUIRED 2
00099 
00107 #define CS_CLIP_NOT 0
00108 
00113 #define CS_CLIP_NEEDED 1
00114 
00119 #define CS_CLIP_TOPLEVEL 2
00120 
00125 struct csFog
00126 {
00128   bool enabled;
00130   float density;
00132   float red;
00134   float green;
00136   float blue;
00137 };
00138 
00140 enum csZBufMode
00141 {
00142   // values below are sometimes used as bit masks, so don't change them!
00144   CS_ZBUF_NONE     = 0x00000000,
00146   CS_ZBUF_FILL     = 0x00000001,
00148   CS_ZBUF_TEST     = 0x00000002,
00150   CS_ZBUF_USE      = 0x00000003,
00152   CS_ZBUF_FILLONLY = 0x00000004,
00154   CS_ZBUF_EQUAL    = 0x00000005,
00156   CS_ZBUF_INVERT   = 0x00000006,
00158   CS_ZBUF_MESH     = 0x00000007,
00167   CS_ZBUF_MESH2    = 0x00000008
00168 };
00169 
00170 // @@@ Keep in sync with values below
00171 // @@@ Document me better!
00172 #define CS_VATTRIB_GENERIC_FIRST     0
00173 #define CS_VATTRIB_GENERIC_LAST     15
00174 #define CS_VATTRIB_SPECIFIC_FIRST  100
00175 #define CS_VATTRIB_SPECIFIC_LAST   (CS_VATTRIB_SPECIFIC_FIRST + 15)
00176 
00177 #define CS_VATTRIB_IS_GENERIC(va)   \
00178   ((va >= CS_VATTRIB_GENERIC_FIRST) && (va <=CS_VATTRIB_GENERIC_LAST))
00179 #define CS_VATTRIB_IS_SPECIFIC(va)   \
00180   ((va >= CS_VATTRIB_SPECIFIC_FIRST) && (va <=CS_VATTRIB_SPECIFIC_LAST))
00181 
00187 enum csVertexAttrib
00188 {
00189   CS_VATTRIB_0 = 0,
00190   CS_VATTRIB_1 = 1,
00191   CS_VATTRIB_2 = 2,
00192   CS_VATTRIB_3 = 3,
00193   CS_VATTRIB_4 = 4,
00194   CS_VATTRIB_5 = 5,
00195   CS_VATTRIB_6 = 6,
00196   CS_VATTRIB_7 = 7,
00197   CS_VATTRIB_8 = 8,
00198   CS_VATTRIB_9 = 9,
00199   CS_VATTRIB_10 = 10,
00200   CS_VATTRIB_11 = 11,
00201   CS_VATTRIB_12 = 12,
00202   CS_VATTRIB_13 = 13,
00203   CS_VATTRIB_14 = 14,
00204   CS_VATTRIB_15 = 15,
00205   CS_VATTRIB_POSITION = CS_VATTRIB_SPECIFIC_FIRST + 0,
00206   CS_VATTRIB_WEIGHT = CS_VATTRIB_SPECIFIC_FIRST + 1,
00207   CS_VATTRIB_NORMAL = CS_VATTRIB_SPECIFIC_FIRST + 2,
00208   CS_VATTRIB_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 3,
00209   CS_VATTRIB_PRIMARY_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 3,
00210   CS_VATTRIB_SECONDARY_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 4,
00211   CS_VATTRIB_FOGCOORD = CS_VATTRIB_SPECIFIC_FIRST + 5,
00212   CS_VATTRIB_TEXCOORD = CS_VATTRIB_SPECIFIC_FIRST + 8,
00213   CS_VATTRIB_TEXCOORD0 = CS_VATTRIB_SPECIFIC_FIRST + 8,
00214   CS_VATTRIB_TEXCOORD1 = CS_VATTRIB_SPECIFIC_FIRST + 9,
00215   CS_VATTRIB_TEXCOORD2 = CS_VATTRIB_SPECIFIC_FIRST + 10,
00216   CS_VATTRIB_TEXCOORD3 = CS_VATTRIB_SPECIFIC_FIRST + 11,
00217   CS_VATTRIB_TEXCOORD4 = CS_VATTRIB_SPECIFIC_FIRST + 12,
00218   CS_VATTRIB_TEXCOORD5 = CS_VATTRIB_SPECIFIC_FIRST + 13,
00219   CS_VATTRIB_TEXCOORD6 = CS_VATTRIB_SPECIFIC_FIRST + 14,
00220   CS_VATTRIB_TEXCOORD7 = CS_VATTRIB_SPECIFIC_FIRST + 15,
00221 };
00222 
00224 enum G3D_FOGMETHOD
00225 {
00226   G3DFOGMETHOD_NONE = 0x00,
00227   G3DFOGMETHOD_ZBUFFER = 0x01,
00228   G3DFOGMETHOD_VERTEX = 0x02
00229 };
00230 
00234 
00235 #define CS_FX_MASK_MIXMODE 0xF0000000 
00236 
00237 #define CS_FX_COPY         0x00000000 
00238 
00239 #define CS_FX_MULTIPLY     0x10000000 
00240 
00241 #define CS_FX_MULTIPLY2    0x20000000 
00242 
00243 #define CS_FX_ADD          0x30000000 
00244 
00245 #define CS_FX_ALPHA        0x40000000 
00246 
00247 #define CS_FX_TRANSPARENT  0x50000000 
00248 
00249 #define CS_FX_DESTALPHAADD 0x60000000 
00250 
00251 #define CS_FX_SRCALPHAADD  0x70000000 
00252 
00253 #define CS_FX_KEYCOLOR     0x08000000 
00254 
00255 #define CS_FX_GOURAUD      0x04000000 
00256 
00257 #define CS_FX_TILING       0x02000000 
00258 
00259 #define CS_FX_MASK_ALPHA   0x000000FF 
00260 
00262 #define CS_FX_SETALPHA(alpha) \
00263   (CS_FX_ALPHA | uint (alpha * CS_FX_MASK_ALPHA))
00264 
00265 #define CS_FX_SETALPHA_INT(alpha) \
00266   (CS_FX_ALPHA | uint (alpha & CS_FX_MASK_ALPHA))
00267 
00269 struct csAlphaMode
00270 {
00271   enum AlphaType
00272   {
00273     alphaNone = 1,
00274     alphaBinary,
00275     alphaSmooth
00276   };
00277   bool autoAlphaMode;
00278   union
00279   {
00280     AlphaType alphaType;
00281     csStringID autoModeTexture;
00282   };
00283 };
00284 
00287 
00288 #define CS_LIGHTPARAM_POSITION 0
00289 
00290 #define CS_LIGHTPARAM_DIFFUSE 1
00291 
00292 #define CS_LIGHTPARAM_SPECULAR 2
00293 
00294 #define CS_LIGHTPARAM_ATTENUATION 3
00295 
00299 
00300 #define CS_SHADOW_VOLUME_BEGIN 1
00301 
00302 #define CS_SHADOW_VOLUME_PASS1 2
00303 
00304 #define CS_SHADOW_VOLUME_PASS2 3
00305 
00306 #define CS_SHADOW_VOLUME_FAIL1 4
00307 
00308 #define CS_SHADOW_VOLUME_FAIL2 5
00309 
00310 #define CS_SHADOW_VOLUME_USE 6
00311 
00312 #define CS_SHADOW_VOLUME_FINISH 7
00313 
00315 
00316 enum G3D_RENDERSTATEOPTION
00317 {
00319   G3DRENDERSTATE_ZBUFFERMODE,
00321   G3DRENDERSTATE_DITHERENABLE,
00323   G3DRENDERSTATE_BILINEARMAPPINGENABLE,
00325   G3DRENDERSTATE_TRILINEARMAPPINGENABLE,
00327   G3DRENDERSTATE_TRANSPARENCYENABLE,
00329   G3DRENDERSTATE_MIPMAPENABLE,
00331   G3DRENDERSTATE_TEXTUREMAPPINGENABLE,
00333   G3DRENDERSTATE_LIGHTINGENABLE,
00335   G3DRENDERSTATE_INTERLACINGENABLE,
00337   G3DRENDERSTATE_MMXENABLE,
00339   G3DRENDERSTATE_INTERPOLATIONSTEP,
00341   G3DRENDERSTATE_MAXPOLYGONSTODRAW,
00343   G3DRENDERSTATE_GOURAUDENABLE,
00345   G3DRENDERSTATE_EDGES
00346 };
00347 
00349 struct csGraphics3DCaps
00350 {
00351   bool CanClip;
00352   int minTexHeight, minTexWidth;
00353   int maxTexHeight, maxTexWidth;
00354   G3D_FOGMETHOD fog;
00355   bool NeedsPO2Maps;
00356   int MaxAspectRatio;
00357   bool SupportsPointSprites;
00358 };
00359 
00360 //===========================================================================
00361 // Not for new renderer! @@@NR@@@
00362 // The stuff below is either to be ported to new renderer or else
00363 // it will be removed.
00364 //===========================================================================
00365 
00366 #define CS_FOG_FRONT  0
00367 #define CS_FOG_BACK   1
00368 #define CS_FOG_VIEW   2
00369 
00370 //======================================================================
00371 // For vertex based fog the following defines are used:
00372 #define CS_FOGTABLE_SIZE 64
00373 
00374 // Each texel in the fog table holds the fog alpha value at a certain
00375 // (distance*density).  The median distance parameter determines the
00376 // (distance*density) value represented by the texel at the center of
00377 // the fog table.  The fog calculation is:
00378 // alpha = 1.0 - exp( -(density*distance) / CS_FOGTABLE_MEDIANDISTANCE)
00379 #define CS_FOGTABLE_MEDIANDISTANCE 10.0f
00380 #define CS_FOGTABLE_MAXDISTANCE (CS_FOGTABLE_MEDIANDISTANCE * 2.0f)
00381 #define CS_FOGTABLE_DISTANCESCALE (1.0f / CS_FOGTABLE_MAXDISTANCE)
00382 
00383 // Fog (distance*density) is mapped to a texture coordinate and then
00384 // clamped.  This determines the clamp value.  Some drivers don't
00385 // like clamping textures so we must do it ourself
00386 #define CS_FOGTABLE_CLAMPVALUE 0.85f
00387 #define CS_FOG_MAXVALUE (CS_FOGTABLE_MAXDISTANCE * CS_FOGTABLE_CLAMPVALUE)
00388 //======================================================================
00389 
00391 class G3DFogInfo
00392 {
00393 public:
00395   float r, g, b;
00402   float intensity;
00403   float intensity2;
00404 };
00405 
00407 class G3DCam2TextureTransform
00408 {
00409 public:
00411   csMatrix3* m_cam2tex;
00413   csVector3* v_cam2tex;
00414 };
00415 
00417 struct G3DPolygonDPFX
00418 {
00420   int num;
00422   csVector2 vertices[100];
00424   float z[100];
00426   csVector2 texels[100];
00428   csColor colors[100];
00429 
00431   G3DFogInfo fog_info[100];
00433   bool use_fog;
00434 
00436   iMaterialHandle *mat_handle;
00438   uint mixmode;
00439 
00441   uint8 flat_color_r;
00442   uint8 flat_color_g;
00443   uint8 flat_color_b;
00444 
00445   // A dummy constructor to appease NextStep compiler which otherwise
00446   // complains that it is unable to create this object.  This happens when
00447   // a subcomponent such as csVector2 has a constructor.
00448   G3DPolygonDPFX() {}
00449 };
00450 
00452 struct G3DPolygonDFP
00453 {
00455   int num;
00457   csVector2 vertices[100];
00458 
00460   csPlane3 normal;
00461 };
00462 
00464 struct G3DPolygonDP : public G3DPolygonDFP
00465 {
00467   G3DFogInfo fog_info[100];
00469   bool use_fog;
00470 
00472   iMaterialHandle* mat_handle;
00473 
00475   G3DCam2TextureTransform cam2tex;
00476 
00478   csPolyTextureMapping* texmap;
00479   iRendererLightmap* rlm;
00480   
00482   bool do_fullbright;
00483 
00485   uint mixmode;
00486 
00488   float z_value;
00489 };
00490 
00492 typedef G3DPolygonDP G3DPolygonDPF;
00493 
00505 struct G3DTriangleMesh
00506 {
00507   enum
00508   {
00510     MAX_VERTEXPOOL = 2
00511   };
00512 
00514   int num_vertices_pool;
00515 
00517   int num_triangles;
00519   csTriangle* triangles;
00520 
00522   int clip_portal;
00524   int clip_plane;
00526   int clip_z_plane;
00527 
00529   bool use_vertex_color;
00530 
00532   bool do_fog;
00534   bool do_mirror;
00536   bool do_morph_texels;
00538   bool do_morph_colors;
00539 
00541   enum VertexMode
00542   {
00544     VM_WORLDSPACE,
00546     VM_VIEWSPACE
00547   };
00548   
00550   VertexMode vertex_mode;
00551 
00553   uint mixmode;
00554   float morph_factor;
00559   iVertexBuffer* buffers[MAX_VERTEXPOOL];
00560   iMaterialHandle* mat_handle;
00562   G3DFogInfo* vertex_fog;
00563 
00564   // TODO : store information required for lighting calculation
00565 };
00566 
00577 struct G3DPolygonMesh
00578 {
00580   iPolygonBuffer* polybuf;
00581 
00582   // Apply fogging?
00583   bool do_fog;
00584 
00586   uint mixmode;
00587 
00589   int clip_portal;
00591   int clip_plane;
00593   int clip_z_plane;
00594 
00596   bool do_mirror;
00597 
00599   enum VertexMode
00600   {
00602     VM_WORLDSPACE,
00604     VM_VIEWSPACE
00605   };
00606   
00608   VertexMode vertex_mode;
00609 
00611   G3DFogInfo* vertex_fog;
00612 };
00613 
00615 enum csRenderMeshType
00616 {
00617   CS_MESHTYPE_TRIANGLES,
00618   CS_MESHTYPE_QUADS,
00619   CS_MESHTYPE_TRIANGLESTRIP,
00620   CS_MESHTYPE_TRIANGLEFAN,
00621   CS_MESHTYPE_POINTS,
00622   CS_MESHTYPE_POINT_SPRITES,
00623   CS_MESHTYPE_LINES,
00624   CS_MESHTYPE_LINESTRIP,
00625   CS_MESHTYPE_POLYGON,
00626 };
00627 
00631 struct csSimpleRenderMesh
00632 {
00634   csRenderMeshType meshtype;
00635 
00637   uint indexCount;
00639   uint* indices;
00640 
00642   uint vertexCount;
00648   csVector3* vertices;
00650   csVector2* texcoords;
00656   csVector4* colors;
00661   iTextureHandle* texture;
00662 
00664   iShader* shader;
00666   iShaderVariableContext* dynDomain;
00668   csAlphaMode alphaType;
00670   csZBufMode z_buf_mode;
00672   uint mixmode;
00673 
00674   csSimpleRenderMesh () : texture (0), shader (0), dynDomain (0), 
00675     z_buf_mode (CS_ZBUF_NONE), mixmode (CS_FX_COPY)
00676   {  
00677     alphaType.autoAlphaMode = true;
00678     alphaType.autoModeTexture = csInvalidStringID;
00679   };
00680 };
00681 
00682 SCF_VERSION (iGraphics3D, 5, 2, 2);
00683 
00690 struct iGraphics3D : public iBase
00691 {
00693   virtual bool Open () = 0;
00695   virtual void Close () = 0;
00696 
00701   virtual iGraphics2D *GetDriver2D () = 0;
00702 
00704   virtual iTextureManager *GetTextureManager () = 0;
00705 
00707   virtual void SetDimensions (int width, int height) = 0;
00709   virtual int GetWidth () const = 0;
00711   virtual int GetHeight () const = 0;
00712 
00717   virtual const csGraphics3DCaps *GetCaps () const = 0;
00718 
00723   virtual void SetPerspectiveCenter (int x, int y) = 0;
00724 
00726   virtual void GetPerspectiveCenter (int& x, int& y) const = 0;
00727 
00731   virtual void SetPerspectiveAspect (float aspect) = 0;
00732 
00734   virtual float GetPerspectiveAspect () const = 0;
00735 
00740   virtual void SetObjectToCamera (csReversibleTransform* o2c) = 0;
00741 
00745   virtual const csReversibleTransform& GetObjectToCamera () = 0;
00746   
00760   virtual void SetRenderTarget (iTextureHandle* handle,
00761         bool persistent = false) = 0;
00762 
00766   virtual iTextureHandle* GetRenderTarget () const = 0;
00767 
00769   virtual bool BeginDraw (int DrawFlags) = 0;
00770 
00772   virtual void FinishDraw () = 0;
00773 
00779   virtual void Print (csRect *area) = 0;
00780 
00795   virtual void DrawPixmap (iTextureHandle *hTex, int sx, int sy,
00796     int sw, int sh, int tx, int ty, int tw, int th, uint8 Alpha = 0) = 0;
00797 
00802   virtual void DrawLine (const csVector3& v1, const csVector3& v2,
00803     float fov, int color) = 0;
00804 
00810   virtual void SetClipper (iClipper2D* clipper, int cliptype) = 0;
00811 
00815   virtual iClipper2D* GetClipper () = 0;
00816 
00820   virtual int GetClipType () const = 0;
00821 
00826   virtual void SetNearPlane (const csPlane3& pl) = 0;
00827 
00831   virtual void ResetNearPlane () = 0;
00832 
00836   virtual const csPlane3& GetNearPlane () const = 0;
00837 
00841   virtual bool HasNearPlane () const = 0;
00842 
00844   virtual bool SetRenderState (G3D_RENDERSTATEOPTION op, long val) = 0;
00845 
00847   virtual long GetRenderState (G3D_RENDERSTATEOPTION op) const = 0;
00848 
00857   virtual csPtr<iRenderBuffer> CreateRenderBuffer (int size, 
00858     csRenderBufferType type, csRenderBufferComponentType componentType, 
00859     int componentCount, bool index) = 0;
00860 
00867   virtual void CreateInterleavedRenderBuffers (int size, 
00868     csRenderBufferType type, int count, csArray<iRenderBuffer*> &buffers) = 0;
00869 
00874   virtual void SetBufferState (csVertexAttrib* attribs,
00875         iRenderBuffer** buffers, int count) = 0;
00876 
00881   virtual void SetTextureState (int* units, iTextureHandle** textures,
00882         int count) = 0;
00883 
00885   virtual void DrawMesh (csRenderMesh* mymesh) = 0;
00886 
00888   virtual void SetWriteMask (bool red, bool green, bool blue, bool alpha) = 0;
00889 
00891   virtual void GetWriteMask (bool &red, bool &green, bool &blue,
00892         bool &alpha) const = 0;
00893 
00895   virtual void SetZMode (csZBufMode mode) = 0;
00896 
00898   virtual void EnableZOffset () = 0;
00899 
00901   virtual void DisableZOffset () = 0;
00902 
00904   virtual void SetShadowState (int state) = 0;
00905 
00906   //=========================================================================
00907   // Below this line are all functions that are not yet implemented by
00908   // the new renderer or are not going to be implemented ever. In the
00909   // last case they will be removed as soon as we permanently switch
00910   // to the new renderer. @@@NR@@@
00911   //=========================================================================
00913   virtual uint32 *GetZBuffAt (int x, int y) = 0;
00914 
00916   virtual float GetZBuffValue (int x, int y) = 0;
00917 
00919   virtual void DrawPolygon (G3DPolygonDP& poly) = 0;
00920 
00927   virtual void DrawPolygonDebug (G3DPolygonDP& poly) = 0;
00928 
00947   virtual void DrawPolygonFX (G3DPolygonDPFX& poly) = 0;
00948 
00952   virtual void DrawTriangleMesh (G3DTriangleMesh& mesh) = 0;
00953 
00957   virtual void DrawPolygonMesh (G3DPolygonMesh& mesh) = 0;
00958 
00966   virtual void OpenFogObject (CS_ID id, csFog* fog) = 0;
00967 
00979   virtual void DrawFogPolygon (CS_ID id, G3DPolygonDFP& poly, int fogtype) = 0;
00980 
00986   virtual void CloseFogObject (CS_ID id) = 0;
00987 
00997   virtual void OpenPortal (G3DPolygonDFP* poly) = 0;
00998 
01002   virtual void ClosePortal () = 0;
01003 
01005   virtual iHalo *CreateHalo (float iR, float iG, float iB,
01006     unsigned char *iAlpha, int iWidth, int iHeight) = 0;
01007 
01009   virtual void DumpCache () = 0;
01010 
01012   virtual void ClearCache () = 0;
01013 
01019   virtual void RemoveFromCache (iRendererLightmap* rlm) = 0;
01020 
01025   virtual iVertexBufferManager* GetVertexBufferManager () = 0;
01026   
01027   //=========================================================================
01028   // Here ends the zone of unimplemented methods.
01029   //=========================================================================
01030 
01035   virtual bool IsLightmapOK (int lmw, int lmh, 
01036     int lightCellSize) = 0;
01037     
01038   virtual csPtr<iPolygonRenderer> CreatePolygonRenderer () = 0;
01039 
01040   /*
01041     @@@ Needed for SW poly drawing ATM.
01042    */
01043   virtual void SetWorldToCamera (csReversibleTransform* w2c) = 0;
01044 
01056   virtual void DrawSimpleMesh (const csSimpleRenderMesh& mesh) = 0;
01057 
01059   virtual csZBufMode GetZMode () = 0;
01060 };
01061 
01064 #endif // __CS_IVIDEO_GRAPH3D_H__
01065 

Generated for Crystal Space by doxygen 1.2.18