Commit f41522b6 by Jamie Madill

Split vertex translation into helper methods.

Refactoring patch only. BUG=angle:571 Change-Id: I17e8c1eb80bdf7c3ec7cc4bad4e70e81590e4a89 Reviewed-on: https://chromium-review.googlesource.com/210644Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 39e7bc05
...@@ -166,11 +166,59 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], ...@@ -166,11 +166,59 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
{ {
if (translated[i].active) if (translated[i].active)
{ {
GLenum result;
if (attribs[i].enabled) if (attribs[i].enabled)
{ {
result = storeAttribute(attribs[i], currentValues[i], &translated[i],
start, count, instances);
}
else
{
if (!mCurrentValueBuffer[i])
{
mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mRenderer, CONSTANT_VERTEX_BUFFER_SIZE);
}
result = storeCurrentValue(attribs[i], currentValues[i], &translated[i],
&mCurrentValue[i], &mCurrentValueOffsets[i],
mCurrentValueBuffer[i]);
}
if (result != GL_NO_ERROR)
{
return result;
}
}
}
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{
if (translated[i].active && attribs[i].enabled)
{
gl::Buffer *buffer = attribs[i].buffer.get(); gl::Buffer *buffer = attribs[i].buffer.get();
if (!buffer && attribs[i].pointer == NULL) if (buffer)
{
BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation());
bufferImpl->promoteStaticUsage(count * ComputeVertexAttributeTypeSize(attribs[i]));
}
}
}
return GL_NO_ERROR;
}
GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated,
GLint start,
GLsizei count,
GLsizei instances)
{
gl::Buffer *buffer = attrib.buffer.get();
if (!buffer && attrib.pointer == NULL)
{ {
// This is an application error that would normally result in a crash, but we catch it and return an error // This is an application error that would normally result in a crash, but we catch it and return an error
ERR("An enabled vertex array has no buffer and no pointer."); ERR("An enabled vertex array has no buffer and no pointer.");
...@@ -180,38 +228,38 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], ...@@ -180,38 +228,38 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
BufferD3D *storage = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL; BufferD3D *storage = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL;
StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL; StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
bool directStorage = vertexBuffer->directStoragePossible(attribs[i], currentValues[i]); bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue);
unsigned int streamOffset = 0; unsigned int streamOffset = 0;
unsigned int outputElementSize = 0; unsigned int outputElementSize = 0;
if (directStorage) if (directStorage)
{ {
outputElementSize = ComputeVertexAttributeStride(attribs[i]); outputElementSize = ComputeVertexAttributeStride(attrib);
streamOffset = attribs[i].offset + outputElementSize * start; streamOffset = attrib.offset + outputElementSize * start;
} }
else if (staticBuffer) else if (staticBuffer)
{ {
if (!staticBuffer->getVertexBuffer()->getSpaceRequired(attribs[i], 1, 0, &outputElementSize)) if (!staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize))
{ {
return GL_OUT_OF_MEMORY; return GL_OUT_OF_MEMORY;
} }
if (!staticBuffer->lookupAttribute(attribs[i], &streamOffset)) if (!staticBuffer->lookupAttribute(attrib, &streamOffset))
{ {
// Convert the entire buffer // Convert the entire buffer
int totalCount = ElementsInBuffer(attribs[i], storage->getSize()); int totalCount = ElementsInBuffer(attrib, storage->getSize());
int startIndex = attribs[i].offset / ComputeVertexAttributeStride(attribs[i]); int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib);
if (!staticBuffer->storeVertexAttributes(attribs[i], currentValues[i], -startIndex, totalCount, if (!staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount,
0, &streamOffset)) 0, &streamOffset))
{ {
return GL_OUT_OF_MEMORY; return GL_OUT_OF_MEMORY;
} }
} }
unsigned int firstElementOffset = (attribs[i].offset / ComputeVertexAttributeStride(attribs[i])) * outputElementSize; unsigned int firstElementOffset = (attrib.offset / ComputeVertexAttributeStride(attrib)) * outputElementSize;
unsigned int startOffset = (instances == 0 || attribs[i].divisor == 0) ? start * outputElementSize : 0; unsigned int startOffset = (instances == 0 || attrib.divisor == 0) ? start * outputElementSize : 0;
if (streamOffset + firstElementOffset + startOffset < streamOffset) if (streamOffset + firstElementOffset + startOffset < streamOffset)
{ {
return GL_OUT_OF_MEMORY; return GL_OUT_OF_MEMORY;
...@@ -221,77 +269,61 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], ...@@ -221,77 +269,61 @@ GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[],
} }
else else
{ {
int totalCount = StreamingBufferElementCount(attribs[i], count, instances); int totalCount = StreamingBufferElementCount(attrib, count, instances);
if (!mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attribs[i], 1, 0, &outputElementSize) || if (!mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize) ||
!mStreamingBuffer->storeVertexAttributes(attribs[i], currentValues[i], start, totalCount, instances, !mStreamingBuffer->storeVertexAttributes(attrib, currentValue, start, totalCount, instances,
&streamOffset)) &streamOffset))
{ {
return GL_OUT_OF_MEMORY; return GL_OUT_OF_MEMORY;
} }
} }
translated[i].storage = directStorage ? storage : NULL; translated->storage = directStorage ? storage : NULL;
translated[i].vertexBuffer = vertexBuffer->getVertexBuffer(); translated->vertexBuffer = vertexBuffer->getVertexBuffer();
translated[i].serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial(); translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial();
translated[i].divisor = attribs[i].divisor; translated->divisor = attrib.divisor;
translated[i].attribute = &attribs[i]; translated->attribute = &attrib;
translated[i].currentValueType = currentValues[i].Type; translated->currentValueType = currentValue.Type;
translated[i].stride = outputElementSize; translated->stride = outputElementSize;
translated[i].offset = streamOffset; translated->offset = streamOffset;
}
else
{
if (!mCurrentValueBuffer[i])
{
mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mRenderer, CONSTANT_VERTEX_BUFFER_SIZE);
}
StreamingVertexBufferInterface *buffer = mCurrentValueBuffer[i]; return GL_NO_ERROR;
}
if (mCurrentValue[i] != currentValues[i]) GLenum VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated,
gl::VertexAttribCurrentValueData *cachedValue,
size_t *cachedOffset,
StreamingVertexBufferInterface *buffer)
{
if (*cachedValue != currentValue)
{ {
if (!buffer->reserveVertexSpace(attribs[i], 1, 0)) if (!buffer->reserveVertexSpace(attrib, 1, 0))
{ {
return GL_OUT_OF_MEMORY; return GL_OUT_OF_MEMORY;
} }
unsigned int streamOffset; unsigned int streamOffset;
if (!buffer->storeVertexAttributes(attribs[i], currentValues[i], 0, 1, 0, &streamOffset)) if (!buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset))
{ {
return GL_OUT_OF_MEMORY; return GL_OUT_OF_MEMORY;
} }
mCurrentValue[i] = currentValues[i]; *cachedValue = currentValue;
mCurrentValueOffsets[i] = streamOffset; *cachedOffset = streamOffset;
}
translated[i].storage = NULL;
translated[i].vertexBuffer = mCurrentValueBuffer[i]->getVertexBuffer();
translated[i].serial = mCurrentValueBuffer[i]->getSerial();
translated[i].divisor = 0;
translated[i].attribute = &attribs[i];
translated[i].currentValueType = currentValues[i].Type;
translated[i].stride = 0;
translated[i].offset = mCurrentValueOffsets[i];
}
}
} }
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) translated->storage = NULL;
{ translated->vertexBuffer = buffer->getVertexBuffer();
if (translated[i].active && attribs[i].enabled) translated->serial = buffer->getSerial();
{ translated->divisor = 0;
gl::Buffer *buffer = attribs[i].buffer.get();
if (buffer) translated->attribute = &attrib;
{ translated->currentValueType = currentValue.Type;
BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation()); translated->stride = 0;
bufferImpl->promoteStaticUsage(count * ComputeVertexAttributeTypeSize(attribs[i])); translated->offset = *cachedOffset;
}
}
}
return GL_NO_ERROR; return GL_NO_ERROR;
} }
......
...@@ -58,6 +58,20 @@ class VertexDataManager ...@@ -58,6 +58,20 @@ class VertexDataManager
private: private:
DISALLOW_COPY_AND_ASSIGN(VertexDataManager); DISALLOW_COPY_AND_ASSIGN(VertexDataManager);
GLenum storeAttribute(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated,
GLint start,
GLsizei count,
GLsizei instances);
GLenum storeCurrentValue(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated,
gl::VertexAttribCurrentValueData *cachedValue,
size_t *cachedOffset,
StreamingVertexBufferInterface *buffer);
rx::Renderer *const mRenderer; rx::Renderer *const mRenderer;
StreamingVertexBufferInterface *mStreamingBuffer; StreamingVertexBufferInterface *mStreamingBuffer;
......
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