48#define DEFAULT_IB_SIZE 5000
50static bool _DynamicSortingIndexArrayInUse=
false;
52static unsigned short _DynamicSortingIndexArraySize=0;
53static unsigned short _DynamicSortingIndexArrayOffset=0;
55static bool _DynamicDX8IndexBufferInUse=
false;
58static unsigned short _DynamicDX8IndexBufferOffset=0;
60static int _IndexBufferCount;
61static int _IndexBufferTotalIndices;
62static int _IndexBufferTotalSize;
81 _IndexBufferTotalSize+=
index_count*
sizeof(
unsigned short);
82#ifdef VERTEX_BUFFER_LOG
84 WWDEBUG_SAY((
"Total IB count: %d, total %d indices, total size %d bytes\n",
86 _IndexBufferTotalIndices,
87 _IndexBufferTotalSize));
95 _IndexBufferTotalSize-=
index_count*
sizeof(
unsigned short);
96#ifdef VERTEX_BUFFER_LOG
98 WWDEBUG_SAY((
"Total IB count: %d, total %d indices, total size %d bytes\n",
100 _IndexBufferTotalIndices,
101 _IndexBufferTotalSize));
107 return _IndexBufferCount;
112 return _IndexBufferTotalIndices;
117 return _IndexBufferTotalSize;
144 for (
unsigned v=0;v<count;++v) {
145 *inds++=
unsigned short(*indices++);
151 for (
unsigned v=0;v<count;++v) {
152 *inds++=
unsigned short(*indices++);
166 for (
unsigned v=0;v<count;++v) {
173 for (
unsigned v=0;v<count;++v) {
189 WWASSERT(!index_buffer->Engine_Refs());
190 index_buffer->Add_Ref();
191 switch (index_buffer->Type()) {
196 index_buffer->Get_Index_Count()*
sizeof(
WORD),
197 (
unsigned char**)&indices,
217 switch (index_buffer->Type()) {
228 index_buffer->Release_Ref();
235 index_buffer(index_buffer_)
240 WWASSERT(!index_buffer->Engine_Refs());
241 index_buffer->Add_Ref();
242 switch (index_buffer->Type()) {
246 start_index*
sizeof(
unsigned short),
247 index_range*
sizeof(
unsigned short),
248 (
unsigned char**)&indices,
265 switch (index_buffer->Type()) {
276 index_buffer->Release_Ref();
291 unsigned usage_flags=
297 usage_flags|=D3DUSAGE_SOFTWAREPROCESSING;
307 if (SUCCEEDED(ret)) {
311 WWDEBUG_SAY((
"Index buffer creation failed, trying to release assets...\n"));
329 if (SUCCEEDED(ret)) {
330 WWDEBUG_SAY((
"...Index buffer creation succesful\n"));
341 index_buffer->Release();
375 IndexCount(index_count_),
381 Allocate_DX8_Dynamic_Buffer();
384 Allocate_Sorting_Dynamic_Buffer();
392 _DynamicDX8IndexBufferInUse=
false;
393 _DynamicDX8IndexBufferOffset+=IndexCount;
396 _DynamicSortingIndexArrayInUse=
false;
397 _DynamicSortingIndexArrayOffset+=IndexCount;
403 WWASSERT ((_DynamicDX8IndexBuffer ==
NULL) || (_DynamicDX8IndexBuffer->Num_Refs() == 1));
405 _DynamicDX8IndexBufferInUse=
false;
407 _DynamicDX8IndexBufferOffset=0;
409 WWASSERT ((_DynamicSortingIndexArray ==
NULL) || (_DynamicSortingIndexArray->Num_Refs() == 1));
411 _DynamicSortingIndexArrayInUse=
false;
412 _DynamicSortingIndexArraySize=0;
413 _DynamicSortingIndexArrayOffset=0;
424 DynamicIBAccess(ib_access_)
427 DynamicIBAccess->IndexBuffer->Add_Ref();
428 switch (DynamicIBAccess->Get_Type()) {
435 DynamicIBAccess->IndexBufferOffset*
sizeof(
WORD),
436 DynamicIBAccess->Get_Index_Count()*
sizeof(
WORD),
437 (
unsigned char**)&Indices,
438 !DynamicIBAccess->IndexBufferOffset ? D3DLOCK_DISCARD : D3DLOCK_NOOVERWRITE));
442 Indices+=DynamicIBAccess->IndexBufferOffset;
453 switch (DynamicIBAccess->Get_Type()) {
464 DynamicIBAccess->IndexBuffer->Release_Ref();
473void DynamicIBAccessClass::Allocate_DX8_Dynamic_Buffer()
476 WWASSERT(!_DynamicDX8IndexBufferInUse);
477 _DynamicDX8IndexBufferInUse=
true;
481 if (IndexCount>_DynamicDX8IndexBufferSize) {
483 _DynamicDX8IndexBufferSize=IndexCount;
488 if (!_DynamicDX8IndexBuffer) {
494 _DynamicDX8IndexBuffer=
NEW_REF(DX8IndexBufferClass,(
495 _DynamicDX8IndexBufferSize,
497 _DynamicDX8IndexBufferOffset=0;
501 if (((
unsigned)IndexCount+_DynamicDX8IndexBufferOffset)>_DynamicDX8IndexBufferSize) {
502 _DynamicDX8IndexBufferOffset=0;
506 IndexBufferOffset=_DynamicDX8IndexBufferOffset;
509void DynamicIBAccessClass::Allocate_Sorting_Dynamic_Buffer()
512 WWASSERT(!_DynamicSortingIndexArrayInUse);
513 _DynamicSortingIndexArrayInUse=
true;
515 unsigned new_index_count=_DynamicSortingIndexArrayOffset+IndexCount;
517 if (new_index_count>_DynamicSortingIndexArraySize) {
519 _DynamicSortingIndexArraySize=new_index_count;
523 if (!_DynamicSortingIndexArray) {
524 _DynamicSortingIndexArray=
NEW_REF(SortingIndexBufferClass,(_DynamicSortingIndexArraySize));
525 _DynamicSortingIndexArrayOffset=0;
528 REF_PTR_SET(IndexBuffer,_DynamicSortingIndexArray);
529 IndexBufferOffset=_DynamicSortingIndexArrayOffset;
534 _DynamicSortingIndexArrayOffset=0;
535 if (frame_changed) _DynamicDX8IndexBufferOffset=0;
540 return _DynamicDX8IndexBufferSize;
549 b += _IndexBufferTotalIndices;
DX8IndexBufferClass(unsigned short index_count, UsageType usage=USAGE_DEFAULT)
@ USAGE_SOFTWAREPROCESSING
IDirect3DIndexBuffer8 * Get_DX8_Index_Buffer()
static IDirect3DDevice8 * _Get_D3D_Device8()
static const DX8Caps * Get_Current_Caps()
WriteLockClass(DynamicIBAccessClass *ib_access)
static unsigned short Get_Default_Index_Count(void)
current size of dynamic index buffer
static void _Reset(bool frame_changed)
DynamicIBAccessClass(unsigned short type, unsigned short index_count)
AppendLockClass(IndexBufferClass *index_buffer, unsigned start_index, unsigned index_range)
unsigned short * Get_Index_Array()
unsigned short * Get_Index_Array()
WriteLockClass(IndexBufferClass *index_buffer, int flags=0)
void Release_Engine_Ref() const
IndexBufferClass(unsigned type, unsigned short index_count)
static unsigned Get_Total_Allocated_Memory()
virtual ~IndexBufferClass()
static unsigned Get_Total_Buffer_Count()
unsigned short Get_Index_Count() const
static unsigned Get_Total_Allocated_Indices()
void Copy(unsigned int *indices, unsigned start_index, unsigned index_count)
void Add_Engine_Ref() const
unsigned short index_count
~SortingIndexBufferClass()
SortingIndexBufferClass(unsigned short index_count)
unsigned short * index_buffer
static void Invalidate_Old_Unused_Textures(unsigned inactive_time_override)
Invalidate old unused textures.
static void _Invalidate_Mesh_Cache()
int IndexBufferExceptionFunc(void)
@ BUFFER_TYPE_DYNAMIC_DX8
@ BUFFER_TYPE_DYNAMIC_SORTING
#define DX8_THREAD_ASSERT()
WWINLINE void DX8_ErrorCode(unsigned res)
#define REF_PTR_RELEASE(x)
#define REF_PTR_SET(dst, src)
#define WWMEMLOG(category)