1、java端
1、Cocos2dxRenderer类 @OverrIDe public voID onDrawFrame(final GL10 gl) { /* * No need to use algorithm in default(60 FPS) situation,* since onDrawFrame() was called by system 60 times per second by default. */ if (sAnimationInterval <= 1.0 / 60 * Cocos2dxRenderer.NANOSECONDSPERSECOND) { Cocos2dxRenderer.nativeRender(); } else { final long Now = System.nanoTime(); final long remain = mLastTickInNanoSeconds + Cocos2dxRenderer.sAnimationInterval - Now; if (remain > 0) { try { Thread.sleep(remain / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND); } catch (final Exception e) { } } /* * Render time MUST be counted in,or the FPS will slower than appointed. */ mLastTickInNanoSeconds = System.nanoTime(); Cocos2dxRenderer.nativeRender(); //调用C++部分的函数 } }2、Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp C++端
JNIEXPORT voID JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(jnienv* env) { cocos2d::CCDirector::sharedDirector()->mainLoop(); } -->> mainLoop函数 voID CCdisplaylinkDirector::mainLoop(voID){ if (m_bPurgeDirecotorInNextLoop) { m_bPurgeDirecotorInNextLoop = false; purgeDirector(); } else if (! m_bInvalID) { drawScene(); // release the objects CCPoolManager::sharedPoolManager()->pop(); }}-->>drawScene渲染// Draw the ScenevoID CCDirector::drawScene(voID){ // calculate "global" dt calculateDeltaTime(); //tick before glClear: issue #533 if (! m_bPaused) //定时器相关,以后说 { m_pScheduler->update(m_fDeltaTime); } glClear(GL_color_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* to avoID flickr,nextScene MUST be here: after tick and before draw. XXX: Which BUG is this one. It seems that it can't be reproduced with v0.9 */ if (m_pNextScene) { setNextScene(); } kmGLPushmatrix(); // draw the scene 渲染 if (m_pRunningScene) { m_pRunningScene->visit(); } // draw the notifications node if (m_pNotificationNode) { m_pNotificationNode->visit(); } if (m_bdisplayStats) { showStats(); } kmGLPopMatrix(); m_uTotalFrames++; // swap buffers if (m_pobOpenGLVIEw) { m_pobOpenGLVIEw->swapBuffers(); } if (m_bdisplayStats) { calculateMPF(); }}
-->>visit函数,遍历UI树,调用visit和draw进行每个node的渲染voID CCNode::visit(){ // quick return if not visible. children won't be drawn. if (!m_bVisible) { return; } kmGLPushmatrix(); if (m_pGrID && m_pGrID->isActive()) { m_pGrID->beforeDraw(); } this->transform(); CCNode* pNode = NulL; unsigned int i = 0; if(m_pChildren && m_pChildren->count() > 0) { sortAllChildren(); // draw children zOrder < 0 ccArray *arrayData = m_pChildren->data; for( ; i < arrayData->num; i++ ) { pNode = (CCNode*) arrayData->arr[i]; if ( pNode && pNode->m_nZOrder < 0 ) { pNode->visit(); } else { break; } } // self draw this->draw(); for( ; i < arrayData->num; i++ ) { pNode = (CCNode*) arrayData->arr[i]; if (pNode) { pNode->visit(); } } } else { this->draw(); } // reset for next frame m_uOrderOfArrival = 0; if (m_pGrID && m_pGrID->isActive()) { m_pGrID->afterDraw(this); } kmGLPopMatrix();}总结
以上是内存溢出为你收集整理的cocos2dx 2.x 每帧渲染分析全部内容,希望文章能够帮你解决cocos2dx 2.x 每帧渲染分析所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)