Optimized non-static usage of static buffers.

Validate buffer pointers. TRAC #14889 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@528 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 37b141e2
......@@ -75,8 +75,11 @@ void Buffer::bufferSubData(const void *data, GLsizeiptr size, GLintptr offset)
if (mUsage == GL_STATIC_DRAW)
{
mVertexBuffer = new StaticVertexBuffer(getDevice());
mIndexBuffer = new StaticIndexBuffer(getDevice());
// If applications update the buffer data after it has already been used in a draw call,
// it most likely isn't used as a static buffer so we should fall back to streaming usage
// for best performance. So ignore the usage hint and don't create new static buffers.
// mVertexBuffer = new StaticVertexBuffer(getDevice());
// mIndexBuffer = new StaticIndexBuffer(getDevice());
}
}
}
......
......@@ -156,9 +156,14 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *bu
}
}
indexBuffer->reserveSpace(convertCount * indexSize(format), type);
void *output = indexBuffer->map(indexSize(format) * convertCount, &streamOffset);
void *output = NULL;
if (indexBuffer)
{
indexBuffer->reserveSpace(convertCount * indexSize(format), type);
output = indexBuffer->map(indexSize(format) * convertCount, &streamOffset);
}
if (output == NULL)
{
ERR("Failed to map index buffer.");
......
......@@ -59,7 +59,12 @@ UINT VertexDataManager::writeAttributeData(ArrayVertexBuffer *vertexBuffer, GLin
const FormatConverter &converter = formatConverter(attribute);
UINT streamOffset = 0;
void *output = vertexBuffer->map(attribute, spaceRequired(attribute, count), &streamOffset);
void *output = NULL;
if (vertexBuffer)
{
output = vertexBuffer->map(attribute, spaceRequired(attribute, count), &streamOffset);
}
if (output == NULL)
{
......@@ -123,7 +128,10 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
}
else if (!staticBuffer || staticBuffer->lookupAttribute(attribs[i]) == -1)
{
mStreamingBuffer->addRequiredSpace(spaceRequired(attribs[i], count));
if (mStreamingBuffer)
{
mStreamingBuffer->addRequiredSpace(spaceRequired(attribs[i], count));
}
}
}
}
......@@ -153,7 +161,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
}
}
if (!matchingAttributes)
if (!matchingAttributes && mStreamingBuffer)
{
mStreamingBuffer->addRequiredSpaceFor(staticBuffer);
buffer->invalidateStaticData();
......@@ -172,7 +180,10 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
ArrayVertexBuffer *staticBuffer = buffer ? buffer->getVertexBuffer() : NULL;
ArrayVertexBuffer *vertexBuffer = staticBuffer ? staticBuffer : mStreamingBuffer;
vertexBuffer->reserveRequiredSpace();
if (vertexBuffer)
{
vertexBuffer->reserveRequiredSpace();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment