00001 /* 00002 * Copyright (c) 1998 by Tech Soft 3D, LLC. 00003 * The information contained herein is confidential and proprietary to 00004 * Tech Soft 3D, LLC., and considered a trade secret as defined under 00005 * civil and criminal statutes. Tech Soft 3D shall pursue its civil 00006 * and criminal remedies in the event of unauthorized use or misappropriation 00007 * of its trade secrets. Use of this information by anyone other than 00008 * authorized employees of Tech Soft 3D, LLC. is granted only under a 00009 * written non-disclosure agreement, expressly prescribing the scope and 00010 * manner of such use. 00011 * 00012 * $Id: 3d__common_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $ 00013 */ 00014 00015 #ifndef H3DCOMMON_H 00016 #define H3DCOMMON_H 00017 00018 #include "hoops.h" 00019 #include "hc_proto.h" 00020 #include "hd_proto.h" 00021 #include "hi_proto.h" 00022 #include "adt.h" 00023 #include "database.h" 00024 #include "driver.h" 00025 #include "hpserror.h" 00026 #include "patterns.h" 00027 #include "phdraw.h" 00028 #include "phedron.h" 00029 #include "please.h" 00030 #include "searchh.h" 00031 #include "tandt.h" 00032 #include "hversion.h" 00033 00034 #include "msw.h" 00035 00036 00037 00038 #define H3D_Display_List_MINIMUM 100 00039 #define H3D_Display_List_PREFERRED_SIZE 5000 //pointcount 00040 00041 /***************************************************************************** 00042 ***************************************************************************** 00043 Category: General macros and enums 00044 ***************************************************************************** 00045 *****************************************************************************/ 00046 #undef ASSERT 00047 #ifdef _DEBUG 00048 # include "assert.h" 00049 # define ASSERT(x) assert(x) 00050 #else 00051 # define ASSERT(x) DO_NOTHING(x) 00052 #endif 00053 00054 00055 #ifndef memeq 00056 # define memeq(a,b,siz) !memcmp(a,b,siz) 00057 #endif 00058 00059 00060 00061 //#define PURE_ABSTRACT 00062 #ifndef PURE_ABSTRACT 00063 #define ABSTRACT_ERROR HE_ERROR(HEC_INTERNAL_ERROR, HEC_INTERNAL_ERROR, "Function needs implementation.") 00064 #endif 00065 00066 00067 #define H3DD(dc) ((H3DData alter *)((dc)->data2)) 00068 #define H3DNRD(nr) (H3DD((nr)->display_context)) 00069 00070 00071 #define H_SAFE_DELETE(p) { if (p) { delete (p); (p)=NULL; } } 00072 #define H_SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p)=NULL; } } 00073 #define H_SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } } 00074 00075 00076 /* a variant of SKIP_ALL that breaks instead of returning */ 00077 #define SKIP_ALL_BREAK(geom_list, geom_type) do { \ 00078 if (geom_list->h.type == geom_type) { \ 00079 int table_type = GT_REF_TYPE(geom_type); \ 00080 if (geom_list->h.next == null) { \ 00081 geom_list = null; \ 00082 break; \ 00083 } \ 00084 if (geom_list->h.owner == null) { \ 00085 do if ((geom_list = geom_list->h.next) == null) \ 00086 break; \ 00087 until (geom_list->h.type != geom_type); \ 00088 } \ 00089 else for (;;) { \ 00090 table_type++; \ 00091 if (table_type > GT_OO) { \ 00092 geom_list = null; \ 00093 break; \ 00094 } \ 00095 if (geom_list->h.owner->geometry_table[table_type] != null) { \ 00096 geom_list = geom_list->h.owner->geometry_table[table_type]; \ 00097 break;\ 00098 } \ 00099 } \ 00100 } \ 00101 } while (0) 00102 00103 00104 #define LINE_STYLE_PUNT(line_style)\ 00105 (!BIT(line_style->flags, LSF_SOLID) && \ 00106 (\ 00107 /* no accurate 16-bit representation */ \ 00108 !ANYBIT(line_style->flags, LSF_BITS16|LSF_BITS32) || \ 00109 ANYBIT(line_style->flags, LSF_COMPLEX_ANYBITS)\ 00110 )\ 00111 ) 00112 00113 /* 00114 * Make it explicit when we're using DC or 3D mode - a boolean is easy to misinterpret without context. 00115 */ 00116 enum DrawPrimitiveMode 00117 { 00118 DP_DC, // DC primitives 00119 DP_3D, // 3D primitives 00120 }; 00121 00122 00123 #define TEX_USAGE_ENVIRONMENT 1 00124 #define TEX_USAGE_INDEX_INTERPOLATION 2 00125 #define TEX_USAGE_3D_IMAGE 3 00126 #define TEX_USAGE_FACE_PATTERN 4 00127 #define TEX_USAGE_LINE_PATTERN 5 00128 #define TEX_USAGE_LINE_TOOLS 6 00129 #define TEX_USAGE_BUMP 7 00130 00131 00132 enum H3D_Color_Format 00133 { 00134 H3D_COLOR_RGBA, 00135 H3D_COLOR_ARGB, 00136 H3D_COLOR_ABGR, 00137 }; 00138 typedef unsigned int H3D_Color; 00139 #define H3D_PACK_BYTES(a,b,c,d) ((H3D_Color)((((a)&0xff)<<24)|(((b)&0xff)<<16)|(((c)&0xff)<<8)|((d)&0xff))) 00140 local H3D_Color h3d_pack_color(H3D_Color_Format format, char r, char g, char b, char a) 00141 { 00142 H3D_Color color; 00143 switch (format) 00144 { 00145 case H3D_COLOR_ARGB: 00146 color = H3D_PACK_BYTES(a,r,g,b); 00147 break; 00148 case H3D_COLOR_ABGR: 00149 color = H3D_PACK_BYTES(a,b,g,r); 00150 break; 00151 case H3D_COLOR_RGBA: 00152 default: 00153 color = H3D_PACK_BYTES(r,g,b,a); 00154 break; 00155 } 00156 return color; 00157 } 00158 local H3D_Color h3d_pack_colorf(H3D_Color_Format format, float r, float g, float b, float a) 00159 { 00160 return h3d_pack_color(format, r*255, g*255, b*255, a*255); 00161 } 00162 00163 00164 00165 00166 #define H3D_OBJ_INVALID 0 00167 #define H3D_OBJ_IndexBuffer 1 /* index buffered object (H3DIndexedBufferObject)*/ 00168 #define H3D_OBJ_VertexBuffer 2 /* vertex buffer (H3DVertexBufferCache) */ 00169 #define H3D_OBJ_Mesh 3 /* index buffered object (Mesh uses this interface too)*/ 00170 00171 00172 /***************************************************************************** 00173 ***************************************************************************** 00174 Category: Driver Specific Preprocessor 00175 ***************************************************************************** 00176 *****************************************************************************/ 00177 #ifdef DX9_DRIVER 00178 #include "d3dutil.h" 00179 #define H3D_SURFACE_ID LPDIRECT3DSURFACE9 00180 00181 #else 00182 00183 #define H3D_SURFACE_ID void * 00184 #endif 00185 00186 00187 /***************************************************************************** 00188 ***************************************************************************** 00189 Category: Forward Declarations 00190 ***************************************************************************** 00191 *****************************************************************************/ 00192 class H3DShaderID; 00193 class H3DShader; 00194 class H3DShaderHASH; 00195 class H3DActions; 00196 class H3DTexture; 00197 class H3DVertexBufferCache; 00198 class H3DIndexBufferCache; 00199 class H3DIndexedBufferObject; 00200 class H3D_Display_List_Bin; 00201 00202 00203 /***************************************************************************** 00204 ***************************************************************************** 00205 Category: H3DVertexFormat Class 00206 00207 This class is a wrapper around a vertex format description. Needs to be 00208 subclassed per driver. 00209 ***************************************************************************** 00210 *****************************************************************************/ 00211 00212 #define H3DVF unsigned int 00213 00214 #define H3DVF_POSITION 0x0001 00215 #define H3DVF_NORMAL 0x0002 00216 #define H3DVF_DIFFUSE 0x0004 00217 #define H3DVF_SPECULAR 0x0008 00218 #define H3DVF_TEXCOUNT_1 0x0010 00219 #define H3DVF_TEXCOUNT_2 0x0020 00220 #define H3DVF_TEXCOUNT_3 0x0030 00221 #define H3DVF_TEXCOUNT_4 0x0040 00222 #define H3DVF_TEXCOUNT_5 0x0050 00223 #define H3DVF_TEXCOUNT_6 0x0060 00224 #define H3DVF_TEXCOUNT_7 0x0070 00225 #define H3DVF_TEXCOUNT_8 0x0080 00226 #define H3DVF_TEXCOUNT_MASK 0x00f0 00227 #define H3DVF_TEXCOUNT_SHIFT 4 00228 #define H3DVF_TEXCOUNT_LOOKUP(vf) ((vf & H3DVF_TEXCOUNT_MASK) >> H3DVF_TEXCOUNT_SHIFT) 00229 00230 #define H3DVF_TEXCOORD_SIZE(i, size) ((size-1) << (i * 2 + 16)) 00231 #define H3DVF_TEXCOORD_SIZE_LOOKUP(vf, i) (((vf >> (i * 2 + 16)) & (0x3)) + 1) 00232 00233 00234 00235 00236 /* A few compact definitions */ 00237 #define H3DVF_PT (H3DVF_POSITION) 00238 #define H3DVF_PT_CLR (H3DVF_POSITION | H3DVF_DIFFUSE) 00239 #define H3DVF_PT_TEX (H3DVF_POSITION | H3DVF_TEXCOUNT_1 | H3DVF_TEXCOORD_SIZE(0,3)) 00240 #define H3DVF_PT_NML_TEX (H3DVF_PT_TEX | H3DVF_NORMAL) 00241 #define H3DVF_PT_NML_TEX2 (H3DVF_PT_NML_TEX | H3DVF_TEXCOUNT_2 | H3DVF_TEXCOORD_SIZE(1,3)) 00242 00243 00244 class H3DVertexFormat 00245 { 00246 protected: 00247 H3DVF m_bits; 00248 00249 H3DVF m_bits_when_sized; 00250 unsigned int m_size; 00251 00252 00253 00254 void set_bit(int bit, bool state) { 00255 if (state) 00256 m_bits |= bit; 00257 else 00258 m_bits &= ~bit; 00259 }; 00260 public: 00261 H3DVertexFormat(H3DVF h3dvf) 00262 { 00263 reset(); 00264 set_vf(h3dvf); 00265 }; 00266 00267 H3DVertexFormat() { reset(); }; 00268 ~H3DVertexFormat(){}; 00269 00270 void reset() 00271 { 00272 SET_MEMORY(this, sizeof(H3DVertexFormat), 0); 00273 } 00274 00275 void set_vf(H3DVF h3dvf) 00276 { 00277 m_bits |= h3dvf; 00278 }; 00279 00280 void set_position(bool state = true) {set_bit(H3DVF_POSITION, state);}; 00281 void set_normals(bool state = true) {set_bit(H3DVF_NORMAL, state);}; 00282 void set_diffuse(bool state = true) {set_bit(H3DVF_DIFFUSE, state);}; 00283 void set_specular(bool state = true) {set_bit(H3DVF_SPECULAR, state);}; 00284 void incr_tex_count() {m_bits += H3DVF_TEXCOUNT_1;}; 00285 void set_tex_count(int num) {m_bits |= (H3DVF_TEXCOUNT_1 * num);}; 00286 void set_tex_size(int num, int size) {m_bits |= H3DVF_TEXCOORD_SIZE(num, size);}; 00287 00288 H3DVF get_vf() {return m_bits;}; 00289 bool get_position() {return BIT(m_bits, H3DVF_POSITION);}; 00290 bool get_normals() {return BIT(m_bits, H3DVF_NORMAL);}; 00291 bool get_diffuse() {return BIT(m_bits, H3DVF_DIFFUSE);}; 00292 bool get_specular() {return BIT(m_bits, H3DVF_SPECULAR);}; 00293 int get_tex_count() {return H3DVF_TEXCOUNT_LOOKUP(m_bits);}; 00294 int get_tex_size(int num) {return H3DVF_TEXCOORD_SIZE_LOOKUP(m_bits, num);}; 00295 00296 int get_size(bool as_bytes = true) 00297 { 00298 int stride_multiplier = 1; 00299 00300 if (as_bytes) 00301 stride_multiplier = sizeof(float); 00302 00303 if (m_bits_when_sized == m_bits) 00304 return m_size * stride_multiplier; 00305 00306 m_size = 0; 00307 m_bits_when_sized = m_bits; 00308 00309 if( get_position()) m_size += 3; 00310 if( get_normals()) m_size += 3; 00311 if( get_diffuse()) m_size += 1; 00312 if( get_specular()) m_size += 1; 00313 00314 m_size += get_tex_size(0) * get_tex_count(); 00315 00316 return m_size * stride_multiplier; 00317 }; 00318 00319 bool operator == (H3DVertexFormat &right) { return m_bits == right.m_bits; }; 00320 bool operator != (H3DVertexFormat &right) { return m_bits != right.m_bits; }; 00321 }; 00322 00323 00324 /***************************************************************************** 00325 ***************************************************************************** 00326 Category: Driver structures 00327 ***************************************************************************** 00328 *****************************************************************************/ 00329 #define H3D_SOFTWARE_XFORM_BIN_SIZE 256 //max size to allow for bin IM software xforms 00330 00331 #define H3D_DL_BLESSED_GEOMETRY 0x0001 00332 #define H3D_DL_BLESSED_SEGMENT 0x0002 00333 #define H3D_DL_SINGLE_INSTANCED 0x0004 /* indicates that gdl's can be promoted to segdl's for free */ 00334 00335 #define H3D_DL_NONE 0 00336 #define H3D_DL_TEXTURE 1 00337 #define H3D_DL_GEOMETRY 2 00338 #define H3D_DL_SEGMENT_POLYLINE 3 00339 #define H3D_DL_SEGMENT_TREE 4 00340 #define H3D_DL_SHADOW_MAP 5 00341 00342 #define GET_DISPLAY_LIST(nr, h3ddata, source, dl, odl, list_type, list_new) SEMI_PROTECT(\ 00343 (list_new) = HI_Get_Display_List((nr)->display_context->actor, &source, &dl); \ 00344 if (!(dl)->list) { \ 00345 ZALLOC((odl), H3D_Display_List); \ 00346 (dl)->list = (HT_Base_Driver_Display_List*)(odl); \ 00347 (odl)->type = list_type; \ 00348 (odl)->peer = (dl); \ 00349 (odl)->next = (h3ddata)->display_lists; \ 00350 (odl)->prev = &((h3ddata)->display_lists); \ 00351 if ((h3ddata)->display_lists) \ 00352 (h3ddata)->display_lists->prev= &(odl)->next; \ 00353 (h3ddata)->display_lists = (odl); \ 00354 (list_new)=true; \ 00355 } \ 00356 (odl) = (H3D_Display_List*)(dl)->list; \ 00357 ) 00358 00359 typedef struct h3d_display_list { 00360 HT_Display_List *peer; /* must be first */ 00361 struct h3d_display_list * next; 00362 struct h3d_display_list ** prev; 00363 unsigned int type; 00364 int vram_usage; /* approximate amount of memory this object consumes */ 00365 00366 int geometry_bits; 00367 H3DVertexFormat vf; 00368 00369 union { 00370 struct { 00371 HT_Image const * image; 00372 H3DTexture *id; 00373 H3DTexture *env_ids; 00374 bool default_pool; 00375 HT_Simple_Shadow *notify_shadow; 00376 } texture; 00377 struct { 00378 HT_VList * id; 00379 int obj_type; 00380 unsigned int rendo_flags; 00381 unsigned int special_flags; 00382 HT_Param_Source tex_param_source; 00383 struct { 00384 int total; 00385 int strips; 00386 int point_count; 00387 } stats; 00388 } geometry; 00389 struct { 00390 H3DTexture *id; 00391 int resolution; 00392 float transform[16]; 00393 } shadow_map; 00394 struct { 00395 HT_Polyedge *pe; 00396 int budget, continued_budget; 00397 float max_deviation, max_angle, max_length; 00398 } segment_polyline; 00399 struct { 00400 HT_VList * tristrips_list; //<h3d_display_list> 00401 HT_VList * polyedges_list; //<h3d_display_list> 00402 HT_VList * polylines_list; //<h3d_display_list> 00403 HT_Type_Flags visibility; 00404 HT_Rendo_Flags interpolation_options; 00405 unsigned int blessed; // tracks permission to compile for real 00406 } segment_tree; 00407 } item; 00408 } H3D_Display_List; 00409 00410 00411 00412 typedef enum h3d_vertex_buffer_style 00413 { 00414 H3D_Invalid = 0, 00415 H3D_Shared_Vertices = 1, // vertices shared between strips 00416 H3D_Partially_Shared_Vertices = 2, // vertices shared within, but not between, strips. e.g. flat lighting, but we're able to turn off interpolation 00417 H3D_Unshared_Vertices = 3 // vertices not shared. necessary when there are conflicting requirements for shade model, e.g. flat-lit but textured 00418 } H3D_Vertex_Buffer_Style; 00419 00420 00421 typedef struct { 00422 HT_Display_List const *dl; 00423 float priority; 00424 int vram; 00425 } dlheapable; 00426 00427 00428 typedef struct { 00429 dlheapable **dlarray; 00430 int allocated; 00431 int used; 00432 } dlheap; 00433 00434 00435 00436 /* A geometry / matrix pair */ 00437 typedef struct { 00438 void *geo; 00439 HT_Matrix const *mat; 00440 HT_Net_Rendition *nr; 00441 } geo_mat_pair; 00442 00443 00444 typedef struct h3d_collector 00445 { 00446 struct h3d_collector *next; 00447 HT_Net_Rendition const *nr; 00448 HT_VList *list_tristrips; 00449 HT_VList *list_polyedges; 00450 HT_VList *list_polylines; //lines, curves and arcs 00451 unsigned HT_Integer32 mask, original_mask; /* Action_Mask_WHATEVER bits, where 1==handled, 0==not handled */ 00452 bool punted_gref; 00453 bool gref_attributes; 00454 bool compile_only; 00455 } H3D_Collector; 00456 00457 00458 /***************************************************************************** 00459 ***************************************************************************** 00460 Category: H3DData Class 00461 ***************************************************************************** 00462 *****************************************************************************/ 00463 typedef int DC_Type; 00464 #define DCT_UNDEFINED ((DC_Type)0) 00465 #define DCT_OUR_WINDOW ((DC_Type)1) 00466 #define DCT_THEIR_WINDOW ((DC_Type)2) 00467 #define DCT_IMAGE ((DC_Type)3) 00468 #define DCT_PBUFFER_IMAGE ((DC_Type)4) 00469 #define DCT_FBO_IMAGE ((DC_Type)5) 00470 00471 /* All the different enumerations that can go into ensure functions */ 00472 typedef enum _H3DCMPFUNC { 00473 H3DCMP_NEVER = 1, 00474 H3DCMP_LESS = 2, 00475 H3DCMP_EQUAL = 3, 00476 H3DCMP_LESSEQUAL = 4, 00477 H3DCMP_GREATER = 5, 00478 H3DCMP_NOTEQUAL = 6, 00479 H3DCMP_GREATEREQUAL = 7, 00480 H3DCMP_ALWAYS = 8, 00481 H3DCMP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 00482 } H3DCMPFUNC; 00483 00484 typedef enum _H3DSTENCILOP { 00485 H3DSTENCILOP_KEEP = 1, 00486 H3DSTENCILOP_ZERO = 2, 00487 H3DSTENCILOP_REPLACE = 3, 00488 H3DSTENCILOP_INCRSAT = 4, 00489 H3DSTENCILOP_DECRSAT = 5, 00490 H3DSTENCILOP_INVERT = 6, 00491 H3DSTENCILOP_INCR = 7, 00492 H3DSTENCILOP_DECR = 8, 00493 H3DSTENCILOP_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 00494 } H3DSTENCILOP; 00495 00496 typedef enum _H3DSHADEMODE { 00497 H3DSHADE_FLAT = 1, 00498 H3DSHADE_GOURAUD = 2, 00499 H3DSHADE_PHONG = 3, 00500 H3DSHADE_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 00501 } H3DSHADEMODE; 00502 00503 typedef enum _H3DBLEND { 00504 H3DBLEND_ZERO = 1, 00505 H3DBLEND_ONE = 2, 00506 H3DBLEND_SRCCOLOR = 3, 00507 H3DBLEND_INVSRCCOLOR = 4, 00508 H3DBLEND_SRCALPHA = 5, 00509 H3DBLEND_INVSRCALPHA = 6, 00510 H3DBLEND_DESTALPHA = 7, 00511 H3DBLEND_INVDESTALPHA = 8, 00512 H3DBLEND_DESTCOLOR = 9, 00513 H3DBLEND_INVDESTCOLOR = 10, 00514 H3DBLEND_SRCALPHASAT = 11, 00515 H3DBLEND_BOTHSRCALPHA = 12, 00516 H3DBLEND_BOTHINVSRCALPHA = 13, 00517 H3DBLEND_BLENDFACTOR = 14, /* Only supported if H3DPBLENDCAPS_BLENDFACTOR is on */ 00518 H3DBLEND_INVBLENDFACTOR = 15, /* Only supported if H3DPBLENDCAPS_BLENDFACTOR is on */ 00519 H3DBLEND_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 00520 } H3DBLEND; 00521 00522 00523 typedef enum _H3DCULL { 00524 H3DCULL_NONE = 1, 00525 H3DCULL_CW = 2, 00526 H3DCULL_CCW = 3, 00527 H3DCULL_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 00528 } H3DCULL; 00529 00530 typedef enum _H3DPRIMITIVETYPE { 00531 H3DPT_POINTLIST = 1, 00532 H3DPT_LINELIST = 2, 00533 H3DPT_LINESTRIP = 3, 00534 H3DPT_TRIANGLELIST = 4, 00535 H3DPT_TRIANGLESTRIP = 5, 00536 H3DPT_TRIANGLEFAN = 6, 00537 H3DPT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */ 00538 } H3DPRIMITIVETYPE; 00539 00540 typedef enum _H3DCLEAR { 00541 H3DCLEAR_TARGET = 1, 00542 H3DCLEAR_ZBUFFER = 2, 00543 H3DCLEAR_STENCIL = 3, 00544 } H3DCLEAR; 00545 00546 00547 typedef enum _H3DFORMAT 00548 { 00549 H3DFMT_UNKNOWN = 0, 00550 00551 H3DFMT_R8G8B8 = 20, 00552 H3DFMT_A8R8G8B8 = 21, 00553 H3DFMT_X8R8G8B8 = 22, 00554 H3DFMT_R5G6B5 = 23, 00555 H3DFMT_X1R5G5B5 = 24, 00556 H3DFMT_A1R5G5B5 = 25, 00557 H3DFMT_A4R4G4B4 = 26, 00558 H3DFMT_R3G3B2 = 27, 00559 H3DFMT_A8 = 28, 00560 H3DFMT_A8R3G3B2 = 29, 00561 H3DFMT_X4R4G4B4 = 30, 00562 H3DFMT_A2B10G10R10 = 31, 00563 H3DFMT_A8B8G8R8 = 32, 00564 H3DFMT_X8B8G8R8 = 33, 00565 H3DFMT_G16R16 = 34, 00566 H3DFMT_A2R10G10B10 = 35, 00567 H3DFMT_A16B16G16R16 = 36, 00568 00569 H3DFMT_A8P8 = 40, 00570 H3DFMT_P8 = 41, 00571 H3DFMT_L8 = 50, 00572 H3DFMT_A8L8 = 51, 00573 H3DFMT_A4L4 = 52, 00574 00575 H3DFMT_V8U8 = 60, 00576 H3DFMT_L6V5U5 = 61, 00577 H3DFMT_X8L8V8U8 = 62, 00578 H3DFMT_Q8W8V8U8 = 63, 00579 H3DFMT_V16U16 = 64, 00580 H3DFMT_A2W10V10U10 = 67, 00581 00582 H3DFMT_D16_LOCKABLE = 70, 00583 H3DFMT_D32 = 71, 00584 H3DFMT_D15S1 = 73, 00585 H3DFMT_D24S8 = 75, 00586 H3DFMT_D24X8 = 77, 00587 H3DFMT_D24X4S4 = 79, 00588 H3DFMT_D16 = 80, 00589 00590 H3DFMT_D32F_LOCKABLE = 82, 00591 H3DFMT_D24FS8 = 83, 00592 H3DFMT_L16 = 81, 00593 00594 H3DFMT_VERTEXDATA =100, 00595 H3DFMT_INDEX16 =101, 00596 H3DFMT_INDEX32 =102, 00597 00598 H3DFMT_Q16W16V16U16 =110, 00599 00600 // s10e5 formats (16-bits per channel) 00601 H3DFMT_R16F = 111, 00602 H3DFMT_G16R16F = 112, 00603 H3DFMT_A16B16G16R16F = 113, 00604 00605 // IEEE s23e8 formats (32-bits per channel) 00606 H3DFMT_R32F = 114, 00607 H3DFMT_G32R32F = 115, 00608 H3DFMT_A32B32G32R32F = 116, 00609 00610 H3DFMT_CxV8U8 = 117, 00611 H3DFMT_FORCE_DWORD =0x7fffffff 00612 } H3DFORMAT; 00613 00614 #define H3DTEXUSAGE_DEFAULT 0x0000 00615 #define H3DTEXUSAGE_RENDERTARGET 0x0001 00616 #define H3DTEXUSAGE_DEPTHSTENCIL 0x0002 00617 #define H3DTEXUSAGE_AUTOGENMIPMAP 0x0004 00618 00619 00620 00621 00622 /* 00623 * Options for clearing 00624 */ 00625 #define H3DCLEAR_TARGET 0x0001 /* Clear target surface */ 00626 #define H3DCLEAR_ZBUFFER 0x0002 /* Clear target z buffer */ 00627 #define H3DCLEAR_STENCIL 0x0004 /* Clear stencil planes */ 00628 00629 00630 typedef struct _H3DVIEWPORT { 00631 unsigned long X; 00632 unsigned long Y; /* Viewport Top left */ 00633 unsigned long Width; 00634 unsigned long Height; /* Viewport Dimensions */ 00635 float MinZ; /* Min/max of clip Volume */ 00636 float MaxZ; 00637 } H3DVIEWPORT; 00638 00639 00640 /* shadow of device state */ 00641 typedef struct h3dcache_s 00642 { 00643 H3DVertexFormat vf; 00644 } H3DCache; 00645 00646 typedef struct h3ddata_s 00647 { 00648 H3DCache h3dcache; // shadow of device state 00649 00650 HWND hWND; 00651 00652 bool device_objects_inited; // device object state 00653 bool device_objects_restored;// device object state 00654 bool has_scene_began; // state variable to avoid multiple BeginScene calls before an EndScene 00655 00656 HDC hDC; 00657 HDC hInfoDC; 00658 DC_Type dc_type; 00659 WNDPROC saved_window_proc; 00660 HPALETTE ghPalette, ghpalOld; 00661 HT_Image *output_image; // valid iff we're an image driver 00662 00663 /* 00664 * Dimensions 00665 */ 00666 RECT current_window_rect; 00667 RECT master_rectangle; 00668 HT_Int_XY old_size; 00669 HT_Int_XY old_position; 00670 HT_Int_XY original_aspect; 00671 00672 int bottom_border; 00673 int right_border; 00674 int left_border; 00675 int top_border; 00676 00677 int yfudge; 00678 float zfudge; 00679 int y_screen_fudge; 00680 int mouse_x; 00681 int mouse_y; 00682 00683 bool is_software; 00684 bool window_minimized; 00685 bool window_maximized; 00686 00687 struct 00688 { 00689 H3DVIEWPORT viewport; 00690 void *current_buffer_object; 00691 float z_range[2]; 00692 bool zbuffering; 00693 bool stencilling; 00694 H3DCMPFUNC stencil_func; 00695 unsigned long stencil_ref; 00696 unsigned long stencil_mask; 00697 unsigned long stencil_write_mask; 00698 H3DSTENCILOP stencil_fail; 00699 H3DSTENCILOP stencil_zfail; 00700 H3DSTENCILOP stencil_pass; 00701 bool scissoring; 00702 bool transparency_on; 00703 H3DBLEND src_blend; 00704 H3DBLEND dest_blend; 00705 bool color_mask; 00706 bool depth_mask; 00707 bool depth_test_reversed; 00708 RECT scissor_rect; 00709 H3DCULL cull_mode; 00710 H3DShader *Shader; 00711 bool antialias; 00712 00713 bool fog_on; 00714 00715 #define MAX_TEXTURE_UNIT 7 //highest texture unit to use 00716 #define H3D_MAX_TEXTURES 8 00717 #define H3D_MAX_SHADOW_MAPS 4 00718 #define H3D_MAX_CUTTING_PLANES 15 00719 int texture_wrap_s[MAX_TEXTURE_UNIT]; 00720 int texture_wrap_t[MAX_TEXTURE_UNIT]; 00721 int texture_mag_filter[MAX_TEXTURE_UNIT]; 00722 int texture_min_filter[MAX_TEXTURE_UNIT]; 00723 int texture_mip_filter[MAX_TEXTURE_UNIT]; 00724 00725 int colormap_width; 00726 00727 H3DSHADEMODE shade_mode; 00728 H3DTexture *texture_current[MAX_TEXTURE_UNIT]; 00729 H3DTexture *texture_indexed; 00730 } cache; 00731 00732 HT_Log_Font_Item *local_font_list; 00733 00734 #define LEFT_MOUSE 0x01 00735 #define RIGHT_MOUSE 0x02 00736 #define MIDDLE_MOUSE 0x04 00737 int mouse_buttons; 00738 bool mouse_was_queued; 00739 bool pending_resize; 00740 bool kill_me; 00741 00742 char *revision_string; 00743 bool double_buffering; 00744 HT_Display_Context const *dc; 00745 00746 #define INVALID_INCARNATION (HT_Incarnation) -1 00747 #define INDC(incarn) (-(incarn)) 00748 #define IN3D(incarn) (incarn) 00749 HT_Incarnation tr_incarnation; 00750 HT_Incarnation tr_incarnation_dc; 00751 HT_Incarnation tr_incarnation_3d; 00752 int tr_is_dc; 00753 HT_Incarnation geom_incarnation; 00754 HT_Incarnation light_incarnation; 00755 HT_Incarnation material_incarnation; 00756 HT_Incarnation cutting_plane_incarnation; 00757 HT_Incarnation fog_incarnation; 00758 HT_Incarnation clip_region_incarnation; 00759 00760 /* 00761 * Advanced Rendering Structs 00762 */ 00763 #define DEPTH_PEELING_MAX_LAYERS 16 00764 struct { 00765 bool mode; 00766 bool rts; /* is render to stencil under way */ 00767 int flags; 00768 H3DTexture *peel_z_texture; 00769 int w, h; 00770 H3DFORMAT z_format; 00771 bool single_pass; 00772 H3DTexture *z_textures[DEPTH_PEELING_MAX_LAYERS]; 00773 H3DTexture *rgba_textures[DEPTH_PEELING_MAX_LAYERS]; 00774 H3D_SURFACE_ID msaa_target; 00775 } depth_peeling; 00776 00777 struct { 00778 bool mode; 00779 HT_Integer32 resolution; 00780 HT_Integer32 resolution_fallback; 00781 HT_Integer32 samples; 00782 H3D_SURFACE_ID depth_buffer; // depth buffer for the shadow map 00783 H3D_SURFACE_ID dummy_buffer; // color buffer (not used) 00784 H3D_Display_List *current_odl; 00785 H3DTexture *jitter; // Per-pixel jitter in some form. 00786 } shadow_maps; 00787 00788 struct { 00789 bool mode; 00790 HT_Integer32 resolution; 00791 00792 } simple_shadows; 00793 00794 struct ReflectionPlaneConstants 00795 { 00796 HT_Plane plane; 00797 float scale; 00798 float bias; 00799 }; 00800 00801 struct { 00802 bool mode; 00803 HT_Integer32 resolution; 00804 H3DTexture *bump_map; 00805 ReflectionPlaneConstants constants; 00806 00807 } reflection_plane; 00808 00809 /* 00810 * Face and line patterns 00811 */ 00812 #define NUM_FACE_PATTERNS (FP_WINDOW_TRANSPARENT + 1) 00813 H3DTexture *fpatterns[128]; 00814 int user_defined_pattern; 00815 00816 H3DTexture *lpatterns; 00817 HT_VHash *lpatternhash; 00818 int lpattern_count; 00819 00820 #define H3D_LARGEST_PRECOMPUTED_CIRCLE 20 00821 #define H3D_LINE_TOOLS_SIZE 256 00822 struct { 00823 bool valid; 00824 int data_size; 00825 unsigned char *data; 00826 H3DTexture *texture; 00827 float circle_subimage_starts[H3D_LARGEST_PRECOMPUTED_CIRCLE+1]; 00828 } line_tools; 00829 00830 00831 00832 // these matrices cache calculation results, but have no effect on rendering 00833 // until they are copied into the shaders' constant tables 00834 float matrix_dc[16]; 00835 float matrix_model_3d[16]; 00836 float matrix_modelview_3d[16]; 00837 float matrix_projection_3d[16]; 00838 float matrix_world_to_eye_3d[16]; 00839 bool matrix_texture_touched[H3D_MAX_TEXTURES]; 00840 float matrix_texture_styled[H3D_MAX_TEXTURES][16]; 00841 float general_displacement; 00842 float face_displacement_dc; 00843 float face_displacement_3d; 00844 bool net_modelling_is_identity; 00845 00846 00847 H3DShaderHASH *ShaderHash; 00848 HT_VHash *vb_cache_hash; 00849 H3DIndexBufferCache *ib_cache; 00850 00851 /* 00852 * Segment-level display lists 00853 */ 00854 HT_Integer32 collect_geometry; 00855 H3D_Collector *collect_list; 00856 bool ref_matrix_negative_3x3; 00857 unsigned int display_list_vram_usage; 00858 dlheap geometry_dl_requests; 00859 dlheap segment_dl_requests; 00860 HT_VList *seen_list; 00861 00862 bool was_iconic; 00863 bool no_punting; 00864 00865 bool right_handed_world; 00866 bool right_handed_nmm; 00867 00868 #define ENSURE_POINTMAP(dx9data, size) SEMI_PROTECT(\ 00869 if (dx9data->pointmap == NULL || dx9data->pointmaplength < size) { \ 00870 H_SAFE_DELETE_ARRAY(dx9data->pointmap); \ 00871 dx9data->pointmap = new int[size]; \ 00872 dx9data->pointmaplength = size; \ 00873 } \ 00874 ) 00875 int *pointmap; 00876 int pointmaplength; 00877 00878 bool culling; 00879 bool continuous_mode; 00880 00881 int max_cutting_planes; 00882 bool can_scissor; 00883 int zbuffer_planes; 00884 unsigned long zbuffer_max; 00885 00886 bool two_sided_lighting; 00887 int multisamples; 00888 int face_index_offset; //used for flat shade model / no interpolation (dx9 uses first vertex of a triangle, ogl uses last) 00889 00890 H3D_Display_List *display_lists; 00891 00892 bool has_depth_texture; //hardware shadow maps 00893 bool has_r32f_texture; //32-bit floating point textures 00894 int mrt_count; //multiple render target count 00895 HT_Driver_Config *card_entry; //XBIT stuff 00896 int debug; 00897 00898 00899 // Store some generic capabilities here 00900 struct { 00901 unsigned int max_vertex_index; 00902 unsigned int max_primitive_count; 00903 unsigned int max_texture_width; 00904 unsigned int max_texture_height; 00905 } caps; 00906 00907 int error_type; 00908 H3D_Color_Format rgba_format; 00909 00910 H3DActions *h3d_actions; 00911 HT_Action_Table at; 00912 } H3DData; 00913 00914 #define SYSTEM_DATA() ((System_Data alter *)OUR (system_specific_data)) 00915 00916 00917 /***************************************************************************** 00918 ***************************************************************************** 00919 Category: H3DTexture Class 00920 00921 This class is a wrapper around a driver specific texture ID. 00922 ***************************************************************************** 00923 *****************************************************************************/ 00924 typedef struct _H3DRect { 00925 long left; 00926 long top; 00927 long right; 00928 long bottom; 00929 } H3DRect; 00930 00931 #define INVALID_CACHE (-1) 00932 #define INVALID_H3D_TEXTURE (H3DTexture*)(-1) 00933 #define INVALID_GEOMETRY_CACHE (void*)(-1) 00934 00935 #define INVALIDATE_H3D_TEXTURE_SETTING_CACHE(h3ddata) SEMI_PROTECT(\ 00936 { \ 00937 int _unit_; \ 00938 for (_unit_ = 0; _unit_ < MAX_TEXTURE_UNIT; ++_unit_) { \ 00939 (h3ddata)->cache.texture_wrap_s[_unit_] = INVALID_CACHE; \ 00940 (h3ddata)->cache.texture_wrap_t[_unit_] = INVALID_CACHE; \ 00941 (h3ddata)->cache.texture_mag_filter[_unit_] = INVALID_CACHE; \ 00942 (h3ddata)->cache.texture_min_filter[_unit_] = INVALID_CACHE; \ 00943 (h3ddata)->cache.texture_mip_filter[_unit_] = INVALID_CACHE; \ 00944 } \ 00945 } \ 00946 ) 00947 00948 class H3DTexture 00949 { 00950 public: 00951 H3DData *m_h3ddata; 00952 00953 public: 00954 virtual ~H3DTexture(){}; 00955 virtual bool Lock(H3DRect *h3drect, void ** data, int *pitch = null) = 0; 00956 virtual void Unlock() = 0; 00957 virtual void GenerateMipMaps() = 0; 00958 }; 00959 00960 /***************************************************************************** 00961 ***************************************************************************** 00962 Category: H3DShaderID Class 00963 ***************************************************************************** 00964 *****************************************************************************/ 00965 //stored on data[0] 00966 #define H3DID_DC 0x00000001 00967 #define H3DID_TRIANGLE 0x00000002 00968 #define H3DID_POINT 0x00000004 00969 #define H3DID_LINE 0x00000008 00970 #define H3DID_GOURAUD 0x00000010 00971 #define H3DID_COLOR_INTERPOLATED 0x00000020 00972 #define H3DID_COLOR_INDEX_INTERPOLATED 0x00000040 00973 #define H3DID_VERTEX_COLORS 0x00000080 00974 #define H3DID_VERTEX_FINDICES 0x00000100 00975 #define H3DID_ENVIRONMENT_TEXTURE 0x00000200 00976 #define H3DID_PHYSICAL_REFLECTION 0x00000400 00977 #define H3DID_DEPTH_PEELING 0x00000800 00978 #define H3DID_DEPTH_WRITING 0x00001000 00979 #define H3DID_DEPTH_TEXTURE_HARDWARE 0x00002000 00980 #define H3DID_USE_FACE_DISPLACEMENT 0x00004000 00981 #define H3DID_TINTED_IMAGE 0x00008000 00982 #define H3DID_FLAT_SHADING 0x00010000 00983 #define H3DID_ATMOSPHERIC_ATTENUATION 0x00020000 00984 #define H3DID_NON_UNIFORM_SCALE 0x00040000 00985 #define H3DID_CREATE_SHADOW_MAP 0x00080000 00986 #define H3DID_FACE_PATTERN 0x00100000 00987 #define H3DID_LINE_PATTERN 0x00200000 00988 #define H3DID_TRANSPARENCY_STIPPLE 0x00400000 00989 #define H3DID_PERSPECTIVE 0x00800000 00990 #define H3DID_SPECULAR_TEXTURE 0x01000000 00991 #define H3DID_CREATE_SIMPLE_SHADOW 0x02000000 00992 #define H3DID_CREATE_REFLECTION_PLANE 0x04000000 00993 #define H3DID_SHADOW_MAP_JITTER 0x08000000 00994 #define H3DID_PER_PIXEL_LIGHTING 0x10000000 00995 #define H3DID_RIGHT_HANDED_MATRIX 0x20000000 00996 #define H3DID_NORMAL_FLIP_NEGATIVE 0x40000000 00997 #define H3DID_NR_ONLY 0X80000000 00998 // Mutually exclusive! 00999 #ifdef PRT_DEMO 01000 #define H3DID_PRT 0x80000000 01001 #elif defined(SHADOW_DISTORTION_DEMO) 01002 #define H3DID_SHADOW_MAP_DISTORTION 0x80000000 01003 #endif // SHADOW_DISTORTION_DEMO 01004 01005 //stored on data[1] 01006 #define H3DID_WIDE_LINE 0x00000001 01007 #define H3DID_ROUND_LINE 0x00000002 01008 #define H3DID_MITER 0x00000004 01009 #define H3DID_ANTI_ALIASED_LINE 0x00000008 01010 #define H3DID_SHADOW_MAP_RESOLUTION 0x00000030 01011 #define H3DID_SHADOW_MAP_SAMPLES 0x000000C0 01012 #define H3DID_SHADOW_MAP_MASK 0x00000F00 01013 #define H3DID_CUTTING_PLANE_MASK 0x0000F000 01014 #define H3DID_TEXTURE_MASK 0x000F0000 01015 #define H3DID_SPOT_LIGHT_MASK 0x00F00000 01016 #define H3DID_POINT_LIGHT_MASK 0x0F000000 01017 #define H3DID_DISTANT_LIGHT_MASK 0xF0000000 01018 01019 //stored on data[2] (if that changes, update needed in H3DShaderID::Init) 01020 #define H3DID_TEX0_DECAL 0x00000001 01021 #define H3DID_TEX0_WORLD 0x00000002 01022 #define H3DID_TEX0_COLOR 0x00000004 01023 #define H3DID_TEX0_MODULATE 0x00000008 01024 #define H3DID_TEX1_WORLD 0x00000010 01025 #define H3DID_TEX1_COLOR 0x00000020 01026 #define H3DID_TEX1_MODULATE 0x00000040 01027 #define H3DID_TEX2_WORLD 0x00000080 01028 #define H3DID_TEX2_COLOR 0x00000100 01029 #define H3DID_TEX2_MODULATE 0x00000200 01030 #define H3DID_TEX3_WORLD 0x00000400 01031 #define H3DID_TEX3_COLOR 0x00000800 01032 #define H3DID_TEX3_MODULATE 0x00001000 01033 #define H3DID_TEX4_WORLD 0x00002000 01034 #define H3DID_TEX4_COLOR 0x00004000 01035 #define H3DID_TEX4_MODULATE 0x00008000 01036 #define H3DID_TEX5_WORLD 0x00010000 01037 #define H3DID_TEX5_COLOR 0x00020000 01038 #define H3DID_TEX5_MODULATE 0x00040000 01039 #define H3DID_TEX6_WORLD 0x00080000 01040 #define H3DID_TEX6_COLOR 0x00100000 01041 #define H3DID_TEX6_MODULATE 0x00200000 01042 #define H3DID_TEX7_WORLD 0x00400000 01043 #define H3DID_TEX7_COLOR 0x00800000 01044 #define H3DID_TEX7_MODULATE 0x01000000 01045 #define H3DID_HAS_HANDEDNESS 0x02000000 01046 #define H3DID_DEPTH_PEELING_RGBA 0x04000000 01047 #define H3DID_DEPTH_PEELING_SINGLE_PASS 0x08000000 01048 01049 class H3DShaderID 01050 { 01051 private: 01052 #define H3DShaderID_SIZE 3 01053 unsigned int m_data[H3DShaderID_SIZE]; 01054 01055 void AddLights ( 01056 HT_Net_Rendition const *nr, 01057 HT_Light_Rendition const *lr, 01058 unsigned int visibility_mask); 01059 void SetShadowMapResolution(int res) { 01060 int resolution = 0; 01061 switch (res) { 01062 case 2048: resolution++; 01063 case 1024: resolution++; 01064 case 512: m_data[1] |= (resolution << 4); 01065 break; 01066 case 0: 01067 //if we get here, we probably were never using shadow maps 01068 break; 01069 default: 01070 HE_ERROR(HEC_INTERNAL_ERROR, HEC_INTERNAL_ERROR, 01071 "Invalid shadow map resolution! Must be 512, 1024, or 2048."); 01072 break; 01073 } 01074 }; 01075 void SetShadowMapSamples(int samples) { 01076 int samp = 0; 01077 if (samples >= 4) samp++; 01078 if (samples >= 8) samp++; 01079 if (samples >= 16) samp++; 01080 samp <<= 6; 01081 01082 m_data[1] |= samp; 01083 }; 01084 void SetShadowMapCount(int count) { m_data[1] &= ~H3DID_SHADOW_MAP_MASK; m_data[1] |= (count << 8); }; 01085 void SetCuttingPlaneCount(int count) { ASSERT(count <= 15); m_data[1] &= ~H3DID_CUTTING_PLANE_MASK; m_data[1] |= (count << 12); }; 01086 void SetTextureCount(int count) { m_data[1] &= ~H3DID_TEXTURE_MASK; m_data[1] |= (count << 16); }; 01087 void SetSpotLightCount(int count) { m_data[1] &= ~H3DID_SPOT_LIGHT_MASK; m_data[1] |= (count << 20); }; 01088 void SetPointLightCount(int count) { m_data[1] &= ~H3DID_POINT_LIGHT_MASK; m_data[1] |= (count << 24); }; 01089 void SetDistantLightCount(int count) { m_data[1] &= ~H3DID_DISTANT_LIGHT_MASK; m_data[1] |= (count << 28); }; 01090 01091 public: 01092 H3DShaderID () { ZERO_ARRAY (m_data, H3DShaderID_SIZE, int); }; 01093 ~H3DShaderID() {}; 01094 01095 void Init ( 01096 HT_Net_Rendition const *nr, 01097 int type, 01098 void const *thing, // tristrip, polyedge or polymarker 01099 int flags, 01100 int thing_contents = 0); 01101 01102 void InitTexturedRectangle () { 01103 m_data[0] = H3DID_DC; 01104 SetTextureCount(1); 01105 }; 01106 01107 void AddFlags (int flags, int index = 0) { 01108 ASSERT(index < H3DShaderID_SIZE); 01109 m_data[index] |= flags; 01110 }; 01111 01112 int GetData (int index) { 01113 return m_data[index]; 01114 }; 01115 01116 bool operator == (const H3DShaderID &id) const { 01117 return memeq(id.m_data, m_data, sizeof(m_data)); 01118 }; 01119 bool operator != (const H3DShaderID &id) const { 01120 return !memeq(id.m_data, m_data, sizeof(m_data)); 01121 }; 01122 H3DShaderID& operator = (const H3DShaderID &id) { 01123 COPY_MEMORY (id.m_data, sizeof(m_data), m_data); 01124 return *this; 01125 }; 01126 bool IsDC() { return BIT(m_data[0], H3DID_DC); }; 01127 bool IsTriangle() { return BIT(m_data[0], H3DID_TRIANGLE); }; 01128 bool IsPoint() { return BIT(m_data[0], H3DID_POINT); }; 01129 bool IsMitered() { return BIT(m_data[1], H3DID_MITER); }; 01130 bool IsRoundLine() { return BIT(m_data[1], H3DID_ROUND_LINE); }; //round capped or round joined 01131 bool IsAntiAliasedLine() {return BIT(m_data[1], H3DID_ANTI_ALIASED_LINE); }; //AA lines 01132 bool HasVertexColors() { return BIT(m_data[0], H3DID_VERTEX_COLORS); }; 01133 bool HasVertexFIndices() { return BIT(m_data[0], H3DID_VERTEX_FINDICES); }; 01134 bool IsDepthWriting() { return BIT(m_data[0], H3DID_DEPTH_WRITING); }; 01135 bool IsDepthPeeling() { return BIT(m_data[0], H3DID_DEPTH_PEELING); }; 01136 bool IsDepthTextureHardware() { return BIT(m_data[0], H3DID_DEPTH_TEXTURE_HARDWARE); }; 01137 bool IsCreateShadowMap() { return BIT(m_data[0], H3DID_CREATE_SHADOW_MAP); }; 01138 bool UseFaceDisplacement() { return BIT(m_data[0], H3DID_USE_FACE_DISPLACEMENT); }; 01139 bool IsFlatShading() { return BIT(m_data[0], H3DID_FLAT_SHADING); }; 01140 bool HasFacePattern() { return BIT(m_data[0], H3DID_FACE_PATTERN); }; 01141 bool HasLinePattern() { return BIT(m_data[0], H3DID_LINE_PATTERN); }; 01142 bool IsWideLine() { return BIT(m_data[1], H3DID_WIDE_LINE); }; 01143 bool HasTransparencyStipple() {return BIT(m_data[0], H3DID_TRANSPARENCY_STIPPLE); }; 01144 bool IsPerspective() { return BIT(m_data[0], H3DID_PERSPECTIVE); }; 01145 bool IsCreateSimpleShadow() { return BIT(m_data[0], H3DID_CREATE_SIMPLE_SHADOW); } 01146 bool IsCreateReflectionPlane() { return BIT(m_data[0], H3DID_CREATE_REFLECTION_PLANE); } 01147 bool IsShadowMapJitter() { return BIT(m_data[0], H3DID_SHADOW_MAP_JITTER); } 01148 bool IsPerPixelLighting() { return BIT(m_data[0], H3DID_PER_PIXEL_LIGHTING); } 01149 #ifdef PRT_DEMO 01150 bool IsPRT() { return BIT(m_data[0], H3DID_PRT); } 01151 #endif // PRT_DEMO 01152 #ifdef SHADOW_DISTORTION_DEMO 01153 bool IsShadowMapDistortion() { return BIT(m_data[0], H3DID_SHADOW_MAP_DISTORTION); } 01154 #endif // SHADOW_DISTORTION_DEMO 01155 int GetShadowMapResolution(){ return (512 << ((m_data[1] & H3DID_SHADOW_MAP_RESOLUTION) >> 4)); }; 01156 int GetShadowMapSamples() { 01157 int samples = ((m_data[1] & H3DID_SHADOW_MAP_SAMPLES) >> 6); 01158 switch (samples) { 01159 case 0: return 1; 01160 case 1: return 4; 01161 case 2: return 8; 01162 case 3: return 16; 01163 default: return 1; 01164 } 01165 }; 01166 int GetShadowMapCount() { return (m_data[1] >> 8) & 0xF; }; 01167 int GetCuttingPlaneCount() { return (m_data[1] >> 12) & 0xF; }; 01168 int GetTextureCount() { return (m_data[1] >> 16) & 0xF; }; 01169 int GetSpotLightCount() { return (m_data[1] >> 20) & 0xF; }; 01170 int GetPointLightCount() { return (m_data[1] >> 24) & 0xF; }; 01171 int GetDistantLightCount() { return (m_data[1] >> 28) & 0xF; }; 01172 01173 bool IsDecal(int texnum) { if (texnum == 0) return BIT(m_data[2], H3DID_TEX0_DECAL); return false;}; 01174 bool IsModulate(int texnum) { 01175 switch (texnum) { 01176 case 0: return ( 01177 BIT(m_data[2], H3DID_TEX0_MODULATE) || 01178 BIT(m_data[0], H3DID_TINTED_IMAGE)); 01179 case 1: return BIT(m_data[2], H3DID_TEX1_MODULATE); 01180 case 2: return BIT(m_data[2], H3DID_TEX2_MODULATE); 01181 case 3: return BIT(m_data[2], H3DID_TEX3_MODULATE); 01182 case 4: return BIT(m_data[2], H3DID_TEX4_MODULATE); 01183 case 5: return BIT(m_data[2], H3DID_TEX5_MODULATE); 01184 case 6: return BIT(m_data[2], H3DID_TEX6_MODULATE); 01185 case 7: return BIT(m_data[2], H3DID_TEX7_MODULATE); 01186 default: return false; 01187 } 01188 }; 01189 bool IsTexColor(int texnum) { 01190 switch (texnum) { 01191 case 0: return BIT(m_data[2], H3DID_TEX0_COLOR); 01192 case 1: return BIT(m_data[2], H3DID_TEX1_COLOR); 01193 case 2: return BIT(m_data[2], H3DID_TEX2_COLOR); 01194 case 3: return BIT(m_data[2], H3DID_TEX3_COLOR); 01195 case 4: return BIT(m_data[2], H3DID_TEX4_COLOR); 01196 case 5: return BIT(m_data[2], H3DID_TEX5_COLOR); 01197 case 6: return BIT(m_data[2], H3DID_TEX6_COLOR); 01198 case 7: return BIT(m_data[2], H3DID_TEX7_COLOR); 01199 default: return false; 01200 } 01201 }; 01202 bool IsWorld(int texnum) { 01203 switch (texnum) { 01204 case 0: return BIT(m_data[2], H3DID_TEX0_WORLD); 01205 case 1: return BIT(m_data[2], H3DID_TEX1_WORLD); 01206 case 2: return BIT(m_data[2], H3DID_TEX2_WORLD); 01207 case 3: return BIT(m_data[2], H3DID_TEX3_WORLD); 01208 case 4: return BIT(m_data[2], H3DID_TEX4_WORLD); 01209 case 5: return BIT(m_data[2], H3DID_TEX5_WORLD); 01210 case 6: return BIT(m_data[2], H3DID_TEX6_WORLD); 01211 case 7: return BIT(m_data[2], H3DID_TEX7_WORLD); 01212 default: return false; 01213 } 01214 }; 01215 01216 01217 bool HasPhysicalReflection() { return BIT(m_data[0], H3DID_PHYSICAL_REFLECTION); }; 01218 bool HasEnvironmentTexture() { return BIT(m_data[0], H3DID_ENVIRONMENT_TEXTURE); }; 01219 bool HasBumpTexture() { return false; }; 01220 bool HasSpecularTexture() { return BIT(m_data[0], H3DID_SPECULAR_TEXTURE); }; 01221 01222 bool HasHandedness() { return BIT(m_data[2], H3DID_HAS_HANDEDNESS); }; 01223 bool IsDepthPeelingRGBA() { return BIT(m_data[2], H3DID_DEPTH_PEELING_RGBA); } 01224 bool IsDepthPeelingSinglePass() { return BIT(m_data[2], H3DID_DEPTH_PEELING_SINGLE_PASS); } 01225 int GetNormalFlipSign() { return BIT(m_data[0], H3DID_NORMAL_FLIP_NEGATIVE) ? -1 : +1; } 01226 int RightHandedMatrix() { return BIT(m_data[0], H3DID_RIGHT_HANDED_MATRIX); } 01227 bool HasAtmosphericAttenuation() { return BIT(m_data[0], H3DID_ATMOSPHERIC_ATTENUATION); }; 01228 bool HasNonUniformScale() {return BIT(m_data[0], H3DID_NON_UNIFORM_SCALE); }; 01229 01230 int GetTextureUnitUsage(int usage, int number); 01231 01232 01233 // Determine which model this shader would work best with 01234 int PreferredShaderModel() 01235 { 01236 if (IsPerPixelLighting()) 01237 // Need SM3 for face register 01238 return 3; 01239 01240 if (IsShadowMapJitter()) 01241 // Jitter is expensive, we prefer SM 3 here too 01242 return 3; 01243 01244 // SM2 is fine 01245 return 2; 01246 } 01247 // Reduce quality settings of this shader. Return false when no reduction was possible. 01248 bool ReduceQuality() 01249 { 01250 bool success = true; 01251 01252 // Shadowmap samples are expensive - start here. 01253 int samples = ((m_data[1] & H3DID_SHADOW_MAP_SAMPLES) >> 6); 01254 if (samples > 1) 01255 { 01256 // Reduce by one level 01257 --samples; 01258 m_data[1] &= ~H3DID_SHADOW_MAP_SAMPLES; 01259 m_data[1] |= samples << 6; 01260 } 01261 else if (IsShadowMapJitter()) 01262 { 01263 // Jittered sampling is expensive, disable that next 01264 m_data[0] &= ~H3DID_SHADOW_MAP_JITTER; 01265 } 01266 else if (IsPerPixelLighting()) 01267 { 01268 // Per pixel lighting is expensive, disable that next 01269 m_data[0] &= ~H3DID_PER_PIXEL_LIGHTING; 01270 } 01271 else if (GetShadowMapCount() > 0) 01272 { 01273 SetShadowMapCount(GetShadowMapCount() - 1); 01274 } 01275 /* Other ways to reduce quality would go here, in decreasing order of effectiveness/ 01276 increasing order of consequence... 01277 else 01278 { 01279 } 01280 */ 01281 else 01282 { 01283 // Nothing else to do 01284 success = false; 01285 } 01286 01287 return success; 01288 } 01289 01290 friend class H3DShaderHASH; 01291 friend class H3DShader; 01292 }; 01293 01294 01295 01296 /***************************************************************************** 01297 ***************************************************************************** 01298 Category: H3DShader Class 01299 ***************************************************************************** 01300 *****************************************************************************/ 01301 #define SHADER_SCRATCH_SIZE 65536 01302 01303 class H3DShader 01304 { 01305 protected: 01306 const H3DShaderID m_key; // This ID was used to create the shader, and never changes. It is used for finding the shader. 01307 H3DShaderID m_id; // This ID is used at runtime to configure the shader. It may be different from the key if the shader was reduced in complexity. 01308 int m_model; // Which shader model was this shader targeted to? 01309 inline char const *eat_white_spaces (char const *ptr); 01310 inline char const *grab_token (char const *start, char alter *buffer); 01311 inline char const *kill_block (char const *start); 01312 bool resolve_expression (HT_VHash *macros, char const *ptr); 01313 01314 // Define dummy copy-assignment operator since compiler can't. 01315 void operator=(const H3DShader& other) 01316 { 01317 (void)other; 01318 ASSERT(0); 01319 } 01320 01321 protected: 01322 bool StripHLSL (char alter *contents, int alter *length_out); 01323 01324 01325 public: 01326 int m_tr_incarnation; 01327 int m_lr_incarnation; 01328 int m_matr_incarnation; 01329 int m_misc_incarnation; 01330 HT_Direct_RGB m_color; 01331 01332 H3DShader (const H3DShaderID& id); 01333 virtual ~H3DShader (){}; 01334 01335 virtual bool Create(H3DData *h3ddata) = 0; 01336 virtual bool Activate() = 0; 01337 01338 virtual void Force2DTransform (float *matrix) = 0; 01339 virtual void Ensure3DTransform (HT_Net_Rendition const *nr) = 0; 01340 virtual void EnsureDCTransform (HT_Net_Rendition const *nr) = 0; 01341 virtual void EnsureColor (HT_Direct_RGB const *color) = 0; 01342 virtual void EnsureLights ( 01343 HT_Net_Rendition const *nr, 01344 HT_Light_Rendition const *lr, 01345 HT_Material_Rendition const *mr, 01346 HT_Driver_Color const *color) = 0; 01347 virtual void EnsureLineStyle ( 01348 HT_Net_Rendition const *nr, 01349 HT_Line_Rendition const *er) = 0; 01350 virtual void EnsureCuttingPlanes (HT_Net_Rendition const *nr, HT_Cutting_Plane_Set const *cutset) = 0; 01351 virtual void EnsureDCCuttingPlanes (HT_Cutting_Plane_Set const *cutset) = 0; 01352 virtual void EnsureReflectionPlane (H3DData::ReflectionPlaneConstants const & constants) = 0; 01353 virtual void EnsureDepthPeeling(H3DTexture *texture, H3DData *h3ddata) = 0; 01354 01355 // Shader's key is used to identify it. 01356 inline const H3DShaderID Key() const { return m_key; } 01357 }; 01358 01359 01360 /***************************************************************************** 01361 ***************************************************************************** 01362 Category: H3DShaderHash Class 01363 ***************************************************************************** 01364 *****************************************************************************/ 01365 local int shader_cleanup_callback(void *shader_ptr, void *dummy, void *dummy2) 01366 { 01367 H3DShader *shader = (H3DShader *)shader_ptr; 01368 H_SAFE_DELETE(shader); 01369 01370 UNREFERENCED(dummy); 01371 UNREFERENCED(dummy2); 01372 return VHASH_STATUS_SUCCESS; 01373 } 01374 01375 class H3DShaderHASH { 01376 private: 01377 HT_VHash *m_hash; 01378 H3DData *m_h3ddata; 01379 public: 01380 H3DShaderHASH (H3DData *h3ddata, int nominal_size=1024) { 01381 m_h3ddata = h3ddata; 01382 m_hash = HI_New_VHash (nominal_size); 01383 } 01384 ~H3DShaderHASH () { 01385 HI_VHash_Map_Function (m_hash, shader_cleanup_callback, m_h3ddata); 01386 HI_Delete_VHash (m_hash); 01387 m_hash = null; 01388 } 01389 void Insert (const H3DShaderID &id, H3DShader *shader) { 01390 HI_VHash_Insert_Item (m_hash, I2V(id.m_data[0]), shader); 01391 } 01392 H3DShader *Lookup (const H3DShaderID &id) { 01393 H3DShader *shader; 01394 int status, n; 01395 01396 for (n = 0; ; n++) { 01397 status = HI_VHash_Lookup_Nth_Item (m_hash, I2V(id.m_data[0]), n, (void**)&shader); 01398 if (status != VHASH_STATUS_SUCCESS) 01399 return null; 01400 if (shader->Key() == id) 01401 return shader; 01402 } 01403 } 01404 01405 }; 01406 01407 01408 /***************************************************************************** 01409 ***************************************************************************** 01410 Category: ENSURE macros 01411 ***************************************************************************** 01412 *****************************************************************************/ 01413 #define VB_CACHE_MAX_SIZE 16384 01414 #define ENSURE_VB_CACHE_HASH(h3ddata) SEMI_PROTECT( \ 01415 if (!h3ddata->vb_cache_hash) \ 01416 h3ddata->vb_cache_hash = HI_New_VHash(10); \ 01417 ) 01418 01419 #define ENSURE_VB_CACHE_VF(h3ddata, vf, vbcache) SEMI_PROTECT( \ 01420 ENSURE_VB_CACHE_HASH(h3ddata); \ 01421 H3DVertexBufferCache *_vbcache; \ 01422 if (HI_VHash_Lookup_Item(h3ddata->vb_cache_hash, I2V(vf.get_vf()), (void **)&_vbcache) != VHASH_STATUS_SUCCESS) { \ 01423 _vbcache = h3ddata->h3d_actions->CreateVertexBufferCache(); \ 01424 _vbcache->CreateVertexBuffer(h3ddata, VB_CACHE_MAX_SIZE, vf); \ 01425 HI_VHash_Insert_Item(h3ddata->vb_cache_hash, I2V(vf.get_vf()), _vbcache); \ 01426 } \ 01427 vbcache = _vbcache; \ 01428 ) 01429 01430 #define ENSURE_VB_CACHE(h3ddata, vf) SEMI_PROTECT( \ 01431 H3DVertexBufferCache *_vbcache; \ 01432 ENSURE_VB_CACHE_VF(h3ddata, vf, _vbcache); \ 01433 ) 01434 01435 01436 #define ENSURE_IB_CACHE(h3ddata, vb) SEMI_PROTECT(\ 01437 if (h3ddata->ib_cache == NULL) { \ 01438 h3ddata->ib_cache = h3ddata->h3d_actions->CreateIndexBufferCache(); \ 01439 h3ddata->ib_cache->CreateIndexBuffer(h3ddata); \ 01440 } \ 01441 h3ddata->ib_cache->SetVertexBufferCache(vb); \ 01442 ) 01443 01444 01445 #define ENSURE_ID_SHADER(h3ddata,nr,geom_type,geom,flags,bits,ppShader) SEMI_PROTECT(\ 01446 H3DShader *_shader_; \ 01447 H3DShaderID __id__; \ 01448 __id__.Init (nr, geom_type, geom, flags, bits); \ 01449 _shader_ = h3ddata->ShaderHash->Lookup (__id__); \ 01450 if (!_shader_) { \ 01451 _shader_ = h3ddata->h3d_actions->CreateShader(__id__); \ 01452 if (!_shader_->Create(h3ddata)) {\ 01453 /* shader compile error. Error message already thrown */ \ 01454 delete _shader_; \ 01455 HD_Interrupt_Update (nr->display_context, true, false); \ 01456 return; \ 01457 } \ 01458 h3ddata->ShaderHash->Insert (__id__, _shader_); \ 01459 } \ 01460 if (h3ddata->cache.Shader != _shader_) {\ 01461 _shader_->Activate(); \ 01462 h3ddata->cache.Shader = _shader_; \ 01463 SET_MEMORY(h3ddata->matrix_texture_touched, H3D_MAX_TEXTURES * sizeof(bool), true); \ 01464 } \ 01465 *(ppShader) = h3ddata->cache.Shader; \ 01466 ) 01467 01468 #define ENSURE_SHADER(h3ddata,nr,geom_type,geom,flags,ppShader) SEMI_PROTECT( \ 01469 ENSURE_ID_SHADER(h3ddata,nr,geom_type,geom,flags,0,ppShader); \ 01470 ) 01471 01472 #define ENSURE_LIGHTS(h3ddata,nr,lr,matr,color,shader) SEMI_PROTECT(\ 01473 shader->EnsureLights(nr, lr, matr, color); \ 01474 ) 01475 01476 #define ENSURE_LINE_STYLE(dx9data,nr,er,shader) SEMI_PROTECT(\ 01477 shader->EnsureLineStyle(nr,er); \ 01478 ) 01479 01480 #define ENSURE_DC_XFORM(h3ddata,nr,shader) SEMI_PROTECT( \ 01481 if (h3ddata->tr_incarnation != nr->transform_rendition->incarnation || \ 01482 h3ddata->tr_is_dc == FALSE) { \ 01483 h3ddata->h3d_actions->set_dc_xform (nr); \ 01484 h3ddata->tr_incarnation = nr->transform_rendition->incarnation; \ 01485 h3ddata->tr_is_dc = TRUE; \ 01486 } \ 01487 shader->EnsureDCTransform(nr); \ 01488 ) 01489 01490 /* 01491 * Transformations 01492 * computes transformation matrices. Some state goes on the device (e.g. 01493 * culling modes, viewport). Other state goes in the shaders' constant tables 01494 */ 01495 #define ENSURE_3D_XFORM(h3ddata,nr,shader) SEMI_PROTECT(\ 01496 if (h3ddata->tr_incarnation != nr->transform_rendition->incarnation || \ 01497 h3ddata->tr_is_dc == TRUE) { \ 01498 h3ddata->h3d_actions->set_3d_xform (nr); \ 01499 h3ddata->tr_incarnation = nr->transform_rendition->incarnation; \ 01500 h3ddata->tr_is_dc = FALSE; \ 01501 } \ 01502 shader->Ensure3DTransform(nr); \ 01503 ) 01504 01505 01506 01507 /* 01508 * VIEWPORT 01509 */ 01510 #define INVALIDATE_VIEWPORT(h3ddata) SEMI_PROTECT(\ 01511 ZERO_STRUCT (&h3ddata->cache.viewport, H3DVIEWPORT); \ 01512 h3ddata->tr_incarnation = INVALID_INCARNATION; \ 01513 ) 01514 #define FORCE_VIEWPORT(h3ddata, left, top, width, height) SEMI_PROTECT(\ 01515 H3DVIEWPORT *hvp = &h3ddata->cache.viewport; \ 01516 ASSERT((int)(left) >= 0 && (int)(top) >= 0); \ 01517 hvp->X = (left); \ 01518 hvp->Y = (top); \ 01519 hvp->Width = (width); \ 01520 hvp->Height = (height); \ 01521 hvp->MinZ = h3ddata->cache.z_range[0]; \ 01522 hvp->MaxZ = h3ddata->cache.z_range[1]; \ 01523 h3ddata->h3d_actions->SetViewport(hvp); \ 01524 ) 01525 #define ENSURE_VIEWPORT(h3ddata, left, top, width, height) SEMI_PROTECT(\ 01526 if ((DWORD)left != h3ddata->cache.viewport.X || (DWORD)top != h3ddata->cache.viewport.Y || \ 01527 (DWORD)width != h3ddata->cache.viewport.Width || (DWORD)height != h3ddata->cache.viewport.Height || \ 01528 h3ddata->cache.z_range[0] != h3ddata->cache.viewport.MinZ || \ 01529 h3ddata->cache.z_range[1] != h3ddata->cache.viewport.MaxZ \ 01530 ) { \ 01531 FORCE_VIEWPORT(h3ddata, (left), (top), (width), (height)); \ 01532 } \ 01533 ) 01534 01535 01536 01537 #define FORCE_VF(h3ddata,_vf) h3ddata->h3d_actions->force_vf(_vf); 01538 #define ENSURE_VF(h3ddata,_vf) SEMI_PROTECT( \ 01539 if (h3ddata->h3dcache.vf != _vf) \ 01540 FORCE_VF(h3ddata,_vf); \ 01541 ) 01542 01543 #define FORCE_SHADE_MODE(h3ddata,mode) h3ddata->h3d_actions->force_shade_mode(mode); 01544 #define ENSURE_SHADE_MODE(h3ddata,mode) SEMI_PROTECT( \ 01545 if (h3ddata->cache.shade_mode != mode) \ 01546 FORCE_SHADE_MODE(h3ddata, mode); \ 01547 ) 01548 01549 #define FORCE_CULLING(h3ddata,mode) h3ddata->h3d_actions->force_culling(mode); 01550 #define ENSURE_CULLING(h3ddata,mode) SEMI_PROTECT( \ 01551 if (h3ddata->cache.cull_mode != mode) \ 01552 FORCE_CULLING(h3ddata, mode); \ 01553 ) 01554 01555 #define FORCE_ZBUFFERING(h3ddata,mode) h3ddata->h3d_actions->force_zbuffering(mode); 01556 #define ENSURE_ZBUFFERING(h3ddata,mode) SEMI_PROTECT( \ 01557 if (h3ddata->cache.zbuffering != mode) \ 01558 FORCE_ZBUFFERING(h3ddata, mode); \ 01559 ) 01560 01561 #define FORCE_DEPTH_MASK(h3ddata,mode) h3ddata->h3d_actions->force_depth_mask(mode); 01562 #define ENSURE_DEPTH_MASK(h3ddata,mode) SEMI_PROTECT( \ 01563 if (h3ddata->cache.depth_mask != mode) \ 01564 FORCE_DEPTH_MASK(h3ddata, mode); \ 01565 ) 01566 01567 #define FORCE_DEPTH_RANGE_SET(h3ddata,zmin,zmax) h3ddata->h3d_actions->force_depth_range_set(zmin,zmax); 01568 #define ENSURE_DEPTH_RANGE_SET(h3ddata,zmin,zmax) SEMI_PROTECT(\ 01569 if ((zmin != h3ddata->cache.z_range[0]) || (zmax != h3ddata->cache.z_range[1])) { \ 01570 FORCE_DEPTH_RANGE_SET(h3ddata, zmin, zmax); \ 01571 } \ 01572 ) 01573 01574 #define FORCE_ANTI_ALIAS(h3ddata,mode) h3ddata->h3d_actions->force_anti_alias(mode); 01575 #define ENSURE_ANTI_ALIAS(h3ddata,mode) SEMI_PROTECT( \ 01576 if (h3ddata->cache.antialias != mode) \ 01577 FORCE_ANTI_ALIAS(h3ddata, mode); \ 01578 ) 01579 01580 #define FORCE_COLOR_MASK(h3ddata,mode) h3ddata->h3d_actions->force_color_mask(mode); 01581 #define ENSURE_COLOR_MASK(h3ddata,mode) SEMI_PROTECT( \ 01582 if (h3ddata->cache.color_mask != mode) \ 01583 FORCE_COLOR_MASK(h3ddata,mode); \ 01584 ) 01585 01586 #define FORCE_TRANSPARENCY(h3ddata,mode) h3ddata->h3d_actions->force_transparency(mode); 01587 #define ENSURE_TRANSPARENCY(h3ddata,mode) SEMI_PROTECT( \ 01588 if (h3ddata->cache.transparency_on != mode) \ 01589 FORCE_TRANSPARENCY(h3ddata,mode); \ 01590 ) 01591 01592 #define FORCE_SCISSOR(h3ddata,mode) h3ddata->h3d_actions->force_scissor(mode); 01593 #define ENSURE_SCISSOR(h3ddata,mode) SEMI_PROTECT(\ 01594 if (h3ddata->cache.scissoring != mode) \ 01595 FORCE_SCISSOR(h3ddata,mode); \ 01596 ) 01597 01598 01599 /***************************************************************************** 01600 ***************************************************************************** 01601 Category: Bin Class 01602 ***************************************************************************** 01603 *****************************************************************************/ 01604 /* Display list "bin packing" */ 01605 class H3D_Display_List_Bin { 01606 public: 01607 H3D_Display_List_Bin() { 01608 ZERO_STRUCT(this, H3D_Display_List_Bin); 01609 geo_list = HI_New_VList(); 01610 }; 01611 ~H3D_Display_List_Bin() { 01612 if (geo_list) 01613 HI_Delete_VList(geo_list); 01614 01615 if (nr) { 01616 if (DECR_UTILITY(nr) == 0) 01617 HD_Free_Net_Rendition(nr); 01618 } 01619 }; 01620 01621 struct { 01622 int total; 01623 int strips; 01624 int point_count; 01625 } stats; 01626 01627 /* Use these as you see fit... */ 01628 H3DShaderID id; 01629 int flags; //any special flags 01630 HT_VList *geo_list; //list of geometry matrix pairs (geo_mat_pair) 01631 HT_Net_Rendition const *nr; //the geometry in a bin should all have the same net rendition 01632 H3D_Display_List *odl; //output; the resulting display list 01633 }; 01634 01635 /***************************************************************************** 01636 ***************************************************************************** 01637 Category: H3DVertexBuffer Class 01638 01639 This class is a wrapper around a generic float vertex buffer. It allows a 01640 vertex position, normals, etc. to be set in a more intuitive manner. 01641 ***************************************************************************** 01642 *****************************************************************************/ 01643 class H3DVertexBuffer 01644 { 01645 private: 01646 int stride; 01647 H3DVertexFormat vf; 01648 float *pvbuf; 01649 float *pvbuf_start; 01650 01651 int xyz_offset; 01652 int nxyz_offset; 01653 int color_offset; 01654 int uvw_offset; 01655 01656 bool owns_buffer; 01657 int buffer_size; 01658 01659 public: 01660 H3DVertexBuffer(float *in_pvbuf, H3DVertexFormat in_vf, int vertices_to_allocate = 0) 01661 { 01662 Init(in_pvbuf, in_vf, vertices_to_allocate); 01663 } 01664 H3DVertexBuffer() 01665 { 01666 SET_MEMORY (this, sizeof(H3DVertexBuffer), 0); 01667 }; 01668 ~H3DVertexBuffer() 01669 { 01670 if (owns_buffer) { 01671 H_SAFE_DELETE_ARRAY (pvbuf_start); 01672 } 01673 }; 01674 01675 void Init(float *in_pvbuf, H3DVertexFormat in_vf, int vertices_to_allocate = 0) { 01676 if (vertices_to_allocate > 0) 01677 owns_buffer = true; 01678 else 01679 owns_buffer = false; 01680 01681 stride = 0; 01682 vf = in_vf; 01683 01684 // cache the offsets to the various components 01685 xyz_offset = nxyz_offset = color_offset = uvw_offset = -1; 01686 if (vf.get_position()) { 01687 xyz_offset = stride; 01688 stride += 3; 01689 } 01690 if (vf.get_normals()) { 01691 nxyz_offset = stride; 01692 stride += 3; 01693 } 01694 if (vf.get_diffuse()) { 01695 color_offset = stride; 01696 stride += 1; 01697 } 01698 if (vf.get_tex_count() > 0) { 01699 uvw_offset = stride; 01700 stride += vf.get_tex_size(0) * vf.get_tex_count(); 01701 } 01702 01703 /* Make sure the stride we calculate here is the same as the one we calculate from the vf */ 01704 ASSERT(stride == vf.get_size(false)); 01705 01706 buffer_size = vertices_to_allocate; 01707 if (owns_buffer) 01708 pvbuf = new float[stride * buffer_size]; 01709 else 01710 pvbuf = in_pvbuf; 01711 01712 pvbuf_start = pvbuf; 01713 } 01714 // utility functions 01715 void reset() {pvbuf = pvbuf_start;}; 01716 void resize(int new_size) { 01717 int pvbuf_offset = pvbuf - pvbuf_start; 01718 float *pvbuf_saved = pvbuf_start; 01719 01720 pvbuf_start = new float[stride * new_size]; 01721 COPY_MEMORY(pvbuf_saved, stride * min(buffer_size, new_size) * sizeof(float), pvbuf_start); 01722 01723 buffer_size = new_size; 01724 pvbuf = pvbuf_start + pvbuf_offset; 01725 } 01726 01727 int get_buffer_size() {return buffer_size;}; 01728 float * get_ptr() {return pvbuf;}; 01729 float * get_start_ptr() {return pvbuf_start;}; 01730 float * get_index_ptr(int index) {return pvbuf_start + index * stride;}; 01731 H3DVertexFormat get_vf() {return vf;}; 01732 int get_stride() {return stride;}; 01733 int get_position_offset() {return xyz_offset;}; 01734 int get_normals_offset() {return nxyz_offset;}; 01735 int get_color_offset() {return color_offset;}; 01736 int get_texture_offset() {return uvw_offset;}; 01737 01738 // get() functions 01739 float get_x() {return pvbuf[xyz_offset+0];} 01740 float get_y() {return pvbuf[xyz_offset+1];} 01741 float get_z() {return pvbuf[xyz_offset+2];} 01742 01743 float get_nx() {return pvbuf[nxyz_offset+0];} 01744 float get_ny() {return pvbuf[nxyz_offset+1];} 01745 float get_nz() {return pvbuf[nxyz_offset+2];} 01746 01747 float get_u(int texcoord = 0) { 01748 if (texcoord < vf.get_tex_count()) return pvbuf[uvw_offset+texcoord*3+0]; 01749 return -1; 01750 } 01751 float get_v(int texcoord = 0) { 01752 if (texcoord < vf.get_tex_count()) return pvbuf[uvw_offset+texcoord*3+1]; 01753 return -1; 01754 } 01755 float get_w(int texcoord = 0) { 01756 if (texcoord < vf.get_tex_count()) return pvbuf[uvw_offset+texcoord*3+2]; 01757 return -1; 01758 } 01759 01760 // set() functions 01761 void xyz(float ix, float iy, float iz) {x(ix); y(iy); z(iz);} 01762 void x(float ix) {if (xyz_offset >= 0) pvbuf[xyz_offset+0] = ix;} 01763 void y(float iy) {if (xyz_offset >= 0) pvbuf[xyz_offset+1] = iy;} 01764 void z(float iz) {if (xyz_offset >= 0) pvbuf[xyz_offset+2] = iz;} 01765 01766 void nxyz(float inx, float iny, float inz) {nx(inx); ny(iny); nz(inz);} 01767 void nx(float inx) {if (nxyz_offset >= 0) pvbuf[nxyz_offset+0] = inx;} 01768 void ny(float iny) {if (nxyz_offset >= 0) pvbuf[nxyz_offset+1] = iny;} 01769 void nz(float inz) {if (nxyz_offset >= 0) pvbuf[nxyz_offset+2] = inz;} 01770 01771 void color(H3D_Color const in_color) {COPY_MEMORY(&in_color, sizeof(H3D_Color), &pvbuf[color_offset]);} 01772 void color(char a, char b, char c, char d) {color(H3D_PACK_BYTES(a, b, c, d));} 01773 void color(H3D_Color_Format format, char a, char b, char c, char d) {color(h3d_pack_color(format,a,b,c,d));} 01774 void color(H3D_Color_Format format, float a, float b, float c, float d) {color(h3d_pack_colorf(format,a,b,c,d));} 01775 void color(H3D_Color_Format format, const HT_RGBAS32 rgba) { 01776 color(h3d_pack_color(format,rgba.rgb.r, rgba.rgb.g, rgba.rgb.b, rgba.rgb.a)); 01777 } 01778 01779 void uvw(float iu, float iv, float iw, int texcoord = 0) {u(iu,texcoord); v(iv,texcoord); w(iw,texcoord);} 01780 void u(float iu, int texcoord = 0) { 01781 if (uvw_offset >= 0 && texcoord < vf.get_tex_count() && vf.get_tex_size(0) > 0) 01782 pvbuf[uvw_offset+texcoord*3+0] = iu; 01783 } 01784 void v(float iv, int texcoord = 0) { 01785 if (uvw_offset >= 0 && texcoord < vf.get_tex_count() && vf.get_tex_size(0) > 1) 01786 pvbuf[uvw_offset+texcoord*3+1] = iv; 01787 } 01788 void w(float iw, int texcoord = 0) { 01789 if (uvw_offset >= 0 && texcoord < vf.get_tex_count() && vf.get_tex_size(0) > 2) 01790 pvbuf[uvw_offset+texcoord*3+2] = iw; 01791 } 01792 01793 // operators 01794 H3DVertexBuffer operator[](int const index) { 01795 return H3DVertexBuffer(pvbuf + index*stride, vf); 01796 } 01797 H3DVertexBuffer const & operator+=(int const steps) { 01798 pvbuf += steps * stride; 01799 return *this; 01800 } 01801 H3DVertexBuffer const & operator++() { 01802 pvbuf += stride; 01803 return *this; 01804 } 01805 H3DVertexBuffer const & next() { 01806 pvbuf += stride; 01807 return *this; 01808 } 01809 H3DVertexBuffer operator+(int const steps) const { 01810 return H3DVertexBuffer(pvbuf + steps*stride, vf); 01811 } 01812 H3DVertexBuffer operator-(int const steps) const { 01813 return H3DVertexBuffer(pvbuf + steps*stride, vf); 01814 } 01815 }; 01816 01817 01818 01819 /***************************************************************************** 01820 ***************************************************************************** 01821 Category: H3DIndexBuffer Class 01822 01823 This class is a wrapper around a generic index buffer. It transparently 01824 handles both short and int based indexed buffers. 01825 ***************************************************************************** 01826 *****************************************************************************/ 01827 class H3DIndexBuffer 01828 { 01829 public: 01830 H3DIndexBuffer():m_ibptr(0), m_stride(0){} 01831 01832 H3DIndexBuffer(int const stride, void * const ib): 01833 m_ibptr((short*)ib), m_stride(stride) 01834 { 01835 } 01836 01837 01838 H3DIndexBuffer(H3DFORMAT const format, void * const ib) 01839 { 01840 Init(format, ib); 01841 } 01842 01843 ~H3DIndexBuffer(){} 01844 01845 void Init(H3DFORMAT const format, void * const ib) 01846 { 01847 m_ibptr = (short *) ib; 01848 01849 if (format == H3DFMT_INDEX16) 01850 m_stride = 1; 01851 else if (format == H3DFMT_INDEX32) 01852 m_stride = 2; 01853 else 01854 HE_ERROR(HEC_INTERNAL_ERROR, HEC_INTERNAL_ERROR, 01855 "Index buffer format must be H3DFMT_INDEX16 or H3DFMT_INDEX32."); 01856 } 01857 01858 void Init(int const stride, void * const ib) 01859 { 01860 m_ibptr = (short *) ib; 01861 m_stride = stride; 01862 } 01863 01864 void CopyBuffer(H3DIndexBuffer const source, int const num_vertices) 01865 { 01866 int i = 0; 01867 short *dest = m_ibptr; 01868 short *src = source.m_ibptr; 01869 01870 if (source.m_stride == m_stride) 01871 COPY_MEMORY(src, num_vertices * m_stride * sizeof(short), dest); 01872 else if (source.m_stride == 2 && m_stride == 1) { 01873 /* This case is usually triggered when we copy from a 32bit mesh to a 16bit indexbufferobject. 01874 * This might happen because meshes have a strange restriction that it can't have more than 01875 * 2^16 indices when it's declared as 16bit, whereas 16bit indexbufferobjects can. In this case, 01876 * all of the mesh's indices would be 16bits or less (we wouldn't have a 16bit IBO otherwise), 01877 * so we can safely copy the points over. 01878 */ 01879 01880 for (i = 0; i < num_vertices; i++) { 01881 *dest = *((int *) src); 01882 dest += m_stride; 01883 src += source.m_stride; 01884 } 01885 } 01886 else { 01887 for (i = 0; i < num_vertices; i++) { 01888 *((int *) dest) = *src; 01889 dest += m_stride; 01890 src += source.m_stride; 01891 } 01892 } 01893 } 01894 01895 // Operators 01896 int const operator*() const { 01897 if (m_stride == 2) 01898 return *((int *)m_ibptr); 01899 else 01900 return *m_ibptr; 01901 } 01902 01903 bool const operator==(H3DIndexBuffer const &right) const { 01904 return (this->m_ibptr == right.m_ibptr); 01905 } 01906 bool const operator!=(H3DIndexBuffer const &right) const { 01907 return (this->m_ibptr != right.m_ibptr); 01908 } 01909 01910 H3DIndexBuffer const & operator=(int const number) { 01911 if (m_stride == 2) 01912 *((int *) m_ibptr) = number; 01913 else 01914 *m_ibptr = number; 01915 return *this; 01916 } 01917 H3DIndexBuffer const & operator++() { 01918 m_ibptr += m_stride; 01919 return *this; 01920 } 01921 H3DIndexBuffer const & operator--() { 01922 m_ibptr -= m_stride; 01923 return *this; 01924 } 01925 H3DIndexBuffer const & operator+=(int const steps) { 01926 m_ibptr += steps * m_stride; 01927 return *this; 01928 } 01929 H3DIndexBuffer const & operator-=(int const steps) { 01930 m_ibptr -= steps * m_stride; 01931 return *this; 01932 } 01933 H3DIndexBuffer const operator+(int const steps) const { 01934 H3DIndexBuffer itr; 01935 itr.m_ibptr = m_ibptr + steps * m_stride; 01936 itr.m_stride = m_stride; 01937 return itr; 01938 } 01939 H3DIndexBuffer operator-(int const steps) const { 01940 return *this + (-steps); 01941 } 01942 H3DIndexBuffer operator[](int const index) { 01943 return H3DIndexBuffer(m_stride, (void*)(m_ibptr + index*m_stride)); 01944 } 01945 01946 int const operator-(H3DIndexBuffer const &right) const { 01947 return (this->m_ibptr - right.m_ibptr) / m_stride; 01948 } 01949 01950 private: 01951 short *m_ibptr; 01952 short m_stride; 01953 }; 01954 01955 01956 /***************************************************************************** 01957 ***************************************************************************** 01958 Category: Buffers 01959 ***************************************************************************** 01960 *****************************************************************************/ 01961 #define CULL_ACCEPT(cull_result) (!BIT(cull_result,Test_EXTENT) && (cull_result != Test_DISJOINT)) 01962 01963 typedef struct h3d_bounding_s { 01964 HT_Bounding const **boundings; 01965 HT_Bounding const *bounding_buffer; 01966 } H3D_Boundings; 01967 01968 01969 // force_vertex_stuff forces each vertex (or index) to be treated as unique (no sharing) 01970 #define MAP_POINT_INDEX_ONLY(mapped_point, i_pt, force_vertex_stuff) SEMI_PROTECT (\ 01971 if (force_vertex_stuff) \ 01972 mapped_point = -1; \ 01973 else \ 01974 mapped_point = pointmap[i_pt]; \ 01975 if (mapped_point < 0) { \ 01976 mapped_point = pointmap[i_pt] = current_point++; \ 01977 } \ 01978 ) 01979 01980 01981 class H3DIndexedBufferObject 01982 { 01983 public: 01984 unsigned int m_point_count; 01985 unsigned int m_stride; 01986 H3DVertexFormat m_VF; 01987 H3DFORMAT m_format; 01988 01989 bool m_owns_boundings; //if true, we need to delete both HT_Bounding arrays 01990 int m_bounding_count; 01991 HT_Bounding const *m_bounding_buffer; 01992 HT_Bounding const **m_boundings; 01993 int *m_tristrip_offsets; 01994 int m_tristrip_first; //the first tristrip's index in the IBO 01995 int m_tristrip_count; 01996 01997 H3DIndexedBufferObject() 01998 { 01999 m_point_count = 0; 02000 m_owns_boundings = false; 02001 m_tristrip_offsets = null; 02002 m_bounding_buffer = null; 02003 m_boundings = null; 02004 m_tristrip_count = 0; 02005 m_bounding_count = 0; 02006 } 02007 virtual ~H3DIndexedBufferObject() 02008 { 02009 if (m_owns_boundings) { 02010 if (m_bounding_buffer) 02011 FREE_ARRAY(m_bounding_buffer, m_bounding_count, HT_Bounding *); 02012 if (m_boundings) 02013 FREE_ARRAY(m_boundings, m_bounding_count, HT_Bounding *); 02014 } 02015 if (m_tristrip_offsets) 02016 FREE_ARRAY(m_tristrip_offsets, m_tristrip_count, int); 02017 } 02018 02019 //called once per HT_Tristrip 02020 virtual bool CreateVertexBuffer (H3DData *h3ddata, 02021 unsigned int point_count, 02022 H3DVertexFormat VF) = 0; 02023 02024 //called ts->strips times per HT_Tristrip 02025 virtual bool CreateIndexBuffer (H3DData *h3ddata, 02026 H3DPRIMITIVETYPE type, 02027 unsigned int size, 02028 unsigned int count) = 0; 02029 02030 virtual bool CreateMesh (H3DData *h3ddata, 02031 unsigned int point_count, 02032 unsigned int face_count, 02033 H3DVertexFormat VF) 02034 { 02035 if (CreateVertexBuffer(h3ddata, point_count, VF) && 02036 CreateIndexBuffer(h3ddata, H3DPT_TRIANGLELIST, face_count * 3 * sizeof(int), face_count)) 02037 return true; 02038 return false; 02039 }; 02040 02041 virtual bool LockIndexBuffer(unsigned int OffsetToLock, unsigned int SizeToLock, H3DIndexBuffer *ib, DWORD Flags) = 0; 02042 virtual bool LockVertexBuffer(unsigned int OffsetToLock, unsigned int SizeToLock, H3DVertexBuffer *pv, DWORD Flags) = 0; 02043 virtual void UnlockIndexBuffer() = 0; 02044 virtual void UnlockVertexBuffer() = 0; 02045 virtual void Draw(H3DData *h3ddata, HT_Test *cull_results = null) = 0; 02046 }; 02047 02048 02049 02050 class H3DVertexBufferCache { 02051 public: 02052 H3DVertexBufferCache(){} 02053 virtual ~H3DVertexBufferCache(){} 02054 02055 virtual bool CreateVertexBuffer(H3DData *h3ddata, unsigned int max_points, H3DVertexFormat VF) = 0; 02056 virtual bool Reset() = 0; 02057 02058 virtual bool Discard() = 0; 02059 virtual bool Lock(unsigned int count, H3DVertexBuffer *pv) = 0; 02060 virtual bool Unlock() = 0; 02061 virtual bool Draw(H3DData *h3ddata , H3DPRIMITIVETYPE PrimitiveType, unsigned int PrimitiveCount) = 0; 02062 virtual bool DrawRepeatable(H3DData *h3ddata , H3DPRIMITIVETYPE PrimitiveType, unsigned int PrimitiveCount) = 0; 02063 virtual void DrawComplete() = 0; 02064 02065 H3DVertexFormat m_VF; 02066 unsigned int m_nVertexStride; 02067 unsigned int m_nMaxPoints; 02068 unsigned int m_nCurVertexData; 02069 unsigned int m_nNextVertexData; 02070 }; 02071 02072 02073 class H3DIndexBufferCache 02074 { 02075 public: 02076 H3DIndexBufferCache(){}; 02077 virtual ~H3DIndexBufferCache(){}; 02078 02079 virtual bool CreateIndexBuffer(H3DData *h3ddata) = 0; 02080 virtual bool Lock(short count, void **ppbData) = 0; 02081 virtual bool Unlock() = 0; 02082 virtual bool Draw(H3DData *h3ddata, H3DPRIMITIVETYPE PrimitiveType, 02083 unsigned int VertexCount, 02084 unsigned int PrimitiveCount) = 0; 02085 02086 virtual void DrawComplete() = 0; 02087 virtual void SetVertexBufferCache (H3DVertexBufferCache *vbcache) = 0; 02088 }; 02089 02090 02091 /***************************************************************************** 02092 ***************************************************************************** 02093 Category: Geometry Contents 02094 ***************************************************************************** 02095 *****************************************************************************/ 02096 02097 //geometry content bits 02098 #define GEO_VERTEX_INDICES 0x00000001 02099 #define GEO_FACE_INDICES 0x00000002 02100 #define GEO_VERTEX_COLORS 0x00000004 02101 #define GEO_VERTEX_FINDICES 0x00000008 02102 #define GEO_VERTEX_NORMALS 0x00000010 02103 #define GEO_VERTEX_PARAMS 0x00000020 02104 #define GEO_VERTEX_PARAM_WIDTH 0x00000040 02105 #define GEO_FACE_COLORS 0x00000080 02106 #define GEO_FACE_NORMALS 0x00000100 02107 #define GEO_INDEXED_TRISTRIP 0x00000200 02108 #define GEO_EDGE_NORMALS 0x00000400 02109 #define GEO_EDGE_COLORS 0x00000800 02110 02111 int get_tristrip_contents(HT_Tristrip const *ts); 02112 int get_polyedge_contents(HT_Polyedge const *pe); 02113 02114 H3D_Vertex_Buffer_Style figure_ts_vertex_buffer_style ( 02115 HT_Tristrip const *ts, 02116 HT_Face_Rendition const *fr, 02117 H3D_Display_List_Bin alter *bin, 02118 unsigned int *special_flags_out); 02119 02120 02121 int get_tristrip_point_count(HT_Tristrip const *ts); 02122 02123 void gather_ts_stats( 02124 HT_Net_Rendition const *nr, 02125 HT_Tristrip const *ts, 02126 H3D_Display_List_Bin alter *bin, 02127 H3D_Vertex_Buffer_Style buffer_style, 02128 unsigned int alter *total_point_count, 02129 int alter *face_count); 02130 02131 02132 02133 02134 02135 H3D_Vertex_Buffer_Style figure_pe_vertex_buffer_style ( 02136 HT_Polyedge const *pe, 02137 H3D_Display_List_Bin alter *bin, 02138 unsigned int *special_flags_out); 02139 02140 /* Figure out the total length, point count and edge count */ 02141 void gather_pe_stats ( 02142 HT_Polyedge const *pe, 02143 H3D_Display_List_Bin alter *bin, 02144 H3D_Vertex_Buffer_Style buffer_style, 02145 int alter *total_length_out, 02146 int alter *point_count_out, 02147 int alter *edge_count_out); 02148 02149 /* 02150 * HELPER 02151 */ 02152 int get_bin_point_count(H3DData *h3ddata, H3D_Display_List_Bin *bin); 02153 02154 /***************************************************************************** 02155 ***************************************************************************** 02156 Category: Texture Usage methods 02157 ***************************************************************************** 02158 *****************************************************************************/ 02159 #define TU_SPECIAL -1 //used only to offset the usage calculations 02160 #define TU_INVALID 0 02161 #define TU_DIFFUSE_TEXTURE 1 02162 #define TU_SPECULAR_TEXTURE 2 02163 #define TU_ENVIRONMENT_TEXTURE 3 02164 #define TU_SHADOW_MAP_TEXTURE 4 02165 #define TU_CUTTING_PLANE 5 02166 #define TU_FACE_PATTERN 6 02167 #define TU_DEPTH_PEELING_TEXTURE 7 02168 #define TU_INDEX_TEXTURE 8 02169 #define TU_SHADOW_MAP_JITTER 9 02170 #define TU_PER_PIXEL_EYE_POSITION 10 02171 #define TU_GET_UNIT_USAGE 0xffff 02172 02173 typedef struct tex_usage_counts_s { 02174 int index_texture; 02175 int linetools; 02176 int diffuse; 02177 int specular; 02178 int environment; 02179 int shadowmap; 02180 int cuttingplane; 02181 int facepattern; 02182 int depthpeeling; 02183 int shadowmapjitter; 02184 int perpixeleyeposition; 02185 } Tex_Usage_Counts; 02186 02187 HT_Param_Source GetTextureUnitParam( 02188 HT_Material_Rendition const *matr, 02189 int type, 02190 int number); 02191 02192 void GetTextureUsageCounts( 02193 void const * rendition, 02194 int type, 02195 int flags, 02196 Tex_Usage_Counts *counts); 02197 02198 /* To use this function, you *must* populate the Tex_Usage_Counts struct with 02199 * texture counts. Then pass it in, and the function will calculate which 02200 * TEXCOORD should be used for the specified texture. 02201 * 02202 * Normally, this function returns the texture unit associated with a given texture type; 02203 * for instance, TU_DIFFUSE_TEXTURE might return unit 0, meaning TEXCOORD0. However, when 02204 * TU_GET_UNIT_USAGE is queried, it's a reverse lookup; for a given TEXCOORD, it returns 02205 * the associated type (such as TU_DIFFUSE_TEXTURE). 02206 */ 02207 int GetTextureUnitUsage(int usage, int number, Tex_Usage_Counts *counts); 02208 02209 02210 02211 /***************************************************************************** 02212 ***************************************************************************** 02213 Category: Misc Helper Functions 02214 ***************************************************************************** 02215 *****************************************************************************/ 02216 float determinant3x3 (HT_Row_Vector const *m); 02217 02218 02229 bool get_cutting_plane_set( 02230 HT_Net_Rendition const *nr, 02231 HT_Cutting_Plane_Set const *& cut_set); 02232 02233 02234 bool ts_has_display_lists(HT_Tristrip const *ts, H3D_Display_List_Bin *bin); 02235 02236 02237 void flush_display_lists(HT_Display_Context alter *dc); 02238 02239 void invalidate_h3dcache (H3DData alter * h3ddata); 02240 02241 02242 02243 /* 02244 * HELPER 02245 * Add primitive and count to appropriate DC stats. 02246 */ 02247 void add_primitives_to_stats (H3DData const *h3ddata, int count, int Mode, H3DPRIMITIVETYPE Type); 02248 02249 /* 02250 * HELPER 02251 * Handle the little drawing loop for cutting planes with vertex buffers. 02252 * Saves repeating the same ten lines of code all over. 02253 */ 02254 void draw_primitives( 02255 H3DData alter *h3ddata, 02256 HT_Net_Rendition const *nr, 02257 H3DVertexBufferCache *vertex_buffer, 02258 HT_Cutting_Plane_Set const *cut_set, 02259 int prim_count, 02260 int Mode, 02261 H3DPRIMITIVETYPE Type); 02262 02263 /* 02264 * HELPER 02265 * 02266 * Handle the little drawing loop for cutting planes with index buffers. 02267 * Saves repeating the same ten lines of code all over. 02268 */ 02269 void draw_indexed_primitives( 02270 H3DData alter *dx9data, 02271 HT_Net_Rendition const *nr, 02272 H3DIndexBufferCache *index_buffer, 02273 HT_Cutting_Plane_Set const *cut_set, 02274 int vertex_count, 02275 int prim_count, 02276 int Mode, 02277 H3DPRIMITIVETYPE Type, 02278 bool two_sided_coloring = FALSE); 02279 02280 02281 02282 02283 /* 02284 * HELPER 02285 */ 02286 bool action_mask_matches_gref( 02287 HT_Action_Mask mask, 02288 HT_Geometry const *gr); 02289 02290 02291 void set_pe_vertex_data ( 02292 HT_Net_Rendition const *nr, 02293 HT_Polyedge const *pe, 02294 HT_Line_Rendition const *er, 02295 H3DVertexBuffer *vb, 02296 float current_screen_length, 02297 int i_pt, 02298 int i_edge, 02299 HT_Matrix const *matrix); 02300 02301 02302 #define DEBUG_SET_VERTEX_DATA 02303 #ifdef DEBUG_SET_VERTEX_DATA 02304 void set_vertex_data (HT_Net_Rendition const *nr, 02305 HT_Tristrip const *ts, 02306 H3DVertexBuffer *vb, 02307 int i_pt, 02308 HT_Matrix const *matrix, 02309 int i_face = 0); 02310 #endif 02311 02312 #define MAP_TS_POINT(mapped_point, i_pt, force_vertex_stuff) SEMI_PROTECT (\ 02313 if (force_vertex_stuff) \ 02314 mapped_point = -1; \ 02315 else \ 02316 mapped_point = pointmap[i_pt]; \ 02317 if (mapped_point < 0) { \ 02318 mapped_point = pointmap[i_pt] = current_point++; \ 02319 set_vertex_data (nr, ts, &pv, i_pt, matrix, i_face); \ 02320 ++pv; \ 02321 } \ 02322 ) 02323 02324 02325 02326 /* 02327 * HELPER 02328 * ensures that our D3D state has the correct settings for 02329 * a) two sided lighting, 02330 * b) cull face 02331 */ 02332 void set_handedness ( 02333 H3DData alter * h3ddata, 02334 HT_Transform_Rendition const * tr, 02335 bool backface_pass); 02336 02337 /* 02338 * HELPER 02339 * 02340 * Set key renderstates and special shader options. 02341 * Prevents code duplication between the three versions of draw_3d_tristrip. 02342 */ 02343 int configure_shader_flags(H3DData *h3ddata, 02344 HT_Net_Rendition const *nr, 02345 HT_Transform_Rendition const *tr, 02346 H3D_Vertex_Buffer_Style buffer_style, 02347 int transparency_stipple, 02348 int flags); 02349 02350 int get_handedness_flags(HT_Net_Rendition const *nr); 02351 02352 02358 void apply_shader_settings(H3DData *h3ddata, 02359 HT_Net_Rendition const *nr, 02360 H3DShader *shader); 02361 02362 02363 /***************************************************************************** 02364 ***************************************************************************** 02365 Category: Textures 02366 ***************************************************************************** 02367 *****************************************************************************/ 02368 H3DTexture * define_texture ( 02369 H3DData alter *h3ddata, 02370 HT_Net_Rendition const * nr, 02371 HT_Texture alter *txr, 02372 int usage); 02373 02374 H3DTexture * define_interpolation_texture ( 02375 H3DData alter * dx9data, 02376 HT_Net_Rendition const * nr); 02377 02378 int define_line_pattern ( 02379 HT_Display_Context alter * dc, 02380 HT_Line_Style const *style); 02381 02382 02383 02384 /* this table should be just 520 bytes, so it shouldn't be much of a size issue */ 02385 static const unsigned char transparency_stipple_patterns[65][8] = { 02386 {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 02387 {0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 02388 {0x0, 0x80, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0}, 02389 {0x0, 0x80, 0x0, 0x0, 0x0, 0x88, 0x0, 0x0}, 02390 {0x0, 0x88, 0x0, 0x0, 0x0, 0x88, 0x0, 0x0}, 02391 {0x0, 0x88, 0x0, 0x20, 0x0, 0x88, 0x0, 0x0}, 02392 {0x0, 0x88, 0x0, 0x20, 0x0, 0x88, 0x0, 0x2}, 02393 {0x0, 0x88, 0x0, 0x20, 0x0, 0x88, 0x0, 0x22}, 02394 {0x0, 0x88, 0x0, 0x22, 0x0, 0x88, 0x0, 0x22}, 02395 {0x0, 0x88, 0x0, 0xa2, 0x0, 0x88, 0x0, 0x22}, 02396 {0x0, 0x88, 0x0, 0xa2, 0x0, 0x88, 0x0, 0x2a}, 02397 {0x0, 0x88, 0x0, 0xa2, 0x0, 0x88, 0x0, 0xaa}, 02398 {0x0, 0x88, 0x0, 0xaa, 0x0, 0x88, 0x0, 0xaa}, 02399 {0x0, 0xa8, 0x0, 0xaa, 0x0, 0x88, 0x0, 0xaa}, 02400 {0x0, 0xa8, 0x0, 0xaa, 0x0, 0x8a, 0x0, 0xaa}, 02401 {0x0, 0xa8, 0x0, 0xaa, 0x0, 0xaa, 0x0, 0xaa}, 02402 {0x0, 0xaa, 0x0, 0xaa, 0x0, 0xaa, 0x0, 0xaa}, 02403 {0x40, 0xaa, 0x0, 0xaa, 0x0, 0xaa, 0x0, 0xaa}, 02404 {0x40, 0xaa, 0x0, 0xaa, 0x4, 0xaa, 0x0, 0xaa}, 02405 {0x40, 0xaa, 0x0, 0xaa, 0x44, 0xaa, 0x0, 0xaa}, 02406 {0x44, 0xaa, 0x0, 0xaa, 0x44, 0xaa, 0x0, 0xaa}, 02407 {0x44, 0xaa, 0x10, 0xaa, 0x44, 0xaa, 0x0, 0xaa}, 02408 {0x44, 0xaa, 0x10, 0xaa, 0x44, 0xaa, 0x1, 0xaa}, 02409 {0x44, 0xaa, 0x10, 0xaa, 0x44, 0xaa, 0x11, 0xaa}, 02410 {0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11, 0xaa}, 02411 {0x44, 0xaa, 0x51, 0xaa, 0x44, 0xaa, 0x11, 0xaa}, 02412 {0x44, 0xaa, 0x51, 0xaa, 0x44, 0xaa, 0x15, 0xaa}, 02413 {0x44, 0xaa, 0x51, 0xaa, 0x44, 0xaa, 0x55, 0xaa}, 02414 {0x44, 0xaa, 0x55, 0xaa, 0x44, 0xaa, 0x55, 0xaa}, 02415 {0x54, 0xaa, 0x55, 0xaa, 0x44, 0xaa, 0x55, 0xaa}, 02416 {0x54, 0xaa, 0x55, 0xaa, 0x45, 0xaa, 0x55, 0xaa}, 02417 {0x54, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa}, 02418 {0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa}, 02419 {0xd5, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa}, 02420 {0xd5, 0xaa, 0x55, 0xaa, 0x5d, 0xaa, 0x55, 0xaa}, 02421 {0xd5, 0xaa, 0x55, 0xaa, 0xdd, 0xaa, 0x55, 0xaa}, 02422 {0xdd, 0xaa, 0x55, 0xaa, 0xdd, 0xaa, 0x55, 0xaa}, 02423 {0xdd, 0xaa, 0x75, 0xaa, 0xdd, 0xaa, 0x55, 0xaa}, 02424 {0xdd, 0xaa, 0x75, 0xaa, 0xdd, 0xaa, 0x57, 0xaa}, 02425 {0xdd, 0xaa, 0x75, 0xaa, 0xdd, 0xaa, 0x77, 0xaa}, 02426 {0xdd, 0xaa, 0x77, 0xaa, 0xdd, 0xaa, 0x77, 0xaa}, 02427 {0xdd, 0xaa, 0xf7, 0xaa, 0xdd, 0xaa, 0x77, 0xaa}, 02428 {0xdd, 0xaa, 0xf7, 0xaa, 0xdd, 0xaa, 0x7f, 0xaa}, 02429 {0xdd, 0xaa, 0xf7, 0xaa, 0xdd, 0xaa, 0xff, 0xaa}, 02430 {0xdd, 0xaa, 0xff, 0xaa, 0xdd, 0xaa, 0xff, 0xaa}, 02431 {0xfd, 0xaa, 0xff, 0xaa, 0xdd, 0xaa, 0xff, 0xaa}, 02432 {0xfd, 0xaa, 0xff, 0xaa, 0xdf, 0xaa, 0xff, 0xaa}, 02433 {0xfd, 0xaa, 0xff, 0xaa, 0xff, 0xaa, 0xff, 0xaa}, 02434 {0xff, 0xaa, 0xff, 0xaa, 0xff, 0xaa, 0xff, 0xaa}, 02435 {0xff, 0xea, 0xff, 0xaa, 0xff, 0xaa, 0xff, 0xaa}, 02436 {0xff, 0xea, 0xff, 0xaa, 0xff, 0xae, 0xff, 0xaa}, 02437 {0xff, 0xea, 0xff, 0xaa, 0xff, 0xee, 0xff, 0xaa}, 02438 {0xff, 0xee, 0xff, 0xaa, 0xff, 0xee, 0xff, 0xaa}, 02439 {0xff, 0xee, 0xff, 0xba, 0xff, 0xee, 0xff, 0xaa}, 02440 {0xff, 0xee, 0xff, 0xba, 0xff, 0xee, 0xff, 0xab}, 02441 {0xff, 0xee, 0xff, 0xba, 0xff, 0xee, 0xff, 0xbb}, 02442 {0xff, 0xee, 0xff, 0xbb, 0xff, 0xee, 0xff, 0xbb}, 02443 {0xff, 0xee, 0xff, 0xfb, 0xff, 0xee, 0xff, 0xbb}, 02444 {0xff, 0xee, 0xff, 0xfb, 0xff, 0xee, 0xff, 0xbf}, 02445 {0xff, 0xee, 0xff, 0xfb, 0xff, 0xee, 0xff, 0xff}, 02446 {0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xff, 0xff}, 02447 {0xff, 0xfe, 0xff, 0xff, 0xff, 0xee, 0xff, 0xff}, 02448 {0xff, 0xfe, 0xff, 0xff, 0xff, 0xef, 0xff, 0xff}, 02449 {0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 02450 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} 02451 }; 02452 void define_face_pattern ( 02453 HT_Display_Context alter * dc, 02454 int face_pattern, 02455 int user_pattern, 02456 int transparency_stipple = 0); 02457 02458 /***************************************************************************** 02459 ***************************************************************************** 02460 Category: Triangulation Helpers 02461 ***************************************************************************** 02462 *****************************************************************************/ 02463 /* 02464 * HELPER 02465 */ 02466 void callback_collect_triangles ( 02467 void * vp, 02468 int convex_triangulation, 02469 HT_Point const * p1, 02470 HT_Point const * p2, 02471 HT_Point const * p3, 02472 int s1, 02473 int s2, 02474 int s3, 02475 HT_Intersection const * i1, 02476 HT_Intersection const * i2, 02477 HT_Intersection const * i3); 02478 02479 02480 struct concave_tri 02481 { 02482 H3DData alter *h3ddata; 02483 bool doing_dc; 02484 union { 02485 HT_DC_Point const *dc; 02486 HT_Point const *threed; 02487 } points; 02488 union { 02489 H3DVertexBuffer *vb_dc; //hd3d_pt_clr* vb_dc; 02490 H3DVertexBuffer *vb_threed; //hd3d_pt* vb_threed; 02491 }; 02492 float normal[3]; 02493 HT_Driver_Color color; 02494 int triangle_count; 02495 int buffer_triangle_count; 02496 void (*draw_triangle) (void alter * info, 02497 HT_Integer32 convex_triangulation, 02498 HT_Point const * p1, 02499 HT_Point const * p2, 02500 HT_Point const * p3, 02501 HT_Integer32 v1, 02502 HT_Integer32 v2, 02503 HT_Integer32 v3, 02504 HT_Intersection const * i1, 02505 HT_Intersection const * i2, 02506 HT_Intersection const * i3); 02507 }; 02508 02509 /* 02510 * HELPER 02511 * TODO: Fix assumption is wrong for many cases 02512 * Note: this was written with the assumption that triangulation is expensive and that 02513 * it is preferable to do many color changes versus doing multiple triangulations. This 02514 * assumption may be invalid. SAVE triangles for patterned stuff! 02515 */ 02516 void draw_concave_face (HT_Net_Rendition const * nr, 02517 int count, struct concave_tri const * ct); 02518 02519 /* given a clip region defined in dc, draw everywhere else */ 02520 void everything_but_region (HT_Net_Rendition const *nr, 02521 int count, struct concave_tri * ct); 02522 02523 void draw_concave_polygon ( 02524 HT_Net_Rendition const *nr, 02525 HT_Polygon const *polygon); 02526 02527 /***************************************************************************** 02528 ***************************************************************************** 02529 Category: Begin/End Display List 02530 ***************************************************************************** 02531 *****************************************************************************/ 02532 void execute_display_list ( 02533 HT_Net_Rendition const *nr, 02534 HT_Display_List *dl); 02535 02536 void check_display_list( 02537 HT_Net_Rendition const *nr, 02538 HT_Display_List **dll, 02539 unsigned HT_Integer32 *mask); 02540 02541 void begin_display_list( 02542 HT_Net_Rendition const *nr, 02543 HT_Display_List **dll, 02544 unsigned HT_Integer32 *mask, 02545 bool compile_only); 02546 02547 void end_display_list( 02548 HT_Net_Rendition const *nr, 02549 HT_Display_List **dll, 02550 bool compile_only); 02551 02552 02553 /* Helpers */ 02554 #define HPARENT(i) ((i-1)/2) 02555 #define HLEFT(i) (2*i+1) 02556 #define HRIGHT(i) (2*i+2) 02557 02558 local void 02559 upheap (dlheap alter *heap, int i); 02560 02561 local void 02562 downheap(dlheap alter *heap, int i); 02563 02564 local void 02565 dlheapable_push ( 02566 dlheap alter *heap, 02567 dlheapable alter *dlh); 02568 02569 local dlheapable * 02570 dlheapable_pop (dlheap alter *heap); 02571 02572 void bless_display_lists (H3DData alter *h3ddata); 02573 02574 local bool 02575 check_segment_display_list_valid ( 02576 HT_Net_Rendition const *nr, 02577 HT_Display_List const *dl, 02578 H3D_Display_List const *segdl); 02579 02580 bool check_tristrip_display_list_valid ( 02581 HT_Net_Rendition const *nr, 02582 HT_Tristrip const *ts, 02583 HT_Display_List const *dl, 02584 H3D_Display_List const *odl); 02585 02586 02587 02588 02589 02590 /***************************************************************************** 02591 ***************************************************************************** 02592 Category: Actions 02593 ***************************************************************************** 02594 *****************************************************************************/ 02595 void draw_dc_rgb32_rasters (HT_Net_Rendition const * nr, 02596 HT_DC_Point const * start, 02597 HT_DC_Point const * end, 02598 int row_bytes, HT_RGBAS32 const * raster); 02599 02600 void draw_dc_rectangle ( 02601 HT_Net_Rendition const *nr, 02602 int left, 02603 int right, 02604 int bottom, 02605 int top); 02606 02607 void draw_dc_gouraud_polyline ( 02608 HT_Net_Rendition const * nr, 02609 int count_in, 02610 HT_DC_Point const *points_in, 02611 HT_RGBAS32 const *colors_in); 02612 void draw_dc_polyline ( 02613 HT_Net_Rendition const * nr, 02614 int count_in, 02615 HT_DC_Point const *points_in); 02616 02617 void draw_dc_polytriangle_helper ( 02618 HT_Net_Rendition const * nr, 02619 int count, 02620 HT_DC_Point const * points, 02621 HT_RGBAS32 const * colors, 02622 const int color_mode); 02623 void draw_dc_colorized_polytriangle ( 02624 HT_Net_Rendition const * nr, 02625 int count, 02626 HT_DC_Point const * points, 02627 HT_RGBAS32 const * colors, 02628 bool single); 02629 void draw_dc_polytriangle ( 02630 HT_Net_Rendition const * nr, 02631 int count, 02632 HT_DC_Point const * points); 02633 void draw_dc_gouraud_polytriangle ( 02634 HT_Net_Rendition const *nr, 02635 int count, 02636 HT_DC_Point const *points, 02637 HT_RGBAS32 const *colors); 02638 void draw_dc_textured_polytriangle ( 02639 HT_Net_Rendition const * nr, 02640 int count, 02641 HT_DC_Point const * points, 02642 HT_RGBA const * color, 02643 HT_Plane const * planes, 02644 HT_Parameter const * params, 02645 HT_Integer32 param_width, 02646 HT_Parameter_Flags param_flags); 02647 02648 void draw_dc_colorized_polydot ( 02649 HT_Net_Rendition const * nr, 02650 int count, 02651 HT_DC_Point const * points, 02652 HT_RGBAS32 const * colors, 02653 bool single); 02654 void draw_dc_polydot ( 02655 HT_Net_Rendition const * nr, 02656 int count, 02657 HT_DC_Point const * points); 02658 02659 02660 void draw_indexed_polyedge ( 02661 HT_Net_Rendition const * nr, 02662 HT_Polyedge const *pe); 02663 02664 void draw_3d_polymarker ( 02665 HT_Net_Rendition const * nr, 02666 HT_Polymarker const *pm); 02667 02668 void draw_3d_text ( 02669 HT_Net_Rendition const * nr, 02670 HT_Text const *text); 02671 02672 void draw_3d_grid ( 02673 HT_Net_Rendition const * nr, 02674 HT_Grid const *grid); 02675 02676 void draw_3d_image( 02677 HT_Net_Rendition const * nr, 02678 HT_Image const *image); 02679 02680 void really_draw_3d_polyedge_im ( 02681 HT_Net_Rendition const * nr, 02682 HT_Polyedge const *pe, 02683 HT_Line_Rendition const *er, 02684 H3DVertexFormat vf); 02685 02686 void really_draw_3d_polyedge ( 02687 HT_Net_Rendition const * nr, 02688 HT_Polyedge const *pe, 02689 HT_Line_Rendition const *er, 02690 H3D_Display_List_Bin *bin); 02691 02692 void draw_3d_polyedge ( 02693 HT_Net_Rendition const * nr, 02694 HT_Polyedge const *pe); 02695 02696 void draw_3d_polyline ( 02697 HT_Net_Rendition const * nr, 02698 HT_Polyline const *p); 02699 02700 void really_draw_indexed_tristrip ( 02701 HT_Net_Rendition const * nr, 02702 HT_Tristrip const * ts, 02703 H3D_Display_List_Bin * bin); 02704 02705 void draw_indexed_tristrip ( 02706 HT_Net_Rendition const * nr, 02707 HT_Tristrip const * ts); 02708 02709 void draw_3d_tristrip_im_strips( 02710 HT_Net_Rendition const *nr, 02711 HT_Tristrip const *ts, 02712 H3D_Display_List_Bin *bin, 02713 HT_Cutting_Plane_Set const *cut_set, 02714 H3DVertexFormat vf, 02715 H3D_Vertex_Buffer_Style buffer_style, 02716 int transparency_stipple = 0); 02717 02718 void draw_3d_tristrip_im_lists( 02719 HT_Net_Rendition const *nr, 02720 HT_Tristrip const *ts, 02721 H3D_Display_List_Bin *bin, 02722 HT_Cutting_Plane_Set const *cut_set, 02723 H3DVertexFormat vf, 02724 H3D_Vertex_Buffer_Style buffer_style, 02725 int transparency_stipple = 0); 02726 02727 void really_draw_3d_tristrip ( 02728 HT_Net_Rendition const * nr, 02729 HT_Tristrip const * ts, 02730 H3D_Display_List_Bin * bin); 02731 02732 void draw_3d_tristrip ( 02733 HT_Net_Rendition const * nr, 02734 HT_Tristrip const * ts); 02735 02736 void draw_3d_polygon ( 02737 HT_Net_Rendition const *inr, 02738 HT_Polygon const *polygon); 02739 02740 /***************************************************************************** 02741 ***************************************************************************** 02742 Category: Uncategorized 02743 ***************************************************************************** 02744 *****************************************************************************/ 02745 02746 //curve_metadata here is a little container so that we can link together 02747 // HD_Determine_Elliptical_Res computation results. Otherwise we'd have to 02748 // call it once before allocating and again to generate the points -- and 02749 // it can get to be kind of expensive. 02750 struct curve_metadata { 02751 int needed; //upper bound for allocation 02752 int count; //actual count 02753 HT_Point *points; 02754 }; 02755 02756 HT_Polyedge alter *lines_to_polyedge ( 02757 HT_Net_Rendition const *nr, 02758 HT_Geometry const *start_g); 02759 02760 /* 02761 * HELPER 02762 */ 02763 void linebin_to_edgebin ( 02764 HT_Net_Rendition const * nr, 02765 H3D_Display_List_Bin *bin); 02766 02767 /* Make a fake polyedge, push a given odl into it, and return 02768 * an odl of type H3D_DL_SEGMENT_POLYLINE to wrap it together with 02769 * information to determine whether or not it is still valid */ 02770 H3D_Display_List *edgeodl_to_lineodl ( 02771 HT_Net_Rendition const *nr, 02772 H3D_Display_List alter *odl); 02773 02774 02775 void destroy_list (HT_Display_Context alter *dc, void *list); 02776 02777 /* 02778 * ACTION 02779 */ 02780 void clear_z_buffer (HT_Net_Rendition const * nr, 02781 int left, int right, int bottom, int top); 02782 02783 02784 void render_3d_lines ( 02785 HT_Net_Rendition const * nr, 02786 HT_Geometry const * start_g, 02787 HT_Action_Mask mask); 02788 02789 void segment_render ( 02790 HT_Net_Rendition const * nr, 02791 HT_Geometry const * start_g, 02792 HT_Action_Mask mask, 02793 bool single); 02794 02795 02796 02797 /***************************************************************************** 02798 ***************************************************************************** 02799 Category: H3DActions Class 02800 02801 This class contains pointers to driver specific helper functions. 02802 ***************************************************************************** 02803 *****************************************************************************/ 02804 class H3DActions { 02805 protected: 02806 H3DData *m_h3ddata; 02807 02808 public: 02809 H3DActions(){}; 02810 H3DActions(H3DData *h3ddata) {m_h3ddata = h3ddata;}; 02811 02812 02813 public: 02814 #ifdef PURE_ABSTRACT 02815 virtual H3DVertexBufferCache* CreateVertexBufferCache() = 0; 02816 virtual H3DIndexBufferCache* CreateIndexBufferCache() = 0; 02817 virtual H3DIndexedBufferObject* CreateIndexedBufferObject() = 0; 02818 virtual H3DIndexedBufferObject* CreateMesh() 02819 { 02820 return CreateIndexedBufferObject(); 02821 } 02822 02823 virtual bool CreateTexture( 02824 unsigned int width, 02825 unsigned int height, 02826 unsigned int levels, 02827 unsigned int usage, 02828 H3DFORMAT z_format, 02829 H3DTexture **id) = 0; 02830 virtual void SetTexture(int unit, H3DTexture *id) = 0;; 02831 02832 virtual void SetViewport(H3DVIEWPORT const *hvp) = 0;; 02833 02834 virtual H3DShader* CreateShader(H3DShaderID id) = 0;; 02835 02836 virtual void Clear(int flags, int color, float z_value, int stencil_value) = 0;; 02837 02838 virtual void Begin_Trace(WCHAR *string) { UNREFERENCED(string);}; 02839 virtual void End_Trace() {}; 02840 02841 virtual bool bind_texture(HT_Net_Rendition const *nr, HT_Texture *txr, int usage, H3DTexture *id, int texture_unit) = 0;; 02842 02843 virtual void set_dc_xform (HT_Net_Rendition const *nr) = 0;; 02844 virtual void set_3d_xform (HT_Net_Rendition const *nr) = 0;; 02845 virtual void force_anti_alias (bool mode) = 0;; 02846 virtual void force_color_mask (bool mode) = 0;; 02847 virtual void force_culling (H3DCULL mode) = 0;; 02848 virtual void force_depth_mask (bool mode) = 0;; 02849 virtual void force_depth_range_set (float zmin, float zmax) = 0;; 02850 virtual void force_scissor (bool mode) = 0;; 02851 virtual void force_shade_mode (H3DSHADEMODE mode) = 0;; 02852 virtual void force_transparency (bool mode) = 0;; 02853 virtual void force_vf (H3DVertexFormat vf) = 0;; 02854 virtual void force_zbuffering (bool mode) = 0;; 02855 #else 02856 virtual H3DVertexBufferCache* CreateVertexBufferCache() {ABSTRACT_ERROR; return null;}; 02857 virtual H3DIndexBufferCache* CreateIndexBufferCache() {ABSTRACT_ERROR; return null;}; 02858 virtual H3DIndexedBufferObject* CreateIndexedBufferObject() {ABSTRACT_ERROR; return null;}; 02859 virtual H3DIndexedBufferObject* CreateMesh() 02860 { 02861 return CreateIndexedBufferObject(); 02862 } 02863 02864 virtual bool CreateTexture( 02865 unsigned int width, 02866 unsigned int height, 02867 unsigned int levels, 02868 unsigned int usage, 02869 H3DFORMAT z_format, 02870 H3DTexture **id) 02871 { 02872 ABSTRACT_ERROR; 02873 UNREFERENCED(width); 02874 UNREFERENCED(height); 02875 UNREFERENCED(levels); 02876 UNREFERENCED(usage); 02877 UNREFERENCED(z_format); 02878 UNREFERENCED(id); 02879 return false; 02880 }; 02881 virtual void SetTexture(int unit, H3DTexture *id) 02882 { 02883 ABSTRACT_ERROR; 02884 UNREFERENCED(unit); 02885 UNREFERENCED(id); 02886 } 02887 02888 virtual void SetViewport(H3DVIEWPORT const *hvp) 02889 { 02890 ABSTRACT_ERROR; 02891 UNREFERENCED(hvp); 02892 } 02893 02894 virtual H3DShader* CreateShader(H3DShaderID id) 02895 { 02896 ABSTRACT_ERROR; 02897 UNREFERENCED(id); 02898 return null; 02899 } 02900 02901 virtual void Clear(int flags, int color, float z_value, int stencil_value) 02902 { 02903 ABSTRACT_ERROR; 02904 UNREFERENCED(flags); 02905 UNREFERENCED(color); 02906 UNREFERENCED(z_value); 02907 UNREFERENCED(stencil_value); 02908 } 02909 02910 virtual void Begin_Trace(WCHAR *string) 02911 { 02912 ABSTRACT_ERROR; 02913 UNREFERENCED(string); 02914 } 02915 virtual void End_Trace() 02916 { 02917 ABSTRACT_ERROR; 02918 } 02919 02920 virtual bool bind_texture(HT_Net_Rendition const *nr, HT_Texture *txr, int usage, H3DTexture *id, int texture_unit) 02921 { 02922 ABSTRACT_ERROR; 02923 UNREFERENCED(nr); 02924 UNREFERENCED(txr); 02925 UNREFERENCED(usage); 02926 UNREFERENCED(id); 02927 UNREFERENCED(texture_unit); 02928 return false; 02929 } 02930 02931 virtual void set_dc_xform (HT_Net_Rendition const *nr) 02932 { 02933 ABSTRACT_ERROR; 02934 UNREFERENCED(nr); 02935 } 02936 virtual void set_3d_xform (HT_Net_Rendition const *nr) 02937 { 02938 ABSTRACT_ERROR; 02939 UNREFERENCED(nr); 02940 } 02941 virtual void force_anti_alias (bool mode) 02942 { 02943 ABSTRACT_ERROR; 02944 UNREFERENCED(mode); 02945 } 02946 virtual void force_color_mask (bool mode) 02947 { 02948 ABSTRACT_ERROR; 02949 UNREFERENCED(mode); 02950 } 02951 virtual void force_culling (H3DCULL mode) 02952 { 02953 ABSTRACT_ERROR; 02954 UNREFERENCED(mode); 02955 } 02956 virtual void force_depth_mask (bool mode) 02957 { 02958 ABSTRACT_ERROR; 02959 UNREFERENCED(mode); 02960 } 02961 virtual void force_depth_range_set (float zmin, float zmax) 02962 { 02963 ABSTRACT_ERROR; 02964 UNREFERENCED(zmin); 02965 UNREFERENCED(zmax); 02966 } 02967 virtual void force_scissor (bool mode) 02968 { 02969 ABSTRACT_ERROR; 02970 UNREFERENCED(mode); 02971 } 02972 virtual void force_shade_mode (H3DSHADEMODE mode) 02973 { 02974 ABSTRACT_ERROR; 02975 UNREFERENCED(mode); 02976 } 02977 virtual void force_transparency (bool mode) 02978 { 02979 ABSTRACT_ERROR; 02980 UNREFERENCED(mode); 02981 } 02982 virtual void force_vf (H3DVertexFormat vf) 02983 { 02984 ABSTRACT_ERROR; 02985 UNREFERENCED(vf); 02986 } 02987 virtual void force_zbuffering (bool mode) 02988 { 02989 ABSTRACT_ERROR; 02990 UNREFERENCED(mode); 02991 } 02992 #endif 02993 02994 }; 02995 02996 02997 #endif // H3DCOMMON_H 02998 02999