daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 1 | // |
daniel@transgaming.com | 8ca9c6e | 2012-01-27 15:38:54 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
daniel@transgaming.com | 8fd34bd | 2011-02-18 02:52:14 +0000 | [diff] [blame] | 7 | // VertexDataManager.h: Defines the VertexDataManager, a class that |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 8 | // runs the Buffer translation process. |
| 9 | |
Brandon Jones | c7a4104 | 2014-06-23 12:03:25 -0700 | [diff] [blame] | 10 | #include "libGLESv2/renderer/d3d/VertexDataManager.h" |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 11 | #include "libGLESv2/renderer/d3d/BufferD3D.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 12 | #include "libGLESv2/renderer/d3d/VertexBuffer.h" |
| 13 | #include "libGLESv2/renderer/Renderer.h" |
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" |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 17 | |
| 18 | namespace |
| 19 | { |
| 20 | enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 }; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 21 | // This has to be at least 4k or else it fails on ATI cards. |
| 22 | enum { CONSTANT_VERTEX_BUFFER_SIZE = 4096 }; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 23 | } |
| 24 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 25 | namespace rx |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 26 | { |
| 27 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 28 | static int ElementsInBuffer(const gl::VertexAttribute &attrib, unsigned int size) |
jbauman@chromium.org | 059fc15 | 2011-11-18 19:26:17 +0000 | [diff] [blame] | 29 | { |
Geoff Lang | a36ead4 | 2013-08-02 11:54:08 -0400 | [diff] [blame] | 30 | // Size cannot be larger than a GLsizei |
| 31 | if (size > static_cast<unsigned int>(std::numeric_limits<int>::max())) |
| 32 | { |
| 33 | size = static_cast<unsigned int>(std::numeric_limits<int>::max()); |
| 34 | } |
| 35 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 36 | GLsizei stride = ComputeVertexAttributeStride(attrib); |
| 37 | return (size - attrib.offset % stride + (stride - ComputeVertexAttributeTypeSize(attrib))) / stride; |
jbauman@chromium.org | 059fc15 | 2011-11-18 19:26:17 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 40 | static int StreamingBufferElementCount(const gl::VertexAttribute &attrib, int vertexDrawCount, int instanceDrawCount) |
Jamie Madill | 9b4f384 | 2013-08-26 15:29:30 -0400 | [diff] [blame] | 41 | { |
| 42 | // For instanced rendering, we draw "instanceDrawCount" sets of "vertexDrawCount" vertices. |
| 43 | // |
| 44 | // A vertex attribute with a positive divisor loads one instanced vertex for every set of |
| 45 | // non-instanced vertices, and the instanced vertex index advances once every "mDivisor" instances. |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 46 | if (instanceDrawCount > 0 && attrib.divisor > 0) |
Jamie Madill | 9b4f384 | 2013-08-26 15:29:30 -0400 | [diff] [blame] | 47 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 48 | return instanceDrawCount / attrib.divisor; |
Jamie Madill | 9b4f384 | 2013-08-26 15:29:30 -0400 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | return vertexDrawCount; |
| 52 | } |
| 53 | |
daniel@transgaming.com | 4150d36 | 2012-12-20 21:07:43 +0000 | [diff] [blame] | 54 | VertexDataManager::VertexDataManager(Renderer *renderer) : mRenderer(renderer) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 55 | { |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 56 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 57 | { |
shannon.woods%transgaming.com@gtempaccount.com | 3026dc7 | 2013-04-13 03:37:27 +0000 | [diff] [blame] | 58 | mCurrentValue[i].FloatValues[0] = std::numeric_limits<float>::quiet_NaN(); |
| 59 | mCurrentValue[i].FloatValues[1] = std::numeric_limits<float>::quiet_NaN(); |
| 60 | mCurrentValue[i].FloatValues[2] = std::numeric_limits<float>::quiet_NaN(); |
| 61 | mCurrentValue[i].FloatValues[3] = std::numeric_limits<float>::quiet_NaN(); |
| 62 | mCurrentValue[i].Type = GL_FLOAT; |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 63 | mCurrentValueBuffer[i] = NULL; |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 64 | mCurrentValueOffsets[i] = 0; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 65 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 66 | |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 67 | mStreamingBuffer = new StreamingVertexBufferInterface(renderer, INITIAL_STREAM_BUFFER_SIZE); |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 68 | |
| 69 | if (!mStreamingBuffer) |
| 70 | { |
| 71 | ERR("Failed to allocate the streaming vertex buffer."); |
| 72 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | VertexDataManager::~VertexDataManager() |
| 76 | { |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 77 | delete mStreamingBuffer; |
| 78 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 79 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 80 | { |
| 81 | delete mCurrentValueBuffer[i]; |
| 82 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Jamie Madill | a857c36 | 2013-07-02 11:57:02 -0400 | [diff] [blame] | 85 | GLenum VertexDataManager::prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[], |
| 86 | gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *translated, GLsizei instances) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 87 | { |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 88 | if (!mStreamingBuffer) |
| 89 | { |
| 90 | return GL_OUT_OF_MEMORY; |
| 91 | } |
| 92 | |
Jamie Madill | 6d11380 | 2014-08-25 15:47:52 -0400 | [diff] [blame] | 93 | // Invalidate static buffers that don't contain matching attributes |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 94 | for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++) |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 95 | { |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 96 | translated[attributeIndex].active = (programBinary->getSemanticIndex(attributeIndex) != -1); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 97 | |
Jamie Madill | 6d11380 | 2014-08-25 15:47:52 -0400 | [diff] [blame] | 98 | if (translated[attributeIndex].active && attribs[attributeIndex].enabled) |
daniel@transgaming.com | c828b14 | 2010-05-12 03:42:04 +0000 | [diff] [blame] | 99 | { |
Jamie Madill | 6d11380 | 2014-08-25 15:47:52 -0400 | [diff] [blame] | 100 | invalidateMatchingStaticData(attribs[attributeIndex], currentValues[attributeIndex]); |
shannon.woods@transgaming.com | a9a509e | 2013-02-28 23:10:44 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | // Reserve the required space in the buffers |
| 105 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
| 106 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 107 | if (translated[i].active && attribs[i].enabled) |
shannon.woods@transgaming.com | a9a509e | 2013-02-28 23:10:44 +0000 | [diff] [blame] | 108 | { |
Jamie Madill | 6d11380 | 2014-08-25 15:47:52 -0400 | [diff] [blame] | 109 | if (!reserveSpaceForAttrib(attribs[i], currentValues[i], count, instances)) |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 110 | { |
Jamie Madill | 6d11380 | 2014-08-25 15:47:52 -0400 | [diff] [blame] | 111 | return GL_OUT_OF_MEMORY; |
daniel@transgaming.com | 72b9e18 | 2011-04-13 14:58:33 +0000 | [diff] [blame] | 112 | } |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | // Perform the vertex data translations |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 117 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 118 | { |
| 119 | if (translated[i].active) |
| 120 | { |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 121 | GLenum result; |
| 122 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 123 | if (attribs[i].enabled) |
daniel@transgaming.com | 8392138 | 2011-01-08 05:46:00 +0000 | [diff] [blame] | 124 | { |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 125 | result = storeAttribute(attribs[i], currentValues[i], &translated[i], |
| 126 | start, count, instances); |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 127 | } |
daniel@transgaming.com | 9a0606c | 2010-05-12 03:42:00 +0000 | [diff] [blame] | 128 | else |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 129 | { |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 130 | if (!mCurrentValueBuffer[i]) |
| 131 | { |
daniel@transgaming.com | e4e4506 | 2012-12-20 20:56:53 +0000 | [diff] [blame] | 132 | mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mRenderer, CONSTANT_VERTEX_BUFFER_SIZE); |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 135 | result = storeCurrentValue(attribs[i], currentValues[i], &translated[i], |
| 136 | &mCurrentValue[i], &mCurrentValueOffsets[i], |
| 137 | mCurrentValueBuffer[i]); |
| 138 | } |
jbauman@chromium.org | 83b61bc | 2011-09-02 18:59:24 +0000 | [diff] [blame] | 139 | |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 140 | if (result != GL_NO_ERROR) |
| 141 | { |
| 142 | return result; |
daniel@transgaming.com | 9a0606c | 2010-05-12 03:42:00 +0000 | [diff] [blame] | 143 | } |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 146 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 147 | for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 148 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 149 | if (translated[i].active && attribs[i].enabled) |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 150 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 151 | gl::Buffer *buffer = attribs[i].buffer.get(); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 152 | |
| 153 | if (buffer) |
| 154 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 155 | BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation()); |
| 156 | bufferImpl->promoteStaticUsage(count * ComputeVertexAttributeTypeSize(attribs[i])); |
daniel@transgaming.com | 78624ca | 2011-04-22 04:17:57 +0000 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
apatrick@chromium.org | f99fbb7 | 2010-11-16 01:57:05 +0000 | [diff] [blame] | 161 | return GL_NO_ERROR; |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Jamie Madill | 6d11380 | 2014-08-25 15:47:52 -0400 | [diff] [blame] | 164 | void VertexDataManager::invalidateMatchingStaticData(const gl::VertexAttribute &attrib, |
| 165 | const gl::VertexAttribCurrentValueData ¤tValue) const |
| 166 | { |
| 167 | gl::Buffer *buffer = attrib.buffer.get(); |
| 168 | |
| 169 | if (buffer) |
| 170 | { |
| 171 | BufferD3D *bufferImpl = BufferD3D::makeBufferD3D(buffer->getImplementation()); |
| 172 | StaticVertexBufferInterface *staticBuffer = bufferImpl->getStaticVertexBuffer(); |
| 173 | |
| 174 | if (staticBuffer && |
| 175 | staticBuffer->getBufferSize() > 0 && |
| 176 | !staticBuffer->lookupAttribute(attrib, NULL) && |
| 177 | !staticBuffer->directStoragePossible(attrib, currentValue)) |
| 178 | { |
| 179 | bufferImpl->invalidateStaticData(); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | bool VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib, |
| 185 | const gl::VertexAttribCurrentValueData ¤tValue, |
| 186 | GLsizei count, |
| 187 | GLsizei instances) const |
| 188 | { |
| 189 | gl::Buffer *buffer = attrib.buffer.get(); |
| 190 | BufferD3D *bufferImpl = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL; |
| 191 | StaticVertexBufferInterface *staticBuffer = bufferImpl ? bufferImpl->getStaticVertexBuffer() : NULL; |
| 192 | VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); |
| 193 | |
| 194 | if (!vertexBuffer->directStoragePossible(attrib, currentValue)) |
| 195 | { |
| 196 | if (staticBuffer) |
| 197 | { |
| 198 | if (staticBuffer->getBufferSize() == 0) |
| 199 | { |
| 200 | int totalCount = ElementsInBuffer(attrib, bufferImpl->getSize()); |
| 201 | if (!staticBuffer->reserveVertexSpace(attrib, totalCount, 0)) |
| 202 | { |
| 203 | return false; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | int totalCount = StreamingBufferElementCount(attrib, count, instances); |
| 210 | ASSERT(!bufferImpl || ElementsInBuffer(attrib, bufferImpl->getSize()) >= totalCount); |
| 211 | |
| 212 | if (!mStreamingBuffer->reserveVertexSpace(attrib, totalCount, instances)) |
| 213 | { |
| 214 | return false; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return true; |
| 220 | } |
| 221 | |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 222 | GLenum VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib, |
| 223 | const gl::VertexAttribCurrentValueData ¤tValue, |
| 224 | TranslatedAttribute *translated, |
| 225 | GLint start, |
| 226 | GLsizei count, |
| 227 | GLsizei instances) |
| 228 | { |
| 229 | gl::Buffer *buffer = attrib.buffer.get(); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 230 | ASSERT(buffer || attrib.pointer); |
Jamie Madill | f41522b | 2014-08-18 16:39:49 -0400 | [diff] [blame] | 231 | |
| 232 | BufferD3D *storage = buffer ? BufferD3D::makeBufferD3D(buffer->getImplementation()) : NULL; |
| 233 | StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL; |
| 234 | VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); |
| 235 | bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue); |
| 236 | |
| 237 | unsigned int streamOffset = 0; |
| 238 | unsigned int outputElementSize = 0; |
| 239 | |
| 240 | if (directStorage) |
| 241 | { |
| 242 | outputElementSize = ComputeVertexAttributeStride(attrib); |
| 243 | streamOffset = attrib.offset + outputElementSize * start; |
| 244 | } |
| 245 | else if (staticBuffer) |
| 246 | { |
| 247 | if (!staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize)) |
| 248 | { |
| 249 | return GL_OUT_OF_MEMORY; |
| 250 | } |
| 251 | |
| 252 | if (!staticBuffer->lookupAttribute(attrib, &streamOffset)) |
| 253 | { |
| 254 | // Convert the entire buffer |
| 255 | int totalCount = ElementsInBuffer(attrib, storage->getSize()); |
| 256 | int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib); |
| 257 | |
| 258 | if (!staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount, |
| 259 | 0, &streamOffset)) |
| 260 | { |
| 261 | return GL_OUT_OF_MEMORY; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | unsigned int firstElementOffset = (attrib.offset / ComputeVertexAttributeStride(attrib)) * outputElementSize; |
| 266 | unsigned int startOffset = (instances == 0 || attrib.divisor == 0) ? start * outputElementSize : 0; |
| 267 | if (streamOffset + firstElementOffset + startOffset < streamOffset) |
| 268 | { |
| 269 | return GL_OUT_OF_MEMORY; |
| 270 | } |
| 271 | |
| 272 | streamOffset += firstElementOffset + startOffset; |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | int totalCount = StreamingBufferElementCount(attrib, count, instances); |
| 277 | if (!mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize) || |
| 278 | !mStreamingBuffer->storeVertexAttributes(attrib, currentValue, start, totalCount, instances, |
| 279 | &streamOffset)) |
| 280 | { |
| 281 | return GL_OUT_OF_MEMORY; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | translated->storage = directStorage ? storage : NULL; |
| 286 | translated->vertexBuffer = vertexBuffer->getVertexBuffer(); |
| 287 | translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial(); |
| 288 | translated->divisor = attrib.divisor; |
| 289 | |
| 290 | translated->attribute = &attrib; |
| 291 | translated->currentValueType = currentValue.Type; |
| 292 | translated->stride = outputElementSize; |
| 293 | translated->offset = streamOffset; |
| 294 | |
| 295 | return GL_NO_ERROR; |
| 296 | } |
| 297 | |
| 298 | GLenum VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib, |
| 299 | const gl::VertexAttribCurrentValueData ¤tValue, |
| 300 | TranslatedAttribute *translated, |
| 301 | gl::VertexAttribCurrentValueData *cachedValue, |
| 302 | size_t *cachedOffset, |
| 303 | StreamingVertexBufferInterface *buffer) |
| 304 | { |
| 305 | if (*cachedValue != currentValue) |
| 306 | { |
| 307 | if (!buffer->reserveVertexSpace(attrib, 1, 0)) |
| 308 | { |
| 309 | return GL_OUT_OF_MEMORY; |
| 310 | } |
| 311 | |
| 312 | unsigned int streamOffset; |
| 313 | if (!buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset)) |
| 314 | { |
| 315 | return GL_OUT_OF_MEMORY; |
| 316 | } |
| 317 | |
| 318 | *cachedValue = currentValue; |
| 319 | *cachedOffset = streamOffset; |
| 320 | } |
| 321 | |
| 322 | translated->storage = NULL; |
| 323 | translated->vertexBuffer = buffer->getVertexBuffer(); |
| 324 | translated->serial = buffer->getSerial(); |
| 325 | translated->divisor = 0; |
| 326 | |
| 327 | translated->attribute = &attrib; |
| 328 | translated->currentValueType = currentValue.Type; |
| 329 | translated->stride = 0; |
| 330 | translated->offset = *cachedOffset; |
| 331 | |
| 332 | return GL_NO_ERROR; |
| 333 | } |
| 334 | |
daniel@transgaming.com | 0f7aaf5 | 2010-03-11 19:41:38 +0000 | [diff] [blame] | 335 | } |