MCPcopy Create free account
hub / github.com/axmolengine/axmol / drawBatchedTriangles

Method drawBatchedTriangles

core/renderer/Renderer.cpp:608–715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606}
607
608void Renderer::drawBatchedTriangles()
609{
610 if (_queuedTriangleCommands.empty())
611 return;
612
613 /************** 1: Setup up vertices/indices *************/
614#ifdef AX_USE_METAL
615 unsigned int vertexBufferFillOffset = _queuedTotalVertexCount - _queuedVertexCount;
616 unsigned int indexBufferFillOffset = _queuedTotalIndexCount - _queuedIndexCount;
617#else
618 unsigned int vertexBufferFillOffset = 0;
619 unsigned int indexBufferFillOffset = 0;
620#endif
621
622 _triBatchesToDraw[0].offset = indexBufferFillOffset;
623 _triBatchesToDraw[0].indicesToDraw = 0;
624 _triBatchesToDraw[0].cmd = nullptr;
625
626 int batchesTotal = 0;
627 uint32_t prevMaterialID = 0;
628 bool firstCommand = true;
629
630 _filledVertex = 0;
631 _filledIndex = 0;
632
633 for (const auto& cmd : _queuedTriangleCommands)
634 {
635 auto currentMaterialID = cmd->getMaterialID();
636 const bool batchable = !cmd->isSkipBatching();
637
638 fillVerticesAndIndices(cmd, vertexBufferFillOffset);
639
640 // in the same batch ?
641 if (batchable && (prevMaterialID == currentMaterialID || firstCommand))
642 {
643 AX_ASSERT((firstCommand || _triBatchesToDraw[batchesTotal].cmd->getMaterialID() == cmd->getMaterialID()) &&
644 "argh... error in logic");
645 _triBatchesToDraw[batchesTotal].indicesToDraw += cmd->getIndexCount();
646 _triBatchesToDraw[batchesTotal].cmd = cmd;
647 }
648 else
649 {
650 // is this the first one?
651 if (!firstCommand)
652 {
653 batchesTotal++;
654 _triBatchesToDraw[batchesTotal].offset =
655 _triBatchesToDraw[batchesTotal - 1].offset + _triBatchesToDraw[batchesTotal - 1].indicesToDraw;
656 }
657
658 _triBatchesToDraw[batchesTotal].cmd = cmd;
659 _triBatchesToDraw[batchesTotal].indicesToDraw = (int)cmd->getIndexCount();
660
661 // is this a single batch ? Prevent creating a batch group then
662 if (!batchable)
663 currentMaterialID = 0;
664 }
665

Callers

nothing calls this directly

Calls 11

reallocFunction · 0.85
getIndexCountMethod · 0.80
updatePipelineStateMethod · 0.80
drawElementsMethod · 0.80
emptyMethod · 0.45
updateSubDataMethod · 0.45
updateDataMethod · 0.45
setVertexBufferMethod · 0.45
setIndexBufferMethod · 0.45
setProgramStateMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected