Commit 059fc15f by jbauman@chromium.org

Fix count of elements in buffer

There can be one extra element at the end even if an entire stride doesn't fit. BUG= TEST= Review URL: http://codereview.appspot.com/5401046 git-svn-id: https://angleproject.googlecode.com/svn/trunk@884 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 1e44645a
#define MAJOR_VERSION 0 #define MAJOR_VERSION 0
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 883 #define BUILD_REVISION 884
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -29,6 +29,12 @@ namespace gl ...@@ -29,6 +29,12 @@ namespace gl
{ {
unsigned int VertexBuffer::mCurrentSerial = 1; unsigned int VertexBuffer::mCurrentSerial = 1;
int elementsInBuffer(const VertexAttribute &attribute, int size)
{
int stride = attribute.stride();
return (size - attribute.mOffset % stride + (stride - attribute.typeSize())) / stride;
}
VertexDataManager::VertexDataManager(Context *context, IDirect3DDevice9 *device) : mContext(context), mDevice(device) VertexDataManager::VertexDataManager(Context *context, IDirect3DDevice9 *device) : mContext(context), mDevice(device)
{ {
for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
...@@ -137,7 +143,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat ...@@ -137,7 +143,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
{ {
if (staticBuffer->size() == 0) if (staticBuffer->size() == 0)
{ {
int totalCount = buffer->size() / attribs[i].stride(); int totalCount = elementsInBuffer(attribs[i], buffer->size());
staticBuffer->addRequiredSpace(spaceRequired(attribs[i], totalCount)); staticBuffer->addRequiredSpace(spaceRequired(attribs[i], totalCount));
} }
else if (staticBuffer->lookupAttribute(attribs[i]) == -1) else if (staticBuffer->lookupAttribute(attribs[i]) == -1)
...@@ -216,7 +222,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat ...@@ -216,7 +222,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
if (streamOffset == -1) if (streamOffset == -1)
{ {
// Convert the entire buffer // Convert the entire buffer
int totalCount = buffer->size() / attribs[i].stride(); int totalCount = elementsInBuffer(attribs[i], buffer->size());
int startIndex = attribs[i].mOffset / attribs[i].stride(); int startIndex = attribs[i].mOffset / attribs[i].stride();
streamOffset = writeAttributeData(staticBuffer, -startIndex, totalCount, attribs[i]); streamOffset = writeAttributeData(staticBuffer, -startIndex, totalCount, attribs[i]);
......
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