78 auto& vertexFormat =
m_pFactory->GetVertexFormat();
79 m_HALBuffer.uiNumStreams = vertexFormat.m_uiNumStreams;
83 UINT length = vertexFormat.m_aStreamFormats[ i ].m_uiVertexSize *
m_uiMaxVertices;
84 DWORD usage = D3DUSAGE_WRITEONLY;
88 usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
92 if ( !pRenderer->GetCurrentDevice()->SupportsHardwareTransfomations() )
94 usage |= D3DUSAGE_SOFTWAREPROCESSING;
97 HRESULT hRes = pRenderer->GetDirect3DDevice()->CreateVertexBuffer(
101 (
m_uiFlags & 1 ) ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT,
105 if ( FAILED( hRes ) )
115 s_iCurrentNumHALCreated += 1;
116 s_iTotalNumHALCreated += 1;
117 s_iTotalVertexBufferBytesAllocated += length;
118 s_iCurrentVertexBufferBytesAllocated += length;
120 if ( s_iTotalVertexBufferBytesAllocated < s_iHALMemoryUsage )
122 s_iWastedVertexBufferBytesAllocated = s_iHALMemoryUsage - s_iTotalVertexBufferBytesAllocated;
141 s_iCurrentNumHALCreated -= 1;
142 s_iTotalNumHALDestroyed += 1;
143 s_iCurrentVertexBufferBytesAllocated -=
m_pFactory->GetVertexFormat().m_aStreamFormats[ i ].m_uiVertexSize *
m_uiMaxVertices;
150 s_iHALMemoryUsage = s_iHALMemoryUsage - memInfoHAL.
m_uiMemUsage;
152 if ( s_iTotalVertexBufferBytesAllocated < s_iHALMemoryUsage )
154 s_iWastedVertexBufferBytesAllocated = s_iHALMemoryUsage - s_iTotalVertexBufferBytesAllocated;
209 if (
Lock( &pair.second, 0 ) )
214 [](
TResource* a_pResource,
void* a_pUserData ) {
220 auto pFactory = pPool->GetFactory();
221 auto vertexFormat = pFactory->GetVertexFormat();
223 if ( pPool->m_uiFlags & 1 )
225 pPool->m_uiVertexOffset = pPair->second.uiOffset;
226 pPair->second.uiOffset += pPool->GetNumVertices();
228 for (
TUINT i = 0; i < vertexFormat.GetNumStreams(); i++ )
230 auto uiVertexSize = vertexFormat.m_aStreamFormats[ i ].m_uiVertexSize;
233 pPair->second.apStreams[ i ] + pPool->m_uiVertexOffset * uiVertexSize,
234 pPool->GetManagedStream( i ),
235 pPool->GetNumVertices() * uiVertexSize
271 auto& vertexFormat =
m_pFactory->GetVertexFormat();
272 a_pLockBuffer->
uiNumStreams = vertexFormat.m_uiNumStreams;
275 TUINT uiNumVertices = 0;
280 uiFlags = D3DLOCK_NOSYSLOCK;
293 uiNumVertices = a_uiNumVertices;
297 uiFlags = D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK;
303 uiFlags = D3DLOCK_NOOVERWRITE | D3DLOCK_NOSYSLOCK;
311 uiFlags = D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK;
318 HRESULT hRes =
m_HALBuffer.apVertexBuffers[ i ]->Lock(
319 a_pLockBuffer->
uiOffset * vertexFormat.m_aStreamFormats[ i ].m_uiVertexSize,
320 uiNumVertices * vertexFormat.m_aStreamFormats[ i ].m_uiVertexSize,
325 if ( FAILED( hRes ) )
342 for (
TUINT i = 0; i <
m_pFactory->GetVertexFormat().m_uiNumStreams; i++ )
344 HRESULT hRes =
m_HALBuffer.apVertexBuffers[ i ]->Unlock();
346 if ( FAILED( hRes ) )
#define TSTATICCAST(POINTERTYPE, VALUE)
#define TOSHI_NAMESPACE_START
#define TOSHI_NAMESPACE_END
#define TDEFINE_FREELIST_ALLOCATOR(CLASS_NAME)
#define TDEFINE_CLASS(...)
static void GetHALMemInfo(HALMemInfo &a_rHALMemInfo)
Hardware abstraction layer memory information.
TSIZE m_uiMemUsage
Total memory usage.
static void PrintError(TINT32 a_eError, const TCHAR *a_szInfo)
Prints error text caused by some directx call.
static TFORCEINLINE TRenderD3DInterface * Interface()
Gets the render interface singleton.
virtual TBOOL Validate() override
virtual TBOOL TryInvalidate() override
TBOOL GetHALBuffer(HALBuffer *a_pHALBuffer) const
TVertexFactoryResourceInterface * m_pFactory
TBOOL Lock(TVertexPoolResourceInterface::LockBuffer *a_pLockBuffer, TUINT16 a_uiNumVertices)
TBOOL AttachPool(TVertexPoolResource *a_pPool)
void ChildVertexUsedChanged(TINT a_iChange)
virtual void Invalidate() override
TBOOL DettachPool(TVertexPoolResource *a_pPool)
TBOOL CanFit(TVertexPoolResource *a_pPoolResource) const
virtual TBOOL TryValidate() override
IDirect3DVertexBuffer8 * apVertexBuffers[TVertexFactoryFormat::MAX_NUM_STREAMS]
void DestroyResource(TResource *resource)
virtual void Invalidate()
void SetParent(TResource *a_pParent)
TBOOL RecurseSimple(t_RecurseCb a_pCallback, TResource *a_pResource, void *a_pUserData)
TRenderInterface * GetRenderer() const
TUINT16 GetNumVertices() const
TBYTE * apStreams[TVertexFactoryFormat::MAX_NUM_STREAMS]
TNodeTree< T > * Tree() const
TBOOL IsExactly(TClass *a_pClass)
static void * MemCopy(void *dst, const void *src, TSIZE size)