Merge pull request #1525 from TheDushan/ImmutableBuffers

Added immutable vertex and index buffers.
This commit is contained in:
Anis 2016-02-25 15:38:07 +01:00
commit a31dea224c
13 changed files with 99 additions and 32 deletions

View file

@ -355,23 +355,47 @@ GFXPrimitiveBuffer* GFXGLDevice::findVolatilePBO(U32 numIndices, U32 numPrimitiv
GFXVertexBuffer *GFXGLDevice::allocVertexBuffer( U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertSize,
GFXBufferType bufferType )
GFXBufferType bufferType,
void* data )
{
if(bufferType == GFXBufferTypeVolatile)
return findVolatileVBO(numVerts, vertexFormat, vertSize);
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;
}
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)
return findVolatilePBO(numIndices, numPrimitives);
GFXGLPrimitiveBuffer* buf = new GFXGLPrimitiveBuffer(GFX, numIndices, numPrimitives, bufferType);
buf->registerResourceWithDevice(this);
{
buf = findVolatilePBO(numIndices, numPrimitives);
}
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;
}

View file

@ -173,8 +173,9 @@ protected:
virtual GFXVertexBuffer *allocVertexBuffer( U32 numVerts,
const GFXVertexFormat *vertexFormat,
U32 vertSize,
GFXBufferType bufferType );
virtual GFXPrimitiveBuffer *allocPrimitiveBuffer( U32 numIndices, U32 numPrimitives, GFXBufferType bufferType );
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
// this time, but we need to return something to keep the system

View file

@ -45,6 +45,7 @@ void GFXGLEnumTranslate::init()
GFXGLBufferType[GFXBufferTypeStatic] = GL_STATIC_DRAW;
GFXGLBufferType[GFXBufferTypeDynamic] = GL_DYNAMIC_DRAW;
GFXGLBufferType[GFXBufferTypeVolatile] = GL_STREAM_DRAW;
GFXGLBufferType[GFXBufferTypeImmutable] = GL_STATIC_DRAW;
// Primitives
GFXGLPrimType[GFXPointList] = GL_POINTS;