CrystalSpace

Public API Reference

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 iShaderVarStack;
00048 struct iTextureHandle;
00049 struct iTextureManager;
00050 
00051 class csRect;
00052 class csPlane3;
00053 class csShaderVariable;
00054 class csVector2;
00055 class csVector3;
00056 class csVector4;
00057 
00058 
00059 struct csCoreRenderMesh;
00060 struct csRenderMeshModes;
00061 class csRenderBufferHolder;
00062 
00063 
00066 
00067 #define CSDRAW_2DGRAPHICS   0x00000001
00069 #define CSDRAW_3DGRAPHICS   0x00000002
00071 #define CSDRAW_CLEARZBUFFER 0x00000010
00073 #define CSDRAW_CLEARSCREEN  0x00000020
00074 
00081 #define CS_CLIPPER_NONE -1
00082 
00085 #define CS_CLIPPER_OPTIONAL 0
00086 
00089 #define CS_CLIPPER_TOPLEVEL 1
00090 
00093 #define CS_CLIPPER_REQUIRED 2
00094 
00102 #define CS_CLIP_NOT 0
00103 
00108 #define CS_CLIP_NEEDED 1
00109 
00111 
00112 enum csZBufMode
00113 {
00115   CS_ZBUF_NONE     = 0x00000000,
00117   CS_ZBUF_FILL     = 0x00000001,
00119   CS_ZBUF_TEST     = 0x00000002,
00121   CS_ZBUF_USE      = 0x00000003,
00123   CS_ZBUF_EQUAL    = 0x00000004,
00125   CS_ZBUF_INVERT   = 0x00000005,
00126   
00128   CS_ZBUF_MESH     = 0x80000000,
00137   CS_ZBUF_MESH2    = 0x80000001
00138 };
00139 
00140 // @@@ Keep in sync with values below
00141 // \todo Document me!
00142 #define CS_VATTRIB_SPECIFIC_FIRST    0
00143 #define CS_VATTRIB_SPECIFIC_LAST    15
00144 #define CS_VATTRIB_GENERIC_FIRST   100
00145 #define CS_VATTRIB_GENERIC_LAST    (CS_VATTRIB_GENERIC_FIRST + 15)
00146 
00147 #define CS_VATTRIB_IS_GENERIC(va)   \
00148   ((va >= CS_VATTRIB_GENERIC_FIRST) && (va <=CS_VATTRIB_GENERIC_LAST))
00149 #define CS_VATTRIB_IS_SPECIFIC(va)   \
00150   ((va >= CS_VATTRIB_SPECIFIC_FIRST) && (va <=CS_VATTRIB_SPECIFIC_LAST))
00151 
00155 enum csVertexAttrib
00156 {
00160   CS_VATTRIB_UNUSED           = -2,
00162   CS_VATTRIB_INVALID          = -1,
00164   CS_VATTRIB_POSITION         = CS_VATTRIB_SPECIFIC_FIRST + 0,
00166   CS_VATTRIB_WEIGHT           = CS_VATTRIB_SPECIFIC_FIRST + 1,
00168   CS_VATTRIB_NORMAL           = CS_VATTRIB_SPECIFIC_FIRST + 2,
00170   CS_VATTRIB_COLOR            = CS_VATTRIB_SPECIFIC_FIRST + 3,
00172   CS_VATTRIB_PRIMARY_COLOR    = CS_VATTRIB_SPECIFIC_FIRST + 3,
00174   CS_VATTRIB_SECONDARY_COLOR  = CS_VATTRIB_SPECIFIC_FIRST + 4,
00176   CS_VATTRIB_FOGCOORD         = CS_VATTRIB_SPECIFIC_FIRST + 5,
00178   CS_VATTRIB_TEXCOORD         = CS_VATTRIB_SPECIFIC_FIRST + 8,
00180   CS_VATTRIB_TEXCOORD0        = CS_VATTRIB_SPECIFIC_FIRST + 8,
00182   CS_VATTRIB_TEXCOORD1        = CS_VATTRIB_SPECIFIC_FIRST + 9,
00184   CS_VATTRIB_TEXCOORD2        = CS_VATTRIB_SPECIFIC_FIRST + 10,
00186   CS_VATTRIB_TEXCOORD3        = CS_VATTRIB_SPECIFIC_FIRST + 11,
00188   CS_VATTRIB_TEXCOORD4        = CS_VATTRIB_SPECIFIC_FIRST + 12,
00190   CS_VATTRIB_TEXCOORD5        = CS_VATTRIB_SPECIFIC_FIRST + 13,
00192   CS_VATTRIB_TEXCOORD6        = CS_VATTRIB_SPECIFIC_FIRST + 14,
00194   CS_VATTRIB_TEXCOORD7        = CS_VATTRIB_SPECIFIC_FIRST + 15,
00196 
00199   CS_VATTRIB_0  = CS_VATTRIB_GENERIC_FIRST + 0,
00200   CS_VATTRIB_1  = CS_VATTRIB_GENERIC_FIRST + 1,
00201   CS_VATTRIB_2  = CS_VATTRIB_GENERIC_FIRST + 2,
00202   CS_VATTRIB_3  = CS_VATTRIB_GENERIC_FIRST + 3,
00203   CS_VATTRIB_4  = CS_VATTRIB_GENERIC_FIRST + 4,
00204   CS_VATTRIB_5  = CS_VATTRIB_GENERIC_FIRST + 5,
00205   CS_VATTRIB_6  = CS_VATTRIB_GENERIC_FIRST + 6,
00206   CS_VATTRIB_7  = CS_VATTRIB_GENERIC_FIRST + 7,
00207   CS_VATTRIB_8  = CS_VATTRIB_GENERIC_FIRST + 8,
00208   CS_VATTRIB_9  = CS_VATTRIB_GENERIC_FIRST + 9,
00209   CS_VATTRIB_10 = CS_VATTRIB_GENERIC_FIRST + 10,
00210   CS_VATTRIB_11 = CS_VATTRIB_GENERIC_FIRST + 11,
00211   CS_VATTRIB_12 = CS_VATTRIB_GENERIC_FIRST + 12,
00212   CS_VATTRIB_13 = CS_VATTRIB_GENERIC_FIRST + 13,
00213   CS_VATTRIB_14 = CS_VATTRIB_GENERIC_FIRST + 14,
00214   CS_VATTRIB_15 = CS_VATTRIB_GENERIC_FIRST + 15
00216 };
00217 
00227 #define CS_MIXMODE_TYPE_AUTO (0x00000000)
00228 
00236 #define CS_MIXMODE_TYPE_BLENDOP (0x40000000)
00237 
00241 #define CS_MIXMODE_TYPE_MESH (0x80000000)
00242 
00244 #define CS_MIXMODE_TYPE_MASK (0xc0000000)
00245 
00247 
00248 enum
00249 {
00251   CS_MIXMODE_FACT_ZERO          = 0x0,
00253   CS_MIXMODE_FACT_ONE           = 0x1,
00255   CS_MIXMODE_FACT_SRCCOLOR      = 0x2,
00257   CS_MIXMODE_FACT_SRCCOLOR_INV  = 0x3,
00259   CS_MIXMODE_FACT_DSTCOLOR      = 0x4,
00261   CS_MIXMODE_FACT_DSTCOLOR_INV  = 0x5,
00263   CS_MIXMODE_FACT_SRCALPHA      = 0x6,
00265   CS_MIXMODE_FACT_SRCALPHA_INV  = 0x7,
00267   CS_MIXMODE_FACT_DSTALPHA      = 0x8,
00269   CS_MIXMODE_FACT_DSTALPHA_INV  = 0x9,
00270   
00272   CS_MIXMODE_FACT_COUNT         = 0xa,
00273   
00275   CS_MIXMODE_FACT_MASK          = 0xf
00276 };
00277 
00288 #define CS_MIXMODE_ALPHATEST_AUTO (0x00000000)
00290 #define CS_MIXMODE_ALPHATEST_ENABLE (0x10000000)
00292 #define CS_MIXMODE_ALPHATEST_DISABLE (0x20000000)
00293   
00295 #define CS_MIXMODE_ALPHATEST_MASK (0x30000000)
00296 
00310 #define CS_MIXMODE_BLEND(Src, Dst)                                      \
00311   (CS_MIXMODE_TYPE_BLENDOP                                              \
00312   | (CS_MIXMODE_FACT_ ## Src << 20) | (CS_MIXMODE_FACT_ ## Dst << 16))
00314 #define CS_MIXMODE_BLENDOP_SRC(mode)    ((mode >> 20) & CS_MIXMODE_FACT_MASK)
00316 #define CS_MIXMODE_BLENDOP_DST(mode)    ((mode >> 16) & CS_MIXMODE_FACT_MASK)
00317 
00332 #define CS_FX_COPY (CS_MIXMODE_TYPE_AUTO | CS_MIXMODE_ALPHATEST_AUTO)
00334 #define CS_FX_MULTIPLY \
00335     (CS_MIXMODE_BLEND(DSTCOLOR, ZERO) | CS_MIXMODE_ALPHATEST_DISABLE)
00337 #define CS_FX_MULTIPLY2 \
00338     (CS_MIXMODE_BLEND(DSTCOLOR, SRCCOLOR) | CS_MIXMODE_ALPHATEST_DISABLE)
00340 #define CS_FX_ADD \
00341     (CS_MIXMODE_BLEND(ONE, ONE) | CS_MIXMODE_ALPHATEST_DISABLE)
00342 
00347 #define CS_FX_ALPHA \
00348     (CS_MIXMODE_BLEND(SRCALPHA, SRCALPHA_INV) | CS_MIXMODE_ALPHATEST_DISABLE)
00349 
00354 #define CS_FX_TRANSPARENT \
00355     (CS_MIXMODE_BLEND(ZERO, ONE) | CS_MIXMODE_ALPHATEST_DISABLE)
00356 
00360 #define CS_FX_DESTALPHAADD \
00361     (CS_MIXMODE_BLEND(DSTALPHA, ONE) | CS_MIXMODE_ALPHATEST_DISABLE)
00362 
00366 #define CS_FX_SRCALPHAADD \
00367     (CS_MIXMODE_BLEND(SRCALPHA, ONE) | CS_MIXMODE_ALPHATEST_DISABLE)
00368 
00377 #define CS_FX_PREMULTALPHA \
00378     (CS_MIXMODE_BLEND(ONE, SRCALPHA_INV) | CS_MIXMODE_ALPHATEST_DISABLE)
00379 
00383 #define CS_FX_MESH (CS_MIXMODE_TYPE_MESH)
00384   
00386 #define CS_FX_FLAT (0x04000000)
00387 
00396 #define CS_FX_MASK_ALPHA (0x000000FF)
00397   
00402 #define CS_FX_MASK_MIXMODE (0xf0ff0000)
00403 
00407 
00408 #define CS_FX_SETALPHA(alpha) \
00409   (CS_FX_ALPHA | uint ((alpha) * CS_FX_MASK_ALPHA))
00411 #define CS_FX_SETALPHA_INT(alpha) \
00412   (CS_FX_ALPHA | uint ((alpha) & CS_FX_MASK_ALPHA))
00413 
00418 struct csAlphaMode
00419 {
00421   enum AlphaType
00422   {
00424     alphaNone = 1,
00426     alphaBinary,
00428     alphaSmooth
00429   };
00431   bool autoAlphaMode;
00432   union
00433   {
00435     AlphaType alphaType;
00437     csStringID autoModeTexture;
00438   };
00439 };
00444 
00445 #define CS_LIGHTPARAM_POSITION 0
00447 #define CS_LIGHTPARAM_DIFFUSE 1
00449 #define CS_LIGHTPARAM_SPECULAR 2
00451 #define CS_LIGHTPARAM_ATTENUATION 3
00452 
00456 
00457 #define CS_SHADOW_VOLUME_BEGIN 1
00459 #define CS_SHADOW_VOLUME_PASS1 2
00461 #define CS_SHADOW_VOLUME_PASS2 3
00463 #define CS_SHADOW_VOLUME_FAIL1 4
00465 #define CS_SHADOW_VOLUME_FAIL2 5
00467 #define CS_SHADOW_VOLUME_USE 6
00469 #define CS_SHADOW_VOLUME_FINISH 7
00470 
00472 
00473 enum G3D_RENDERSTATEOPTION
00474 {
00476   G3DRENDERSTATE_ZBUFFERMODE,
00478   G3DRENDERSTATE_DITHERENABLE,
00480   G3DRENDERSTATE_BILINEARMAPPINGENABLE,
00482   G3DRENDERSTATE_TRILINEARMAPPINGENABLE,
00484   G3DRENDERSTATE_TRANSPARENCYENABLE,
00486   G3DRENDERSTATE_MIPMAPENABLE,
00488   G3DRENDERSTATE_TEXTUREMAPPINGENABLE,
00490   G3DRENDERSTATE_LIGHTINGENABLE,
00492   G3DRENDERSTATE_INTERLACINGENABLE,
00494   G3DRENDERSTATE_MMXENABLE,
00496   G3DRENDERSTATE_INTERPOLATIONSTEP,
00498   G3DRENDERSTATE_MAXPOLYGONSTODRAW,
00500   G3DRENDERSTATE_GOURAUDENABLE,
00502   G3DRENDERSTATE_EDGES
00503 };
00504 
00506 struct csGraphics3DCaps
00507 {
00509   int minTexHeight, minTexWidth;
00511   int maxTexHeight, maxTexWidth;
00516   bool SupportsPointSprites;
00520   bool DestinationAlpha;
00524   bool StencilShadows;
00525 };
00526 
00528 enum csRenderMeshType
00529 {
00531   CS_MESHTYPE_TRIANGLES,
00533   CS_MESHTYPE_QUADS,
00543   CS_MESHTYPE_TRIANGLESTRIP,
00549   CS_MESHTYPE_TRIANGLEFAN,
00553   CS_MESHTYPE_POINTS,
00559   CS_MESHTYPE_POINT_SPRITES,
00563   CS_MESHTYPE_LINES,
00568   CS_MESHTYPE_LINESTRIP
00569 };
00570 
00574 enum csSimpleMeshFlags
00575 {
00582   csSimpleMeshScreenspace = 0x01
00583 };
00584 
00589 enum csOpenPortalFlags
00590 {
00599   CS_OPENPORTAL_ZFILL = 0x00000004,
00604   CS_OPENPORTAL_MIRROR = 0x00000010,
00612   CS_OPENPORTAL_FLOAT = 0x00000040
00613 };
00614 
00618 struct csSimpleRenderMesh
00619 {
00621   csRenderMeshType meshtype;
00622 
00624   uint indexCount;
00632   const uint* indices;
00633 
00635   uint vertexCount;
00641   const csVector3* vertices;
00643   const csVector2* texcoords;
00649   const csVector4* colors;
00654   iTextureHandle* texture;
00655 
00657   iShader* shader;
00659   iShaderVariableContext* dynDomain;
00661   csAlphaMode alphaType;
00663   csZBufMode z_buf_mode;
00665   uint mixmode;
00676   csReversibleTransform object2world;
00677 
00678   csSimpleRenderMesh () : indexCount(0), indices(0), texcoords(0), colors(0), 
00679     texture (0), shader (0), dynDomain (0), z_buf_mode (CS_ZBUF_NONE), 
00680     mixmode (CS_FX_COPY)
00681   {  
00682     alphaType.autoAlphaMode = true;
00683     alphaType.autoModeTexture = csInvalidStringID;
00684   };
00685 };
00686 
00701 struct iGraphics3D : public virtual iBase
00702 {
00703   SCF_INTERFACE(iGraphics3D, 2, 1, 1);
00704   
00706   virtual bool Open () = 0;
00708   virtual void Close () = 0;
00709 
00717   virtual iGraphics2D *GetDriver2D () = 0;
00718 
00725   virtual iTextureManager *GetTextureManager () = 0;
00726 
00728   virtual void SetDimensions (int width, int height) = 0;
00730   virtual int GetWidth () const = 0;
00732   virtual int GetHeight () const = 0;
00733 
00738   virtual const csGraphics3DCaps *GetCaps () const = 0;
00739 
00746   virtual void SetPerspectiveCenter (int x, int y) = 0;
00747 
00754   virtual void GetPerspectiveCenter (int& x, int& y) const = 0;
00755 
00759   virtual void SetPerspectiveAspect (float aspect) = 0;
00760 
00762   virtual float GetPerspectiveAspect () const = 0;
00763  
00779   virtual void SetRenderTarget (iTextureHandle* handle,
00780         bool persistent = false,
00781         int subtexture = 0) = 0;
00782 
00786   virtual iTextureHandle* GetRenderTarget () const = 0;
00787 
00789   virtual bool BeginDraw (int DrawFlags) = 0;
00790 
00792   virtual void FinishDraw () = 0;
00793 
00799   virtual void Print (csRect const* area) = 0;
00800 
00802   virtual void DrawMesh (const csCoreRenderMesh* mymesh,
00803                          const csRenderMeshModes& modes,
00804                          const iShaderVarStack* stacks) = 0;
00821   virtual void DrawSimpleMesh (const csSimpleRenderMesh& mesh,
00822     uint flags = 0) = 0;
00823 
00838   virtual void DrawPixmap (iTextureHandle *hTex, int sx, int sy,
00839     int sw, int sh, int tx, int ty, int tw, int th, uint8 Alpha = 0) = 0;
00840 
00845   virtual void DrawLine (const csVector3& v1, const csVector3& v2,
00846     float fov, int color) = 0;
00847 
00851   virtual bool ActivateBuffers (csRenderBufferHolder* holder, 
00852     csRenderBufferName mapping[CS_VATTRIB_SPECIFIC_LAST+1]) = 0;
00853 
00857   virtual bool ActivateBuffers (csVertexAttrib *attribs,
00858     iRenderBuffer **buffers, unsigned int count) = 0;
00859 
00864   virtual void DeactivateBuffers (csVertexAttrib *attribs, unsigned int count) = 0;
00865 
00870   virtual void SetTextureState (int* units, iTextureHandle** textures,
00871     int count) = 0;
00872 
00873 
00879   virtual void SetClipper (iClipper2D* clipper, int cliptype) = 0;
00880 
00884   virtual iClipper2D* GetClipper () = 0;
00885 
00889   virtual int GetClipType () const = 0;
00890 
00895   virtual void SetNearPlane (const csPlane3& pl) = 0;
00896 
00900   virtual void ResetNearPlane () = 0;
00901 
00905   virtual const csPlane3& GetNearPlane () const = 0;
00906 
00910   virtual bool HasNearPlane () const = 0;
00911 
00913   virtual bool SetRenderState (G3D_RENDERSTATEOPTION op, long val) = 0;
00914 
00916   virtual long GetRenderState (G3D_RENDERSTATEOPTION op) const = 0;
00917 
00922   virtual bool SetOption (const char*, const char*) = 0;
00923   
00925   virtual void SetWriteMask (bool red, bool green, bool blue, bool alpha) = 0;
00926 
00928   virtual void GetWriteMask (bool &red, bool &green, bool &blue,
00929         bool &alpha) const = 0;
00930 
00932   virtual void SetZMode (csZBufMode mode) = 0;
00933 
00935   virtual csZBufMode GetZMode () = 0;
00936 
00938   virtual void EnableZOffset () = 0;
00939 
00941   virtual void DisableZOffset () = 0;
00942 
00944   virtual void SetShadowState (int state) = 0;
00945 
00947   virtual float GetZBuffValue (int x, int y) = 0;
00948 
00959   virtual void OpenPortal (size_t numVertices, const csVector2* vertices,
00960     const csPlane3& normal, csFlags flags) = 0;
00961 
00966   virtual void ClosePortal () = 0;
00967 
00969   virtual iHalo *CreateHalo (float iR, float iG, float iB,
00970     unsigned char *iAlpha, int iWidth, int iHeight) = 0;
00971 
00977   virtual void RemoveFromCache (iRendererLightmap* rlm) = 0;
00978 
00984   virtual void SetWorldToCamera (const csReversibleTransform& w2c) = 0;
00985 
00993   virtual bool PerformExtension (char const* command, ...) = 0;
00994 
01000   virtual bool PerformExtensionV (char const* command, va_list) = 0;
01001   
01006   virtual const csReversibleTransform& GetWorldToCamera () = 0;
01010   virtual int GetCurrentDrawFlags() const = 0;
01011 };
01012 
01015 #endif // __CS_IVIDEO_GRAPH3D_H__
01016 

Generated for Crystal Space 1.2.1 by doxygen 1.5.3