Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | 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/refarr.h" 00033 #include "csutil/scf.h" 00034 #include "csgeom/plane3.h" 00035 #include "csgeom/vector2.h" 00036 #include "csgeom/transfrm.h" 00037 #include "csgeom/tri.h" 00038 #include "csutil/cscolor.h" 00039 #include "ivideo/rndbuf.h" 00040 #include "ivideo/polyrender.h" 00041 00042 struct csCoreRenderMesh; 00043 struct csRenderMeshModes; 00044 class csMatrix3; 00045 class csVector4; 00046 class csVector3; 00047 class csVector2; 00048 class csPlane3; 00049 class csRect; 00050 class csReversibleTransform; 00051 class csShaderVariable; 00052 00053 struct iGraphics2D; 00054 struct iPolygonBuffer; 00055 struct iPolygonRenderer; 00056 struct iTextureManager; 00057 struct iTextureHandle; 00058 struct iMaterialHandle; 00059 struct iMaterial; 00060 struct iClipper2D; 00061 struct iHalo; 00062 struct iRendererLightmap; 00063 struct csRGBpixel; 00064 struct csPixelFormat; 00065 struct csPolyTextureMapping; 00066 struct iRenderBuffer; 00067 struct iRenderBufferManager; 00068 struct iLightingManager; 00069 struct iShader; 00070 struct iShaderVariableContext; 00071 struct csRenderBufferHolder; 00072 00075 00076 #define CSDRAW_2DGRAPHICS 0x00000001 00077 00078 #define CSDRAW_3DGRAPHICS 0x00000002 00079 00080 #define CSDRAW_CLEARZBUFFER 0x00000010 00081 00082 #define CSDRAW_CLEARSCREEN 0x00000020 00083 00090 #define CS_CLIPPER_NONE -1 00091 00094 #define CS_CLIPPER_OPTIONAL 0 00095 00098 #define CS_CLIPPER_TOPLEVEL 1 00099 00102 #define CS_CLIPPER_REQUIRED 2 00103 00111 #define CS_CLIP_NOT 0 00112 00117 #define CS_CLIP_NEEDED 1 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, 00156 CS_ZBUF_MESH = 0x00000007, 00165 CS_ZBUF_MESH2 = 0x00000008 00166 }; 00167 00168 // @@@ Keep in sync with values below 00169 // @@@ Document me better! 00170 #define CS_VATTRIB_SPECIFIC_FIRST 0 00171 #define CS_VATTRIB_SPECIFIC_LAST 15 00172 #define CS_VATTRIB_GENERIC_FIRST 100 00173 #define CS_VATTRIB_GENERIC_LAST (CS_VATTRIB_GENERIC_FIRST + 15) 00174 00175 #define CS_VATTRIB_IS_GENERIC(va) \ 00176 ((va >= CS_VATTRIB_GENERIC_FIRST) && (va <=CS_VATTRIB_GENERIC_LAST)) 00177 #define CS_VATTRIB_IS_SPECIFIC(va) \ 00178 ((va >= CS_VATTRIB_SPECIFIC_FIRST) && (va <=CS_VATTRIB_SPECIFIC_LAST)) 00179 00184 enum csVertexAttrib 00185 { 00187 CS_VATTRIB_POSITION = CS_VATTRIB_SPECIFIC_FIRST + 0, 00189 CS_VATTRIB_WEIGHT = CS_VATTRIB_SPECIFIC_FIRST + 1, 00191 CS_VATTRIB_NORMAL = CS_VATTRIB_SPECIFIC_FIRST + 2, 00193 CS_VATTRIB_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 3, 00195 CS_VATTRIB_PRIMARY_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 3, 00197 CS_VATTRIB_SECONDARY_COLOR = CS_VATTRIB_SPECIFIC_FIRST + 4, 00199 CS_VATTRIB_FOGCOORD = CS_VATTRIB_SPECIFIC_FIRST + 5, 00201 CS_VATTRIB_TEXCOORD = CS_VATTRIB_SPECIFIC_FIRST + 8, 00203 CS_VATTRIB_TEXCOORD0 = CS_VATTRIB_SPECIFIC_FIRST + 8, 00205 CS_VATTRIB_TEXCOORD1 = CS_VATTRIB_SPECIFIC_FIRST + 9, 00207 CS_VATTRIB_TEXCOORD2 = CS_VATTRIB_SPECIFIC_FIRST + 10, 00209 CS_VATTRIB_TEXCOORD3 = CS_VATTRIB_SPECIFIC_FIRST + 11, 00211 CS_VATTRIB_TEXCOORD4 = CS_VATTRIB_SPECIFIC_FIRST + 12, 00213 CS_VATTRIB_TEXCOORD5 = CS_VATTRIB_SPECIFIC_FIRST + 13, 00215 CS_VATTRIB_TEXCOORD6 = CS_VATTRIB_SPECIFIC_FIRST + 14, 00217 CS_VATTRIB_TEXCOORD7 = CS_VATTRIB_SPECIFIC_FIRST + 15, 00219 00222 CS_VATTRIB_0 = CS_VATTRIB_GENERIC_FIRST + 0, 00223 CS_VATTRIB_1 = CS_VATTRIB_GENERIC_FIRST + 1, 00224 CS_VATTRIB_2 = CS_VATTRIB_GENERIC_FIRST + 2, 00225 CS_VATTRIB_3 = CS_VATTRIB_GENERIC_FIRST + 3, 00226 CS_VATTRIB_4 = CS_VATTRIB_GENERIC_FIRST + 4, 00227 CS_VATTRIB_5 = CS_VATTRIB_GENERIC_FIRST + 5, 00228 CS_VATTRIB_6 = CS_VATTRIB_GENERIC_FIRST + 6, 00229 CS_VATTRIB_7 = CS_VATTRIB_GENERIC_FIRST + 7, 00230 CS_VATTRIB_8 = CS_VATTRIB_GENERIC_FIRST + 8, 00231 CS_VATTRIB_9 = CS_VATTRIB_GENERIC_FIRST + 9, 00232 CS_VATTRIB_10 = CS_VATTRIB_GENERIC_FIRST + 10, 00233 CS_VATTRIB_11 = CS_VATTRIB_GENERIC_FIRST + 11, 00234 CS_VATTRIB_12 = CS_VATTRIB_GENERIC_FIRST + 12, 00235 CS_VATTRIB_13 = CS_VATTRIB_GENERIC_FIRST + 13, 00236 CS_VATTRIB_14 = CS_VATTRIB_GENERIC_FIRST + 14, 00237 CS_VATTRIB_15 = CS_VATTRIB_GENERIC_FIRST + 15 00239 }; 00240 00242 enum G3D_FOGMETHOD 00243 { 00244 G3DFOGMETHOD_NONE = 0x00, 00245 G3DFOGMETHOD_ZBUFFER = 0x01, 00246 G3DFOGMETHOD_VERTEX = 0x02 00247 }; 00248 00252 00253 #define CS_FX_MASK_MIXMODE 0xF0000000 00254 00255 #define CS_FX_COPY 0x00000000 00256 00257 #define CS_FX_MULTIPLY 0x10000000 00258 00259 #define CS_FX_MULTIPLY2 0x20000000 00260 00261 #define CS_FX_ADD 0x30000000 00262 00263 #define CS_FX_ALPHA 0x40000000 00264 00265 #define CS_FX_TRANSPARENT 0x50000000 00266 00267 #define CS_FX_DESTALPHAADD 0x60000000 00268 00269 #define CS_FX_SRCALPHAADD 0x70000000 00270 00271 #define CS_FX_PREMULTALPHA 0x80000000 00272 00276 #define CS_FX_MESH 0xf0000000 00277 00278 #define CS_FX_KEYCOLOR 0x08000000 00279 00280 #define CS_FX_FLAT 0x04000000 00281 00282 #define CS_FX_TILING 0x02000000 00283 00284 #define CS_FX_MASK_ALPHA 0x000000FF 00285 00287 #define CS_FX_SETALPHA(alpha) \ 00288 (CS_FX_ALPHA | uint (alpha * CS_FX_MASK_ALPHA)) 00289 00290 #define CS_FX_SETALPHA_INT(alpha) \ 00291 (CS_FX_ALPHA | uint (alpha & CS_FX_MASK_ALPHA)) 00292 00297 struct csAlphaMode 00298 { 00300 enum AlphaType 00301 { 00303 alphaNone = 1, 00305 alphaBinary, 00307 alphaSmooth 00308 }; 00310 bool autoAlphaMode; 00311 union 00312 { 00314 AlphaType alphaType; 00316 csStringID autoModeTexture; 00317 }; 00318 }; 00319 00322 00323 #define CS_LIGHTPARAM_POSITION 0 00324 00325 #define CS_LIGHTPARAM_DIFFUSE 1 00326 00327 #define CS_LIGHTPARAM_SPECULAR 2 00328 00329 #define CS_LIGHTPARAM_ATTENUATION 3 00330 00334 00335 #define CS_SHADOW_VOLUME_BEGIN 1 00336 00337 #define CS_SHADOW_VOLUME_PASS1 2 00338 00339 #define CS_SHADOW_VOLUME_PASS2 3 00340 00341 #define CS_SHADOW_VOLUME_FAIL1 4 00342 00343 #define CS_SHADOW_VOLUME_FAIL2 5 00344 00345 #define CS_SHADOW_VOLUME_USE 6 00346 00347 #define CS_SHADOW_VOLUME_FINISH 7 00348 00350 00351 enum G3D_RENDERSTATEOPTION 00352 { 00354 G3DRENDERSTATE_ZBUFFERMODE, 00356 G3DRENDERSTATE_DITHERENABLE, 00358 G3DRENDERSTATE_BILINEARMAPPINGENABLE, 00360 G3DRENDERSTATE_TRILINEARMAPPINGENABLE, 00362 G3DRENDERSTATE_TRANSPARENCYENABLE, 00364 G3DRENDERSTATE_MIPMAPENABLE, 00366 G3DRENDERSTATE_TEXTUREMAPPINGENABLE, 00368 G3DRENDERSTATE_LIGHTINGENABLE, 00370 G3DRENDERSTATE_INTERLACINGENABLE, 00372 G3DRENDERSTATE_MMXENABLE, 00374 G3DRENDERSTATE_INTERPOLATIONSTEP, 00376 G3DRENDERSTATE_MAXPOLYGONSTODRAW, 00378 G3DRENDERSTATE_GOURAUDENABLE, 00380 G3DRENDERSTATE_EDGES 00381 }; 00382 00384 struct csGraphics3DCaps 00385 { 00386 bool CanClip; 00387 int minTexHeight, minTexWidth; 00388 int maxTexHeight, maxTexWidth; 00389 G3D_FOGMETHOD fog; 00390 bool NeedsPO2Maps; 00391 int MaxAspectRatio; 00392 00393 // The following caps are only used by NR 00394 00399 bool SupportsPointSprites; 00403 bool DestinationAlpha; 00407 bool StencilShadows; 00408 }; 00409 00411 enum csRenderMeshType 00412 { 00414 CS_MESHTYPE_TRIANGLES, 00416 CS_MESHTYPE_QUADS, 00426 CS_MESHTYPE_TRIANGLESTRIP, 00432 CS_MESHTYPE_TRIANGLEFAN, 00436 CS_MESHTYPE_POINTS, 00442 CS_MESHTYPE_POINT_SPRITES, 00446 CS_MESHTYPE_LINES, 00451 CS_MESHTYPE_LINESTRIP, 00458 CS_MESHTYPE_POLYGON 00459 }; 00460 00464 enum csSimpleMeshFlags 00465 { 00472 csSimpleMeshScreenspace = 0x01 00473 }; 00474 00478 struct csSimpleRenderMesh 00479 { 00481 csRenderMeshType meshtype; 00482 00484 uint indexCount; 00486 const uint* indices; 00487 00489 uint vertexCount; 00495 const csVector3* vertices; 00497 const csVector2* texcoords; 00503 const csVector4* colors; 00508 iTextureHandle* texture; 00509 00511 iShader* shader; 00513 iShaderVariableContext* dynDomain; 00515 csAlphaMode alphaType; 00517 csZBufMode z_buf_mode; 00519 uint mixmode; 00528 csReversibleTransform object2camera; 00529 00530 csSimpleRenderMesh () : colors(0), texture (0), shader (0), dynDomain (0), 00531 z_buf_mode (CS_ZBUF_NONE), mixmode (CS_FX_COPY) 00532 { 00533 alphaType.autoAlphaMode = true; 00534 alphaType.autoModeTexture = csInvalidStringID; 00535 }; 00536 }; 00537 00538 SCF_VERSION (iGraphics3D, 5, 5, 1); 00539 00557 struct iGraphics3D : public iBase 00558 { 00560 virtual bool Open () = 0; 00562 virtual void Close () = 0; 00563 00571 virtual iGraphics2D *GetDriver2D () = 0; 00572 00579 virtual iTextureManager *GetTextureManager () = 0; 00580 00582 virtual void SetDimensions (int width, int height) = 0; 00584 virtual int GetWidth () const = 0; 00586 virtual int GetHeight () const = 0; 00587 00592 virtual const csGraphics3DCaps *GetCaps () const = 0; 00593 00598 virtual void SetPerspectiveCenter (int x, int y) = 0; 00599 00601 virtual void GetPerspectiveCenter (int& x, int& y) const = 0; 00602 00606 virtual void SetPerspectiveAspect (float aspect) = 0; 00607 00609 virtual float GetPerspectiveAspect () const = 0; 00610 00615 virtual void SetObjectToCamera (csReversibleTransform* o2c) = 0; 00616 00620 virtual const csReversibleTransform& GetObjectToCamera () = 0; 00621 00635 virtual void SetRenderTarget (iTextureHandle* handle, 00636 bool persistent = false) = 0; 00637 00641 virtual iTextureHandle* GetRenderTarget () const = 0; 00642 00644 virtual bool BeginDraw (int DrawFlags) = 0; 00645 00647 virtual void FinishDraw () = 0; 00648 00654 virtual void Print (csRect const* area) = 0; 00655 00670 virtual void DrawPixmap (iTextureHandle *hTex, int sx, int sy, 00671 int sw, int sh, int tx, int ty, int tw, int th, uint8 Alpha = 0) = 0; 00672 00677 virtual void DrawLine (const csVector3& v1, const csVector3& v2, 00678 float fov, int color) = 0; 00679 00685 virtual void SetClipper (iClipper2D* clipper, int cliptype) = 0; 00686 00690 virtual iClipper2D* GetClipper () = 0; 00691 00695 virtual int GetClipType () const = 0; 00696 00701 virtual void SetNearPlane (const csPlane3& pl) = 0; 00702 00706 virtual void ResetNearPlane () = 0; 00707 00711 virtual const csPlane3& GetNearPlane () const = 0; 00712 00716 virtual bool HasNearPlane () const = 0; 00717 00719 virtual bool SetRenderState (G3D_RENDERSTATEOPTION op, long val) = 0; 00720 00722 virtual long GetRenderState (G3D_RENDERSTATEOPTION op) const = 0; 00723 00728 virtual bool SetOption (const char*, const char*) = 0; 00729 00733 virtual bool ActivateBuffers (csRenderBufferHolder* holder, 00734 csRenderBufferName mapping[CS_VATTRIB_SPECIFIC_LAST+1]) = 0; 00735 00739 virtual bool ActivateBuffers (csVertexAttrib *attribs, 00740 iRenderBuffer **buffers, unsigned int count) = 0; 00741 00746 virtual void DeactivateBuffers (csVertexAttrib *attribs, unsigned int count) = 0; 00747 00752 /* virtual void SetBufferState (csVertexAttrib* attribs, 00753 iRenderBuffer** buffers, int count) = 0;*/ 00754 00759 virtual void SetTextureState (int* units, iTextureHandle** textures, 00760 int count) = 0; 00761 00763 virtual void DrawMesh (const csCoreRenderMesh* mymesh, 00764 const csRenderMeshModes& modes, 00765 const csArray< csArray<csShaderVariable*> > &stacks) = 0; 00766 00768 virtual void SetWriteMask (bool red, bool green, bool blue, bool alpha) = 0; 00769 00771 virtual void GetWriteMask (bool &red, bool &green, bool &blue, 00772 bool &alpha) const = 0; 00773 00775 virtual void SetZMode (csZBufMode mode) = 0; 00776 00778 virtual void EnableZOffset () = 0; 00779 00781 virtual void DisableZOffset () = 0; 00782 00784 virtual void SetShadowState (int state) = 0; 00785 00787 virtual float GetZBuffValue (int x, int y) = 0; 00788 00798 virtual void OpenPortal (size_t numVertices, const csVector2* vertices, 00799 const csPlane3& normal, bool floating) = 0; 00800 00805 virtual void ClosePortal (bool zfill_portal) = 0; 00806 00808 virtual iHalo *CreateHalo (float iR, float iG, float iB, 00809 unsigned char *iAlpha, int iWidth, int iHeight) = 0; 00810 00816 virtual void RemoveFromCache (iRendererLightmap* rlm) = 0; 00817 00818 //========================================================================= 00819 // Here ends the zone of unimplemented methods. 00820 //========================================================================= 00821 00826 virtual bool IsLightmapOK (int lmw, int lmh, 00827 int lightCellSize) = 0; 00828 00829 virtual csPtr<iPolygonRenderer> CreatePolygonRenderer () = 0; 00830 00831 /* 00832 @@@ Needed for SW poly drawing ATM. 00833 */ 00834 virtual void SetWorldToCamera (csReversibleTransform* w2c) = 0; 00835 00852 virtual void DrawSimpleMesh (const csSimpleRenderMesh& mesh, 00853 uint flags = 0) = 0; 00854 00856 virtual csZBufMode GetZMode () = 0; 00857 }; 00858 00861 #endif // __CS_IVIDEO_GRAPH3D_H__ 00862
Generated for Crystal Space by doxygen 1.3.9.1