shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 2 | // |
daniel@transgaming.com | 8ca9c6e | 2012-01-27 15:38:54 +0000 | [diff] [blame] | 3 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
daniel@transgaming.com | 8fd34bd | 2011-02-18 02:52:14 +0000 | [diff] [blame] | 8 | // VertexDataManager.h: Defines the VertexDataManager, a class that |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 9 | // runs the Buffer translation process. |
| 10 | |
daniel@transgaming.com | 50aadb0 | 2012-11-28 21:06:11 +0000 | [diff] [blame] | 11 | #include "libGLESv2/renderer/VertexDataManager.h" |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 12 | #include "libGLESv2/renderer/BufferStorage.h" |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 13 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 14 | #include "libGLESv2/Buffer.h" |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 15 | #include "libGLESv2/ProgramBinary.h" |
Jamie Madill | 8793971 | 2013-07-02 11:57:01 -0400 | [diff] [blame] | 16 | #include "libGLESv2/VertexAttribute.h" |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 17 | #include "libGLESv2/renderer/VertexBuffer.h" |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 18 | |
| 19 | namespace |
| 20 | { |
| 21 | enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 }; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 22 | // This has to be at least 4k or else it fails on ATI cards. |
| 23 | enum { CONSTANT_VERTEX_BUFFER_SIZE = 4096 }; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 24 | } |
| 25 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 26 | namespace rx |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 27 | { |
| 28 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 29 | static int ElementsInBuffer(const gl::VertexAttribute &attribute, int size) |
jbauman@chromium.org | 059fc15 | 2011-11-18 19:26:17 +0000 | [diff] [blame] | 30 | { |
| 31 | int stride = attribute.stride(); |
| 32 | return (size - attribute.mOffset % stride + (stride - attribute.typeSize())) / stride; |
| 33 | } |
| 34 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 35 | static bool DirectStoragePossible(VertexBufferInterface *vb, const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue) |
| 36 | { |
| 37 | gl::Buffer *buffer = attrib.mBoundBuffer.get(); |
| 38 | BufferStorage *storage = buffer ? buffer->getStorage() : NULL; |
| 39 | |
| 40 | const bool isAligned = (attrib.stride() % 4 == 0) && (attrib.mOffset % 4 == 0); |
| 41 | const bool requiresConversion = attrib.mArrayEnabled ? |
| 42 | vb->getVertexBuffer()->requiresConversion(attrib) : |
| 43 | vb->getVertexBuffer()->requiresConversion(currentValue); |
| 44 | |
| 45 | return storage && storage->supportsDirectBinding() && !requiresConversion && isAligned; |
| 46 | } |
| 47 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 48 | VertexDataManager::VertexDataManager(Renderer *renderer) : mRenderer(renderer) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 49 | { |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 50 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 51 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3026dc7 | 2013-04-13 03:37:27 +0000 | [diff] [blame] | 52 | mCurrentValue[i].FloatValues[0] = std::numeric_limits<float>::quiet_NaN(); |
| 53 | mCurrentValue[i].FloatValues[1] = std::numeric_limits<float>::quiet_NaN(); |
| 54 | mCurrentValue[i].FloatValues[2] = std::numeric_limits<float>::quiet_NaN(); |
| 55 | mCurrentValue[i].FloatValues[3] = std::numeric_limits<float>::quiet_NaN(); |
| 56 | mCurrentValue[i].Type = GL_FLOAT; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 57 | mCurrentValueBuffer[i] = NULL; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 58 | mCurrentValueOffsets[i] = 0; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 59 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 60 | |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 61 | mStreamingBuffer = new StreamingVertexBufferInterface(renderer, INITIAL_STREAM_BUFFER_SIZE); |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 62 | |
| 63 | if (!mStreamingBuffer) |
| 64 | { |
| 65 | ERR("Failed to allocate the streaming vertex buffer."); |
| 66 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | VertexDataManager::~VertexDataManager() |
| 70 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 71 | delete mStreamingBuffer; |
| 72 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 73 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 74 | { |
| 75 | delete mCurrentValueBuffer[i]; |
| 76 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 79 | GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[], |
| 80 | gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *translated, GLsizei instances) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 81 | { |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 82 | if (!mStreamingBuffer) |
| 83 | { |
| 84 | return GL_OUT_OF_MEMORY; |
| 85 | } |
| 86 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 87 | for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 88 | { |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 89 | translated[attributeIndex].active = (programBinary->getSemanticIndex(attributeIndex) != -1); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 90 | } |
| 91 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 92 | // Invalidate static buffers that don't contain matching attributes |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 93 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 94 | { |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 95 | if (translated[i].active && attribs[i].mArrayEnabled) |
daniel@transgaming.com | c828b14 | 2010-05-12 03:42:04 +0000 | [diff] [blame] | 96 | { |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 97 | gl::Buffer *buffer = attribs[i].mBoundBuffer.get(); |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 98 | StaticVertexBufferInterface *staticBuffer = buffer ? buffer->getStaticVertexBuffer() : NULL; |
daniel@transgaming.com | c828b14 | 2010-05-12 03:42:04 +0000 | [diff] [blame] | 99 | |
shannon.woods@transgaming.com | a9a509e | 2013-02-28 23:10:44 +0000 | [diff] [blame] | 100 | if (staticBuffer && staticBuffer->getBufferSize() > 0 && staticBuffer->lookupAttribute(attribs[i]) == -1 && |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 101 | !DirectStoragePossible(staticBuffer, attribs[i], currentValues[i])) |
shannon.woods@transgaming.com | a9a509e | 2013-02-28 23:10:44 +0000 | [diff] [blame] | 102 | { |
| 103 | buffer->invalidateStaticData(); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Reserve the required space in the buffers |
| 109 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
| 110 | { |
| 111 | if (translated[i].active && attribs[i].mArrayEnabled) |
| 112 | { |
| 113 | gl::Buffer *buffer = attribs[i].mBoundBuffer.get(); |
| 114 | StaticVertexBufferInterface *staticBuffer = buffer ? buffer->getStaticVertexBuffer() : NULL; |
| 115 | VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 116 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 117 | if (!DirectStoragePossible(vertexBuffer, attribs[i], currentValues[i])) |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 118 | { |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 119 | if (staticBuffer) |
daniel@transgaming.com | 5ee2ad0 | 2011-01-08 05:46:20 +0000 | [diff] [blame] | 120 | { |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 121 | if (staticBuffer->getBufferSize() == 0) |
| 122 | { |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 123 | int totalCount = ElementsInBuffer(attribs[i], buffer->size()); |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 124 | staticBuffer->reserveVertexSpace(attribs[i], totalCount, 0); |
| 125 | } |
daniel@transgaming.com | 5ee2ad0 | 2011-01-08 05:46:20 +0000 | [diff] [blame] | 126 | } |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 127 | else |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 128 | { |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 129 | mStreamingBuffer->reserveVertexSpace(attribs[i], count, instances); |
daniel@transgaming.com | 50aadb0 | 2012-11-28 21:06:11 +0000 | [diff] [blame] | 130 | } |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 131 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
| 135 | // Perform the vertex data translations |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 136 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 137 | { |
| 138 | if (translated[i].active) |
| 139 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 140 | if (attribs[i].mArrayEnabled) |
| 141 | { |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 142 | gl::Buffer *buffer = attribs[i].mBoundBuffer.get(); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 143 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 144 | if (!buffer && attribs[i].mPointer == NULL) |
| 145 | { |
| 146 | // This is an application error that would normally result in a crash, but we catch it and return an error |
| 147 | ERR("An enabled vertex array has no buffer and no pointer."); |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 148 | return GL_INVALID_OPERATION; |
| 149 | } |
| 150 | |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 151 | StaticVertexBufferInterface *staticBuffer = buffer ? buffer->getStaticVertexBuffer() : NULL; |
| 152 | VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 153 | |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 154 | BufferStorage *storage = buffer ? buffer->getStorage() : NULL; |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 155 | bool directStorage = DirectStoragePossible(vertexBuffer, attribs[i], currentValues[i]); |
shannon.woods@transgaming.com | 7665541 | 2013-02-28 23:08:09 +0000 | [diff] [blame] | 156 | |
daniel@transgaming.com | 58f76fe | 2011-06-21 14:21:07 +0000 | [diff] [blame] | 157 | std::size_t streamOffset = -1; |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 158 | unsigned int outputElementSize = 0; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 159 | |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 160 | if (directStorage) |
| 161 | { |
| 162 | outputElementSize = attribs[i].stride(); |
| 163 | streamOffset = attribs[i].mOffset + outputElementSize * start; |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 164 | } |
| 165 | else if (staticBuffer) |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 166 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 167 | streamOffset = staticBuffer->lookupAttribute(attribs[i]); |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 168 | outputElementSize = staticBuffer->getVertexBuffer()->getSpaceRequired(attribs[i], 1, 0); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 169 | |
| 170 | if (streamOffset == -1) |
| 171 | { |
| 172 | // Convert the entire buffer |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 173 | int totalCount = ElementsInBuffer(attribs[i], storage->getSize()); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 174 | int startIndex = attribs[i].mOffset / attribs[i].stride(); |
| 175 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 176 | streamOffset = staticBuffer->storeVertexAttributes(attribs[i], currentValues[i], -startIndex, totalCount, 0); |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | if (streamOffset != -1) |
| 180 | { |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 181 | streamOffset += (attribs[i].mOffset / attribs[i].stride()) * outputElementSize; |
daniel@transgaming.com | c41a6fe | 2012-01-27 15:39:04 +0000 | [diff] [blame] | 182 | |
| 183 | if (instances == 0 || attribs[i].mDivisor == 0) |
| 184 | { |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 185 | streamOffset += start * outputElementSize; |
daniel@transgaming.com | c41a6fe | 2012-01-27 15:39:04 +0000 | [diff] [blame] | 186 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | else |
| 190 | { |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 191 | outputElementSize = mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attribs[i], 1, 0); |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 192 | streamOffset = mStreamingBuffer->storeVertexAttributes(attribs[i], currentValues[i], start, count, instances); |
daniel@transgaming.com | 838bcea | 2010-05-20 19:17:42 +0000 | [diff] [blame] | 193 | } |
| 194 | |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 195 | if (streamOffset == -1) |
| 196 | { |
| 197 | return GL_OUT_OF_MEMORY; |
| 198 | } |
| 199 | |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 200 | translated[i].storage = directStorage ? storage : NULL; |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 201 | translated[i].vertexBuffer = vertexBuffer->getVertexBuffer(); |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 202 | translated[i].serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial(); |
daniel@transgaming.com | 8ca9c6e | 2012-01-27 15:38:54 +0000 | [diff] [blame] | 203 | translated[i].divisor = attribs[i].mDivisor; |
| 204 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 205 | translated[i].attribute = &attribs[i]; |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 206 | translated[i].currentValueType = currentValues[i].Type; |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 207 | translated[i].stride = outputElementSize; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 208 | translated[i].offset = streamOffset; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 209 | } |
daniel@transgaming.com | 9a0606c | 2010-05-12 03:42:00 +0000 | [diff] [blame] | 210 | else |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 211 | { |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 212 | if (!mCurrentValueBuffer[i]) |
| 213 | { |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 214 | mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mRenderer, CONSTANT_VERTEX_BUFFER_SIZE); |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 215 | } |
| 216 | |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 217 | StreamingVertexBufferInterface *buffer = mCurrentValueBuffer[i]; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 218 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 219 | if (memcmp(&mCurrentValue[i], ¤tValues[i], sizeof(gl::VertexAttribCurrentValueData)) != 0) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 220 | { |
shannon.woods%transgaming.com@gtempaccount.com | cf8d2f8 | 2013-04-13 03:37:34 +0000 | [diff] [blame] | 221 | buffer->reserveVertexSpace(attribs[i], 1, 0); |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 222 | int streamOffset = buffer->storeVertexAttributes(attribs[i], currentValues[i], 0, 1, 0); |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 223 | if (streamOffset == -1) |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 224 | { |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 225 | return GL_OUT_OF_MEMORY; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 226 | } |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 227 | |
| 228 | mCurrentValueOffsets[i] = streamOffset; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 229 | } |
| 230 | |
shannon.woods@transgaming.com | db1899c | 2013-02-28 23:08:33 +0000 | [diff] [blame] | 231 | translated[i].storage = NULL; |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 232 | translated[i].vertexBuffer = mCurrentValueBuffer[i]->getVertexBuffer(); |
jbauman@chromium.org | d8f3faa | 2011-09-02 01:10:47 +0000 | [diff] [blame] | 233 | translated[i].serial = mCurrentValueBuffer[i]->getSerial(); |
daniel@transgaming.com | 8ca9c6e | 2012-01-27 15:38:54 +0000 | [diff] [blame] | 234 | translated[i].divisor = 0; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 235 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 236 | translated[i].attribute = &attribs[i]; |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 237 | translated[i].currentValueType = currentValues[i].Type; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 238 | translated[i].stride = 0; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 239 | translated[i].offset = mCurrentValueOffsets[i]; |
daniel@transgaming.com | 9a0606c | 2010-05-12 03:42:00 +0000 | [diff] [blame] | 240 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 241 | } |
| 242 | } |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 243 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 244 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 245 | { |
| 246 | if (translated[i].active && attribs[i].mArrayEnabled) |
| 247 | { |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 248 | gl::Buffer *buffer = attribs[i].mBoundBuffer.get(); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 249 | |
| 250 | if (buffer) |
| 251 | { |
| 252 | buffer->promoteStaticUsage(count * attribs[i].typeSize()); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 257 | return GL_NO_ERROR; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 258 | } |
| 259 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 260 | } |