Added immutable vertex and index buffers.

This commit is contained in:
Dušan Jocić 2016-02-20 21:28:18 +01:00
parent d08c0df85d
commit 28d303c5ea
13 changed files with 98 additions and 32 deletions

View file

@ -731,7 +731,8 @@ void GFXD3D9Device::setShader( GFXShader *shader, bool force )
//-----------------------------------------------------------------------------
GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
U32 numPrimitives,
GFXBufferType bufferType )
GFXBufferType bufferType,
void* data )
{
// Allocate a buffer to return
GFXD3D9PrimitiveBuffer * res = new GFXD3D9PrimitiveBuffer(this, numIndices, numPrimitives, bufferType);
@ -741,12 +742,13 @@ GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
D3DPOOL pool = D3DPOOL_DEFAULT;
// Assumptions:
// - static buffers are write once, use many
// - static buffers are write rarely, use many
// - dynamic buffers are write many, use many
// - volatile buffers are write once, use once
// You may never read from a buffer.
switch(bufferType)
{
case GFXBufferTypeImmutable:
case GFXBufferTypeStatic:
pool = isD3D9Ex() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
break;
@ -781,6 +783,14 @@ GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
D3D9Assert(mD3DDevice->CreateIndexBuffer( sizeof(U16) * numIndices , usage, GFXD3D9IndexFormat[GFXIndexFormat16], pool, &res->ib, 0),
"Failed to allocate an index buffer.");
}
if(data)
{
void* dest;
res->lock(0, numIndices, &dest);
dMemcpy(dest, data, sizeof(U16) * numIndices);
res->unlock();
}
return res;
}
@ -791,7 +801,8 @@ GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertSize,
GFXBufferType bufferType )
GFXBufferType bufferType,
void* data)
{
PROFILE_SCOPE( GFXD3D9Device_allocVertexBuffer );
@ -808,7 +819,7 @@ GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts,
res->mNumVerts = 0;
// Assumptions:
// - static buffers are write once, use many
// - static buffers are write rarely, use many
// - dynamic buffers are write many, use many
// - volatile buffers are write once, use once
// You may never read from a buffer.
@ -850,6 +861,15 @@ GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts,
}
res->mNumVerts = numVerts;
if(data)
{
void* dest;
res->lock(0, numVerts, &dest);
dMemcpy(dest, data, vertSize * numVerts);
res->unlock();
}
return res;
}

View file

@ -298,10 +298,12 @@ public:
virtual GFXVertexBuffer* allocVertexBuffer( U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertSize,
GFXBufferType bufferType );
GFXBufferType bufferType,
void* data = NULL );
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
U32 numPrimitives,
GFXBufferType bufferType );
GFXBufferType bufferType,
void* data = NULL );
virtual void deallocVertexBuffer( GFXD3D9VertexBuffer *vertBuff );
virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat );
virtual void setVertexDecl( const GFXVertexDecl *decl );

View file

@ -31,6 +31,7 @@ void GFXD3D9PrimitiveBuffer::lock(U32 indexStart, U32 indexEnd, void **indexPtr)
U32 flags=0;
switch(mBufferType)
{
case GFXBufferTypeImmutable:
case GFXBufferTypeStatic:
// flags |= D3DLOCK_DISCARD;
break;