Skip to content

Commit f936bdb

Browse files
unify(ww3d2): Merge dx8fvf, dx8indexbuffer, dx8vertexbuffer (TheSuperHackers#2690)
1 parent 0ff66c9 commit f936bdb

6 files changed

Lines changed: 86 additions & 25 deletions

File tree

Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8fvf.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@
1616
** along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
/***********************************************************************************************
20+
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21+
***********************************************************************************************
22+
* *
23+
* Project Name : ww3d *
24+
* *
25+
* $Archive:: /Commando/Code/ww3d2/dx8fvf.h $*
26+
* *
27+
* Original Author:: Jani Penttinen *
28+
* *
29+
* $Author:: Kenny Mitchell *
30+
* *
31+
* $Modtime:: 06/26/02 5:06p $*
32+
* *
33+
* $Revision:: 7 $*
34+
* *
35+
* 06/26/02 KM VB Vertex format update for shaders *
36+
* 07/17/02 KM VB Vertex format update for displacement mapping *
37+
* 08/01/02 KM VB Vertex format update for cube mapping *
38+
*---------------------------------------------------------------------------------------------*
39+
* Functions: *
40+
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41+
1942
#include "dx8fvf.h"
2043
#include "wwstring.h"
2144
#include <d3dx8core.h>

Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
* *
2929
* $Author:: Jani_p $*
3030
* *
31-
* $Modtime:: 7/10/01 1:30p $*
31+
* $Modtime:: 11/09/01 3:12p $*
3232
* *
33-
* $Revision:: 22 $*
33+
* $Revision:: 26 $*
3434
* *
3535
*---------------------------------------------------------------------------------------------*
3636
* Functions: *
@@ -43,6 +43,7 @@
4343
#include "dx8caps.h"
4444
#include "sphere.h"
4545
#include "thread.h"
46+
#include "wwmemlog.h"
4647

4748
#define DEFAULT_IB_SIZE 5000
4849

@@ -292,13 +293,45 @@ DX8IndexBufferClass::DX8IndexBufferClass(unsigned short index_count_,UsageType u
292293
((usage&USAGE_DYNAMIC) ? D3DUSAGE_DYNAMIC : 0)|
293294
((usage&USAGE_NPATCHES) ? D3DUSAGE_NPATCHES : 0)|
294295
((usage&USAGE_SOFTWAREPROCESSING) ? D3DUSAGE_SOFTWAREPROCESSING : 0);
296+
if (!DX8Wrapper::Get_Current_Caps()->Support_TnL()) {
297+
usage_flags|=D3DUSAGE_SOFTWAREPROCESSING;
298+
}
295299

296-
DX8CALL(CreateIndexBuffer(
300+
HRESULT ret=DX8Wrapper::_Get_D3D_Device8()->CreateIndexBuffer(
297301
sizeof(WORD)*index_count,
298302
usage_flags,
299303
D3DFMT_INDEX16,
300304
(usage&USAGE_DYNAMIC) ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED,
301-
&index_buffer));
305+
&index_buffer);
306+
307+
if (SUCCEEDED(ret)) {
308+
return;
309+
}
310+
311+
WWDEBUG_SAY(("Index buffer creation failed, trying to release assets..."));
312+
313+
// Index buffer creation failed, so try releasing least used textures and flushing the mesh cache.
314+
315+
// Free all textures that haven't been used in the last 5 seconds
316+
TextureClass::Invalidate_Old_Unused_Textures(5000);
317+
318+
// Invalidate the mesh cache
319+
WW3D::_Invalidate_Mesh_Cache();
320+
321+
// Try again...
322+
ret=DX8Wrapper::_Get_D3D_Device8()->CreateIndexBuffer(
323+
sizeof(WORD)*index_count,
324+
usage_flags,
325+
D3DFMT_INDEX16,
326+
(usage&USAGE_DYNAMIC) ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED,
327+
&index_buffer);
328+
329+
if (SUCCEEDED(ret)) {
330+
WWDEBUG_SAY(("...Index buffer creation successful"));
331+
}
332+
333+
// If it still fails it is fatal
334+
DX8_ErrorCode(ret);
302335
}
303336

304337
// ----------------------------------------------------------------------------
@@ -318,6 +351,7 @@ SortingIndexBufferClass::SortingIndexBufferClass(unsigned short index_count_)
318351
:
319352
IndexBufferClass(BUFFER_TYPE_SORTING,index_count_)
320353
{
354+
WWMEMLOG(MEM_RENDERER);
321355
WWASSERT(index_count);
322356

323357
index_buffer=W3DNEWARRAY unsigned short[index_count];
@@ -438,6 +472,7 @@ DynamicIBAccessClass::WriteLockClass::~WriteLockClass()
438472

439473
void DynamicIBAccessClass::Allocate_DX8_Dynamic_Buffer()
440474
{
475+
WWMEMLOG(MEM_RENDERER);
441476
WWASSERT(!_DynamicDX8IndexBufferInUse);
442477
_DynamicDX8IndexBufferInUse=true;
443478

@@ -473,6 +508,7 @@ void DynamicIBAccessClass::Allocate_DX8_Dynamic_Buffer()
473508

474509
void DynamicIBAccessClass::Allocate_Sorting_Dynamic_Buffer()
475510
{
511+
WWMEMLOG(MEM_RENDERER);
476512
WWASSERT(!_DynamicSortingIndexArrayInUse);
477513
_DynamicSortingIndexArrayInUse=true;
478514

Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
* *
2727
* Original Author:: Jani Penttinen *
2828
* *
29-
* $Author:: Jani_p $*
29+
* $Author:: Kenny Mitchell *
3030
* *
31-
* $Modtime:: 7/10/01 1:33p $*
31+
* $Modtime:: 06/26/02 5:06p $*
3232
* *
33-
* $Revision:: 34 $*
33+
* $Revision:: 39 $*
3434
* *
35+
* 06/26/02 KM VB Vertex format size update for shaders *
3536
*---------------------------------------------------------------------------------------------*
3637
* Functions: *
3738
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
@@ -43,6 +44,7 @@
4344
#include "dx8fvf.h"
4445
#include "dx8caps.h"
4546
#include "thread.h"
47+
#include "wwmemlog.h"
4648
#include <d3dx8core.h>
4749

4850
#define DEFAULT_VB_SIZE 5000
@@ -78,6 +80,7 @@ VertexBufferClass::VertexBufferClass(unsigned type_, unsigned FVF, unsigned shor
7880
type(type_),
7981
engine_refs(0)
8082
{
83+
WWMEMLOG(MEM_RENDERER);
8184
WWASSERT(VertexCount);
8285
WWASSERT(type==BUFFER_TYPE_DX8 || type==BUFFER_TYPE_SORTING);
8386
WWASSERT(FVF != 0);
@@ -284,6 +287,7 @@ SortingVertexBufferClass::SortingVertexBufferClass(unsigned short VertexCount)
284287
:
285288
VertexBufferClass(BUFFER_TYPE_SORTING, dynamic_fvf_type, VertexCount)
286289
{
290+
WWMEMLOG(MEM_RENDERER);
287291
VertexBuffer=W3DNEWARRAY VertexFormatXYZNDUV2[VertexCount];
288292
}
289293

@@ -420,10 +424,10 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)
420424
WWDEBUG_SAY(("CreateVertexBuffer(fvfsize=%d, vertex_count=%d, D3DUSAGE_WRITEONLY|%s|%s, fvf: %s, %s)",
421425
FVF_Info().Get_FVF_Size(),
422426
VertexCount,
423-
usage&USAGE_DYNAMIC ? "D3DUSAGE_DYNAMIC" : "-",
424-
usage&USAGE_SOFTWAREPROCESSING ? "D3DUSAGE_SOFTWAREPROCESSING" : "-",
427+
(usage&USAGE_DYNAMIC) ? "D3DUSAGE_DYNAMIC" : "-",
428+
(usage&USAGE_SOFTWAREPROCESSING) ? "D3DUSAGE_SOFTWAREPROCESSING" : "-",
425429
fvf_name,
426-
dynamic ? "D3DPOOL_DEFAULT" : "D3DPOOL_MANAGED"));
430+
(usage&USAGE_DYNAMIC) ? "D3DPOOL_DEFAULT" : "D3DPOOL_MANAGED"));
427431
_DX8VertexBufferCount++;
428432
WWDEBUG_SAY(("Current vertex buffer count: %d",_DX8VertexBufferCount));
429433
#endif
@@ -433,7 +437,6 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)
433437
((usage&USAGE_DYNAMIC) ? D3DUSAGE_DYNAMIC : 0)|
434438
((usage&USAGE_NPATCHES) ? D3DUSAGE_NPATCHES : 0)|
435439
((usage&USAGE_SOFTWAREPROCESSING) ? D3DUSAGE_SOFTWAREPROCESSING : 0);
436-
437440
// New Code
438441
if (!DX8Wrapper::Get_Current_Caps()->Support_TnL()) {
439442
usage_flags|=D3DUSAGE_SOFTWAREPROCESSING;
@@ -451,8 +454,10 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)
451454

452455
WWDEBUG_SAY(("Vertex buffer creation failed, trying to release assets..."));
453456

454-
// Vertex buffer creation failed. Must be out of memory. Try releasing all our D3D assets and re-creating
455-
// them.
457+
// Vertex buffer creation failed, so try releasing least used textures and flushing the mesh cache.
458+
459+
// Free all textures that haven't been used in the last 5 seconds
460+
TextureClass::Invalidate_Old_Unused_Textures(5000);
456461

457462
// Invalidate the mesh cache
458463
WW3D::_Invalidate_Mesh_Cache();
@@ -759,6 +764,7 @@ void DynamicVBAccessClass::_Deinit()
759764

760765
void DynamicVBAccessClass::Allocate_DX8_Dynamic_Buffer()
761766
{
767+
WWMEMLOG(MEM_RENDERER);
762768
WWASSERT(!_DynamicDX8VertexBufferInUse);
763769
_DynamicDX8VertexBufferInUse=true;
764770

@@ -795,6 +801,7 @@ void DynamicVBAccessClass::Allocate_DX8_Dynamic_Buffer()
795801

796802
void DynamicVBAccessClass::Allocate_Sorting_Dynamic_Buffer()
797803
{
804+
WWMEMLOG(MEM_RENDERER);
798805
WWASSERT(!_DynamicSortingVertexArrayInUse);
799806
_DynamicSortingVertexArrayInUse=true;
800807

Generals/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
* *
2727
* Original Author:: Jani Penttinen *
2828
* *
29-
* $Author:: Jani_p $*
29+
* $Author:: Kenny Mitchell *
3030
* *
31-
* $Modtime:: 7/09/01 8:15p $*
31+
* $Modtime:: 06/26/02 5:06p $*
3232
* *
33-
* $Revision:: 25 $*
33+
* $Revision:: 26 $*
3434
* *
35+
* 06/26/02 KM VB Vertex format size update for shaders *
3536
*---------------------------------------------------------------------------------------------*
3637
* Functions: *
3738
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8indexbuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ DX8IndexBufferClass::DX8IndexBufferClass(unsigned short index_count_,UsageType u
310310

311311
WWDEBUG_SAY(("Index buffer creation failed, trying to release assets..."));
312312

313-
// Vertex buffer creation failed, so try releasing least used textures and flushing the mesh cache.
313+
// Index buffer creation failed, so try releasing least used textures and flushing the mesh cache.
314314

315315
// Free all textures that haven't been used in the last 5 seconds
316316
TextureClass::Invalidate_Old_Unused_Textures(5000);

GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx8vertexbuffer.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,6 @@ void DX8VertexBufferClass::Create_Vertex_Buffer(UsageType usage)
437437
((usage&USAGE_DYNAMIC) ? D3DUSAGE_DYNAMIC : 0)|
438438
((usage&USAGE_NPATCHES) ? D3DUSAGE_NPATCHES : 0)|
439439
((usage&USAGE_SOFTWAREPROCESSING) ? D3DUSAGE_SOFTWAREPROCESSING : 0);
440-
if (!DX8Wrapper::Get_Current_Caps()->Support_TnL()) {
441-
usage_flags|=D3DUSAGE_SOFTWAREPROCESSING;
442-
}
443-
444440
// New Code
445441
if (!DX8Wrapper::Get_Current_Caps()->Support_TnL()) {
446442
usage_flags|=D3DUSAGE_SOFTWAREPROCESSING;
@@ -836,7 +832,7 @@ DynamicVBAccessClass::WriteLockClass::WriteLockClass(DynamicVBAccessClass* dynam
836832
switch (DynamicVBAccess->Get_Type()) {
837833
case BUFFER_TYPE_DYNAMIC_DX8:
838834
#ifdef VERTEX_BUFFER_LOG
839-
/* {
835+
{
840836
WWASSERT(!dx8_lock);
841837
dx8_lock++;
842838
StringClass fvf_name;
@@ -847,7 +843,6 @@ DynamicVBAccessClass::WriteLockClass::WriteLockClass(DynamicVBAccessClass* dynam
847843
DynamicVBAccess->VertexBuffer->FVF_Info().Get_FVF_Size(),
848844
fvf_name));
849845
}
850-
*/
851846
#endif
852847
WWASSERT(_DynamicDX8VertexBuffer);
853848
// WWASSERT(!_DynamicDX8VertexBuffer->Engine_Refs());
@@ -879,10 +874,9 @@ DynamicVBAccessClass::WriteLockClass::~WriteLockClass()
879874
switch (DynamicVBAccess->Get_Type()) {
880875
case BUFFER_TYPE_DYNAMIC_DX8:
881876
#ifdef VERTEX_BUFFER_LOG
882-
/* dx8_lock--;
877+
dx8_lock--;
883878
WWASSERT(!dx8_lock);
884879
WWDEBUG_SAY(("DynamicVertexBuffer->Unlock()"));
885-
*/
886880
#endif
887881
DX8_Assert();
888882
DX8_ErrorCode(static_cast<DX8VertexBufferClass*>(DynamicVBAccess->VertexBuffer)->Get_DX8_Vertex_Buffer()->Unlock());

0 commit comments

Comments
 (0)