CrystalSpace

Public API Reference

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

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 
00037 class csMatrix3;
00038 class csVector3;
00039 class csVector2;
00040 class csPlane3;
00041 class csRect;
00042 class csReversibleTransform;
00043 
00044 struct iGraphics2D;
00045 struct iPolygonTexture;
00046 struct iPolygonBuffer;
00047 struct iVertexBuffer;
00048 struct iVertexBufferManager;
00049 struct iTextureManager;
00050 struct iTextureHandle;
00051 struct iMaterialHandle;
00052 struct iMaterial;
00053 struct iClipper2D;
00054 struct iHalo;
00055 struct csRGBpixel;
00056 struct csPixelFormat;
00057 
00058 #ifndef CS_USE_NEW_RENDERER
00059 
00060 #define CS_FOG_FRONT  0
00061 #define CS_FOG_BACK   1
00062 #define CS_FOG_VIEW   2
00063 
00064 //======================================================================
00065 // For vertex based fog the following defines are used:
00066 #define CS_FOGTABLE_SIZE 64
00067 
00068 // Each texel in the fog table holds the fog alpha value at a certain
00069 // (distance*density).  The median distance parameter determines the
00070 // (distance*density) value represented by the texel at the center of
00071 // the fog table.  The fog calculation is:
00072 // alpha = 1.0 - exp( -(density*distance) / CS_FOGTABLE_MEDIANDISTANCE)
00073 #define CS_FOGTABLE_MEDIANDISTANCE 10.0f
00074 #define CS_FOGTABLE_MAXDISTANCE (CS_FOGTABLE_MEDIANDISTANCE * 2.0f)
00075 #define CS_FOGTABLE_DISTANCESCALE (1.0f / CS_FOGTABLE_MAXDISTANCE)
00076 
00077 // Fog (distance*density) is mapped to a texture coordinate and then
00078 // clamped.  This determines the clamp value.  Some drivers don't
00079 // like clamping textures so we must do it ourself
00080 #define CS_FOGTABLE_CLAMPVALUE 0.85f
00081 #define CS_FOG_MAXVALUE (CS_FOGTABLE_MAXDISTANCE * CS_FOGTABLE_CLAMPVALUE)
00082 //======================================================================
00083 
00087 
00088 #define CS_FX_MASK_MIXMODE 0xF0000000 
00089 
00090 #define CS_FX_COPY         0x00000000 
00091 
00092 #define CS_FX_MULTIPLY     0x10000000 
00093 
00094 #define CS_FX_MULTIPLY2    0x20000000 
00095 
00096 #define CS_FX_ADD          0x30000000 
00097 
00098 #define CS_FX_ALPHA        0x40000000 
00099 
00100 #define CS_FX_TRANSPARENT  0x50000000 
00101 
00102 #define CS_FX_KEYCOLOR     0x08000000 
00103 
00104 #define CS_FX_GOURAUD      0x04000000 
00105 
00106 #define CS_FX_TILING       0x02000000 
00107 
00108 #define CS_FX_MASK_ALPHA   0x000000FF 
00109 
00111 #define CS_FX_SETALPHA(alpha) \
00112   (CS_FX_ALPHA | uint (alpha * CS_FX_MASK_ALPHA))
00113 
00114 #define CS_FX_SETALPHA_INT(alpha) \
00115   (CS_FX_ALPHA | uint (alpha & CS_FX_MASK_ALPHA))
00116 
00118 
00119 class G3DFogInfo
00120 {
00121 public:
00123   float r, g, b;
00130   float intensity;
00131   float intensity2;
00132 };
00133 
00135 class G3DTexturePlane
00136 {
00137 public:
00139   csMatrix3* m_cam2tex;
00141   csVector3* v_cam2tex;
00142 };
00143 
00145 struct G3DPolygonDPFX
00146 {
00148   int num;
00150   csVector2 vertices[100];
00152   float z[100];
00154   csVector2 texels[100];
00156   csColor colors[100];
00157 
00159   G3DFogInfo fog_info[100];
00161   bool use_fog;
00162 
00164   iMaterialHandle *mat_handle;
00166   uint mixmode;
00167 
00169   uint8 flat_color_r;
00170   uint8 flat_color_g;
00171   uint8 flat_color_b;
00172 
00173   // A dummy constructor to appease NextStep compiler which otherwise
00174   // complains that it is unable to create this object.  This happens when
00175   // a subcomponent such as csVector2 has a constructor.
00176   G3DPolygonDPFX() {}
00177 };
00178 
00180 struct G3DPolygonDFP
00181 {
00183   int num;
00185   csVector2 vertices[100];
00186 
00188   csPlane3 normal;
00189 };
00190 
00192 struct G3DPolygonDP : public G3DPolygonDFP
00193 {
00195   G3DFogInfo fog_info[100];
00197   bool use_fog;
00198 
00200   iMaterialHandle* mat_handle;
00201 
00203   G3DTexturePlane plane;
00204 
00206   iPolygonTexture* poly_texture;
00207   
00209   bool do_fullbright;
00210 
00212   uint mixmode;
00213 
00215   float z_value;
00216 };
00217 
00219 typedef G3DPolygonDP G3DPolygonDPF;
00220 
00222 enum csZBufMode
00223 {
00224   // values below are sometimes used as bit masks, so don't change them!
00226   CS_ZBUF_NONE     = 0x00000000,
00228   CS_ZBUF_FILL     = 0x00000001,
00230   CS_ZBUF_TEST     = 0x00000002,
00232   CS_ZBUF_USE      = 0x00000003,
00234   CS_ZBUF_FILLONLY = 0x00000004,
00236   CS_ZBUF_EQUAL    = 0x00000005,
00238   CS_ZBUF_SPECIAL  = 0x00000006
00239 };
00240 
00242 enum G3D_RENDERSTATEOPTION
00243 {
00245   G3DRENDERSTATE_ZBUFFERMODE,
00247   G3DRENDERSTATE_DITHERENABLE,
00249   G3DRENDERSTATE_BILINEARMAPPINGENABLE,
00251   G3DRENDERSTATE_TRILINEARMAPPINGENABLE,
00253   G3DRENDERSTATE_TRANSPARENCYENABLE,
00255   G3DRENDERSTATE_MIPMAPENABLE,
00257   G3DRENDERSTATE_TEXTUREMAPPINGENABLE,
00259   G3DRENDERSTATE_LIGHTINGENABLE,
00261   G3DRENDERSTATE_INTERLACINGENABLE,
00263   G3DRENDERSTATE_MMXENABLE,
00265   G3DRENDERSTATE_INTERPOLATIONSTEP,
00267   G3DRENDERSTATE_MAXPOLYGONSTODRAW,
00269   G3DRENDERSTATE_GOURAUDENABLE,
00271   G3DRENDERSTATE_EDGES
00272 };
00273 
00276 
00277 #define CSDRAW_2DGRAPHICS   0x00000001
00278 
00279 #define CSDRAW_3DGRAPHICS   0x00000002
00280 
00281 #define CSDRAW_CLEARZBUFFER 0x00000010
00282 
00283 #define CSDRAW_CLEARSCREEN  0x00000020
00284 
00286 
00287 enum G3D_FOGMETHOD
00288 {
00289   G3DFOGMETHOD_NONE = 0x00,
00290   G3DFOGMETHOD_ZBUFFER = 0x01,
00291   G3DFOGMETHOD_VERTEX = 0x02
00292 };
00293 
00295 struct csGraphics3DCaps
00296 {
00297   bool CanClip;
00298   int minTexHeight, minTexWidth;
00299   int maxTexHeight, maxTexWidth;
00300   G3D_FOGMETHOD fog;
00301   bool NeedsPO2Maps;
00302   int MaxAspectRatio;
00303 };
00304 
00310 #define CS_CLIPPER_NONE -1
00311 
00314 #define CS_CLIPPER_OPTIONAL 0
00315 
00318 #define CS_CLIPPER_TOPLEVEL 1
00319 
00322 #define CS_CLIPPER_REQUIRED 2
00323 
00331 #define CS_CLIP_NOT 0
00332 
00337 #define CS_CLIP_NEEDED 1
00338 
00343 #define CS_CLIP_TOPLEVEL 2
00344 
00357 struct G3DTriangleMesh
00358 {
00359   enum
00360   {
00362     MAX_VERTEXPOOL = 2
00363   };
00364 
00366   int num_vertices_pool;
00367 
00369   int num_triangles;
00371   csTriangle* triangles;
00372 
00374   int clip_portal;
00376   int clip_plane;
00378   int clip_z_plane;
00379 
00381   bool use_vertex_color;
00382 
00384   bool do_fog;
00386   bool do_mirror;
00388   bool do_morph_texels;
00390   bool do_morph_colors;
00391 
00393   enum VertexMode
00394   {
00396     VM_WORLDSPACE,
00398     VM_VIEWSPACE
00399   };
00400   
00402   VertexMode vertex_mode;
00403 
00405   uint mixmode;
00406   float morph_factor;
00411   iVertexBuffer* buffers[MAX_VERTEXPOOL];
00412   iMaterialHandle* mat_handle;
00414   G3DFogInfo* vertex_fog;
00415 
00416   // TODO : store information required for lighting calculation
00417 };
00418 
00429 struct G3DPolygonMesh
00430 {
00432   iPolygonBuffer* polybuf;
00433 
00434   // Apply fogging?
00435   bool do_fog;
00436 
00438   uint mixmode;
00439 
00441   int clip_portal;
00443   int clip_plane;
00445   int clip_z_plane;
00446 
00448   bool do_mirror;
00449 
00451   enum VertexMode
00452   {
00454     VM_WORLDSPACE,
00456     VM_VIEWSPACE
00457   };
00458   
00460   VertexMode vertex_mode;
00461 
00463   G3DFogInfo* vertex_fog;
00464 };
00465 
00469 struct csFog
00470 {
00472   bool enabled;
00474   float density;
00476   float red;
00478   float green;
00480   float blue;
00481 };
00482 
00483 SCF_VERSION (iGraphics3D, 5, 1, 0);
00484 
00491 struct iGraphics3D : public iBase
00492 {
00494   virtual bool Open () = 0;
00496   virtual void Close () = 0;
00497 
00499   virtual iGraphics2D *GetDriver2D () = 0;
00500 
00502   virtual void SetDimensions (int width, int height) = 0;
00503 
00505   virtual int GetWidth () = 0;
00507   virtual int GetHeight () = 0;
00508 
00513   virtual csGraphics3DCaps *GetCaps () = 0;
00514 
00519   virtual void SetPerspectiveCenter (int x, int y) = 0;
00520 
00522   virtual void GetPerspectiveCenter (int& x, int& y) = 0;
00523 
00527   virtual void SetPerspectiveAspect (float aspect) = 0;
00528 
00530   virtual float GetPerspectiveAspect () = 0;
00531 
00536   virtual void SetObjectToCamera (csReversibleTransform* o2c) = 0;
00537 
00541   virtual const csReversibleTransform& GetObjectToCamera () = 0;
00542 
00548   virtual void SetClipper (iClipper2D* clipper, int cliptype) = 0;
00549 
00553   virtual iClipper2D* GetClipper () = 0;
00554 
00558   virtual int GetClipType () = 0;
00559 
00564   virtual void SetNearPlane (const csPlane3& pl) = 0;
00565 
00569   virtual void ResetNearPlane () = 0;
00570 
00574   virtual const csPlane3& GetNearPlane () = 0;
00575 
00579   virtual bool HasNearPlane () = 0;
00580 
00582   virtual uint32 *GetZBuffAt (int x, int y) = 0;
00583 
00585   virtual float GetZBuffValue (int x, int y) = 0;
00586 
00588   virtual bool BeginDraw (int DrawFlags) = 0;
00589 
00591   virtual void FinishDraw () = 0;
00592 
00598   virtual void Print (csRect *area) = 0;
00599 
00601   virtual bool SetRenderState (G3D_RENDERSTATEOPTION op, long val) = 0;
00602 
00604   virtual long GetRenderState (G3D_RENDERSTATEOPTION op) = 0;
00605 
00607   virtual void DrawPolygon (G3DPolygonDP& poly) = 0;
00608 
00615   virtual void DrawPolygonDebug (G3DPolygonDP& poly) = 0;
00616 
00635   virtual void DrawPolygonFX (G3DPolygonDPFX& poly) = 0;
00636 
00640   virtual void DrawTriangleMesh (G3DTriangleMesh& mesh) = 0;
00641 
00645   virtual void DrawPolygonMesh (G3DPolygonMesh& mesh) = 0;
00646 
00654   virtual void OpenFogObject (CS_ID id, csFog* fog) = 0;
00655 
00667   virtual void DrawFogPolygon (CS_ID id, G3DPolygonDFP& poly, int fogtype) = 0;
00668 
00674   virtual void CloseFogObject (CS_ID id) = 0;
00675 
00685   virtual void OpenPortal (G3DPolygonDFP* poly) = 0;
00686 
00690   virtual void ClosePortal () = 0;
00691 
00696   virtual void DrawLine (const csVector3& v1, const csVector3& v2,
00697     float fov, int color) = 0;
00698 
00700   virtual iHalo *CreateHalo (float iR, float iG, float iB,
00701     unsigned char *iAlpha, int iWidth, int iHeight) = 0;
00702 
00717   virtual void DrawPixmap (iTextureHandle *hTex, int sx, int sy,
00718     int sw, int sh, int tx, int ty, int tw, int th, uint8 Alpha = 0) = 0;
00719 
00721   virtual iTextureManager *GetTextureManager () = 0;
00722 
00724   virtual void DumpCache () = 0;
00725 
00727   virtual void ClearCache () = 0;
00728 
00734   virtual void RemoveFromCache (iPolygonTexture* poly_texture) = 0;
00735 
00740   virtual iVertexBufferManager* GetVertexBufferManager () = 0;
00741 
00746   virtual bool IsLightmapOK (iPolygonTexture* poly_texture) = 0;
00747 
00761   virtual void SetRenderTarget (iTextureHandle* handle,
00762         bool persistent = false) = 0;
00763 
00767   virtual iTextureHandle* GetRenderTarget () const = 0;
00768 };
00769 #else
00770 #include "ivideo/render3d.h"
00771 #define iGraphics3D iRender3D
00772 #endif // CS_USE_NEW_RENDERER
00773 
00776 #endif // __CS_IVIDEO_GRAPH3D_H__
00777 

Generated for Crystal Space by doxygen 1.2.14