blob: 3c3766403de4b516da66f54ceb92f67abbd62951 [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 Madillb3f4e8d2015-06-22 13:57:17 -040058VertexDataManager::CurrentValueState::CurrentValueState()
59 : buffer(nullptr),
60 offset(0)
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000061{
Jamie Madillb3f4e8d2015-06-22 13:57:17 -040062 data.FloatValues[0] = std::numeric_limits<float>::quiet_NaN();
63 data.FloatValues[1] = std::numeric_limits<float>::quiet_NaN();
64 data.FloatValues[2] = std::numeric_limits<float>::quiet_NaN();
65 data.FloatValues[3] = std::numeric_limits<float>::quiet_NaN();
66 data.Type = GL_FLOAT;
67}
daniel@transgaming.com83921382011-01-08 05:46:00 +000068
Jamie Madillb3f4e8d2015-06-22 13:57:17 -040069VertexDataManager::CurrentValueState::~CurrentValueState()
70{
71 SafeDelete(buffer);
72}
73
74VertexDataManager::VertexDataManager(BufferFactoryD3D *factory)
75 : mFactory(factory),
76 mStreamingBuffer(nullptr),
77 // TODO(jmadill): use context caps
78 mCurrentValueCache(gl::MAX_VERTEX_ATTRIBS)
79{
Jamie Madillfd1bf4e2015-03-31 09:46:02 -040080 mStreamingBuffer = new StreamingVertexBufferInterface(factory, INITIAL_STREAM_BUFFER_SIZE);
daniel@transgaming.com72b9e182011-04-13 14:58:33 +000081
82 if (!mStreamingBuffer)
83 {
84 ERR("Failed to allocate the streaming vertex buffer.");
85 }
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000086}
87
88VertexDataManager::~VertexDataManager()
89{
Jamie Madillb3f4e8d2015-06-22 13:57:17 -040090 SafeDelete(mStreamingBuffer);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +000091}
92
Geoff Lang5ead9272015-03-25 12:27:43 -040093void VertexDataManager::hintUnmapAllResources(const std::vector<gl::VertexAttribute> &vertexAttributes)
Austin Kinrossbe0facc2015-01-07 16:22:29 -080094{
95 mStreamingBuffer->getVertexBuffer()->hintUnmapResource();
96
Geoff Lang5ead9272015-03-25 12:27:43 -040097 for (size_t i = 0; i < vertexAttributes.size(); i++)
Austin Kinrossbe0facc2015-01-07 16:22:29 -080098 {
Geoff Lang5ead9272015-03-25 12:27:43 -040099 const gl::VertexAttribute &attrib = vertexAttributes[i];
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800100 if (attrib.enabled)
101 {
102 gl::Buffer *buffer = attrib.buffer.get();
Jamie Madill9236b412015-02-02 16:51:52 -0500103 BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800104 StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
105
106 if (staticBuffer)
107 {
108 staticBuffer->getVertexBuffer()->hintUnmapResource();
109 }
110 }
111 }
112
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400113 for (auto &currentValue : mCurrentValueCache)
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800114 {
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400115 if (currentValue.buffer != nullptr)
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800116 {
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400117 currentValue.buffer->getVertexBuffer()->hintUnmapResource();
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800118 }
119 }
120}
121
Shannon Woods1a965482014-09-22 18:00:32 -0400122gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint start, GLsizei count,
123 TranslatedAttribute *translated, GLsizei instances)
daniel@transgaming.com83921382011-01-08 05:46:00 +0000124{
daniel@transgaming.com72b9e182011-04-13 14:58:33 +0000125 if (!mStreamingBuffer)
126 {
Geoff Langf7100b92014-09-08 16:17:08 -0400127 return gl::Error(GL_OUT_OF_MEMORY, "Internal streaming vertex buffer is unexpectedly NULL.");
daniel@transgaming.com72b9e182011-04-13 14:58:33 +0000128 }
129
Geoff Lang5ead9272015-03-25 12:27:43 -0400130 const gl::VertexArray *vertexArray = state.getVertexArray();
131 const std::vector<gl::VertexAttribute> &vertexAttributes = vertexArray->getVertexAttributes();
132
Jamie Madill9c385802015-06-22 13:57:18 -0400133 for (size_t attribIndex = 0; attribIndex < vertexAttributes.size(); ++attribIndex)
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000134 {
Jamie Madill9c385802015-06-22 13:57:18 -0400135 translated[attribIndex].active = (state.getProgram()->getSemanticIndex(attribIndex) != -1);
136 if (translated[attribIndex].active)
daniel@transgaming.comc828b142010-05-12 03:42:04 +0000137 {
Jamie Madill9c385802015-06-22 13:57:18 -0400138 // Record the attribute now
139 translated[attribIndex].attribute = &vertexAttributes[attribIndex];
140
141 if (vertexAttributes[attribIndex].enabled)
142 {
143 // Also invalidate static buffers that don't contain matching attributes
144 invalidateMatchingStaticData(vertexAttributes[attribIndex],
145 state.getVertexAttribCurrentValue(attribIndex));
146 }
shannon.woods@transgaming.coma9a509e2013-02-28 23:10:44 +0000147 }
148 }
149
150 // Reserve the required space in the buffers
151 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
152 {
Jamie Madill9c385802015-06-22 13:57:18 -0400153 if (translated[i].active && translated[i].attribute->enabled)
shannon.woods@transgaming.coma9a509e2013-02-28 23:10:44 +0000154 {
Jamie Madill9c385802015-06-22 13:57:18 -0400155 gl::Error error = reserveSpaceForAttrib(*translated[i].attribute, state.getVertexAttribCurrentValue(i), count, instances);
Geoff Langf7100b92014-09-08 16:17:08 -0400156 if (error.isError())
apatrick@chromium.orgf99fbb72010-11-16 01:57:05 +0000157 {
Geoff Langf7100b92014-09-08 16:17:08 -0400158 return error;
daniel@transgaming.com72b9e182011-04-13 14:58:33 +0000159 }
daniel@transgaming.com83921382011-01-08 05:46:00 +0000160 }
161 }
162
163 // Perform the vertex data translations
daniel@transgaming.com31240482012-11-28 21:06:41 +0000164 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
daniel@transgaming.com83921382011-01-08 05:46:00 +0000165 {
166 if (translated[i].active)
167 {
Jamie Madill9c385802015-06-22 13:57:18 -0400168 if (translated[i].attribute->enabled)
daniel@transgaming.com83921382011-01-08 05:46:00 +0000169 {
Jamie Madill9c385802015-06-22 13:57:18 -0400170 gl::Error error = storeAttribute(state.getVertexAttribCurrentValue(i),
171 &translated[i],
172 start,
173 count,
174 instances);
Shannon Woods1a965482014-09-22 18:00:32 -0400175
Geoff Langf7100b92014-09-08 16:17:08 -0400176 if (error.isError())
177 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400178 hintUnmapAllResources(vertexAttributes);
Geoff Langf7100b92014-09-08 16:17:08 -0400179 return error;
180 }
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000181 }
daniel@transgaming.com9a0606c2010-05-12 03:42:00 +0000182 else
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000183 {
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400184 if (mCurrentValueCache[i].buffer == nullptr)
jbauman@chromium.org83b61bc2011-09-02 18:59:24 +0000185 {
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400186 mCurrentValueCache[i].buffer = new StreamingVertexBufferInterface(mFactory, CONSTANT_VERTEX_BUFFER_SIZE);
jbauman@chromium.org83b61bc2011-09-02 18:59:24 +0000187 }
188
Jamie Madill9c385802015-06-22 13:57:18 -0400189 gl::Error error = storeCurrentValue(state.getVertexAttribCurrentValue(i),
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400190 &translated[i],
191 &mCurrentValueCache[i]);
Geoff Langf7100b92014-09-08 16:17:08 -0400192 if (error.isError())
193 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400194 hintUnmapAllResources(vertexAttributes);
Geoff Langf7100b92014-09-08 16:17:08 -0400195 return error;
196 }
daniel@transgaming.com9a0606c2010-05-12 03:42:00 +0000197 }
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000198 }
199 }
apatrick@chromium.orgf99fbb72010-11-16 01:57:05 +0000200
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800201 // Hint to unmap all the resources
Geoff Lang5ead9272015-03-25 12:27:43 -0400202 hintUnmapAllResources(vertexAttributes);
Austin Kinrossbe0facc2015-01-07 16:22:29 -0800203
daniel@transgaming.com31240482012-11-28 21:06:41 +0000204 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
daniel@transgaming.com78624ca2011-04-22 04:17:57 +0000205 {
Geoff Lang5ead9272015-03-25 12:27:43 -0400206 const gl::VertexAttribute &curAttrib = vertexAttributes[i];
Shannon Woods1a965482014-09-22 18:00:32 -0400207 if (translated[i].active && curAttrib.enabled)
daniel@transgaming.com78624ca2011-04-22 04:17:57 +0000208 {
Shannon Woods1a965482014-09-22 18:00:32 -0400209 gl::Buffer *buffer = curAttrib.buffer.get();
daniel@transgaming.com78624ca2011-04-22 04:17:57 +0000210
211 if (buffer)
212 {
Jamie Madill9236b412015-02-02 16:51:52 -0500213 BufferD3D *bufferImpl = GetImplAs<BufferD3D>(buffer);
Shannon Woods1a965482014-09-22 18:00:32 -0400214 bufferImpl->promoteStaticUsage(count * ComputeVertexAttributeTypeSize(curAttrib));
daniel@transgaming.com78624ca2011-04-22 04:17:57 +0000215 }
216 }
217 }
218
Geoff Langf7100b92014-09-08 16:17:08 -0400219 return gl::Error(GL_NO_ERROR);
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000220}
221
Jamie Madill6d113802014-08-25 15:47:52 -0400222void VertexDataManager::invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
223 const gl::VertexAttribCurrentValueData &currentValue) const
224{
225 gl::Buffer *buffer = attrib.buffer.get();
226
227 if (buffer)
228 {
Jamie Madill9236b412015-02-02 16:51:52 -0500229 BufferD3D *bufferImpl = GetImplAs<BufferD3D>(buffer);
Jamie Madill6d113802014-08-25 15:47:52 -0400230 StaticVertexBufferInterface *staticBuffer = bufferImpl->getStaticVertexBuffer();
231
232 if (staticBuffer &&
233 staticBuffer->getBufferSize() > 0 &&
234 !staticBuffer->lookupAttribute(attrib, NULL) &&
235 !staticBuffer->directStoragePossible(attrib, currentValue))
236 {
237 bufferImpl->invalidateStaticData();
238 }
239 }
240}
241
Geoff Langf7100b92014-09-08 16:17:08 -0400242gl::Error VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
243 const gl::VertexAttribCurrentValueData &currentValue,
244 GLsizei count,
245 GLsizei instances) const
Jamie Madill6d113802014-08-25 15:47:52 -0400246{
247 gl::Buffer *buffer = attrib.buffer.get();
Jamie Madill9236b412015-02-02 16:51:52 -0500248 BufferD3D *bufferImpl = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
Jamie Madill6d113802014-08-25 15:47:52 -0400249 StaticVertexBufferInterface *staticBuffer = bufferImpl ? bufferImpl->getStaticVertexBuffer() : NULL;
250 VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
251
252 if (!vertexBuffer->directStoragePossible(attrib, currentValue))
253 {
254 if (staticBuffer)
255 {
256 if (staticBuffer->getBufferSize() == 0)
257 {
258 int totalCount = ElementsInBuffer(attrib, bufferImpl->getSize());
Geoff Langf7100b92014-09-08 16:17:08 -0400259 gl::Error error = staticBuffer->reserveVertexSpace(attrib, totalCount, 0);
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 else
267 {
268 int totalCount = StreamingBufferElementCount(attrib, count, instances);
269 ASSERT(!bufferImpl || ElementsInBuffer(attrib, bufferImpl->getSize()) >= totalCount);
270
Geoff Langf7100b92014-09-08 16:17:08 -0400271 gl::Error error = mStreamingBuffer->reserveVertexSpace(attrib, totalCount, instances);
272 if (error.isError())
Jamie Madill6d113802014-08-25 15:47:52 -0400273 {
Geoff Langf7100b92014-09-08 16:17:08 -0400274 return error;
Jamie Madill6d113802014-08-25 15:47:52 -0400275 }
276 }
277 }
278
Geoff Langf7100b92014-09-08 16:17:08 -0400279 return gl::Error(GL_NO_ERROR);
Jamie Madill6d113802014-08-25 15:47:52 -0400280}
281
Jamie Madill9c385802015-06-22 13:57:18 -0400282gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueData &currentValue,
Geoff Langf7100b92014-09-08 16:17:08 -0400283 TranslatedAttribute *translated,
284 GLint start,
285 GLsizei count,
286 GLsizei instances)
Jamie Madillf41522b2014-08-18 16:39:49 -0400287{
Jamie Madill9c385802015-06-22 13:57:18 -0400288 const gl::VertexAttribute &attrib = *translated->attribute;
289
Jamie Madillf41522b2014-08-18 16:39:49 -0400290 gl::Buffer *buffer = attrib.buffer.get();
Jamie Madill2b976812014-08-25 15:47:49 -0400291 ASSERT(buffer || attrib.pointer);
Jamie Madillf41522b2014-08-18 16:39:49 -0400292
Jamie Madill9236b412015-02-02 16:51:52 -0500293 BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
Jamie Madillf41522b2014-08-18 16:39:49 -0400294 StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
295 VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
296 bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue);
297
298 unsigned int streamOffset = 0;
299 unsigned int outputElementSize = 0;
300
Jamie Madilld4b55a02015-01-09 14:21:49 -0500301 // Instanced vertices do not apply the 'start' offset
302 GLint firstVertexIndex = (instances > 0 && attrib.divisor > 0 ? 0 : start);
303
Jamie Madillf41522b2014-08-18 16:39:49 -0400304 if (directStorage)
305 {
306 outputElementSize = ComputeVertexAttributeStride(attrib);
Minmin Gong794e0002015-04-07 18:31:54 -0700307 streamOffset = static_cast<unsigned int>(attrib.offset + outputElementSize * firstVertexIndex);
Jamie Madillf41522b2014-08-18 16:39:49 -0400308 }
309 else if (staticBuffer)
310 {
Geoff Langf7100b92014-09-08 16:17:08 -0400311 gl::Error error = staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
312 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 if (!staticBuffer->lookupAttribute(attrib, &streamOffset))
318 {
319 // Convert the entire buffer
320 int totalCount = ElementsInBuffer(attrib, storage->getSize());
321 int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib);
322
Austin Kinross3ae64652015-01-26 15:51:39 -0800323 error = staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount,
324 0, &streamOffset);
Geoff Langf7100b92014-09-08 16:17:08 -0400325 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400326 {
Geoff Langf7100b92014-09-08 16:17:08 -0400327 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400328 }
329 }
330
331 unsigned int firstElementOffset = (attrib.offset / ComputeVertexAttributeStride(attrib)) * outputElementSize;
Jamie Madilld4b55a02015-01-09 14:21:49 -0500332 unsigned int startOffset = (instances == 0 || attrib.divisor == 0) ? firstVertexIndex * outputElementSize : 0;
Jamie Madillf41522b2014-08-18 16:39:49 -0400333 if (streamOffset + firstElementOffset + startOffset < streamOffset)
334 {
Geoff Langf7100b92014-09-08 16:17:08 -0400335 return gl::Error(GL_OUT_OF_MEMORY);
Jamie Madillf41522b2014-08-18 16:39:49 -0400336 }
337
338 streamOffset += firstElementOffset + startOffset;
339 }
340 else
341 {
342 int totalCount = StreamingBufferElementCount(attrib, count, instances);
Geoff Langf7100b92014-09-08 16:17:08 -0400343 gl::Error error = mStreamingBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
344 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400345 {
Geoff Langf7100b92014-09-08 16:17:08 -0400346 return error;
347 }
348
Jamie Madilld4b55a02015-01-09 14:21:49 -0500349 error = mStreamingBuffer->storeVertexAttributes(attrib, currentValue, firstVertexIndex,
350 totalCount, instances, &streamOffset);
Geoff Langf7100b92014-09-08 16:17:08 -0400351 if (error.isError())
352 {
353 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400354 }
355 }
356
357 translated->storage = directStorage ? storage : NULL;
358 translated->vertexBuffer = vertexBuffer->getVertexBuffer();
359 translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial();
360 translated->divisor = attrib.divisor;
361
Jamie Madillf41522b2014-08-18 16:39:49 -0400362 translated->currentValueType = currentValue.Type;
363 translated->stride = outputElementSize;
364 translated->offset = streamOffset;
365
Geoff Langf7100b92014-09-08 16:17:08 -0400366 return gl::Error(GL_NO_ERROR);
Jamie Madillf41522b2014-08-18 16:39:49 -0400367}
368
Jamie Madill9c385802015-06-22 13:57:18 -0400369gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValueData &currentValue,
Geoff Langf7100b92014-09-08 16:17:08 -0400370 TranslatedAttribute *translated,
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400371 CurrentValueState *cachedState)
Jamie Madillf41522b2014-08-18 16:39:49 -0400372{
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400373 if (cachedState->data != currentValue)
Jamie Madillf41522b2014-08-18 16:39:49 -0400374 {
Jamie Madill9c385802015-06-22 13:57:18 -0400375 const gl::VertexAttribute &attrib = *translated->attribute;
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400376 gl::Error error = cachedState->buffer->reserveVertexSpace(attrib, 1, 0);
Geoff Langf7100b92014-09-08 16:17:08 -0400377 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400378 {
Geoff Langf7100b92014-09-08 16:17:08 -0400379 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400380 }
381
382 unsigned int streamOffset;
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400383 error = cachedState->buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset);
Geoff Langf7100b92014-09-08 16:17:08 -0400384 if (error.isError())
Jamie Madillf41522b2014-08-18 16:39:49 -0400385 {
Geoff Langf7100b92014-09-08 16:17:08 -0400386 return error;
Jamie Madillf41522b2014-08-18 16:39:49 -0400387 }
388
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400389 cachedState->data = currentValue;
390 cachedState->offset = streamOffset;
Jamie Madillf41522b2014-08-18 16:39:49 -0400391 }
392
393 translated->storage = NULL;
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400394 translated->vertexBuffer = cachedState->buffer->getVertexBuffer();
395 translated->serial = cachedState->buffer->getSerial();
Jamie Madillf41522b2014-08-18 16:39:49 -0400396 translated->divisor = 0;
397
Jamie Madillf41522b2014-08-18 16:39:49 -0400398 translated->currentValueType = currentValue.Type;
399 translated->stride = 0;
Jamie Madillb3f4e8d2015-06-22 13:57:17 -0400400 translated->offset = cachedState->offset;
Jamie Madillf41522b2014-08-18 16:39:49 -0400401
Geoff Langf7100b92014-09-08 16:17:08 -0400402 return gl::Error(GL_NO_ERROR);
Jamie Madillf41522b2014-08-18 16:39:49 -0400403}
404
daniel@transgaming.com0f7aaf52010-03-11 19:41:38 +0000405}