mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 00:24:40 +00:00
Added immutable vertex and index buffers.
This commit is contained in:
parent
d08c0df85d
commit
28d303c5ea
13 changed files with 98 additions and 32 deletions
|
|
@ -731,7 +731,8 @@ void GFXD3D9Device::setShader( GFXShader *shader, bool force )
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
|
GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
|
||||||
U32 numPrimitives,
|
U32 numPrimitives,
|
||||||
GFXBufferType bufferType )
|
GFXBufferType bufferType,
|
||||||
|
void* data )
|
||||||
{
|
{
|
||||||
// Allocate a buffer to return
|
// Allocate a buffer to return
|
||||||
GFXD3D9PrimitiveBuffer * res = new GFXD3D9PrimitiveBuffer(this, numIndices, numPrimitives, bufferType);
|
GFXD3D9PrimitiveBuffer * res = new GFXD3D9PrimitiveBuffer(this, numIndices, numPrimitives, bufferType);
|
||||||
|
|
@ -741,12 +742,13 @@ GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
|
||||||
D3DPOOL pool = D3DPOOL_DEFAULT;
|
D3DPOOL pool = D3DPOOL_DEFAULT;
|
||||||
|
|
||||||
// Assumptions:
|
// Assumptions:
|
||||||
// - static buffers are write once, use many
|
// - static buffers are write rarely, use many
|
||||||
// - dynamic buffers are write many, use many
|
// - dynamic buffers are write many, use many
|
||||||
// - volatile buffers are write once, use once
|
// - volatile buffers are write once, use once
|
||||||
// You may never read from a buffer.
|
// You may never read from a buffer.
|
||||||
switch(bufferType)
|
switch(bufferType)
|
||||||
{
|
{
|
||||||
|
case GFXBufferTypeImmutable:
|
||||||
case GFXBufferTypeStatic:
|
case GFXBufferTypeStatic:
|
||||||
pool = isD3D9Ex() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
|
pool = isD3D9Ex() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
|
||||||
break;
|
break;
|
||||||
|
|
@ -781,6 +783,14 @@ GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
|
||||||
D3D9Assert(mD3DDevice->CreateIndexBuffer( sizeof(U16) * numIndices , usage, GFXD3D9IndexFormat[GFXIndexFormat16], pool, &res->ib, 0),
|
D3D9Assert(mD3DDevice->CreateIndexBuffer( sizeof(U16) * numIndices , usage, GFXD3D9IndexFormat[GFXIndexFormat16], pool, &res->ib, 0),
|
||||||
"Failed to allocate an index buffer.");
|
"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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -791,7 +801,8 @@ GFXPrimitiveBuffer * GFXD3D9Device::allocPrimitiveBuffer( U32 numIndices,
|
||||||
GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts,
|
GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts,
|
||||||
const GFXVertexFormat *vertexFormat,
|
const GFXVertexFormat *vertexFormat,
|
||||||
U32 vertSize,
|
U32 vertSize,
|
||||||
GFXBufferType bufferType )
|
GFXBufferType bufferType,
|
||||||
|
void* data)
|
||||||
{
|
{
|
||||||
PROFILE_SCOPE( GFXD3D9Device_allocVertexBuffer );
|
PROFILE_SCOPE( GFXD3D9Device_allocVertexBuffer );
|
||||||
|
|
||||||
|
|
@ -808,7 +819,7 @@ GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts,
|
||||||
res->mNumVerts = 0;
|
res->mNumVerts = 0;
|
||||||
|
|
||||||
// Assumptions:
|
// Assumptions:
|
||||||
// - static buffers are write once, use many
|
// - static buffers are write rarely, use many
|
||||||
// - dynamic buffers are write many, use many
|
// - dynamic buffers are write many, use many
|
||||||
// - volatile buffers are write once, use once
|
// - volatile buffers are write once, use once
|
||||||
// You may never read from a buffer.
|
// You may never read from a buffer.
|
||||||
|
|
@ -850,6 +861,15 @@ GFXVertexBuffer * GFXD3D9Device::allocVertexBuffer( U32 numVerts,
|
||||||
}
|
}
|
||||||
|
|
||||||
res->mNumVerts = numVerts;
|
res->mNumVerts = numVerts;
|
||||||
|
|
||||||
|
if(data)
|
||||||
|
{
|
||||||
|
void* dest;
|
||||||
|
res->lock(0, numVerts, &dest);
|
||||||
|
dMemcpy(dest, data, vertSize * numVerts);
|
||||||
|
res->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -298,10 +298,12 @@ public:
|
||||||
virtual GFXVertexBuffer* allocVertexBuffer( U32 numVerts,
|
virtual GFXVertexBuffer* allocVertexBuffer( U32 numVerts,
|
||||||
const GFXVertexFormat *vertexFormat,
|
const GFXVertexFormat *vertexFormat,
|
||||||
U32 vertSize,
|
U32 vertSize,
|
||||||
GFXBufferType bufferType );
|
GFXBufferType bufferType,
|
||||||
|
void* data = NULL );
|
||||||
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
|
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
|
||||||
U32 numPrimitives,
|
U32 numPrimitives,
|
||||||
GFXBufferType bufferType );
|
GFXBufferType bufferType,
|
||||||
|
void* data = NULL );
|
||||||
virtual void deallocVertexBuffer( GFXD3D9VertexBuffer *vertBuff );
|
virtual void deallocVertexBuffer( GFXD3D9VertexBuffer *vertBuff );
|
||||||
virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat );
|
virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat );
|
||||||
virtual void setVertexDecl( const GFXVertexDecl *decl );
|
virtual void setVertexDecl( const GFXVertexDecl *decl );
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ void GFXD3D9PrimitiveBuffer::lock(U32 indexStart, U32 indexEnd, void **indexPtr)
|
||||||
U32 flags=0;
|
U32 flags=0;
|
||||||
switch(mBufferType)
|
switch(mBufferType)
|
||||||
{
|
{
|
||||||
|
case GFXBufferTypeImmutable:
|
||||||
case GFXBufferTypeStatic:
|
case GFXBufferTypeStatic:
|
||||||
// flags |= D3DLOCK_DISCARD;
|
// flags |= D3DLOCK_DISCARD;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -276,14 +276,16 @@ GFXNullDevice::~GFXNullDevice()
|
||||||
GFXVertexBuffer *GFXNullDevice::allocVertexBuffer( U32 numVerts,
|
GFXVertexBuffer *GFXNullDevice::allocVertexBuffer( U32 numVerts,
|
||||||
const GFXVertexFormat *vertexFormat,
|
const GFXVertexFormat *vertexFormat,
|
||||||
U32 vertSize,
|
U32 vertSize,
|
||||||
GFXBufferType bufferType )
|
GFXBufferType bufferType,
|
||||||
|
void* data )
|
||||||
{
|
{
|
||||||
return new GFXNullVertexBuffer(GFX, numVerts, vertexFormat, vertSize, bufferType);
|
return new GFXNullVertexBuffer(GFX, numVerts, vertexFormat, vertSize, bufferType);
|
||||||
}
|
}
|
||||||
|
|
||||||
GFXPrimitiveBuffer *GFXNullDevice::allocPrimitiveBuffer( U32 numIndices,
|
GFXPrimitiveBuffer *GFXNullDevice::allocPrimitiveBuffer( U32 numIndices,
|
||||||
U32 numPrimitives,
|
U32 numPrimitives,
|
||||||
GFXBufferType bufferType)
|
GFXBufferType bufferType,
|
||||||
|
void* data )
|
||||||
{
|
{
|
||||||
return new GFXNullPrimitiveBuffer(GFX, numIndices, numPrimitives, bufferType);
|
return new GFXNullPrimitiveBuffer(GFX, numIndices, numPrimitives, bufferType);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,12 @@ protected:
|
||||||
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
|
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
|
||||||
const GFXVertexFormat *vertexFormat,
|
const GFXVertexFormat *vertexFormat,
|
||||||
U32 vertSize,
|
U32 vertSize,
|
||||||
GFXBufferType bufferType );
|
GFXBufferType bufferType,
|
||||||
|
void* data = NULL );
|
||||||
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
|
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
|
||||||
U32 numPrimitives,
|
U32 numPrimitives,
|
||||||
GFXBufferType bufferType );
|
GFXBufferType bufferType,
|
||||||
|
void* data = NULL );
|
||||||
|
|
||||||
virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ) { return NULL; }
|
virtual GFXVertexDecl* allocVertexDecl( const GFXVertexFormat *vertexFormat ) { return NULL; }
|
||||||
virtual void setVertexDecl( const GFXVertexDecl *decl ) { }
|
virtual void setVertexDecl( const GFXVertexDecl *decl ) { }
|
||||||
|
|
|
||||||
|
|
@ -637,7 +637,8 @@ protected:
|
||||||
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
|
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
|
||||||
const GFXVertexFormat *vertexFormat,
|
const GFXVertexFormat *vertexFormat,
|
||||||
U32 vertSize,
|
U32 vertSize,
|
||||||
GFXBufferType bufferType ) = 0;
|
GFXBufferType bufferType,
|
||||||
|
void* data = NULL ) = 0;
|
||||||
|
|
||||||
/// Called from GFXVertexFormat to allocate the hardware
|
/// Called from GFXVertexFormat to allocate the hardware
|
||||||
/// specific vertex declaration for rendering.
|
/// specific vertex declaration for rendering.
|
||||||
|
|
@ -674,7 +675,8 @@ protected:
|
||||||
/// @note All index buffers use unsigned 16-bit indices.
|
/// @note All index buffers use unsigned 16-bit indices.
|
||||||
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
|
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices,
|
||||||
U32 numPrimitives,
|
U32 numPrimitives,
|
||||||
GFXBufferType bufferType ) = 0;
|
GFXBufferType bufferType,
|
||||||
|
void* data = NULL ) = 0;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@
|
||||||
|
|
||||||
enum GFXBufferType
|
enum GFXBufferType
|
||||||
{
|
{
|
||||||
GFXBufferTypeStatic, ///< Static vertex buffers are created and filled one time.
|
GFXBufferTypeStatic, ///< Static vertex buffers are created and rarely updated.
|
||||||
///< incur a performance penalty. Resizing a static vertex buffer is not
|
///< Updating might incur a performance penalty. Resizing a static vertex buffer is not
|
||||||
///< allowed.
|
///< allowed.
|
||||||
GFXBufferTypeDynamic, ///< Dynamic vertex buffers are meant for vertices that can be changed
|
GFXBufferTypeDynamic, ///< Dynamic vertex buffers are meant for vertices that can be changed
|
||||||
///< often. Vertices written into dynamic vertex buffers will remain valid
|
///< often. Vertices written into dynamic vertex buffers will remain valid
|
||||||
|
|
@ -48,7 +48,8 @@ enum GFXBufferType
|
||||||
///< allowed.
|
///< allowed.
|
||||||
GFXBufferTypeVolatile, ///< Volatile vertex or index buffers are meant for vertices or indices that are essentially
|
GFXBufferTypeVolatile, ///< Volatile vertex or index buffers are meant for vertices or indices that are essentially
|
||||||
///< only used once. They can be resized without any performance penalty.
|
///< only used once. They can be resized without any performance penalty.
|
||||||
|
GFXBufferTypeImmutable, ///< Immutable buffers must specify the data when creating the buffer. Cannot be modified.
|
||||||
|
|
||||||
GFXBufferType_COUNT ///< Number of buffer types.
|
GFXBufferType_COUNT ///< Number of buffer types.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,3 +80,16 @@ void GFXPrimitiveBufferHandle::set(GFXDevice *theDevice, U32 indexCount, U32 pri
|
||||||
getPointer()->mDebugCreationPath = desc;
|
getPointer()->mDebugCreationPath = desc;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// immutable
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void GFXPrimitiveBufferHandle::immutable(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, void* data, String desc)
|
||||||
|
{
|
||||||
|
StrongRefPtr<GFXPrimitiveBuffer>::operator=( theDevice->allocPrimitiveBuffer(indexCount, primitiveCount, GFXBufferTypeImmutable, data) );
|
||||||
|
|
||||||
|
#ifdef TORQUE_DEBUG
|
||||||
|
if( desc.isNotEmpty() )
|
||||||
|
getPointer()->mDebugCreationPath = desc;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, GFXBufferType bufferType, String desc = String::EmptyString );
|
void set(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, GFXBufferType bufferType, String desc = String::EmptyString );
|
||||||
|
|
||||||
|
void immutable(GFXDevice *theDevice, U32 indexCount, U32 primitiveCount, void* data, String desc = String::EmptyString );
|
||||||
|
|
||||||
void lock(U16 **indexBuffer, GFXPrimitive **primitiveBuffer = NULL, U32 indexStart = 0, U32 indexEnd = 0)
|
void lock(U16 **indexBuffer, GFXPrimitive **primitiveBuffer = NULL, U32 indexStart = 0, U32 indexEnd = 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -355,23 +355,46 @@ GFXPrimitiveBuffer* GFXGLDevice::findVolatilePBO(U32 numIndices, U32 numPrimitiv
|
||||||
GFXVertexBuffer *GFXGLDevice::allocVertexBuffer( U32 numVerts,
|
GFXVertexBuffer *GFXGLDevice::allocVertexBuffer( U32 numVerts,
|
||||||
const GFXVertexFormat *vertexFormat,
|
const GFXVertexFormat *vertexFormat,
|
||||||
U32 vertSize,
|
U32 vertSize,
|
||||||
GFXBufferType bufferType )
|
GFXBufferType bufferType,
|
||||||
|
void* data = NULL )
|
||||||
{
|
{
|
||||||
if(bufferType == GFXBufferTypeVolatile)
|
if(bufferType == GFXBufferTypeVolatile)
|
||||||
return findVolatileVBO(numVerts, vertexFormat, vertSize);
|
return findVolatileVBO(numVerts, vertexFormat, vertSize);
|
||||||
|
|
||||||
GFXGLVertexBuffer* buf = new GFXGLVertexBuffer( GFX, numVerts, vertexFormat, vertSize, bufferType );
|
GFXGLVertexBuffer* buf = new GFXGLVertexBuffer( GFX, numVerts, vertexFormat, vertSize, bufferType );
|
||||||
buf->registerResourceWithDevice(this);
|
buf->registerResourceWithDevice(this);
|
||||||
|
|
||||||
|
if(data)
|
||||||
|
{
|
||||||
|
void* dest;
|
||||||
|
buf->lock(0, numVerts, &dest);
|
||||||
|
dMemcpy(dest, data, vertSize * numVerts);
|
||||||
|
buf->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
GFXPrimitiveBuffer *GFXGLDevice::allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType )
|
GFXPrimitiveBuffer *GFXGLDevice::allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType, void* data )
|
||||||
{
|
{
|
||||||
|
GFXPrimitiveBuffer* buf
|
||||||
if(bufferType == GFXBufferTypeVolatile)
|
if(bufferType == GFXBufferTypeVolatile)
|
||||||
return findVolatilePBO(numIndices, numPrimitives);
|
{
|
||||||
|
buf = findVolatilePBO(numIndices, numPrimitives);
|
||||||
GFXGLPrimitiveBuffer* buf = new GFXGLPrimitiveBuffer(GFX, numIndices, numPrimitives, bufferType);
|
}
|
||||||
buf->registerResourceWithDevice(this);
|
else
|
||||||
|
{
|
||||||
|
buf = new GFXGLPrimitiveBuffer(GFX, numIndices, numPrimitives, bufferType);
|
||||||
|
buf->registerResourceWithDevice(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data)
|
||||||
|
{
|
||||||
|
void* dest;
|
||||||
|
buf->lock(0, numIndices, &dest);
|
||||||
|
dMemcpy(dest, data, sizeof(U16) * numIndices);
|
||||||
|
buf->unlock();
|
||||||
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -173,8 +173,9 @@ protected:
|
||||||
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
|
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
|
||||||
const GFXVertexFormat *vertexFormat,
|
const GFXVertexFormat *vertexFormat,
|
||||||
U32 vertSize,
|
U32 vertSize,
|
||||||
GFXBufferType bufferType );
|
GFXBufferType bufferType,
|
||||||
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType );
|
void* data = NULL);
|
||||||
|
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType, void* data = NULL );
|
||||||
|
|
||||||
// NOTE: The GL device doesn't need a vertex declaration at
|
// NOTE: The GL device doesn't need a vertex declaration at
|
||||||
// this time, but we need to return something to keep the system
|
// this time, but we need to return something to keep the system
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ void GFXGLEnumTranslate::init()
|
||||||
GFXGLBufferType[GFXBufferTypeStatic] = GL_STATIC_DRAW;
|
GFXGLBufferType[GFXBufferTypeStatic] = GL_STATIC_DRAW;
|
||||||
GFXGLBufferType[GFXBufferTypeDynamic] = GL_DYNAMIC_DRAW;
|
GFXGLBufferType[GFXBufferTypeDynamic] = GL_DYNAMIC_DRAW;
|
||||||
GFXGLBufferType[GFXBufferTypeVolatile] = GL_STREAM_DRAW;
|
GFXGLBufferType[GFXBufferTypeVolatile] = GL_STREAM_DRAW;
|
||||||
|
GFXGLBufferType[GFXBufferTypeImmutable] = GL_STATIC_DRAW;
|
||||||
|
|
||||||
// Primitives
|
// Primitives
|
||||||
GFXGLPrimType[GFXPointList] = GL_POINTS;
|
GFXGLPrimType[GFXPointList] = GL_POINTS;
|
||||||
|
|
|
||||||
|
|
@ -338,14 +338,10 @@ void RenderParticleMgr::render( SceneRenderState *state )
|
||||||
void RenderParticleMgr::_initGFXResources()
|
void RenderParticleMgr::_initGFXResources()
|
||||||
{
|
{
|
||||||
// Screen quad
|
// Screen quad
|
||||||
U16 *prims = NULL;
|
U16 prims [] = {
|
||||||
mScreenQuadPrimBuff.set(GFX, 4, 2, GFXBufferTypeStatic);
|
0, 1, 2, 3,
|
||||||
mScreenQuadPrimBuff.lock(&prims);
|
};
|
||||||
(*prims++) = 0;
|
mScreenQuadPrimBuff.immutable(GFX, 4, 2, prims);
|
||||||
(*prims++) = 1;
|
|
||||||
(*prims++) = 2;
|
|
||||||
(*prims++) = 3;
|
|
||||||
mScreenQuadPrimBuff.unlock();
|
|
||||||
|
|
||||||
mScreenQuadVertBuff.set(GFX, 4, GFXBufferTypeStatic);
|
mScreenQuadVertBuff.set(GFX, 4, GFXBufferTypeStatic);
|
||||||
CompositeQuadVert *verts = mScreenQuadVertBuff.lock();
|
CompositeQuadVert *verts = mScreenQuadVertBuff.lock();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue