| 287 | } |
| 288 | |
| 289 | void Renderer::processRenderCommand(RenderCommand* command) |
| 290 | { |
| 291 | auto commandType = command->getType(); |
| 292 | switch (commandType) |
| 293 | { |
| 294 | case RenderCommand::Type::TRIANGLES_COMMAND: |
| 295 | { |
| 296 | // flush other queues |
| 297 | flush3D(); |
| 298 | |
| 299 | auto cmd = static_cast<TrianglesCommand*>(command); |
| 300 | |
| 301 | // flush own queue when buffer is full |
| 302 | if (_queuedTotalVertexCount + cmd->getVertexCount() > VBO_SIZE || |
| 303 | _queuedTotalIndexCount + cmd->getIndexCount() > INDEX_VBO_SIZE) |
| 304 | { |
| 305 | AXASSERT(cmd->getVertexCount() >= 0 && cmd->getVertexCount() < VBO_SIZE, |
| 306 | "VBO for vertex is not big enough, please break the data down or use customized render command"); |
| 307 | AXASSERT(cmd->getIndexCount() >= 0 && cmd->getIndexCount() < INDEX_VBO_SIZE, |
| 308 | "VBO for index is not big enough, please break the data down or use customized render command"); |
| 309 | drawBatchedTriangles(); |
| 310 | |
| 311 | _queuedTotalIndexCount = _queuedTotalVertexCount = 0; |
| 312 | #ifdef AX_USE_METAL |
| 313 | _queuedIndexCount = _queuedVertexCount = 0; |
| 314 | _triangleCommandBufferManager.prepareNextBuffer(); |
| 315 | _vertexBuffer = _triangleCommandBufferManager.getVertexBuffer(); |
| 316 | _indexBuffer = _triangleCommandBufferManager.getIndexBuffer(); |
| 317 | #endif |
| 318 | } |
| 319 | |
| 320 | // queue it |
| 321 | _queuedTriangleCommands.emplace_back(cmd); |
| 322 | #ifdef AX_USE_METAL |
| 323 | _queuedIndexCount += cmd->getIndexCount(); |
| 324 | _queuedVertexCount += cmd->getVertexCount(); |
| 325 | #endif |
| 326 | _queuedTotalVertexCount += cmd->getVertexCount(); |
| 327 | _queuedTotalIndexCount += cmd->getIndexCount(); |
| 328 | } |
| 329 | break; |
| 330 | case RenderCommand::Type::MESH_COMMAND: |
| 331 | flush2D(); |
| 332 | drawMeshCommand(command); |
| 333 | break; |
| 334 | case RenderCommand::Type::GROUP_COMMAND: |
| 335 | processGroupCommand(static_cast<GroupCommand*>(command)); |
| 336 | _groupCommandPool.emplace_back(static_cast<GroupCommand*>(command)); |
| 337 | break; |
| 338 | case RenderCommand::Type::CUSTOM_COMMAND: |
| 339 | flush(); |
| 340 | drawCustomCommand(command); |
| 341 | break; |
| 342 | case RenderCommand::Type::CALLBACK_COMMAND: |
| 343 | flush(); |
| 344 | static_cast<CallbackCommand*>(command)->execute(); |
| 345 | _callbackCommandsPool.emplace_back(static_cast<CallbackCommand*>(command)); |
| 346 | break; |
nothing calls this directly
no test coverage detected