Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
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/strset.h" 00036 00037 #include "ivideo/rndbuf.h" 00038 00039 struct iClipper2D; 00040 struct iGraphics2D; 00041 struct iHalo; 00042 struct iPolygonRenderer; 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 struct 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 enum csFogMode 00111 { 00112 CS_FOG_MODE_NONE = 0, 00113 CS_FOG_MODE_LINEAR, 00114 CS_FOG_MODE_EXP, 00115 CS_FOG_MODE_EXP2 00116 }; 00117 00121 struct csFog 00122 { 00124 bool enabled; 00126 float density; 00128 float red; 00130 float green; 00132 float blue; 00134 float start; 00136 float end; 00138 csFogMode mode; 00139 }; 00140 00142 enum csZBufMode 00143 { 00144 // values below are sometimes used as bit masks, so don't change them! 00146 CS_ZBUF_NONE = 0x00000000, 00148 CS_ZBUF_FILL = 0x00000001, 00150 CS_ZBUF_TEST = 0x00000002, 00152 CS_ZBUF_USE = 0x00000003, 00154 CS_ZBUF_FILLONLY = 0x00000004, 00156 CS_ZBUF_EQUAL = 0x00000005, 00158 CS_ZBUF_INVERT = 0x00000006, 00160 CS_ZBUF_MESH = 0x00000007, 00169 CS_ZBUF_MESH2 = 0x00000008 00170 }; 00171 00172 // @@@ Keep in sync with values below 00173 // @@@ Document me better! 00174 #define CS_VATTRIB_SPECIFIC_FIRST 0 00175 #define CS_VATTRIB_SPECIFIC_LAST 15 00176 #define CS_VATTRIB_GENERIC_FIRST 100 00177 #define CS_VATTRIB_GENERIC_LAST (CS_VATTRIB_GENERIC_FIRST + 15) 00178 00179 #define CS_VATTRIB_IS_GENERIC(va) \ 00180 ((va >= CS_VATTRIB_GENERIC_FIRST) && (va <=CS_VATTRIB_GENERIC_LAST)) 00181 #define CS_VATTRIB_IS_SPECIFIC(va) \ 00182 ((va >= CS_VATTRIB_SPECIFIC_FIRST) && (va <=CS_VATTRIB_SPECIFIC_LAST)) 00183 00188 enum csVertexAttrib 00189 { 00191 CS_VATTRIB_POSITION = CS_VATTRIB_SPECIFIC_FIRST + 0, 00193 CS_VATTRIB_WEIGHT = CS_VATTRIB_SPECIFIC_FIRST + 1, 00195 CS_VATTRIB_NORMAL = CS_VATTRIB_SPECIFIC_FIRST + 2, 00197 CS_VATTRIB_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 3, 00199 CS_VATTRIB_PRIMARY_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 3, 00201 CS_VATTRIB_SECONDARY_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 4, 00203 CS_VATTRIB_FOGCOORD = CS_VATTRIB_SPECIFIC_FIRST + 5, 00205 CS_VATTRIB_TEXCOORD = CS_VATTRIB_SPECIFIC_FIRST + 8, 00207 CS_VATTRIB_TEXCOORD0 = CS_VATTRIB_SPECIFIC_FIRST + 8, 00209 CS_VATTRIB_TEXCOORD1 = CS_VATTRIB_SPECIFIC_FIRST + 9, 00211 CS_VATTRIB_TEXCOORD2 = CS_VATTRIB_SPECIFIC_FIRST + 10, 00213 CS_VATTRIB_TEXCOORD3 = CS_VATTRIB_SPECIFIC_FIRST + 11, 00215 CS_VATTRIB_TEXCOORD4 = CS_VATTRIB_SPECIFIC_FIRST + 12, 00217 CS_VATTRIB_TEXCOORD5 = CS_VATTRIB_SPECIFIC_FIRST + 13, 00219 CS_VATTRIB_TEXCOORD6 = CS_VATTRIB_SPECIFIC_FIRST + 14, 00221 CS_VATTRIB_TEXCOORD7 = CS_VATTRIB_SPECIFIC_FIRST + 15, 00223 00226 CS_VATTRIB_0 = CS_VATTRIB_GENERIC_FIRST + 0, 00227 CS_VATTRIB_1 = CS_VATTRIB_GENERIC_FIRST + 1, 00228 CS_VATTRIB_2 = CS_VATTRIB_GENERIC_FIRST + 2, 00229 CS_VATTRIB_3 = CS_VATTRIB_GENERIC_FIRST + 3, 00230 CS_VATTRIB_4 = CS_VATTRIB_GENERIC_FIRST + 4, 00231 CS_VATTRIB_5 = CS_VATTRIB_GENERIC_FIRST + 5, 00232 CS_VATTRIB_6 = CS_VATTRIB_GENERIC_FIRST + 6, 00233 CS_VATTRIB_7 = CS_VATTRIB_GENERIC_FIRST + 7, 00234 CS_VATTRIB_8 = CS_VATTRIB_GENERIC_FIRST + 8, 00235 CS_VATTRIB_9 = CS_VATTRIB_GENERIC_FIRST + 9, 00236 CS_VATTRIB_10 = CS_VATTRIB_GENERIC_FIRST + 10, 00237 CS_VATTRIB_11 = CS_VATTRIB_GENERIC_FIRST + 11, 00238 CS_VATTRIB_12 = CS_VATTRIB_GENERIC_FIRST + 12, 00239 CS_VATTRIB_13 = CS_VATTRIB_GENERIC_FIRST + 13, 00240 CS_VATTRIB_14 = CS_VATTRIB_GENERIC_FIRST + 14, 00241 CS_VATTRIB_15 = CS_VATTRIB_GENERIC_FIRST + 15 00243 }; 00244 00248 00249 #define CS_FX_MASK_MIXMODE 0xF0000000 00250 00251 #define CS_FX_COPY 0x00000000 00252 00253 #define CS_FX_MULTIPLY 0x10000000 00254 00255 #define CS_FX_MULTIPLY2 0x20000000 00256 00257 #define CS_FX_ADD 0x30000000 00258 00259 #define CS_FX_ALPHA 0x40000000 00260 00261 #define CS_FX_TRANSPARENT 0x50000000 00262 00263 #define CS_FX_DESTALPHAADD 0x60000000 00264 00265 #define CS_FX_SRCALPHAADD 0x70000000 00266 00267 #define CS_FX_PREMULTALPHA 0x80000000 00268 00272 #define CS_FX_MESH 0xf0000000 00273 00274 #define CS_FX_KEYCOLOR 0x08000000 00275 00276 #define CS_FX_FLAT 0x04000000 00277 00278 #define CS_FX_TILING 0x02000000 00279 00280 #define CS_FX_MASK_ALPHA 0x000000FF 00281 00283 #define CS_FX_SETALPHA(alpha) \ 00284 (CS_FX_ALPHA | uint (alpha * CS_FX_MASK_ALPHA)) 00285 00286 #define CS_FX_SETALPHA_INT(alpha) \ 00287 (CS_FX_ALPHA | uint (alpha & CS_FX_MASK_ALPHA)) 00288 00293 struct csAlphaMode 00294 { 00296 enum AlphaType 00297 { 00299 alphaNone = 1, 00301 alphaBinary, 00303 alphaSmooth 00304 }; 00306 bool autoAlphaMode; 00307 union 00308 { 00310 AlphaType alphaType; 00312 csStringID autoModeTexture; 00313 }; 00314 }; 00315 00318 00319 #define CS_LIGHTPARAM_POSITION 0 00320 00321 #define CS_LIGHTPARAM_DIFFUSE 1 00322 00323 #define CS_LIGHTPARAM_SPECULAR 2 00324 00325 #define CS_LIGHTPARAM_ATTENUATION 3 00326 00330 00331 #define CS_SHADOW_VOLUME_BEGIN 1 00332 00333 #define CS_SHADOW_VOLUME_PASS1 2 00334 00335 #define CS_SHADOW_VOLUME_PASS2 3 00336 00337 #define CS_SHADOW_VOLUME_FAIL1 4 00338 00339 #define CS_SHADOW_VOLUME_FAIL2 5 00340 00341 #define CS_SHADOW_VOLUME_USE 6 00342 00343 #define CS_SHADOW_VOLUME_FINISH 7 00344 00346 00347 enum G3D_RENDERSTATEOPTION 00348 { 00350 G3DRENDERSTATE_ZBUFFERMODE, 00352 G3DRENDERSTATE_DITHERENABLE, 00354 G3DRENDERSTATE_BILINEARMAPPINGENABLE, 00356 G3DRENDERSTATE_TRILINEARMAPPINGENABLE, 00358 G3DRENDERSTATE_TRANSPARENCYENABLE, 00360 G3DRENDERSTATE_MIPMAPENABLE, 00362 G3DRENDERSTATE_TEXTUREMAPPINGENABLE, 00364 G3DRENDERSTATE_LIGHTINGENABLE, 00366 G3DRENDERSTATE_INTERLACINGENABLE, 00368 G3DRENDERSTATE_MMXENABLE, 00370 G3DRENDERSTATE_INTERPOLATIONSTEP, 00372 G3DRENDERSTATE_MAXPOLYGONSTODRAW, 00374 G3DRENDERSTATE_GOURAUDENABLE, 00376 G3DRENDERSTATE_EDGES 00377 }; 00378 00380 struct csGraphics3DCaps 00381 { 00382 bool CanClip; 00383 int minTexHeight, minTexWidth; 00384 int maxTexHeight, maxTexWidth; 00385 bool NeedsPO2Maps; 00386 int MaxAspectRatio; 00387 00388 // The following caps are only used by NR 00389 00394 bool SupportsPointSprites; 00398 bool DestinationAlpha; 00402 bool StencilShadows; 00403 }; 00404 00406 enum csRenderMeshType 00407 { 00409 CS_MESHTYPE_TRIANGLES, 00411 CS_MESHTYPE_QUADS, 00421 CS_MESHTYPE_TRIANGLESTRIP, 00427 CS_MESHTYPE_TRIANGLEFAN, 00431 CS_MESHTYPE_POINTS, 00437 CS_MESHTYPE_POINT_SPRITES, 00441 CS_MESHTYPE_LINES, 00446 CS_MESHTYPE_LINESTRIP, 00453 CS_MESHTYPE_POLYGON 00454 }; 00455 00459 enum csSimpleMeshFlags 00460 { 00467 csSimpleMeshScreenspace = 0x01 00468 }; 00469 00473 struct csSimpleRenderMesh 00474 { 00476 csRenderMeshType meshtype; 00477 00479 uint indexCount; 00487 const uint* indices; 00488 00490 uint vertexCount; 00496 const csVector3* vertices; 00498 const csVector2* texcoords; 00504 const csVector4* colors; 00509 iTextureHandle* texture; 00510 00512 iShader* shader; 00514 iShaderVariableContext* dynDomain; 00516 csAlphaMode alphaType; 00518 csZBufMode z_buf_mode; 00520 uint mixmode; 00529 csReversibleTransform object2world; 00530 00531 csSimpleRenderMesh () : indexCount(0), indices(0), texcoords(0), colors(0), 00532 texture (0), shader (0), dynDomain (0), z_buf_mode (CS_ZBUF_NONE), 00533 mixmode (CS_FX_COPY) 00534 { 00535 alphaType.autoAlphaMode = true; 00536 alphaType.autoModeTexture = csInvalidStringID; 00537 }; 00538 }; 00539 00540 SCF_VERSION (iGraphics3D, 5, 5, 1); 00541 00559 struct iGraphics3D : public iBase 00560 { 00562 virtual bool Open () = 0; 00564 virtual void Close () = 0; 00565 00573 virtual iGraphics2D *GetDriver2D () = 0; 00574 00581 virtual iTextureManager *GetTextureManager () = 0; 00582 00584 virtual void SetDimensions (int width, int height) = 0; 00586 virtual int GetWidth () const = 0; 00588 virtual int GetHeight () const = 0; 00589 00594 virtual const csGraphics3DCaps *GetCaps () const = 0; 00595 00600 virtual void SetPerspectiveCenter (int x, int y) = 0; 00601 00603 virtual void GetPerspectiveCenter (int& x, int& y) const = 0; 00604 00608 virtual void SetPerspectiveAspect (float aspect) = 0; 00609 00611 virtual float GetPerspectiveAspect () const = 0; 00612 00626 virtual void SetRenderTarget (iTextureHandle* handle, 00627 bool persistent = false) = 0; 00628 00632 virtual iTextureHandle* GetRenderTarget () const = 0; 00633 00635 virtual bool BeginDraw (int DrawFlags) = 0; 00636 00638 virtual void FinishDraw () = 0; 00639 00645 virtual void Print (csRect const* area) = 0; 00646 00648 virtual void DrawMesh (const csCoreRenderMesh* mymesh, 00649 const csRenderMeshModes& modes, 00650 const csArray<csShaderVariable*> &stacks) = 0; 00667 virtual void DrawSimpleMesh (const csSimpleRenderMesh& mesh, 00668 uint flags = 0) = 0; 00669 00684 virtual void DrawPixmap (iTextureHandle *hTex, int sx, int sy, 00685 int sw, int sh, int tx, int ty, int tw, int th, uint8 Alpha = 0) = 0; 00686 00691 virtual void DrawLine (const csVector3& v1, const csVector3& v2, 00692 float fov, int color) = 0; 00693 00697 virtual bool ActivateBuffers (csRenderBufferHolder* holder, 00698 csRenderBufferName mapping[CS_VATTRIB_SPECIFIC_LAST+1]) = 0; 00699 00703 virtual bool ActivateBuffers (csVertexAttrib *attribs, 00704 iRenderBuffer **buffers, unsigned int count) = 0; 00705 00710 virtual void DeactivateBuffers (csVertexAttrib *attribs, unsigned int count) = 0; 00711 00716 virtual void SetTextureState (int* units, iTextureHandle** textures, 00717 int count) = 0; 00718 00719 00725 virtual void SetClipper (iClipper2D* clipper, int cliptype) = 0; 00726 00730 virtual iClipper2D* GetClipper () = 0; 00731 00735 virtual int GetClipType () const = 0; 00736 00740 virtual void SetNearPlane (const csPlane3& pl) = 0; 00741 00745 virtual void ResetNearPlane () = 0; 00746 00750 virtual const csPlane3& GetNearPlane () const = 0; 00751 00755 virtual bool HasNearPlane () const = 0; 00756 00758 virtual bool SetRenderState (G3D_RENDERSTATEOPTION op, long val) = 0; 00759 00761 virtual long GetRenderState (G3D_RENDERSTATEOPTION op) const = 0; 00762 00767 virtual bool SetOption (const char*, const char*) = 0; 00768 00770 virtual void SetWriteMask (bool red, bool green, bool blue, bool alpha) = 0; 00771 00773 virtual void GetWriteMask (bool &red, bool &green, bool &blue, 00774 bool &alpha) const = 0; 00775 00777 virtual void SetZMode (csZBufMode mode) = 0; 00778 00780 virtual csZBufMode GetZMode () = 0; 00781 00783 virtual void EnableZOffset () = 0; 00784 00786 virtual void DisableZOffset () = 0; 00787 00789 virtual void SetShadowState (int state) = 0; 00790 00792 virtual float GetZBuffValue (int x, int y) = 0; 00793 00803 virtual void OpenPortal (size_t numVertices, const csVector2* vertices, 00804 const csPlane3& normal, bool floating) = 0; 00805 00810 virtual void ClosePortal (bool zfill_portal) = 0; 00811 00813 virtual iHalo *CreateHalo (float iR, float iG, float iB, 00814 unsigned char *iAlpha, int iWidth, int iHeight) = 0; 00815 00821 virtual void RemoveFromCache (iRendererLightmap* rlm) = 0; 00822 00823 virtual csPtr<iPolygonRenderer> CreatePolygonRenderer () = 0; 00824 00829 virtual void SetWorldToCamera (const csReversibleTransform& w2c) = 0; 00830 }; 00831 00834 #endif // __CS_IVIDEO_GRAPH3D_H__ 00835
Generated for Crystal Space by doxygen 1.4.4