| 424 | } |
| 425 | |
| 426 | void FastTMXLayer::updatePrimitives() |
| 427 | { |
| 428 | |
| 429 | for (auto& e : _customCommands) |
| 430 | { |
| 431 | e.second->setIndexDrawInfo(0, 0); |
| 432 | } |
| 433 | |
| 434 | auto blendfunc = |
| 435 | _texture->hasPremultipliedAlpha() ? BlendFunc::ALPHA_PREMULTIPLIED : BlendFunc::ALPHA_NON_PREMULTIPLIED; |
| 436 | for (const auto& iter : _indicesVertexZNumber) |
| 437 | { |
| 438 | int start = _indicesVertexZOffsets.at(iter.first); |
| 439 | |
| 440 | auto commandIter = _customCommands.find(iter.first); |
| 441 | if (_customCommands.end() == commandIter) |
| 442 | { |
| 443 | auto command = new CustomCommand(); |
| 444 | command->setVertexBuffer(_vertexBuffer); |
| 445 | |
| 446 | #ifdef AX_FAST_TILEMAP_32_BIT_INDICES |
| 447 | CustomCommand::IndexFormat indexFormat = CustomCommand::IndexFormat::U_INT; |
| 448 | #else |
| 449 | CustomCommand::IndexFormat indexFormat = CustomCommand::IndexFormat::U_SHORT; |
| 450 | #endif |
| 451 | command->setIndexBuffer(_indexBuffer, indexFormat); |
| 452 | |
| 453 | command->setIndexDrawInfo(start * 6, iter.second * 6); |
| 454 | |
| 455 | auto& pipelineDescriptor = command->getPipelineDescriptor(); |
| 456 | |
| 457 | if (_useAutomaticVertexZ) |
| 458 | { |
| 459 | AX_SAFE_RELEASE(pipelineDescriptor.programState); |
| 460 | auto* program = |
| 461 | backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_COLOR_ALPHA_TEST); |
| 462 | auto programState = new backend::ProgramState(program); |
| 463 | pipelineDescriptor.programState = programState; |
| 464 | _alphaValueLocation = pipelineDescriptor.programState->getUniformLocation("u_alpha_value"); |
| 465 | pipelineDescriptor.programState->setUniform(_alphaValueLocation, &_alphaFuncValue, |
| 466 | sizeof(_alphaFuncValue)); |
| 467 | } |
| 468 | else |
| 469 | { |
| 470 | AX_SAFE_RELEASE(pipelineDescriptor.programState); |
| 471 | auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_COLOR); |
| 472 | auto programState = new backend::ProgramState(program); |
| 473 | pipelineDescriptor.programState = programState; |
| 474 | } |
| 475 | |
| 476 | _mvpMatrixLocaiton = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix"); |
| 477 | _textureLocation = pipelineDescriptor.programState->getUniformLocation("u_tex0"); |
| 478 | pipelineDescriptor.programState->setTexture(_textureLocation, 0, _texture->getBackendTexture()); |
| 479 | command->init(_globalZOrder, blendfunc); |
| 480 | |
| 481 | _customCommands[iter.first] = command; |
| 482 | } |
| 483 | else |
nothing calls this directly
no test coverage detected