大佬教程收集整理的这篇文章主要介绍了cocos2dx auto culling 和 auto batching,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
(1)drawScene开始绘制场景
(2)遍历场景的子节点,调用visit函数,递归遍历子节点的子节点,以及子节点的子节点的子节点,以及…
(3)对每一个子节点调用draw函数
(4)初始化QuadCommand对象,这就是渲染命令,会丢到渲染队列里
(5)丢完QuadCommand就完事了,接着就交给渲染逻辑处理了。
auto culling 的实现见如下代码:void Sprite::draw(Renderer *renderer,const Mat4 &transform,uint32_t flags) { // Don't do calculate the culling if the transform was not updated _insideBounds = (flags & FLAGS_TRANSFORM_DIRTY) ? renderer->checkVisibility(transform,_contentSizE) : _insideBounds; if(_insideBounds) { _quadCommand.init(_globalZOrder,_texture->getName(),getGLProgramState(),_blendFunc,&_quad,1,transform); renderer->addCommand(&_quadCommand); #if CC_SPRITE_DEBUG_DRAW _customDebugDrawCommand.init(_globalZOrder); _customDebugDrawCommand.func = CC_CALLBACK_0(Sprite::drawDebugData,this); renderer->addCommand(&_customDebugDrawCommand); #endif //CC_SPRITE_DEBUG_DRAW } }
//Start drawing verties in batch for(const auto& cmd : _batchedQuadCommands) { auto newMaterialID = cmd->getMaterialID(); if(_lastMaterialID != newMaterialID || newMaterialID == QuadCommand::MATERIAL_ID_DO_NOT_BATCH) { //Draw quads if(quadsToDraw > 0) { glDrawElements(GL_TRIANGLES,(GLsizei) quadsToDraw*6,GL_UNSIGNED_SHORT,(GLvoid*) (startQuad*6*sizeof(_inDices[0])) ); _drawnBatches++; _drawnVertices += quadsToDraw*6; startQuad += quadsToDraw; quadsToDraw = 0; } //Use new material cmd->useMaterial(); _lastMaterialID = newMaterialID; } quadsToDraw += cmd->getQuadCount(); } //Draw any remaining quad if(quadsToDraw > 0) { glDrawElements(GL_TRIANGLES,(GLvoid*) (startQuad*6*sizeof(_inDices[0])) ); _drawnBatches++; _drawnVertices += quadsToDraw*6; }auto batching还有另外一种使用。比如渲染字体。文字的长度决定了一次渲染多少个quad。所以renderCommand有一个参数是quad个数。_quadCommand.init 倒数第二个参数。这样也能实现一次性渲染多个文字。
以上是大佬教程为你收集整理的cocos2dx auto culling 和 auto batching全部内容,希望文章能够帮你解决cocos2dx auto culling 和 auto batching所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。