|
graph3d.h00001 /* 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 __IVIDEO_GRAPH3D_H__ 00021 #define __IVIDEO_GRAPH3D_H__ 00022 00023 #include "csutil/scf.h" 00024 #include "csgeom/plane3.h" 00025 #include "csgeom/vector2.h" 00026 00027 class csMatrix3; 00028 class csVector3; 00029 class csVector2; 00030 class csPlane3; 00031 class csRect; 00032 class csReversibleTransform; 00033 class csColor; 00034 00035 struct iGraphics2D; 00036 struct iPolygonTexture; 00037 struct iPolygonBuffer; 00038 struct iVertexBuffer; 00039 struct iVertexBufferManager; 00040 struct iTextureManager; 00041 struct iTextureHandle; 00042 struct iMaterialHandle; 00043 struct iClipper2D; 00044 struct iHalo; 00045 struct csRGBpixel; 00046 struct csPixelFormat; 00047 00048 #define CS_FOG_FRONT 0 00049 #define CS_FOG_BACK 1 00050 #define CS_FOG_VIEW 2 00051 00052 //====================================================================== 00053 // For vertex based fog the following defines are used: 00054 #define CS_FOGTABLE_SIZE 64 00055 00056 // Each texel in the fog table holds the fog alpha value at a certain 00057 // (distance*density). The median distance parameter determines the 00058 // (distance*density) value represented by the texel at the center of 00059 // the fog table. The fog calculation is: 00060 // alpha = 1.0 - exp( -(density*distance) / CS_FOGTABLE_MEDIANDISTANCE) 00061 #define CS_FOGTABLE_MEDIANDISTANCE 10.0f 00062 #define CS_FOGTABLE_MAXDISTANCE (CS_FOGTABLE_MEDIANDISTANCE * 2.0f) 00063 #define CS_FOGTABLE_DISTANCESCALE (1.0f / CS_FOGTABLE_MAXDISTANCE) 00064 00065 // Fog (distance*density) is mapped to a texture coordinate and then 00066 // clamped. This determines the clamp value. Some drivers don't 00067 // like clamping textures so we must do it ourself 00068 #define CS_FOGTABLE_CLAMPVALUE 0.85f 00069 #define CS_FOG_MAXVALUE (CS_FOGTABLE_MAXDISTANCE * CS_FOGTABLE_CLAMPVALUE) 00070 //====================================================================== 00071 00076 #define CS_FX_MASK_MIXMODE 0xF0000000 // SRC/DST mixing mode mask 00077 #define CS_FX_COPY 0x00000000 // =SRC 00078 #define CS_FX_MULTIPLY 0x10000000 // =SRC*DST 00079 #define CS_FX_MULTIPLY2 0x20000000 // =2*SRC*DST 00080 #define CS_FX_ADD 0x30000000 // =SRC+DST 00081 #define CS_FX_ALPHA 0x40000000 // =(1-alpha)*SRC + alpha*DST 00082 #define CS_FX_TRANSPARENT 0x50000000 // =DST 00083 #define CS_FX_KEYCOLOR 0x08000000 // color 0 is transparent 00084 #define CS_FX_GOURAUD 0x04000000 // Gouraud shading 00085 #define CS_FX_TILING 0x02000000 // Tiling 00086 #define CS_FX_MASK_ALPHA 0x000000FF // alpha = 0..FF (opaque..transparent) 00087 00089 #define CS_FX_SETALPHA(alpha) \ 00090 (CS_FX_ALPHA | uint (alpha * CS_FX_MASK_ALPHA)) 00091 00092 #define CS_FX_SETALPHA_INT(alpha) \ 00093 (CS_FX_ALPHA | uint (alpha & CS_FX_MASK_ALPHA)) 00094 00096 class G3DTexturedVertex : public csVector2 00097 { 00098 public: 00100 float z; 00101 00102 // Texture coordinates 00103 float u, v; 00104 00105 // Lighting info (Used only with Gouraud shading (between 0 and 1)) 00106 float r, g, b; 00107 }; 00108 00110 class G3DFogInfo 00111 { 00112 public: 00114 float r, g, b; 00121 float intensity; 00122 float intensity2; 00123 }; 00124 00126 class G3DTexturePlane 00127 { 00128 public: 00130 csMatrix3* m_cam2tex; 00132 csVector3* v_cam2tex; 00133 }; 00134 00136 struct G3DPolygonDPFX 00137 { 00139 int num; 00141 G3DTexturedVertex vertices[100]; 00143 G3DFogInfo fog_info[100]; 00145 bool use_fog; 00146 00148 iMaterialHandle *mat_handle; 00150 uint mixmode; 00151 00153 uint8 flat_color_r; 00154 uint8 flat_color_g; 00155 uint8 flat_color_b; 00156 00157 // A dummy constructor to appease NextStep compiler which otherwise 00158 // complains that it is unable to create this object. This happens when 00159 // a subcomponent such as G3DTexturedVertex has a constructor. 00160 G3DPolygonDPFX() {} 00161 }; 00162 00164 struct G3DPolygonDFP 00165 { 00167 int num; 00169 csVector2 vertices[100]; 00170 00172 csPlane3 normal; 00173 }; 00174 00176 struct G3DPolygonDP : public G3DPolygonDFP 00177 { 00179 G3DFogInfo fog_info[100]; 00181 bool use_fog; 00182 00184 iMaterialHandle* mat_handle; 00185 00187 G3DTexturePlane plane; 00188 00190 iPolygonTexture* poly_texture; 00191 00193 bool do_fullbright; 00194 00196 uint mixmode; 00197 00199 float z_value; 00200 00201 #ifdef DO_HW_UVZ 00202 csVector3* uvz; 00203 bool mirror; 00204 #endif 00205 }; 00206 00208 typedef G3DPolygonDP G3DPolygonDPF; 00209 00215 enum csZBufMode 00216 { 00217 CS_ZBUF_NONE = 0x00000000, 00218 CS_ZBUF_FILL = 0x00000001, 00219 CS_ZBUF_TEST = 0x00000002, 00220 CS_ZBUF_USE = 0x00000003, 00221 CS_ZBUF_FILLONLY = 0x00000004, 00222 CS_ZBUF_EQUAL = 0x00000005 00223 }; 00224 00226 enum G3D_RENDERSTATEOPTION 00227 { 00229 G3DRENDERSTATE_ZBUFFERMODE, 00231 G3DRENDERSTATE_DITHERENABLE, 00233 G3DRENDERSTATE_BILINEARMAPPINGENABLE, 00235 G3DRENDERSTATE_TRILINEARMAPPINGENABLE, 00237 G3DRENDERSTATE_TRANSPARENCYENABLE, 00239 G3DRENDERSTATE_MIPMAPENABLE, 00241 G3DRENDERSTATE_TEXTUREMAPPINGENABLE, 00243 G3DRENDERSTATE_LIGHTINGENABLE, 00245 G3DRENDERSTATE_INTERLACINGENABLE, 00247 G3DRENDERSTATE_MMXENABLE, 00249 G3DRENDERSTATE_INTERPOLATIONSTEP, 00251 G3DRENDERSTATE_MAXPOLYGONSTODRAW, 00253 G3DRENDERSTATE_GOURAUDENABLE, 00255 G3DRENDERSTATE_GAMMACORRECTION, 00257 G3DRENDERSTATE_EDGES 00258 }; 00259 00260 // Bit flags for iGraphics3D::BeginDraw () 00262 #define CSDRAW_2DGRAPHICS 0x00000001 00264 #define CSDRAW_3DGRAPHICS 0x00000002 00266 #define CSDRAW_CLEARZBUFFER 0x00000010 00268 #define CSDRAW_CLEARSCREEN 0x00000020 00269 00271 enum G3D_FOGMETHOD 00272 { 00273 G3DFOGMETHOD_NONE = 0x00, 00274 G3DFOGMETHOD_ZBUFFER = 0x01, 00275 G3DFOGMETHOD_VERTEX = 0x02 00276 }; 00277 00279 struct csGraphics3DCaps 00280 { 00281 bool CanClip; 00282 int minTexHeight, minTexWidth; 00283 int maxTexHeight, maxTexWidth; 00284 G3D_FOGMETHOD fog; 00285 bool NeedsPO2Maps; 00286 int MaxAspectRatio; 00287 }; 00288 00294 struct csTriangle 00295 { 00296 int a, b, c; 00297 00299 csTriangle() {} 00300 00302 csTriangle(int _a, int _b, int _c):a(_a), b(_b), c(_c) {} 00303 }; 00304 00309 #define CS_CLIPPER_NONE -1 00310 00315 #define CS_CLIPPER_OPTIONAL 0 00316 00321 #define CS_CLIPPER_TOPLEVEL 1 00322 00327 #define CS_CLIPPER_REQUIRED 2 00328 00329 00335 #define CS_CLIP_NOT 0 00336 00344 #define CS_CLIP_NEEDED 1 00345 00352 #define CS_CLIP_TOPLEVEL 2 00353 00365 struct G3DTriangleMesh 00366 { 00367 enum 00368 { 00370 MAX_VERTEXPOOL = 2 00371 }; 00372 00374 int num_vertices_pool; 00375 00377 int num_triangles; 00379 csTriangle* triangles; 00380 00382 int clip_portal; 00384 int clip_plane; 00386 int clip_z_plane; 00387 00389 bool use_vertex_color; 00390 00392 bool do_fog; 00394 bool do_mirror; 00396 bool do_morph_texels; 00398 bool do_morph_colors; 00399 00401 enum 00402 { 00404 VM_WORLDSPACE, 00406 VM_VIEWSPACE 00407 } vertex_mode; 00408 00410 uint mixmode; 00411 float morph_factor; 00416 iVertexBuffer* buffers[MAX_VERTEXPOOL]; 00417 iMaterialHandle* mat_handle; 00419 G3DFogInfo* vertex_fog; 00420 00421 // TODO : store information required for lighting calculation 00422 }; 00423 00434 struct G3DPolygonMesh 00435 { 00437 iPolygonBuffer* polybuf; 00438 00439 // Apply fogging? 00440 bool do_fog; 00441 00443 uint mixmode; 00444 00446 int clip_portal; 00448 int clip_plane; 00450 int clip_z_plane; 00451 00453 bool do_mirror; 00454 00456 enum 00457 { 00459 VM_WORLDSPACE, 00461 VM_VIEWSPACE 00462 } vertex_mode; 00463 00465 G3DFogInfo* vertex_fog; 00466 }; 00467 00471 struct csFog 00472 { 00474 bool enabled; 00476 float density; 00478 float red; 00480 float green; 00482 float blue; 00483 }; 00484 00485 SCF_VERSION (iGraphics3D, 5, 0, 2); 00486 00493 struct iGraphics3D : public iBase 00494 { 00496 virtual bool Open () = 0; 00498 virtual void Close () = 0; 00499 00501 virtual iGraphics2D *GetDriver2D () = 0; 00502 00504 virtual void SetDimensions (int width, int height) = 0; 00505 00507 virtual int GetWidth () = 0; 00509 virtual int GetHeight () = 0; 00510 00515 virtual csGraphics3DCaps *GetCaps () = 0; 00516 00521 virtual void SetPerspectiveCenter (int x, int y) = 0; 00522 00524 virtual void GetPerspectiveCenter (int& x, int& y) = 0; 00525 00529 virtual void SetPerspectiveAspect (float aspect) = 0; 00530 00532 virtual float GetPerspectiveAspect () = 0; 00533 00538 virtual void SetObjectToCamera (csReversibleTransform* o2c) = 0; 00539 00543 virtual const csReversibleTransform& GetObjectToCamera () = 0; 00544 00550 virtual void SetClipper (iClipper2D* clipper, int cliptype) = 0; 00551 00555 virtual iClipper2D* GetClipper () = 0; 00556 00560 virtual int GetClipType () = 0; 00561 00566 virtual void SetNearPlane (const csPlane3& pl) = 0; 00567 00571 virtual void ResetNearPlane () = 0; 00572 00576 virtual const csPlane3& GetNearPlane () = 0; 00577 00581 virtual bool HasNearPlane () = 0; 00582 00584 virtual uint32 *GetZBuffAt (int x, int y) = 0; 00585 00587 virtual float GetZBuffValue (int x, int y) = 0; 00588 00590 virtual bool BeginDraw (int DrawFlags) = 0; 00591 00593 virtual void FinishDraw () = 0; 00594 00600 virtual void Print (csRect *area) = 0; 00601 00603 virtual bool SetRenderState (G3D_RENDERSTATEOPTION op, long val) = 0; 00604 00606 virtual long GetRenderState (G3D_RENDERSTATEOPTION op) = 0; 00607 00609 virtual void DrawPolygon (G3DPolygonDP& poly) = 0; 00610 00617 virtual void DrawPolygonDebug (G3DPolygonDP& poly) = 0; 00618 00637 virtual void DrawPolygonFX (G3DPolygonDPFX& poly) = 0; 00638 00642 virtual void DrawTriangleMesh (G3DTriangleMesh& mesh) = 0; 00643 00647 virtual void DrawPolygonMesh (G3DPolygonMesh& mesh) = 0; 00648 00656 virtual void OpenFogObject (CS_ID id, csFog* fog) = 0; 00657 00669 virtual void DrawFogPolygon (CS_ID id, G3DPolygonDFP& poly, int fogtype) = 0; 00670 00676 virtual void CloseFogObject (CS_ID id) = 0; 00677 00679 virtual void DrawLine (const csVector3& v1, const csVector3& v2, 00680 float fov, int color) = 0; 00681 00683 virtual iHalo *CreateHalo (float iR, float iG, float iB, 00684 unsigned char *iAlpha, int iWidth, int iHeight) = 0; 00685 00700 virtual void DrawPixmap (iTextureHandle *hTex, int sx, int sy, 00701 int sw, int sh, int tx, int ty, int tw, int th, uint8 Alpha = 0) = 0; 00702 00704 virtual iTextureManager *GetTextureManager () = 0; 00705 00707 virtual void DumpCache () = 0; 00708 00710 virtual void ClearCache () = 0; 00711 00717 virtual void RemoveFromCache (iPolygonTexture* poly_texture) = 0; 00718 00723 virtual iVertexBufferManager* GetVertexBufferManager () = 0; 00724 00729 virtual bool IsLightmapOK(iPolygonTexture* poly_texture) = 0; 00730 }; 00731 00732 #endif // __IVIDEO_GRAPH3D_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |