Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 344 vs 350 for /trunk/Source Code/Platform/Video/OpenGL/Buffers/VertexBuffer/glGenericVertexData.cpp

Diff revisions: vs.
  @@ -5,19 +5,19 @@
5 5
6 6 namespace Divide {
7 7
8 - glGenericVertexData::glGenericVertexData(bool persistentMapped) : GenericVertexData(persistentMapped),
9 - _prevResult(nullptr),
10 - _bufferSet(nullptr),
11 - _bufferPersistent(nullptr),
12 - _bufferPersistentData(nullptr),
13 - _elementCount(nullptr),
14 - _elementSize(nullptr),
15 - _sizeFactor(nullptr),
16 - _startDestOffset(nullptr),
17 - _readOffset(nullptr),
18 - _lockManager(nullptr)
19 - {
20 - _numQueries = 0;
8 + glGenericVertexData::glGenericVertexData(bool persistentMapped)
9 + : GenericVertexData(persistentMapped),
10 + _prevResult(nullptr),
11 + _bufferSet(nullptr),
12 + _bufferPersistent(nullptr),
13 + _bufferPersistentData(nullptr),
14 + _elementCount(nullptr),
15 + _elementSize(nullptr),
16 + _sizeFactor(nullptr),
17 + _startDestOffset(nullptr),
18 + _readOffset(nullptr),
19 + _lockManager(nullptr) {
20 + _numQueries = 0;
21 21 _indexBuffer = 0;
22 22 _currentReadQuery = 0;
23 23 _transformFeedback = 0;
  @@ -39,8 +39,7 @@
39 39 }
40 40 }
41 41
42 - glGenericVertexData::~glGenericVertexData()
43 - {
42 + glGenericVertexData::~glGenericVertexData() {
44 43 if (!_bufferObjects.empty()) {
45 44 // If we have persistently mapped buffers, we need to unmap them first
46 45 for (U8 i = 0; i < _bufferObjects.size(); ++i) {
  @@ -67,7 +66,7 @@
67 66 _vertexArray[GVD_USAGE_FDBCK] = 0;
68 67 }
69 68 // Make sure we don't have the indirect draw buffer bound
70 - //glBindBuffer(GL_QUERY_BUFFER_AMD, 0);
69 + // glBindBuffer(GL_QUERY_BUFFER_AMD, 0);
71 70 // Make sure we don't have our transform feedback object bound
72 71 GL_API::setActiveTransformFeedback(0);
73 72 // If we have a transform feedback object, delete it
  @@ -79,23 +78,23 @@
79 78 if (_numQueries > 0) {
80 79 for (U8 i = 0; i < 2; ++i) {
81 80 glDeleteQueries(_numQueries, _feedbackQueries[i]);
82 - MemoryManager::DELETE_ARRAY( _feedbackQueries[i] );
83 - MemoryManager::DELETE_ARRAY( _resultAvailable[i] );
81 + MemoryManager::DELETE_ARRAY(_feedbackQueries[i]);
82 + MemoryManager::DELETE_ARRAY(_resultAvailable[i]);
84 83 }
85 84 }
86 - if (_indexBuffer > 0) {
85 + if (_indexBuffer > 0) {
87 86 glDeleteBuffers(1, &_indexBuffer);
88 87 }
89 88 // Delete the rest of the data
90 - MemoryManager::DELETE_ARRAY( _prevResult );
91 - MemoryManager::DELETE_ARRAY( _bufferSet );
92 - MemoryManager::DELETE_ARRAY( _bufferPersistent );
93 - MemoryManager::DELETE_ARRAY( _elementCount );
94 - MemoryManager::DELETE_ARRAY( _elementSize );
95 - MemoryManager::DELETE_ARRAY( _sizeFactor );
96 - MemoryManager::DELETE_ARRAY( _startDestOffset );
97 - MemoryManager::DELETE_ARRAY( _readOffset );
98 - MemoryManager::DELETE( _lockManager );
89 + MemoryManager::DELETE_ARRAY(_prevResult);
90 + MemoryManager::DELETE_ARRAY(_bufferSet);
91 + MemoryManager::DELETE_ARRAY(_bufferPersistent);
92 + MemoryManager::DELETE_ARRAY(_elementCount);
93 + MemoryManager::DELETE_ARRAY(_elementSize);
94 + MemoryManager::DELETE_ARRAY(_sizeFactor);
95 + MemoryManager::DELETE_ARRAY(_startDestOffset);
96 + MemoryManager::DELETE_ARRAY(_readOffset);
97 + MemoryManager::DELETE(_lockManager);
99 98 if (_bufferPersistentData != nullptr) {
100 99 free(_bufferPersistentData);
101 100 }
  @@ -104,13 +103,18 @@
104 103 _feedbackBuffers.clear();
105 104 }
106 105
107 - /// Create the specified number of buffers and queries and attach them to this vertex data container
106 + /// Create the specified number of buffers and queries and attach them to this
107 + /// vertex data container
108 108 void glGenericVertexData::Create(U8 numBuffers, U8 numQueries) {
109 109 // Prevent double create
110 - DIVIDE_ASSERT(_bufferObjects.empty(), "glGenericVertexData error: create called with no buffers specified!");
111 - // Create two vertex array objects. One for rendering and one for transform feedback
110 + DIVIDE_ASSERT(
111 + _bufferObjects.empty(),
112 + "glGenericVertexData error: create called with no buffers specified!");
113 + // Create two vertex array objects. One for rendering and one for transform
114 + // feedback
112 115 glGenVertexArrays(GVD_USAGE_PLACEHOLDER, &_vertexArray[0]);
113 - // Transform feedback may not be used, but it simplifies the class interface a lot
116 + // Transform feedback may not be used, but it simplifies the class interface
117 + // a lot
114 118 // Create a transform feedback object
115 119 glGenTransformFeedbacks(1, &_transformFeedback);
116 120 // Create our buffer objects
  @@ -125,10 +129,11 @@
125 129 // Create our generic query objects
126 130 for (U8 i = 0; i < 2; ++i) {
127 131 memset(_feedbackQueries[i], 0, sizeof(GLuint) * _numQueries);
128 - memset(_resultAvailable[i], false, sizeof(bool) * _numQueries);
132 + memset(_resultAvailable[i], false, sizeof(bool) * _numQueries);
129 133 glGenQueries(_numQueries, _feedbackQueries[i]);
130 134 }
131 - // How many times larger should the buffer be than the actual data to offset reading and writing
135 + // How many times larger should the buffer be than the actual data to offset
136 + // reading and writing
132 137 _sizeFactor = MemoryManager_NEW GLuint[numBuffers];
133 138 memset(_sizeFactor, 0, numBuffers * sizeof(GLuint));
134 139 // Allocate buffers for all possible data that we may use with this object
  @@ -157,33 +162,40 @@
157 162 _bufferPersistentData = (void**)malloc(sizeof(void*) * numBuffers);
158 163 }
159 164
160 - /// Called at the beginning of each frame to update the currently used queries for reading and writing
165 + /// Called at the beginning of each frame to update the currently used queries
166 + /// for reading and writing
161 167 bool glGenericVertexData::frameStarted(const FrameEvent& evt) {
162 - // Queries are double buffered to avoid stalling (should probably be triple buffered)
163 - if (!_bufferObjects.empty() && _doubleBufferedQuery){
168 + // Queries are double buffered to avoid stalling (should probably be triple
169 + // buffered)
170 + if (!_bufferObjects.empty() && _doubleBufferedQuery) {
164 171 _currentWriteQuery = (_currentWriteQuery + 1) % 2;
165 - _currentReadQuery = (_currentWriteQuery + 1) % 2;
172 + _currentReadQuery = (_currentWriteQuery + 1) % 2;
166 173 }
167 174
168 175 return GenericVertexData::frameStarted(evt);
169 176 }
170 177
171 - /// Bind a specific range of the transform feedback buffer for writing
172 - /// (specified in the number of elements to offset by and the number of elements to be written)
173 - void glGenericVertexData::BindFeedbackBufferRange(U32 buffer, U32 elementCountOffset, size_t elementCount) {
178 + /// Bind a specific range of the transform feedback buffer for writing
179 + /// (specified in the number of elements to offset by and the number of elements
180 + /// to be written)
181 + void glGenericVertexData::BindFeedbackBufferRange(U32 buffer,
182 + U32 elementCountOffset,
183 + size_t elementCount) {
174 184 // Only feedback buffers can be used with this method
175 - DIVIDE_ASSERT(isFeedbackBuffer(buffer), "glGenericVertexData error: called bind buffer range for non-feedback buffer!");
185 + DIVIDE_ASSERT(isFeedbackBuffer(buffer),
186 + "glGenericVertexData error: called bind buffer range for "
187 + "non-feedback buffer!");
176 188
177 189 GL_API::setActiveTransformFeedback(_transformFeedback);
178 - glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER,
179 - getBindPoint(_bufferObjects[buffer]),
180 - _bufferObjects[buffer],
181 - elementCountOffset * _elementSize[buffer],
182 - elementCount * _elementSize[buffer]);
190 + glBindBufferRange(
191 + GL_TRANSFORM_FEEDBACK_BUFFER, getBindPoint(_bufferObjects[buffer]),
192 + _bufferObjects[buffer], elementCountOffset * _elementSize[buffer],
193 + elementCount * _elementSize[buffer]);
183 194 }
184 195
185 196 /// Submit a draw command to the GPU using this object and the specified command
186 - void glGenericVertexData::Draw(const GenericDrawCommand& command, bool skipBind) {
197 + void glGenericVertexData::Draw(const GenericDrawCommand& command,
198 + bool skipBind) {
187 199 // Get the OpenGL specific command from the generic one
188 200 const IndirectDrawCommand& cmd = command.cmd();
189 201 // Instance count can be generated programmatically, so make sure it's valid
  @@ -192,29 +204,39 @@
192 204 }
193 205 // Check if we are rendering to the screen or to a buffer
194 206 bool feedbackActive = (command.drawToBuffer() && !_feedbackBuffers.empty());
195 - // Activate the appropriate vertex array object for the type of rendering we requested
196 - GL_API::setActiveVAO(_vertexArray[feedbackActive ? GVD_USAGE_FDBCK : GVD_USAGE_DRAW]);
207 + // Activate the appropriate vertex array object for the type of rendering we
208 + // requested
209 + GL_API::setActiveVAO(
210 + _vertexArray[feedbackActive ? GVD_USAGE_FDBCK : GVD_USAGE_DRAW]);
197 211 // Update vertex attributes if needed (e.g. if offsets changed)
198 212 SetAttributes(feedbackActive);
199 213
200 214 // Activate transform feedback if needed
201 215 if (feedbackActive) {
202 - GL_API::setActiveTransformFeedback(_transformFeedback);
203 - glBeginTransformFeedback(GLUtil::GL_ENUM_TABLE::glPrimitiveTypeTable[command.primitiveType()]);
204 - // Count the number of primitives written to the buffer
205 - glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, _feedbackQueries[_currentWriteQuery][command.queryID()]);
216 + GL_API::setActiveTransformFeedback(_transformFeedback);
217 + glBeginTransformFeedback(
218 + GLUtil::GL_ENUM_TABLE::glPrimitiveTypeTable[command
219 + .primitiveType()]);
220 + // Count the number of primitives written to the buffer
221 + glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
222 + _feedbackQueries[_currentWriteQuery][command.queryID()]);
206 223 }
207 -
224 +
208 225 // Submit the draw command
209 226 if (!Config::Profile::DISABLE_DRAWS) {
210 - GLenum type = command.renderWireframe() ? GL_LINE_LOOP :
211 - GLUtil::GL_ENUM_TABLE::glPrimitiveTypeTable[command.primitiveType()];
227 + GLenum type = command.renderWireframe()
228 + ? GL_LINE_LOOP
229 + : GLUtil::GL_ENUM_TABLE::glPrimitiveTypeTable
230 + [command.primitiveType()];
212 231
213 232 if (_hasIndexBuffer) {
214 233 GL_API::setActiveBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
215 - glDrawElementsIndirect(type, GL_UNSIGNED_INT, (void*)(cmd.baseInstance * sizeof(IndirectDrawCommand)));
234 + glDrawElementsIndirect(
235 + type, GL_UNSIGNED_INT,
236 + (void*)(cmd.baseInstance * sizeof(IndirectDrawCommand)));
216 237 } else {
217 - glDrawArraysIndirect(type, (void*)(cmd.baseInstance * sizeof(IndirectDrawCommand)));
238 + glDrawArraysIndirect(
239 + type, (void*)(cmd.baseInstance * sizeof(IndirectDrawCommand)));
218 240 }
219 241 }
220 242
  @@ -226,12 +248,11 @@
226 248 _resultAvailable[_currentWriteQuery][command.queryID()] = true;
227 249 }
228 250 // Count the draw call
229 - GFX_DEVICE.registerDrawCall();
251 + GFX_DEVICE.registerDrawCall();
230 252 }
231 253
232 254 void glGenericVertexData::SetIndexBuffer(const vectorImpl<U32>& indices,
233 - bool dynamic,
234 - bool stream) {
255 + bool dynamic, bool stream) {
235 256 bool addBuffer = !indices.empty();
236 257
237 258 if (addBuffer) {
  @@ -241,10 +262,10 @@
241 262 // Assert if the IB creation failed
242 263 DIVIDE_ASSERT(_indexBuffer != 0, Locale::get("ERROR_IB_INIT"));
243 264 }
244 - glNamedBufferDataEXT(_indexBuffer,
245 - indices.size() * sizeof(GLuint),
246 - indices.data(),
247 - dynamic ? (stream ? GL_STREAM_DRAW : GL_DYNAMIC_DRAW) : GL_STATIC_DRAW);
265 + glNamedBufferDataEXT(
266 + _indexBuffer, indices.size() * sizeof(GLuint), indices.data(),
267 + dynamic ? (stream ? GL_STREAM_DRAW : GL_DYNAMIC_DRAW)
268 + : GL_STATIC_DRAW);
248 269
249 270 _hasIndexBuffer = true;
250 271 } else {
  @@ -259,108 +280,136 @@
259 280 }
260 281
261 282 /// Specify the structure and data of the given buffer
262 - void glGenericVertexData::SetBuffer(U32 buffer,
263 - U32 elementCount,
264 - size_t elementSize,
265 - U8 sizeFactor,
266 - void* data,
267 - bool dynamic,
268 - bool stream,
283 + void glGenericVertexData::SetBuffer(U32 buffer, U32 elementCount,
284 + size_t elementSize, U8 sizeFactor,
285 + void* data, bool dynamic, bool stream,
269 286 bool persistentMapped) {
270 287 // Make sure the buffer exists
271 - DIVIDE_ASSERT(buffer >= 0 && buffer < _bufferObjects.size(),
272 - "glGenericVertexData error: set buffer called for invalid buffer index!");
288 + DIVIDE_ASSERT(buffer >= 0 && buffer < _bufferObjects.size(),
289 + "glGenericVertexData error: set buffer called for invalid "
290 + "buffer index!");
273 291 // glBufferData on persistentMapped buffers is not allowed
274 - DIVIDE_ASSERT(!_bufferSet[buffer],
275 - "glGenericVertexData error: set buffer called for an already created buffer!");
292 + DIVIDE_ASSERT(!_bufferSet[buffer],
293 + "glGenericVertexData error: set buffer called for an already "
294 + "created buffer!");
276 295 // Make sure we allow persistent mapping
277 296 if (persistentMapped) {
278 297 persistentMapped = _persistentMapped;
279 298 }
280 - DIVIDE_ASSERT((persistentMapped && _persistentMapped) || !persistentMapped,
281 - "glGenericVertexData error: persistent map flag is not compatible with object details!");
299 + DIVIDE_ASSERT((persistentMapped && _persistentMapped) || !persistentMapped,
300 + "glGenericVertexData error: persistent map flag is not "
301 + "compatible with object details!");
282 302 // Remember the element count and size for the current buffer
283 303 _elementCount[buffer] = elementCount;
284 304 _elementSize[buffer] = elementSize;
285 305 _sizeFactor[buffer] = sizeFactor;
286 306 size_t bufferSize = elementCount * elementSize;
287 -
307 +
288 308 GLuint currentBuffer = _bufferObjects[buffer];
289 309 if (persistentMapped) {
290 - // If we requested a persistently mapped buffer, we use glBufferStorage to pin it in memory
291 - GLenum flag = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
292 - glNamedBufferStorageEXT(currentBuffer, bufferSize * sizeFactor, NULL, flag);
310 + // If we requested a persistently mapped buffer, we use glBufferStorage
311 + // to pin it in memory
312 + GLenum flag =
313 + GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
314 + glNamedBufferStorageEXT(currentBuffer, bufferSize * sizeFactor, NULL,
315 + flag);
293 316 // Map the entire buffer range
294 - _bufferPersistentData[buffer] = glMapNamedBufferRangeEXT(currentBuffer, 0, bufferSize * 3, flag);
295 - DIVIDE_ASSERT(data != nullptr,
296 - "glGenericVertexData error: persistent mapping failed when setting the current buffer!");
317 + _bufferPersistentData[buffer] =
318 + glMapNamedBufferRangeEXT(currentBuffer, 0, bufferSize * 3, flag);
319 + DIVIDE_ASSERT(data != nullptr,
320 + "glGenericVertexData error: persistent mapping failed "
321 + "when setting the current buffer!");
297 322 // Create sizeFactor copies of the data and store them in the buffer
298 - for(U8 i = 0; i < sizeFactor; ++i) {
323 + for (U8 i = 0; i < sizeFactor; ++i) {
299 324 U8* dst = (U8*)_bufferPersistentData[buffer] + bufferSize * i;
300 325 memcpy(dst, data, bufferSize);
301 326 }
302 327 // Make sure we synchronize the write commands
303 328 _lockManager->LockRange(0, bufferSize * sizeFactor);
304 329 } else {
305 - GLenum flag = isFeedbackBuffer(buffer) ? (dynamic ? (stream ? GL_STREAM_COPY : GL_DYNAMIC_COPY) : GL_STATIC_COPY) :
306 - (dynamic ? (stream ? GL_STREAM_DRAW : GL_DYNAMIC_DRAW) : GL_STATIC_DRAW);
307 - // If the buffer is not persistently mapped, allocate storage the classic way
308 - glNamedBufferDataEXT(currentBuffer, bufferSize * sizeFactor, NULL, flag);
330 + GLenum flag =
331 + isFeedbackBuffer(buffer)
332 + ? (dynamic ? (stream ? GL_STREAM_COPY : GL_DYNAMIC_COPY)
333 + : GL_STATIC_COPY)
334 + : (dynamic ? (stream ? GL_STREAM_DRAW : GL_DYNAMIC_DRAW)
335 + : GL_STATIC_DRAW);
336 + // If the buffer is not persistently mapped, allocate storage the
337 + // classic way
338 + glNamedBufferDataEXT(currentBuffer, bufferSize * sizeFactor, NULL,
339 + flag);
309 340 // And upload sizeFactor copies of the data
310 341 for (U8 i = 0; i < sizeFactor; ++i) {
311 - glNamedBufferSubDataEXT(currentBuffer, i * bufferSize, bufferSize, data);
342 + glNamedBufferSubDataEXT(currentBuffer, i * bufferSize, bufferSize,
343 + data);
312 344 }
313 345 }
314 346 _bufferSet[buffer] = true;
315 347 _bufferPersistent[buffer] = persistentMapped;
316 348 }
317 349
318 - /// Update the elementCount worth of data contained in the buffer starting from elementCountOffset size offset
319 - void glGenericVertexData::UpdateBuffer(U32 buffer, U32 elementCount, U32 elementCountOffset, void* data, bool invalidateRange) {
350 + /// Update the elementCount worth of data contained in the buffer starting from
351 + /// elementCountOffset size offset
352 + void glGenericVertexData::UpdateBuffer(U32 buffer, U32 elementCount,
353 + U32 elementCountOffset, void* data,
354 + bool invalidateRange) {
320 355 // Calculate the size of the data that needs updating
321 356 size_t dataCurrentSize = elementCount * _elementSize[buffer];
322 357 // Calculate the offset in the buffer in bytes from which to start writing
323 358 size_t offset = elementCountOffset * _elementSize[buffer];
324 359 // Calculate the entire buffer size
325 360 size_t bufferSize = _elementCount[buffer] * _elementSize[buffer];
326 - // If requested we can invalidate the data in the specified range to hint at the driver to discard the old data
361 + // If requested we can invalidate the data in the specified range to hint at
362 + // the driver to discard the old data
327 363 if (invalidateRange) {
328 - glInvalidateBufferSubData(_bufferObjects[buffer], offset, dataCurrentSize);
364 + glInvalidateBufferSubData(_bufferObjects[buffer], offset,
365 + dataCurrentSize);
329 366 }
330 367
331 368 if (!_bufferPersistent[buffer]) {
332 - // Update part of the data in the buffer at the specified buffer in the copy that's ready for writing
333 - glNamedBufferSubDataEXT(_bufferObjects[buffer], _startDestOffset[buffer] + offset, dataCurrentSize, data);
369 + // Update part of the data in the buffer at the specified buffer in the
370 + // copy that's ready for writing
371 + glNamedBufferSubDataEXT(_bufferObjects[buffer],
372 + _startDestOffset[buffer] + offset,
373 + dataCurrentSize, data);
334 374 } else {
335 375 GL_API::setActiveBuffer(GL_ARRAY_BUFFER, _bufferObjects[buffer]);
336 - // Wait for the target part of the buffer to become available for writing
376 + // Wait for the target part of the buffer to become available for
377 + // writing
337 378 _lockManager->WaitForLockedRange(_startDestOffset[buffer], bufferSize);
338 - // Offset the data pointer by the required offset taking in account the current data copy we are writing into
339 - U8* dst = (U8*)_bufferPersistentData[buffer] + _startDestOffset[buffer] + offset;
340 - // Update the data
341 - memcpy(dst, data, dataCurrentSize);
342 - // Lock the current buffer copy until uploading to GPU visible memory is finished
379 + // Offset the data pointer by the required offset taking in account the
380 + // current data copy we are writing into
381 + U8* dst = (U8*)_bufferPersistentData[buffer] +
382 + _startDestOffset[buffer] + offset;
383 + // Update the data
384 + memcpy(dst, data, dataCurrentSize);
385 + // Lock the current buffer copy until uploading to GPU visible memory is
386 + // finished
343 387 _lockManager->LockRange(_startDestOffset[buffer], bufferSize);
344 388 }
345 389 // Update offset pointers for reading and writing
346 - _startDestOffset[buffer] = (_startDestOffset[buffer] + bufferSize) % (bufferSize * _sizeFactor[buffer]);
347 - _readOffset[buffer] = (_startDestOffset[buffer] + bufferSize) % (bufferSize * _sizeFactor[buffer]);
390 + _startDestOffset[buffer] = (_startDestOffset[buffer] + bufferSize) %
391 + (bufferSize * _sizeFactor[buffer]);
392 + _readOffset[buffer] = (_startDestOffset[buffer] + bufferSize) %
393 + (bufferSize * _sizeFactor[buffer]);
348 394 }
349 395
350 - /// Update the appropriate attributes (either for drawing or for transform feedback)
396 + /// Update the appropriate attributes (either for drawing or for transform
397 + /// feedback)
351 398 void glGenericVertexData::SetAttributes(bool feedbackPass) {
352 399 // Get the appropriate list of attributes
353 400 attributeMap& map = feedbackPass ? _attributeMapFdbk : _attributeMapDraw;
354 401 // And update them in turn
355 - for (attributeMap::value_type& it : map ) {
356 - SetAttributeInternal( it.second );
402 + for (attributeMap::value_type& it : map) {
403 + SetAttributeInternal(it.second);
357 404 }
358 405 }
359 406
360 407 /// Update internal attribute data
361 - void glGenericVertexData::SetAttributeInternal(AttributeDescriptor& descriptor) {
362 - DIVIDE_ASSERT(_elementSize[descriptor.bufferIndex()] != 0,
363 - "glGenericVertexData error: attribute's parent buffer has an invalid element size!");
408 + void glGenericVertexData::SetAttributeInternal(
409 + AttributeDescriptor& descriptor) {
410 + DIVIDE_ASSERT(_elementSize[descriptor.bufferIndex()] != 0,
411 + "glGenericVertexData error: attribute's parent buffer has an "
412 + "invalid element size!");
364 413 // Early out if the attribute didn't change
365 414 if (!descriptor.dirty()) {
366 415 return;
  @@ -370,40 +419,50 @@
370 419 glEnableVertexAttribArray(descriptor.attribIndex());
371 420 descriptor.wasSet(true);
372 421 }
373 - // Persistently mapped buffers are already bound when this function is called
422 + // Persistently mapped buffers are already bound when this function is
423 + // called
374 424 if (!_persistentMapped) {
375 - GL_API::setActiveBuffer(GL_ARRAY_BUFFER, _bufferObjects[descriptor.bufferIndex()]);
425 + GL_API::setActiveBuffer(GL_ARRAY_BUFFER,
426 + _bufferObjects[descriptor.bufferIndex()]);
376 427 }
377 428 // Update the attribute data
378 - glVertexAttribPointer(descriptor.attribIndex(),
379 - descriptor.componentsPerElement(),
380 - GLUtil::GL_ENUM_TABLE::glDataFormat[descriptor.dataType()],
381 - descriptor.normalized() ? GL_TRUE : GL_FALSE,
382 - (GLsizei)descriptor.stride(),
383 - (void*)(descriptor.offset() * _elementSize[descriptor.bufferIndex()]));
429 + glVertexAttribPointer(
430 + descriptor.attribIndex(), descriptor.componentsPerElement(),
431 + GLUtil::GL_ENUM_TABLE::glDataFormat[descriptor.dataType()],
432 + descriptor.normalized() ? GL_TRUE : GL_FALSE,
433 + (GLsizei)descriptor.stride(),
434 + (void*)(descriptor.offset() * _elementSize[descriptor.bufferIndex()]));
384 435
385 436 if (descriptor.instanceDivisor() > 0) {
386 - glVertexAttribDivisor(descriptor.attribIndex(), descriptor.instanceDivisor());
437 + glVertexAttribDivisor(descriptor.attribIndex(),
438 + descriptor.instanceDivisor());
387 439 }
388 440 // Inform the descriptor that the data was updated
389 441 descriptor.clean();
390 442 }
391 443
392 - /// Return the number of primitives written to a transform feedback buffer that used the specified query ID
444 + /// Return the number of primitives written to a transform feedback buffer that
445 + /// used the specified query ID
393 446 U32 glGenericVertexData::GetFeedbackPrimitiveCount(U8 queryID) {
394 - DIVIDE_ASSERT(queryID < _numQueries && !_bufferObjects.empty(),
395 - "glGenericVertexData error: Current object isn't ready for query processing!");
396 - // Double buffered queries return the results from the previous draw call to avoid stalling the GPU pipeline
397 - U32 queryEntry = _doubleBufferedQuery ? _currentReadQuery : _currentWriteQuery;
398 - // If the requested query has valid data available, retrieve that data from the GPU
399 - if (_resultAvailable[queryEntry][queryID]){
400 - // Get the result of the previous query about the generated primitive count
401 - glGetQueryObjectuiv(_feedbackQueries[queryEntry][queryID], GL_QUERY_RESULT, &_prevResult[queryID]);
447 + DIVIDE_ASSERT(queryID < _numQueries && !_bufferObjects.empty(),
448 + "glGenericVertexData error: Current object isn't ready for "
449 + "query processing!");
450 + // Double buffered queries return the results from the previous draw call to
451 + // avoid stalling the GPU pipeline
452 + U32 queryEntry =
453 + _doubleBufferedQuery ? _currentReadQuery : _currentWriteQuery;
454 + // If the requested query has valid data available, retrieve that data from
455 + // the GPU
456 + if (_resultAvailable[queryEntry][queryID]) {
457 + // Get the result of the previous query about the generated primitive
458 + // count
459 + glGetQueryObjectuiv(_feedbackQueries[queryEntry][queryID],
460 + GL_QUERY_RESULT, &_prevResult[queryID]);
402 461 // Mark the query entry data as invalid now
403 462 _resultAvailable[queryEntry][queryID] = false;
404 463 }
405 - // Return either the previous value or the current one depending on the previous check
464 + // Return either the previous value or the current one depending on the
465 + // previous check
406 466 return _prevResult[queryID];
407 467 }
408 -
409 468 };