| 340 | } |
| 341 | |
| 342 | void VertexArrayBuffer::ApplyMutation(ref_ptr<GraphicsContext> context, ref_ptr<IndexBufferMutator> indexMutator, |
| 343 | ref_ptr<AttributeBufferMutator> attrMutator) |
| 344 | { |
| 345 | // We need to bind current VAO before calling glBindBuffer if OES_vertex_array_object is |
| 346 | // supported. Otherwise we risk affecting a previously bound VAO. |
| 347 | Bind(); |
| 348 | |
| 349 | if (indexMutator != nullptr) |
| 350 | { |
| 351 | ASSERT(m_indexBuffer != nullptr, ()); |
| 352 | if (indexMutator->GetCapacity() > m_indexBuffer->GetBuffer()->GetCapacity()) |
| 353 | { |
| 354 | m_indexBuffer = make_unique_dp<IndexBuffer>(indexMutator->GetCapacity()); |
| 355 | m_indexBuffer->MoveToGPU(context, GPUBuffer::IndexBuffer, m_batcherHash); |
| 356 | } |
| 357 | m_indexBuffer->UpdateData(context, indexMutator->GetIndexes(), indexMutator->GetIndexCount()); |
| 358 | } |
| 359 | |
| 360 | if (attrMutator == nullptr) |
| 361 | { |
| 362 | Unbind(); |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | auto const & data = attrMutator->GetMutateData(); |
| 367 | for (auto it = data.begin(); it != data.end(); ++it) |
| 368 | { |
| 369 | auto const & nodes = it->second; |
| 370 | if (nodes.empty()) |
| 371 | continue; |
| 372 | |
| 373 | auto const offsets = CalculateMappingPart(nodes); |
| 374 | |
| 375 | ref_ptr<DataBuffer> buffer = GetDynamicBuffer(it->first); |
| 376 | ASSERT(buffer != nullptr, ()); |
| 377 | DataBufferMapper mapper(context, buffer, offsets.first, offsets.second); |
| 378 | for (size_t i = 0; i < nodes.size(); ++i) |
| 379 | { |
| 380 | MutateNode const & node = nodes[i]; |
| 381 | ASSERT_GREATER(node.m_region.m_count, 0, ()); |
| 382 | mapper.UpdateData(node.m_data.get(), node.m_region.m_offset - offsets.first, node.m_region.m_count); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | Unbind(); |
| 387 | } |
| 388 | |
| 389 | bool VertexArrayBuffer::Bind() const |
| 390 | { |
no test coverage detected