CrystalSpace

Public API Reference

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

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 class csMatrix3;
00039 class csVector3;
00040 class csVector2;
00041 class csPlane3;
00042 class csRect;
00043 class csReversibleTransform;
00044 class csRenderMesh;
00045 
00046 struct iGraphics2D;
00047 struct iPolygonTexture;
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 csPolyLightMapMapping;
00062 struct iRenderBuffer;
00063 struct iRenderBufferManager;
00064 struct iLightingManager;
00065 
00066 
00069 
00070 #define CSDRAW_2DGRAPHICS   0x00000001
00071 
00072 #define CSDRAW_3DGRAPHICS   0x00000002
00073 
00074 #define CSDRAW_CLEARZBUFFER 0x00000010
00075 
00076 #define CSDRAW_CLEARSCREEN  0x00000020
00077 
00084 #define CS_CLIPPER_NONE -1
00085 
00088 #define CS_CLIPPER_OPTIONAL 0
00089 
00092 #define CS_CLIPPER_TOPLEVEL 1
00093 
00096 #define CS_CLIPPER_REQUIRED 2
00097 
00105 #define CS_CLIP_NOT 0
00106 
00111 #define CS_CLIP_NEEDED 1
00112 
00117 #define CS_CLIP_TOPLEVEL 2
00118 
00123 struct csFog
00124 {
00126   bool enabled;
00128   float density;
00130   float red;
00132   float green;
00134   float blue;
00135 };
00136 
00138 enum csZBufMode
00139 {
00140   // values below are sometimes used as bit masks, so don't change them!
00142   CS_ZBUF_NONE     = 0x00000000,
00144   CS_ZBUF_FILL     = 0x00000001,
00146   CS_ZBUF_TEST     = 0x00000002,
00148   CS_ZBUF_USE      = 0x00000003,
00150   CS_ZBUF_FILLONLY = 0x00000004,
00152   CS_ZBUF_EQUAL    = 0x00000005,
00154   CS_ZBUF_INVERT   = 0x00000006
00155 };
00156 
00157 // @@@ Keep in sync with values below
00158 // @@@ Document me better!
00159 #define CS_VATTRIB_GENERIC_FIRST     0
00160 #define CS_VATTRIB_GENERIC_LAST     15
00161 #define CS_VATTRIB_SPECIFIC_FIRST  100
00162 #define CS_VATTRIB_SPECIFIC_LAST   111
00163 
00164 #define CS_VATTRIB_IS_GENERIC(va)   \
00165   ((va >= CS_VATTRIB_GENERIC_FIRST) && (va <=CS_VATTRIB_GENERIC_LAST))
00166 #define CS_VATTRIB_IS_SPECIFIC(va)   \
00167   ((va >= CS_VATTRIB_SPECIFIC_FIRST) && (va <=CS_VATTRIB_SPECIFIC_LAST))
00168 
00174 enum csVertexAttrib
00175 {
00176   CS_VATTRIB_0 = 0,
00177   CS_VATTRIB_1 = 1,
00178   CS_VATTRIB_2 = 2,
00179   CS_VATTRIB_3 = 3,
00180   CS_VATTRIB_4 = 4,
00181   CS_VATTRIB_5 = 5,
00182   CS_VATTRIB_6 = 6,
00183   CS_VATTRIB_7 = 7,
00184   CS_VATTRIB_8 = 8,
00185   CS_VATTRIB_9 = 9,
00186   CS_VATTRIB_10 = 10,
00187   CS_VATTRIB_11 = 11,
00188   CS_VATTRIB_12 = 12,
00189   CS_VATTRIB_13 = 13,
00190   CS_VATTRIB_14 = 14,
00191   CS_VATTRIB_15 = 15,
00192   CS_VATTRIB_POSITION = CS_VATTRIB_SPECIFIC_FIRST + 0,
00193   CS_VATTRIB_WEIGHT = CS_VATTRIB_SPECIFIC_FIRST + 1,
00194   CS_VATTRIB_NORMAL = CS_VATTRIB_SPECIFIC_FIRST + 2,
00195   CS_VATTRIB_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 3,
00196   CS_VATTRIB_PRIMARY_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 3,
00197   CS_VATTRIB_SECONDARY_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 4,
00198   CS_VATTRIB_FOGCOORD = CS_VATTRIB_SPECIFIC_FIRST + 5,
00199   CS_VATTRIB_TEXCOORD = CS_VATTRIB_SPECIFIC_FIRST + 8,
00200   CS_VATTRIB_TEXCOORD0 = CS_VATTRIB_SPECIFIC_FIRST + 8,
00201   CS_VATTRIB_TEXCOORD1 = CS_VATTRIB_SPECIFIC_FIRST + 9,
00202   CS_VATTRIB_TEXCOORD2 = CS_VATTRIB_SPECIFIC_FIRST + 10,
00203   CS_VATTRIB_TEXCOORD3 = CS_VATTRIB_SPECIFIC_FIRST + 11
00204 };
00205 
00207 enum G3D_FOGMETHOD
00208 {
00209   G3DFOGMETHOD_NONE = 0x00,
00210   G3DFOGMETHOD_ZBUFFER = 0x01,
00211   G3DFOGMETHOD_VERTEX = 0x02
00212 };
00213 
00217 
00218 #define CS_FX_MASK_MIXMODE 0xF0000000 
00219 
00220 #define CS_FX_COPY         0x00000000 
00221 
00222 #define CS_FX_MULTIPLY     0x10000000 
00223 
00224 #define CS_FX_MULTIPLY2    0x20000000 
00225 
00226 #define CS_FX_ADD          0x30000000 
00227 
00228 #define CS_FX_ALPHA        0x40000000 
00229 
00230 #define CS_FX_TRANSPARENT  0x50000000 
00231 
00232 #define CS_FX_DESTALPHAADD 0x60000000 
00233 
00234 #define CS_FX_SRCALPHAADD  0x70000000 
00235 
00236 #define CS_FX_KEYCOLOR     0x08000000 
00237 
00238 #define CS_FX_GOURAUD      0x04000000 
00239 
00240 #define CS_FX_TILING       0x02000000 
00241 
00242 #define CS_FX_MASK_ALPHA   0x000000FF 
00243 
00245 #define CS_FX_SETALPHA(alpha) \
00246   (CS_FX_ALPHA | uint (alpha * CS_FX_MASK_ALPHA))
00247 
00248 #define CS_FX_SETALPHA_INT(alpha) \
00249   (CS_FX_ALPHA | uint (alpha & CS_FX_MASK_ALPHA))
00250 
00254 
00255 #define CS_LIGHTPARAM_POSITION 0
00256 
00257 #define CS_LIGHTPARAM_DIFFUSE 1
00258 
00259 #define CS_LIGHTPARAM_SPECULAR 2
00260 
00261 #define CS_LIGHTPARAM_ATTENUATION 3
00262 
00266 
00267 #define CS_SHADOW_VOLUME_BEGIN 1
00268 
00269 #define CS_SHADOW_VOLUME_PASS1 2
00270 
00271 #define CS_SHADOW_VOLUME_PASS2 3
00272 
00273 #define CS_SHADOW_VOLUME_FAIL1 4
00274 
00275 #define CS_SHADOW_VOLUME_FAIL2 5
00276 
00277 #define CS_SHADOW_VOLUME_USE 6
00278 
00279 #define CS_SHADOW_VOLUME_FINISH 7
00280 
00282 
00283 enum G3D_RENDERSTATEOPTION
00284 {
00286   G3DRENDERSTATE_ZBUFFERMODE,
00288   G3DRENDERSTATE_DITHERENABLE,
00290   G3DRENDERSTATE_BILINEARMAPPINGENABLE,
00292   G3DRENDERSTATE_TRILINEARMAPPINGENABLE,
00294   G3DRENDERSTATE_TRANSPARENCYENABLE,
00296   G3DRENDERSTATE_MIPMAPENABLE,
00298   G3DRENDERSTATE_TEXTUREMAPPINGENABLE,
00300   G3DRENDERSTATE_LIGHTINGENABLE,
00302   G3DRENDERSTATE_INTERLACINGENABLE,
00304   G3DRENDERSTATE_MMXENABLE,
00306   G3DRENDERSTATE_INTERPOLATIONSTEP,
00308   G3DRENDERSTATE_MAXPOLYGONSTODRAW,
00310   G3DRENDERSTATE_GOURAUDENABLE,
00312   G3DRENDERSTATE_EDGES
00313 };
00314 
00316 struct csGraphics3DCaps
00317 {
00318   bool CanClip;
00319   int minTexHeight, minTexWidth;
00320   int maxTexHeight, maxTexWidth;
00321   G3D_FOGMETHOD fog;
00322   bool NeedsPO2Maps;
00323   int MaxAspectRatio;
00324 };
00325 
00326 
00327 //===========================================================================
00328 // Not for new renderer! @@@NR@@@
00329 // The stuff below is either to be ported to new renderer or else
00330 // it will be removed.
00331 //===========================================================================
00332 
00333 #define CS_FOG_FRONT  0
00334 #define CS_FOG_BACK   1
00335 #define CS_FOG_VIEW   2
00336 
00337 //======================================================================
00338 // For vertex based fog the following defines are used:
00339 #define CS_FOGTABLE_SIZE 64
00340 
00341 // Each texel in the fog table holds the fog alpha value at a certain
00342 // (distance*density).  The median distance parameter determines the
00343 // (distance*density) value represented by the texel at the center of
00344 // the fog table.  The fog calculation is:
00345 // alpha = 1.0 - exp( -(density*distance) / CS_FOGTABLE_MEDIANDISTANCE)
00346 #define CS_FOGTABLE_MEDIANDISTANCE 10.0f
00347 #define CS_FOGTABLE_MAXDISTANCE (CS_FOGTABLE_MEDIANDISTANCE * 2.0f)
00348 #define CS_FOGTABLE_DISTANCESCALE (1.0f / CS_FOGTABLE_MAXDISTANCE)
00349 
00350 // Fog (distance*density) is mapped to a texture coordinate and then
00351 // clamped.  This determines the clamp value.  Some drivers don't
00352 // like clamping textures so we must do it ourself
00353 #define CS_FOGTABLE_CLAMPVALUE 0.85f
00354 #define CS_FOG_MAXVALUE (CS_FOGTABLE_MAXDISTANCE * CS_FOGTABLE_CLAMPVALUE)
00355 //======================================================================
00356 
00358 class G3DFogInfo
00359 {
00360 public:
00362   float r, g, b;
00369   float intensity;
00370   float intensity2;
00371 };
00372 
00374 class G3DCam2TextureTransform
00375 {
00376 public:
00378   csMatrix3* m_cam2tex;
00380   csVector3* v_cam2tex;
00381 };
00382 
00384 struct G3DPolygonDPFX
00385 {
00387   int num;
00389   csVector2 vertices[100];
00391   float z[100];
00393   csVector2 texels[100];
00395   csColor colors[100];
00396 
00398   G3DFogInfo fog_info[100];
00400   bool use_fog;
00401 
00403   iMaterialHandle *mat_handle;
00405   uint mixmode;
00406 
00408   uint8 flat_color_r;
00409   uint8 flat_color_g;
00410   uint8 flat_color_b;
00411 
00412   // A dummy constructor to appease NextStep compiler which otherwise
00413   // complains that it is unable to create this object.  This happens when
00414   // a subcomponent such as csVector2 has a constructor.
00415   G3DPolygonDPFX() {}
00416 };
00417 
00419 struct G3DPolygonDFP
00420 {
00422   int num;
00424   csVector2 vertices[100];
00425 
00427   csPlane3 normal;
00428 };
00429 
00431 struct G3DPolygonDP : public G3DPolygonDFP
00432 {
00434   G3DFogInfo fog_info[100];
00436   bool use_fog;
00437 
00439   iMaterialHandle* mat_handle;
00440 
00442   G3DCam2TextureTransform cam2tex;
00443 
00445   //iPolygonTexture* poly_texture;
00446   csPolyTextureMapping* texmap;
00447   csPolyLightMapMapping* lmap;
00448   iRendererLightmap* rlm;
00449   
00451   bool do_fullbright;
00452 
00454   uint mixmode;
00455 
00457   float z_value;
00458 };
00459 
00461 typedef G3DPolygonDP G3DPolygonDPF;
00462 
00474 struct G3DTriangleMesh
00475 {
00476   enum
00477   {
00479     MAX_VERTEXPOOL = 2
00480   };
00481 
00483   int num_vertices_pool;
00484 
00486   int num_triangles;
00488   csTriangle* triangles;
00489 
00491   int clip_portal;
00493   int clip_plane;
00495   int clip_z_plane;
00496 
00498   bool use_vertex_color;
00499 
00501   bool do_fog;
00503   bool do_mirror;
00505   bool do_morph_texels;
00507   bool do_morph_colors;
00508 
00510   enum VertexMode
00511   {
00513     VM_WORLDSPACE,
00515     VM_VIEWSPACE
00516   };
00517   
00519   VertexMode vertex_mode;
00520 
00522   uint mixmode;
00523   float morph_factor;
00528   iVertexBuffer* buffers[MAX_VERTEXPOOL];
00529   iMaterialHandle* mat_handle;
00531   G3DFogInfo* vertex_fog;
00532 
00533   // TODO : store information required for lighting calculation
00534 };
00535 
00546 struct G3DPolygonMesh
00547 {
00549   iPolygonBuffer* polybuf;
00550 
00551   // Apply fogging?
00552   bool do_fog;
00553 
00555   uint mixmode;
00556 
00558   int clip_portal;
00560   int clip_plane;
00562   int clip_z_plane;
00563 
00565   bool do_mirror;
00566 
00568   enum VertexMode
00569   {
00571     VM_WORLDSPACE,
00573     VM_VIEWSPACE
00574   };
00575   
00577   VertexMode vertex_mode;
00578 
00580   G3DFogInfo* vertex_fog;
00581 };
00582 
00583 SCF_VERSION (iGraphics3D, 5, 2, 0);
00584 
00591 struct iGraphics3D : public iBase
00592 {
00594   virtual bool Open () = 0;
00596   virtual void Close () = 0;
00597 
00602   virtual iGraphics2D *GetDriver2D () = 0;
00603 
00605   virtual iTextureManager *GetTextureManager () = 0;
00606 
00608   virtual void SetDimensions (int width, int height) = 0;
00610   virtual int GetWidth () const = 0;
00612   virtual int GetHeight () const = 0;
00613 
00618   virtual const csGraphics3DCaps *GetCaps () const = 0;
00619 
00624   virtual void SetPerspectiveCenter (int x, int y) = 0;
00625 
00627   virtual void GetPerspectiveCenter (int& x, int& y) const = 0;
00628 
00632   virtual void SetPerspectiveAspect (float aspect) = 0;
00633 
00635   virtual float GetPerspectiveAspect () const = 0;
00636 
00641   virtual void SetObjectToCamera (csReversibleTransform* o2c) = 0;
00642 
00646   virtual const csReversibleTransform& GetObjectToCamera () = 0;
00647   
00661   virtual void SetRenderTarget (iTextureHandle* handle,
00662         bool persistent = false) = 0;
00663 
00667   virtual iTextureHandle* GetRenderTarget () const = 0;
00668 
00670   virtual bool BeginDraw (int DrawFlags) = 0;
00671 
00673   virtual void FinishDraw () = 0;
00674 
00680   virtual void Print (csRect *area) = 0;
00681 
00696   virtual void DrawPixmap (iTextureHandle *hTex, int sx, int sy,
00697     int sw, int sh, int tx, int ty, int tw, int th, uint8 Alpha = 0) = 0;
00698 
00703   virtual void DrawLine (const csVector3& v1, const csVector3& v2,
00704     float fov, int color) = 0;
00705 
00711   virtual void SetClipper (iClipper2D* clipper, int cliptype) = 0;
00712 
00716   virtual iClipper2D* GetClipper () = 0;
00717 
00721   virtual int GetClipType () const = 0;
00722 
00727   virtual void SetNearPlane (const csPlane3& pl) = 0;
00728 
00732   virtual void ResetNearPlane () = 0;
00733 
00737   virtual const csPlane3& GetNearPlane () const = 0;
00738 
00742   virtual bool HasNearPlane () const = 0;
00743 
00745   virtual bool SetRenderState (G3D_RENDERSTATEOPTION op, long val) = 0;
00746 
00748   virtual long GetRenderState (G3D_RENDERSTATEOPTION op) const = 0;
00749 
00758   virtual csPtr<iRenderBuffer> CreateRenderBuffer (int size, 
00759     csRenderBufferType type, csRenderBufferComponentType componentType, 
00760     int componentCount, bool index) = 0;
00761 
00766   virtual void SetBufferState (csVertexAttrib* attribs,
00767         iRenderBuffer** buffers, int count) = 0;
00768 
00773   virtual void SetTextureState (int* units, iTextureHandle** textures,
00774         int count) = 0;
00775 
00777   virtual void DrawMesh (csRenderMesh* mymesh) = 0;
00778 
00780   virtual void SetWriteMask (bool red, bool green, bool blue, bool alpha) = 0;
00781 
00783   virtual void GetWriteMask (bool &red, bool &green, bool &blue,
00784         bool &alpha) const = 0;
00785 
00787   virtual void SetZMode (csZBufMode mode) = 0;
00788 
00790   virtual void EnableZOffset () = 0;
00791 
00793   virtual void DisableZOffset () = 0;
00794 
00796   virtual void SetShadowState (int state) = 0;
00797 
00798   //=========================================================================
00799   // Below this line are all functions that are not yet implemented by
00800   // the new renderer or are not going to be implemented ever. In the
00801   // last case they will be removed as soon as we permanently switch
00802   // to the new renderer. @@@NR@@@
00803   //=========================================================================
00805   virtual uint32 *GetZBuffAt (int x, int y) = 0;
00806 
00808   virtual float GetZBuffValue (int x, int y) = 0;
00809 
00811   virtual void DrawPolygon (G3DPolygonDP& poly) = 0;
00812 
00819   virtual void DrawPolygonDebug (G3DPolygonDP& poly) = 0;
00820 
00839   virtual void DrawPolygonFX (G3DPolygonDPFX& poly) = 0;
00840 
00844   virtual void DrawTriangleMesh (G3DTriangleMesh& mesh) = 0;
00845 
00849   virtual void DrawPolygonMesh (G3DPolygonMesh& mesh) = 0;
00850 
00858   virtual void OpenFogObject (CS_ID id, csFog* fog) = 0;
00859 
00871   virtual void DrawFogPolygon (CS_ID id, G3DPolygonDFP& poly, int fogtype) = 0;
00872 
00878   virtual void CloseFogObject (CS_ID id) = 0;
00879 
00889   virtual void OpenPortal (G3DPolygonDFP* poly) = 0;
00890 
00894   virtual void ClosePortal () = 0;
00895 
00897   virtual iHalo *CreateHalo (float iR, float iG, float iB,
00898     unsigned char *iAlpha, int iWidth, int iHeight) = 0;
00899 
00901   virtual void DumpCache () = 0;
00902 
00904   virtual void ClearCache () = 0;
00905 
00911   virtual void RemoveFromCache (iRendererLightmap* rlm) = 0;
00912 
00917   virtual iVertexBufferManager* GetVertexBufferManager () = 0;
00918 
00923   virtual bool IsLightmapOK (int lmw, int lmh, 
00924     int lightCellSize) = 0;
00925 };
00926 
00929 #endif // __CS_IVIDEO_GRAPH3D_H__
00930 

Generated for Crystal Space by doxygen 1.2.14