blob: cb70b9e4efa11583d257862b4c56e142e86c910e [file] [log] [blame]
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00001//
daniel@transgaming.com8ca9c6e2012-01-27 15:38:54 +00002// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00003// 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.com8fd34bd2011-02-18 02:52:14 +00007// VertexDataManager.h: Defines the VertexDataManager, a class that
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +00008// runs the Buffer translation process.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/renderer/d3d/VertexDataManager.h"
Jamie Madillfd1bf4e2015-03-31 09:46:02 -040011
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Buffer.h"
Geoff Lang7dd2e102014-11-10 15:19:26 -050013#include "libANGLE/Program.h"
Jamie Madillfd1bf4e2015-03-31 09:46:02 -040014#include "libANGLE/State.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050015#include "libANGLE/VertexAttribute.h"
Geoff Lang5ead9272015-03-25 12:27:43 -040016#include "libANGLE/VertexArray.h"
Jamie Madillfd1bf4e2015-03-31 09:46:02 -040017#include "libANGLE/renderer/d3d/BufferD3D.h"
18#include "libANGLE/renderer/d3d/VertexBuffer.h"
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000019
20namespace
21{
22 enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 };
jbauman@chromium.org83b61bc2011-09-02 18:59:24 +000023 // This has to be at least 4k or else it fails on ATI cards.
24 enum { CONSTANT_VERTEX_BUFFER_SIZE = 4096 };
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000025}
26
daniel@transgaming.com31240482012-11-28 21:06:41 +000027namespace rx
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000028{
29
Brandon Jones5bf98292014-06-06 17:19:38 -070030static int ElementsInBuffer(const gl::VertexAttribute &attrib, unsigned int size)
jbauman@chromium.org059fc152011-11-18 19:26:17 +000031{
Geoff Langa36ead42013-08-02 11:54:08 -040032 // Size cannot be larger than a GLsizei
33 if (size > static_cast<unsigned int>(std::numeric_limits<int>::max()))
34 {
35 size = static_cast<unsigned int>(std::numeric_limits<int>::max());
36 }
37
Brandon Jones5bf98292014-06-06 17:19:38 -070038 GLsizei stride = ComputeVertexAttributeStride(attrib);
39 return (size - attrib.offset % stride + (stride - ComputeVertexAttributeTypeSize(attrib))) / stride;
jbauman@chromium.org059fc152011-11-18 19:26:17 +000040}
41
Brandon Jones5bf98292014-06-06 17:19:38 -070042static int StreamingBufferElementCount(const gl::VertexAttribute &attrib, int vertexDrawCount, int instanceDrawCount)
Jamie Madill9b4f3842013-08-26 15:29:30 -040043{
44 // For instanced rendering, we draw "instanceDrawCount" sets of "vertexDrawCount" vertices.
45 //
46 // A vertex attribute with a positive divisor loads one instanced vertex for every set of
47 // non-instanced vertices, and the instanced vertex index advances once every "mDivisor" instances.
Brandon Jones5bf98292014-06-06 17:19:38 -070048 if (instanceDrawCount > 0 && attrib.divisor > 0)
Jamie Madill9b4f3842013-08-26 15:29:30 -040049 {
Gregoire Payen de La Garanderie2c7ea052015-01-07 12:47:35 +000050 // When instanceDrawCount is not a multiple attrib.divisor, the division must round up.
51 // For instance, with 5 non-instanced vertices and a divisor equal to 3, we need 2 instanced vertices.
52 return (instanceDrawCount + attrib.divisor - 1) / attrib.divisor;
Jamie Madill9b4f3842013-08-26 15:29:30 -040053 }
54
55 return vertexDrawCount;
56}
57
Jamie Madillfd1bf4e2015-03-31 09:46:02 -040058VertexDataManager::VertexDataManager(BufferFactoryD3D *factory)
59 : mFactory(factory)
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000060{
daniel@transgaming.com31240482012-11-28 21:06:41 +000061 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000062 {
shannon.woods%transgaming.com@gtempaccount.com3026dc72013-04-13 03:37:27 +000063 mCurrentValue[i].FloatValues[0] = std::numeric_limits<float>::quiet_NaN();
64 mCurrentValue[i].FloatValues[1] = std::numeric_limits<float>::quiet_NaN();
65 mCurrentValue[i].FloatValues[2] = std::numeric_limits<float>::quiet_NaN();
66 mCurrentValue[i].FloatValues[3] = std::numeric_limits<float>::quiet_NaN();
67 mCurrentValue[i].Type = GL_FLOAT;
daniel@transgaming.com83921382011-01-08 05:46:00 +000068 mCurrentValueBuffer[i] = NULL;
jbauman@chromium.org83b61bc2011-09-02 18:59:24 +000069 mCurrentValueOffsets[i] = 0;
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000070 }
daniel@transgaming.com83921382011-01-08 05:46:00 +000071
Jamie Madillfd1bf4e2015-03-31 09:46:02 -040072 mStreamingBuffer = new StreamingVertexBufferInterface(factory, INITIAL_STREAM_BUFFER_SIZE);
daniel@transgaming.com72b9e182011-04-13 14:58:33 +000073
74 if (!mStreamingBuffer)
75 {
76 ERR("Failed to allocate the streaming vertex buffer.");
77 }
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000078}
79
80VertexDataManager::~VertexDataManager()
81{
daniel@transgaming.com83921382011-01-08 05:46:00 +000082 delete mStreamingBuffer;
83
daniel@transgaming.com31240482012-11-28 21:06:41 +000084 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
daniel@transgaming.com83921382011-01-08 05:46:00 +000085 {
86 delete mCurrentValueBuffer[i];
87 }
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000088}
89
Geoff Lang5ead9272015-03-25 12:27:43 -040090void VertexDataManager::hintUnmapAllResources(const std::vector<gl::VertexAttribute> &vertexAttributes)
Austin Kinrossbe0facc2015-01-07 16:22:29 -080091{
92 mStreamingBuffer->getVertexBuffer()->hintUnmapResource();
93
Geoff Lang5ead9272015-03-25 12:27:43 -040094 for (size_t i = 0; i < vertexAttributes.size(); i++)
Austin Kinrossbe0facc2015-01-07 16:22:29 -080095 {
Geoff Lang5ead9272015-03-25 12:27:43 -040096 const gl::VertexAttribute &attrib = vertexAttributes[i];
Austin Kinrossbe0facc2015-01-07 16:22:29 -080097 if (attrib.enabled)
98 {
99 gl::Buffer *buffer = attrib.buffer.get();
Jamie Madill9236b412015-02-02 16:51:52 -0500100 BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800101 StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
102
103 if (staticBuffer)
104 {
105 staticBuffer->getVertexBuffer()->hintUnmapResource();
106 }
107 }
108 }
109
110 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
111 {
112 if (mCurrentValueBuffer[i] != NULL)
113 {
114 mCurrentValueBuffer[i]->getVertexBuffer()->hintUnmapResource();
115 }
116 }
117}
118
Shannon Woods1a965482014-09-22 18:00:32 -0400119gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint start, GLsizei count,
120 TranslatedAttribute *translated, GLsizei instances)
daniel@transgaming.com83921382011-01-08 05:46:00 +0000121{
daniel@transgaming.com72b9e182011-04-13 14:58:33 +0000122 if (!mStreamingBuffer)
123 {
Geoff Langf7100b92014-09-08 16:17:08 -0400124 return gl::Error(GL_OUT_OF_MEMORY, "Internal streaming vertex buffer is unexpectedly NULL.");
daniel@transgaming.com72b9e182011-04-13 14:58:33 +0000125 }
126
Geoff Lang5ead9272015-03-25 12:27:43 -0400127 const gl::VertexArray *vertexArray = state.getVertexArray();
128 const std::vector<gl::VertexAttribute> &vertexAttributes = vertexArray->getVertexAttributes();
129
Jamie Madill6d113802014-08-25 15:47:52 -0400130 // Invalidate static buffers that don't contain matching attributes
daniel@transgaming.com31240482012-11-28 21:06:41 +0000131 for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000132 {
Geoff Lang7dd2e102014-11-10 15:19:26 -0500133 translated[attributeIndex].active = (state.getProgram()->getSemanticIndex(attributeIndex) != -1);
Geoff Lang5ead9272015-03-25 12:27:43 -0400134 if (translated[attributeIndex].active && vertexAttributes[attributeIndex].enabled)
daniel@transgaming.comc828b142010-05-12 03:42:04 +0000135 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400136 invalidateMatchingStaticData(vertexAttributes[attributeIndex], state.getVertexAttribCurrentValue(attributeIndex));
shannon.woods@transgaming.coma9a509e2013-02-28 23:10:44 +0000137 }
138 }
139
140 // Reserve the required space in the buffers
141 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
142 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400143 if (translated[i].active && vertexAttributes[i].enabled)
shannon.woods@transgaming.coma9a509e2013-02-28 23:10:44 +0000144 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400145 gl::Error error = reserveSpaceForAttrib(vertexAttributes[i], state.getVertexAttribCurrentValue(i), count, instances);
Geoff Langf7100b92014-09-08 16:17:08 -0400146 if (error.isError())
apatrick@chromium.orgf99fbb72010-11-16 01:57:05 +0000147 {
Geoff Langf7100b92014-09-08 16:17:08 -0400148 return error;
daniel@transgaming.com72b9e182011-04-13 14:58:33 +0000149 }
daniel@transgaming.com83921382011-01-08 05:46:00 +0000150 }
151 }
152
153 // Perform the vertex data translations
daniel@transgaming.com31240482012-11-28 21:06:41 +0000154 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
daniel@transgaming.com83921382011-01-08 05:46:00 +0000155 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400156 const gl::VertexAttribute &curAttrib = vertexAttributes[i];
daniel@transgaming.com83921382011-01-08 05:46:00 +0000157 if (translated[i].active)
158 {
Shannon Woods1a965482014-09-22 18:00:32 -0400159 if (curAttrib.enabled)
daniel@transgaming.com83921382011-01-08 05:46:00 +0000160 {
Shannon Woods1a965482014-09-22 18:00:32 -0400161 gl::Error error = storeAttribute(curAttrib, state.getVertexAttribCurrentValue(i),
162 &translated[i], start, count, instances);
163
Geoff Langf7100b92014-09-08 16:17:08 -0400164 if (error.isError())
165 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400166 hintUnmapAllResources(vertexAttributes);
Geoff Langf7100b92014-09-08 16:17:08 -0400167 return error;
168 }
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000169 }
daniel@transgaming.com9a0606c2010-05-12 03:42:00 +0000170 else
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000171 {
jbauman@chromium.org83b61bc2011-09-02 18:59:24 +0000172 if (!mCurrentValueBuffer[i])
173 {
Jamie Madillfd1bf4e2015-03-31 09:46:02 -0400174 mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mFactory, CONSTANT_VERTEX_BUFFER_SIZE);
jbauman@chromium.org83b61bc2011-09-02 18:59:24 +0000175 }
176
Shannon Woods1a965482014-09-22 18:00:32 -0400177 gl::Error error = storeCurrentValue(curAttrib, state.getVertexAttribCurrentValue(i), &translated[i],
Geoff Langf7100b92014-09-08 16:17:08 -0400178 &mCurrentValue[i], &mCurrentValueOffsets[i],
179 mCurrentValueBuffer[i]);
180 if (error.isError())
181 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400182 hintUnmapAllResources(vertexAttributes);
Geoff Langf7100b92014-09-08 16:17:08 -0400183 return error;
184 }
daniel@transgaming.com9a0606c2010-05-12 03:42:00 +0000185 }
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000186 }
187 }
apatrick@chromium.orgf99fbb72010-11-16 01:57:05 +0000188
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800189 // Hint to unmap all the resources
Geoff Lang5ead9272015-03-25 12:27:43 -0400190 hintUnmapAllResources(vertexAttributes);
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800191
daniel@transgaming.com31240482012-11-28 21:06:41 +0000192 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
daniel@transgaming.com78624ca2011-04-22 04:17:57 +0000193 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400194 const gl::VertexAttribute &curAttrib = vertexAttributes[i];
Shannon Woods1a965482014-09-22 18:00:32 -0400195 if (translated[i].active && curAttrib.enabled)
daniel@transgaming.com78624ca2011-04-22 04:17:57 +0000196 {
Shannon Woods1a965482014-09-22 18:00:32 -0400197 gl::Buffer *buffer = curAttrib.buffer.get();
daniel@transgaming.com78624ca2011-04-22 04:17:57 +0000198
199 if (buffer)
200 {
Jamie Madill9236b412015-02-02 16:51:52 -0500201 BufferD3D *bufferImpl = GetImplAs<BufferD3D>(buffer);
Shannon Woods1a965482014-09-22 18:00:32 -0400202 bufferImpl->promoteStaticUsage(count * ComputeVertexAttributeTypeSize(curAttrib));
daniel@transgaming.com78624ca2011-04-22 04:17:57 +0000203 }
204 }
205 }
206
Geoff Langf7100b92014-09-08 16:17:08 -0400207 return gl::Error(GL_NO_ERROR);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000208}
209
Jamie Madill6d113802014-08-25 15:47:52 -0400210void VertexDataManager::invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
211 const gl::VertexAttribCurrentValueData &currentValue) const
212{
213 gl::Buffer *buffer = attrib.buffer.get();
214
215 if (buffer)
216 {
Jamie Madill9236b412015-02-02 16:51:52 -0500217 BufferD3D *bufferImpl = GetImplAs<BufferD3D>(buffer);
Jamie Madill6d113802014-08-25 15:47:52 -0400218 StaticVertexBufferInterface *staticBuffer = bufferImpl->getStaticVertexBuffer();
219
220 if (staticBuffer &&
221 staticBuffer->getBufferSize() > 0 &&
222 !staticBuffer->lookupAttribute(attrib, NULL) &&
223 !staticBuffer->directStoragePossible(attrib, currentValue))
224 {
225 bufferImpl->invalidateStaticData();
226 }
227 }
228}
229
Geoff Langf7100b92014-09-08 16:17:08 -0400230gl::Error VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
231 const gl::VertexAttribCurrentValueData &currentValue,
232 GLsizei count,
233 GLsizei instances) const
Jamie Madill6d113802014-08-25 15:47:52 -0400234{
235 gl::Buffer *buffer = attrib.buffer.get();
Jamie Madill9236b412015-02-02 16:51:52 -0500236 BufferD3D *bufferImpl = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
Jamie Madill6d113802014-08-25 15:47:52 -0400237 StaticVertexBufferInterface *staticBuffer = bufferImpl ? bufferImpl->getStaticVertexBuffer() : NULL;
238 VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
239
240 if (!vertexBuffer->directStoragePossible(attrib, currentValue))
241 {
242 if (staticBuffer)
243 {
244 if (staticBuffer->getBufferSize() == 0)
245 {
246 int totalCount = ElementsInBuffer(attrib, bufferImpl->getSize());
Geoff Langf7100b92014-09-08 16:17:08 -0400247 gl::Error error = staticBuffer->reserveVertexSpace(attrib, totalCount, 0);
248 if (error.isError())
Jamie Madill6d113802014-08-25 15:47:52 -0400249 {
Geoff Langf7100b92014-09-08 16:17:08 -0400250 return error;
Jamie Madill6d113802014-08-25 15:47:52 -0400251 }
252 }
253 }
254 else
255 {
256 int totalCount = StreamingBufferElementCount(attrib, count, instances);
257 ASSERT(!bufferImpl || ElementsInBuffer(attrib, bufferImpl->getSize()) >= totalCount);
258
Geoff Langf7100b92014-09-08 16:17:08 -0400259 gl::Error error = mStreamingBuffer->reserveVertexSpace(attrib, totalCount, instances);
260 if (error.isError())
Jamie Madill6d113802014-08-25 15:47:52 -0400261 {
Geoff Langf7100b92014-09-08 16:17:08 -0400262 return error;
Jamie Madill6d113802014-08-25 15:47:52 -0400263 }
264 }
265 }
266
Geoff Langf7100b92014-09-08 16:17:08 -0400267 return gl::Error(GL_NO_ERROR);
Jamie Madill6d113802014-08-25 15:47:52 -0400268}
269
Geoff Langf7100b92014-09-08 16:17:08 -0400270gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
271 const gl::VertexAttribCurrentValueData &currentValue,
272 TranslatedAttribute *translated,
273 GLint start,
274 GLsizei count,
275 GLsizei instances)
Jamie Madillf41522b2014-08-18 16:39:49 -0400276{
277 gl::Buffer *buffer = attrib.buffer.get();
Jamie Madill2b976812014-08-25 15:47:49 -0400278 ASSERT(buffer || attrib.pointer);
Jamie Madillf41522b2014-08-18 16:39:49 -0400279
Jamie Madill9236b412015-02-02 16:51:52 -0500280 BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
Jamie Madillf41522b2014-08-18 16:39:49 -0400281 StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
282 VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
283 bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue);
284
285 unsigned int streamOffset = 0;
286 unsigned int outputElementSize = 0;
287
Jamie Madilld4b55a02015-01-09 14:21:49 -0500288 // Instanced vertices do not apply the 'start' offset
289 GLint firstVertexIndex = (instances > 0 && attrib.divisor > 0 ? 0 : start);
290
Jamie Madillf41522b2014-08-18 16:39:49 -0400291 if (directStorage)
292 {
293 outputElementSize = ComputeVertexAttributeStride(attrib);
Jamie Madilld4b55a02015-01-09 14:21:49 -0500294 streamOffset = attrib.offset + outputElementSize * firstVertexIndex;
Jamie Madillf41522b2014-08-18 16:39:49 -0400295 }
296 else if (staticBuffer)
297 {
Geoff Langf7100b92014-09-08 16:17:08 -0400298 gl::Error error = staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
299 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400300 {
Geoff Langf7100b92014-09-08 16:17:08 -0400301 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400302 }
303
304 if (!staticBuffer->lookupAttribute(attrib, &streamOffset))
305 {
306 // Convert the entire buffer
307 int totalCount = ElementsInBuffer(attrib, storage->getSize());
308 int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib);
309
Austin Kinross3ae64652015-01-26 15:51:39 -0800310 error = staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount,
311 0, &streamOffset);
Geoff Langf7100b92014-09-08 16:17:08 -0400312 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400313 {
Geoff Langf7100b92014-09-08 16:17:08 -0400314 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400315 }
316 }
317
318 unsigned int firstElementOffset = (attrib.offset / ComputeVertexAttributeStride(attrib)) * outputElementSize;
Jamie Madilld4b55a02015-01-09 14:21:49 -0500319 unsigned int startOffset = (instances == 0 || attrib.divisor == 0) ? firstVertexIndex * outputElementSize : 0;
Jamie Madillf41522b2014-08-18 16:39:49 -0400320 if (streamOffset + firstElementOffset + startOffset < streamOffset)
321 {
Geoff Langf7100b92014-09-08 16:17:08 -0400322 return gl::Error(GL_OUT_OF_MEMORY);
Jamie Madillf41522b2014-08-18 16:39:49 -0400323 }
324
325 streamOffset += firstElementOffset + startOffset;
326 }
327 else
328 {
329 int totalCount = StreamingBufferElementCount(attrib, count, instances);
Geoff Langf7100b92014-09-08 16:17:08 -0400330 gl::Error error = mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
331 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400332 {
Geoff Langf7100b92014-09-08 16:17:08 -0400333 return error;
334 }
335
Jamie Madilld4b55a02015-01-09 14:21:49 -0500336 error = mStreamingBuffer->storeVertexAttributes(attrib, currentValue, firstVertexIndex,
337 totalCount, instances, &streamOffset);
Geoff Langf7100b92014-09-08 16:17:08 -0400338 if (error.isError())
339 {
340 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400341 }
342 }
343
344 translated->storage = directStorage ? storage : NULL;
345 translated->vertexBuffer = vertexBuffer->getVertexBuffer();
346 translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial();
347 translated->divisor = attrib.divisor;
348
349 translated->attribute = &attrib;
350 translated->currentValueType = currentValue.Type;
351 translated->stride = outputElementSize;
352 translated->offset = streamOffset;
353
Geoff Langf7100b92014-09-08 16:17:08 -0400354 return gl::Error(GL_NO_ERROR);
Jamie Madillf41522b2014-08-18 16:39:49 -0400355}
356
Geoff Langf7100b92014-09-08 16:17:08 -0400357gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib,
358 const gl::VertexAttribCurrentValueData &currentValue,
359 TranslatedAttribute *translated,
360 gl::VertexAttribCurrentValueData *cachedValue,
361 size_t *cachedOffset,
362 StreamingVertexBufferInterface *buffer)
Jamie Madillf41522b2014-08-18 16:39:49 -0400363{
364 if (*cachedValue != currentValue)
365 {
Geoff Langf7100b92014-09-08 16:17:08 -0400366 gl::Error error = buffer->reserveVertexSpace(attrib, 1, 0);
367 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400368 {
Geoff Langf7100b92014-09-08 16:17:08 -0400369 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400370 }
371
372 unsigned int streamOffset;
Geoff Langf7100b92014-09-08 16:17:08 -0400373 error = buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset);
374 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400375 {
Geoff Langf7100b92014-09-08 16:17:08 -0400376 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400377 }
378
379 *cachedValue = currentValue;
380 *cachedOffset = streamOffset;
381 }
382
383 translated->storage = NULL;
384 translated->vertexBuffer = buffer->getVertexBuffer();
385 translated->serial = buffer->getSerial();
386 translated->divisor = 0;
387
388 translated->attribute = &attrib;
389 translated->currentValueType = currentValue.Type;
390 translated->stride = 0;
391 translated->offset = *cachedOffset;
392
Geoff Langf7100b92014-09-08 16:17:08 -0400393 return gl::Error(GL_NO_ERROR);
Jamie Madillf41522b2014-08-18 16:39:49 -0400394}
395
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000396}