## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# ivideo/graph3d.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 1998-2001 by Jorrit Tyberghein
    00003                        2004 by Marten Svanfeldt
    00004     Written by Jorrit Tyberghein, Dan Ogles, and Gary Clark.
    00005
    00006     This library is free software; you can redistribute it and/or
    00007     modify it under the terms of the GNU Library General Public
    00008     License as published by the Free Software Foundation; either
    00009     version 2 of the License, or (at your option) any later version.
    00010
    00011     This library is distributed in the hope that it will be useful,
    00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014     Library General Public License for more details.
    00015
    00016     You should have received a copy of the GNU Library General Public
    00017     License along with this library; if not, write to the Free
    00018     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00019 */
    00020
    00021 #ifndef __CS_IVIDEO_GRAPH3D_H__
    00022 #define __CS_IVIDEO_GRAPH3D_H__
    00023
    00032 #include "csutil/scf.h"
    00033
    00034 #include "csgeom/transfrm.h"
    00035 #include "csutil/flags.h"
    00036 #include "csutil/strset.h"
    00037
    00038 #include "ivideo/rndbuf.h"
    00039
    00040 struct iClipper2D;
    00041 struct iGraphics2D;
    00042 struct iHalo;
    00043 struct iRenderBuffer;
    00044 struct iRendererLightmap;
    00045 struct iShader;
    00046 struct iShaderVariableContext;
    00047 struct iTextureHandle;
    00048 struct iTextureManager;
    00049
    00050 class csRect;
    00051 class csPlane3;
    00052 class csShaderVariable;
    00053 class csVector2;
    00054 class csVector3;
    00055 class csVector4;
    00056
    00057
    00058 struct csCoreRenderMesh;
    00059 struct csRenderMeshModes;
    00060 class csRenderBufferHolder;
    00061
    00062
    00065
    00066 #define CSDRAW_2DGRAPHICS   0x00000001
    00067
    00068 #define CSDRAW_3DGRAPHICS   0x00000002
    00069
    00070 #define CSDRAW_CLEARZBUFFER 0x00000010
    00071
    00072 #define CSDRAW_CLEARSCREEN  0x00000020
    00073
    00080 #define CS_CLIPPER_NONE -1
    00081
    00084 #define CS_CLIPPER_OPTIONAL 0
    00085
    00088 #define CS_CLIPPER_TOPLEVEL 1
    00089
    00092 #define CS_CLIPPER_REQUIRED 2
    00093
    00101 #define CS_CLIP_NOT 0
    00102
    00107 #define CS_CLIP_NEEDED 1
    00108
    00110
    00111 enum csZBufMode
    00112 {
    00114   CS_ZBUF_NONE     = 0x00000000,
    00116   CS_ZBUF_FILL     = 0x00000001,
    00118   CS_ZBUF_TEST     = 0x00000002,
    00120   CS_ZBUF_USE      = 0x00000003,
    00122   CS_ZBUF_EQUAL    = 0x00000004,
    00124   CS_ZBUF_INVERT   = 0x00000005,
    00125
    00127   CS_ZBUF_MESH     = 0x80000000,
    00136   CS_ZBUF_MESH2    = 0x80000001
    00137 };
    00138
    00139 // @@@ Keep in sync with values below
    00140 // @@@ Document me better!
    00141 #define CS_VATTRIB_SPECIFIC_FIRST    0
    00142 #define CS_VATTRIB_SPECIFIC_LAST    15
    00143 #define CS_VATTRIB_GENERIC_FIRST   100
    00144 #define CS_VATTRIB_GENERIC_LAST    (CS_VATTRIB_GENERIC_FIRST + 15)
    00145
    00146 #define CS_VATTRIB_IS_GENERIC(va)   \
    00147   ((va >= CS_VATTRIB_GENERIC_FIRST) && (va <=CS_VATTRIB_GENERIC_LAST))
    00148 #define CS_VATTRIB_IS_SPECIFIC(va)   \
    00149   ((va >= CS_VATTRIB_SPECIFIC_FIRST) && (va <=CS_VATTRIB_SPECIFIC_LAST))
    00150
    00154 enum csVertexAttrib
    00155 {
    00157   CS_VATTRIB_INVALID          = -1,
    00159   CS_VATTRIB_POSITION         = CS_VATTRIB_SPECIFIC_FIRST + 0,
    00161   CS_VATTRIB_WEIGHT           = CS_VATTRIB_SPECIFIC_FIRST + 1,
    00163   CS_VATTRIB_NORMAL           = CS_VATTRIB_SPECIFIC_FIRST + 2,
    00165   CS_VATTRIB_COLOR            = CS_VATTRIB_SPECIFIC_FIRST + 3,
    00167   CS_VATTRIB_PRIMARY_COLOR    = CS_VATTRIB_SPECIFIC_FIRST + 3,
    00169   CS_VATTRIB_SECONDARY_COLOR  = CS_VATTRIB_SPECIFIC_FIRST + 4,
    00171   CS_VATTRIB_FOGCOORD         = CS_VATTRIB_SPECIFIC_FIRST + 5,
    00173   CS_VATTRIB_TEXCOORD         = CS_VATTRIB_SPECIFIC_FIRST + 8,
    00175   CS_VATTRIB_TEXCOORD0        = CS_VATTRIB_SPECIFIC_FIRST + 8,
    00177   CS_VATTRIB_TEXCOORD1        = CS_VATTRIB_SPECIFIC_FIRST + 9,
    00179   CS_VATTRIB_TEXCOORD2        = CS_VATTRIB_SPECIFIC_FIRST + 10,
    00181   CS_VATTRIB_TEXCOORD3        = CS_VATTRIB_SPECIFIC_FIRST + 11,
    00183   CS_VATTRIB_TEXCOORD4        = CS_VATTRIB_SPECIFIC_FIRST + 12,
    00185   CS_VATTRIB_TEXCOORD5        = CS_VATTRIB_SPECIFIC_FIRST + 13,
    00187   CS_VATTRIB_TEXCOORD6        = CS_VATTRIB_SPECIFIC_FIRST + 14,
    00189   CS_VATTRIB_TEXCOORD7        = CS_VATTRIB_SPECIFIC_FIRST + 15,
    00191
    00194   CS_VATTRIB_0  = CS_VATTRIB_GENERIC_FIRST + 0,
    00195   CS_VATTRIB_1  = CS_VATTRIB_GENERIC_FIRST + 1,
    00196   CS_VATTRIB_2  = CS_VATTRIB_GENERIC_FIRST + 2,
    00197   CS_VATTRIB_3  = CS_VATTRIB_GENERIC_FIRST + 3,
    00198   CS_VATTRIB_4  = CS_VATTRIB_GENERIC_FIRST + 4,
    00199   CS_VATTRIB_5  = CS_VATTRIB_GENERIC_FIRST + 5,
    00200   CS_VATTRIB_6  = CS_VATTRIB_GENERIC_FIRST + 6,
    00201   CS_VATTRIB_7  = CS_VATTRIB_GENERIC_FIRST + 7,
    00202   CS_VATTRIB_8  = CS_VATTRIB_GENERIC_FIRST + 8,
    00203   CS_VATTRIB_9  = CS_VATTRIB_GENERIC_FIRST + 9,
    00204   CS_VATTRIB_10 = CS_VATTRIB_GENERIC_FIRST + 10,
    00205   CS_VATTRIB_11 = CS_VATTRIB_GENERIC_FIRST + 11,
    00206   CS_VATTRIB_12 = CS_VATTRIB_GENERIC_FIRST + 12,
    00207   CS_VATTRIB_13 = CS_VATTRIB_GENERIC_FIRST + 13,
    00208   CS_VATTRIB_14 = CS_VATTRIB_GENERIC_FIRST + 14,
    00209   CS_VATTRIB_15 = CS_VATTRIB_GENERIC_FIRST + 15
    00211 };
    00212
    00222 #define CS_MIXMODE_TYPE_AUTO (0x00000000)
    00223
    00231 #define CS_MIXMODE_TYPE_BLENDOP (0x40000000)
    00232
    00236 #define CS_MIXMODE_TYPE_MESH (0x80000000)
    00237
    00239 #define CS_MIXMODE_TYPE_MASK (0xc0000000)
    00240
    00242
    00243 enum
    00244 {
    00246   CS_MIXMODE_FACT_ZERO          = 0x0,
    00248   CS_MIXMODE_FACT_ONE           = 0x1,
    00250   CS_MIXMODE_FACT_SRCCOLOR      = 0x2,
    00252   CS_MIXMODE_FACT_SRCCOLOR_INV  = 0x3,
    00254   CS_MIXMODE_FACT_DSTCOLOR      = 0x4,
    00256   CS_MIXMODE_FACT_DSTCOLOR_INV  = 0x5,
    00258   CS_MIXMODE_FACT_SRCALPHA      = 0x6,
    00260   CS_MIXMODE_FACT_SRCALPHA_INV  = 0x7,
    00262   CS_MIXMODE_FACT_DSTALPHA      = 0x8,
    00264   CS_MIXMODE_FACT_DSTALPHA_INV  = 0x9,
    00265
    00267   CS_MIXMODE_FACT_COUNT         = 0xa,
    00268
    00270   CS_MIXMODE_FACT_MASK          = 0xf
    00271 };
    00272
    00283 #define CS_MIXMODE_ALPHATEST_AUTO (0x00000000)
    00284
    00285 #define CS_MIXMODE_ALPHATEST_ENABLE (0x10000000)
    00286
    00287 #define CS_MIXMODE_ALPHATEST_DISABLE (0x20000000)
    00288
    00290 #define CS_MIXMODE_ALPHATEST_MASK (0x30000000)
    00291
    00305 #define CS_MIXMODE_BLEND(Src, Dst)                                      \
    00306   (CS_MIXMODE_TYPE_BLENDOP                                              \
    00307   | (CS_MIXMODE_FACT_ ## Src << 20) | (CS_MIXMODE_FACT_ ## Dst << 16))
    00308
    00309 #define CS_MIXMODE_BLENDOP_SRC(mode)    ((mode >> 20) & CS_MIXMODE_FACT_MASK)
    00310
    00311 #define CS_MIXMODE_BLENDOP_DST(mode)    ((mode >> 16) & CS_MIXMODE_FACT_MASK)
    00312
    00327 #define CS_FX_COPY (CS_MIXMODE_TYPE_AUTO | CS_MIXMODE_ALPHATEST_AUTO)
    00328
    00329 #define CS_FX_MULTIPLY \
    00330     (CS_MIXMODE_BLEND(DSTCOLOR, ZERO) | CS_MIXMODE_ALPHATEST_DISABLE)
    00331
    00332 #define CS_FX_MULTIPLY2 \
    00333     (CS_MIXMODE_BLEND(DSTCOLOR, SRCCOLOR) | CS_MIXMODE_ALPHATEST_DISABLE)
    00334
    00335 #define CS_FX_ADD \
    00336     (CS_MIXMODE_BLEND(ONE, ONE) | CS_MIXMODE_ALPHATEST_DISABLE)
    00337
    00342 #define CS_FX_ALPHA \
    00343     (CS_MIXMODE_BLEND(SRCALPHA, SRCALPHA_INV) | CS_MIXMODE_ALPHATEST_DISABLE)
    00344
    00349 #define CS_FX_TRANSPARENT \
    00350     (CS_MIXMODE_BLEND(ZERO, ONE) | CS_MIXMODE_ALPHATEST_DISABLE)
    00351
    00355 #define CS_FX_DESTALPHAADD \
    00356     (CS_MIXMODE_BLEND(DSTALPHA, ONE) | CS_MIXMODE_ALPHATEST_DISABLE)
    00357
    00361 #define CS_FX_SRCALPHAADD \
    00362     (CS_MIXMODE_BLEND(SRCALPHA, ONE) | CS_MIXMODE_ALPHATEST_DISABLE)
    00363
    00372 #define CS_FX_PREMULTALPHA \
    00373     (CS_MIXMODE_BLEND(ONE, SRCALPHA_INV) | CS_MIXMODE_ALPHATEST_DISABLE)
    00374
    00378 #define CS_FX_MESH (CS_MIXMODE_TYPE_MESH)
    00379
    00381 #define CS_FX_FLAT (0x04000000)
    00382
    00391 #define CS_FX_MASK_ALPHA (0x000000FF)
    00392
    00397 #define CS_FX_MASK_MIXMODE (0xf0ff0000)
    00398
    00402
    00403 #define CS_FX_SETALPHA(alpha) \
    00404   (CS_FX_ALPHA | uint ((alpha) * CS_FX_MASK_ALPHA))
    00405
    00406 #define CS_FX_SETALPHA_INT(alpha) \
    00407   (CS_FX_ALPHA | uint ((alpha) & CS_FX_MASK_ALPHA))
    00408
    00413 struct csAlphaMode
    00414 {
    00416   enum AlphaType
    00417   {
    00419     alphaNone = 1,
    00421     alphaBinary,
    00423     alphaSmooth
    00424   };
    00426   bool autoAlphaMode;
    00427   union
    00428   {
    00430     AlphaType alphaType;
    00432     csStringID autoModeTexture;
    00433   };
    00434 };
    00439
    00440 #define CS_LIGHTPARAM_POSITION 0
    00441
    00442 #define CS_LIGHTPARAM_DIFFUSE 1
    00443
    00444 #define CS_LIGHTPARAM_SPECULAR 2
    00445
    00446 #define CS_LIGHTPARAM_ATTENUATION 3
    00447
    00451
    00452 #define CS_SHADOW_VOLUME_BEGIN 1
    00453
    00454 #define CS_SHADOW_VOLUME_PASS1 2
    00455
    00456 #define CS_SHADOW_VOLUME_PASS2 3
    00457
    00458 #define CS_SHADOW_VOLUME_FAIL1 4
    00459
    00460 #define CS_SHADOW_VOLUME_FAIL2 5
    00461
    00462 #define CS_SHADOW_VOLUME_USE 6
    00463
    00464 #define CS_SHADOW_VOLUME_FINISH 7
    00465
    00467
    00468 enum G3D_RENDERSTATEOPTION
    00469 {
    00471   G3DRENDERSTATE_ZBUFFERMODE,
    00473   G3DRENDERSTATE_DITHERENABLE,
    00475   G3DRENDERSTATE_BILINEARMAPPINGENABLE,
    00477   G3DRENDERSTATE_TRILINEARMAPPINGENABLE,
    00479   G3DRENDERSTATE_TRANSPARENCYENABLE,
    00481   G3DRENDERSTATE_MIPMAPENABLE,
    00483   G3DRENDERSTATE_TEXTUREMAPPINGENABLE,
    00485   G3DRENDERSTATE_LIGHTINGENABLE,
    00487   G3DRENDERSTATE_INTERLACINGENABLE,
    00489   G3DRENDERSTATE_MMXENABLE,
    00491   G3DRENDERSTATE_INTERPOLATIONSTEP,
    00493   G3DRENDERSTATE_MAXPOLYGONSTODRAW,
    00495   G3DRENDERSTATE_GOURAUDENABLE,
    00497   G3DRENDERSTATE_EDGES
    00498 };
    00499
    00501 struct csGraphics3DCaps
    00502 {
    00503   bool CanClip;
    00504   int minTexHeight, minTexWidth;
    00505   int maxTexHeight, maxTexWidth;
    00506   bool NeedsPO2Maps;
    00507   int MaxAspectRatio;
    00508
    00509   // The following caps are only used by NR
    00510
    00515   bool SupportsPointSprites;
    00519   bool DestinationAlpha;
    00523   bool StencilShadows;
    00524 };
    00525
    00527 enum csRenderMeshType
    00528 {
    00530   CS_MESHTYPE_TRIANGLES,
    00532   CS_MESHTYPE_QUADS,
    00542   CS_MESHTYPE_TRIANGLESTRIP,
    00548   CS_MESHTYPE_TRIANGLEFAN,
    00552   CS_MESHTYPE_POINTS,
    00558   CS_MESHTYPE_POINT_SPRITES,
    00562   CS_MESHTYPE_LINES,
    00567   CS_MESHTYPE_LINESTRIP
    00568 };
    00569
    00573 enum csSimpleMeshFlags
    00574 {
    00581   csSimpleMeshScreenspace = 0x01
    00582 };
    00583
    00587 struct csSimpleRenderMesh
    00588 {
    00590   csRenderMeshType meshtype;
    00591
    00593   uint indexCount;
    00601   const uint* indices;
    00602
    00604   uint vertexCount;
    00610   const csVector3* vertices;
    00612   const csVector2* texcoords;
    00618   const csVector4* colors;
    00623   iTextureHandle* texture;
    00624
    00626   iShader* shader;
    00628   iShaderVariableContext* dynDomain;
    00630   csAlphaMode alphaType;
    00632   csZBufMode z_buf_mode;
    00634   uint mixmode;
    00645   csReversibleTransform object2world;
    00646
    00647   csSimpleRenderMesh () : indexCount(0), indices(0), texcoords(0), colors(0),
    00648     texture (0), shader (0), dynDomain (0), z_buf_mode (CS_ZBUF_NONE),
    00649     mixmode (CS_FX_COPY)
    00650   {
    00651     alphaType.autoAlphaMode = true;
    00652     alphaType.autoModeTexture = csInvalidStringID;
    00653   };
    00654 };
    00655
    00670 struct iGraphics3D : public virtual iBase
    00671 {
    00672   SCF_INTERFACE(iGraphics3D, 2, 0, 0);
    00673
    00675   virtual bool Open () = 0;
    00677   virtual void Close () = 0;
    00678
    00686   virtual iGraphics2D *GetDriver2D () = 0;
    00687
    00694   virtual iTextureManager *GetTextureManager () = 0;
    00695
    00697   virtual void SetDimensions (int width, int height) = 0;
    00699   virtual int GetWidth () const = 0;
    00701   virtual int GetHeight () const = 0;
    00702
    00707   virtual const csGraphics3DCaps *GetCaps () const = 0;
    00708
    00715   virtual void SetPerspectiveCenter (int x, int y) = 0;
    00716
    00723   virtual void GetPerspectiveCenter (int& x, int& y) const = 0;
    00724
    00728   virtual void SetPerspectiveAspect (float aspect) = 0;
    00729
    00731   virtual float GetPerspectiveAspect () const = 0;
    00732
    00746   virtual void SetRenderTarget (iTextureHandle* handle,
    00747         bool persistent = false) = 0;
    00748
    00752   virtual iTextureHandle* GetRenderTarget () const = 0;
    00753
    00755   virtual bool BeginDraw (int DrawFlags) = 0;
    00756
    00758   virtual void FinishDraw () = 0;
    00759
    00765   virtual void Print (csRect const* area) = 0;
    00766
    00768   virtual void DrawMesh (const csCoreRenderMesh* mymesh,
    00769                          const csRenderMeshModes& modes,
    00770                          const csArray<csShaderVariable*> &stacks) = 0;
    00787   virtual void DrawSimpleMesh (const csSimpleRenderMesh& mesh,
    00788     uint flags = 0) = 0;
    00789
    00804   virtual void DrawPixmap (iTextureHandle *hTex, int sx, int sy,
    00805     int sw, int sh, int tx, int ty, int tw, int th, uint8 Alpha = 0) = 0;
    00806
    00811   virtual void DrawLine (const csVector3& v1, const csVector3& v2,
    00812     float fov, int color) = 0;
    00813
    00817   virtual bool ActivateBuffers (csRenderBufferHolder* holder,
    00818     csRenderBufferName mapping[CS_VATTRIB_SPECIFIC_LAST+1]) = 0;
    00819
    00823   virtual bool ActivateBuffers (csVertexAttrib *attribs,
    00824     iRenderBuffer **buffers, unsigned int count) = 0;
    00825
    00830   virtual void DeactivateBuffers (csVertexAttrib *attribs, unsigned int count) = 0;
    00831
    00836   virtual void SetTextureState (int* units, iTextureHandle** textures,
    00837     int count) = 0;
    00838
    00839
    00845   virtual void SetClipper (iClipper2D* clipper, int cliptype) = 0;
    00846
    00850   virtual iClipper2D* GetClipper () = 0;
    00851
    00855   virtual int GetClipType () const = 0;
    00856
    00860   virtual void SetNearPlane (const csPlane3& pl) = 0;
    00861
    00865   virtual void ResetNearPlane () = 0;
    00866
    00870   virtual const csPlane3& GetNearPlane () const = 0;
    00871
    00875   virtual bool HasNearPlane () const = 0;
    00876
    00878   virtual bool SetRenderState (G3D_RENDERSTATEOPTION op, long val) = 0;
    00879
    00881   virtual long GetRenderState (G3D_RENDERSTATEOPTION op) const = 0;
    00882
    00887   virtual bool SetOption (const char*, const char*) = 0;
    00888
    00890   virtual void SetWriteMask (bool red, bool green, bool blue, bool alpha) = 0;
    00891
    00893   virtual void GetWriteMask (bool &red, bool &green, bool &blue,
    00894         bool &alpha) const = 0;
    00895
    00897   virtual void SetZMode (csZBufMode mode) = 0;
    00898
    00900   virtual csZBufMode GetZMode () = 0;
    00901
    00903   virtual void EnableZOffset () = 0;
    00904
    00906   virtual void DisableZOffset () = 0;
    00907
    00909   virtual void SetShadowState (int state) = 0;
    00910
    00912   virtual float GetZBuffValue (int x, int y) = 0;
    00913
    00924   virtual void OpenPortal (size_t numVertices, const csVector2* vertices,
    00925     const csPlane3& normal, csFlags flags) = 0;
    00926
    00931   virtual void ClosePortal () = 0;
    00932
    00934   virtual iHalo *CreateHalo (float iR, float iG, float iB,
    00935     unsigned char *iAlpha, int iWidth, int iHeight) = 0;
    00936
    00942   virtual void RemoveFromCache (iRendererLightmap* rlm) = 0;
    00943
    00949   virtual void SetWorldToCamera (const csReversibleTransform& w2c) = 0;
    00950 };
    00951
    00954 #endif // __CS_IVIDEO_GRAPH3D_H__
    00955