OpenBarnyard
 
Loading...
Searching...
No Matches
AWorldMesh.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "AWorldMesh.h"
4
6
7//-----------------------------------------------------------------------------
8// Enables memory debugging.
9// Note: Should be the last include!
10//-----------------------------------------------------------------------------
11#include <Core/TMemoryDebugOn.h>
12
14
16
21
23{
24 if ( !IsValidated() )
25 {
27
28 m_pVertexPool->Validate();
29 BaseClass::Validate();
30 }
31
32 return TTRUE;
33}
34
36{
37 BaseClass::Invalidate();
38}
39
41{
42 AModelLoader::DestroyMaterial( m_pMaterial );
43 DestroyResource();
44
45 BaseClass::OnDestroy();
46}
47
48void AWorldMesh::Create( TUINT32 a_uiFlags, TUINT16 a_uiMaxVertices )
49{
50 TASSERT( !IsCreated() );
51
52 m_uiMaxVertices = a_uiMaxVertices;
53 m_uiFlags = a_uiFlags;
54
55 if ( CreateResource() )
56 {
57 BaseClass::Create();
58 }
59 else
60 {
61 TASSERT( !"Couldn't create AWorldMesh" );
62 }
63}
64
66{
67 TASSERT( 0 == ( m_uiFlags & FLAG_LOCKED ) );
68
69 if ( m_pVertexPool->Lock( &a_rLockBuffer ) )
70 {
71 m_uiFlags |= FLAG_LOCKED;
72 return TTRUE;
73 }
74
75 return TFALSE;
76}
77
78void AWorldMesh::Unlock( TUINT32 a_uiNumVertices )
79{
80 TASSERT( 0 != ( m_uiFlags & FLAG_LOCKED ) );
81
82 if ( TINT16( a_uiNumVertices ) == -1 )
83 {
84 a_uiNumVertices = m_pVertexPool->GetNumVertices();
85 }
86
87 m_pVertexPool->Unlock( a_uiNumVertices );
88 m_uiFlags &= ~FLAG_LOCKED;
89}
90
95
96TBOOL AWorldMesh::CreateResource()
97{
99 TVALIDPTR( pVertexFactory );
100
101 m_pVertexPool = pVertexFactory->CreatePoolResource( m_uiMaxVertices, 1 );
102 m_pSubMeshes = new SubMesh[ NUM_SUBMESHES ];
103
104 return TTRUE;
105}
106
107void AWorldMesh::DestroyResource()
108{
109 if ( m_pVertexPool )
110 {
113 }
114
115 delete[] m_pSubMeshes;
117 m_uiFlags = 0;
118 m_uiMaxVertices = 0;
119}
@ SYSRESOURCE_VFWORLD
Definition TRender.h:14
Rendering system interface for the Toshi engine.
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
#define TVALIDPTR(PTR)
Definition Defines.h:139
#define TDEFINE_CLASS_NORUNTIME(...)
Definition TObject.h:138
uint16_t TUINT16
Definition Typedefs.h:15
int16_t TINT16
Definition Typedefs.h:14
#define TNULL
Definition Typedefs.h:23
uint32_t TUINT32
Definition Typedefs.h:13
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
T * GetSystemResource(SYSRESOURCE systemResource)
void DestroyResource(TResource *resource)
static TFORCEINLINE TRenderInterface * GetSingleton()
Definition TSingleton.h:49
static void DestroyMaterial(Toshi::TMaterial *a_pMaterial)
virtual TBOOL Lock(LockBuffer &a_rLockBuffer)
virtual void Invalidate() override
virtual void OnDestroy() override
virtual Toshi::TVertexPoolResourceInterface * GetVertexPool()
Toshi::TVertexPoolResourceInterface * m_pVertexPool
Definition AWorldMesh.h:54
static constexpr TUINT NUM_SUBMESHES
Definition AWorldMesh.h:19
virtual void Create(TUINT32 a_uiFlags, TUINT16 a_uiMaxVertices)
virtual void Unlock(TUINT32 a_uiNumVertices)
virtual TBOOL Validate() override
TUINT32 m_uiFlags
Definition AWorldMesh.h:52
Toshi::TVertexPoolResourceInterface::LockBuffer LockBuffer
Definition AWorldMesh.h:20
TUINT16 m_uiMaxVertices
Definition AWorldMesh.h:53
SubMesh * m_pSubMeshes
Definition AWorldMesh.h:55