1. Program Entry
Create the application instance appdelegate app; Return Application::getinstance ()->run ();
2. Main loop
int Application::Run ():
while (!glview->windowshouldclose ()) { QueryPerformanceCounter (&nnow); if (Nnow.quadpart-nlast.quadpart > _animationinterval.quadpart) { nlast.quadpart = Nnow.quadpart; Director of the main circulation director->mainloop (); Glview->pollevents (); } else { Sleep (0); } }
Mainloop->drawscene:
Pushmatrix (Matrix_stack_type::matrix_stack_modelview); if (_runningscene) { //clear draw stats _renderer->cleardrawstats (); Visit and draw scene (but draw just add render command)//Render command is in: Renderer->render (); Render the scene _runningscene->render (_renderer); _eventdispatcher->dispatchevent (_eventaftervisit); } Notification node, rendered independently of the scene //Draw the Notifications node if (_notificationnode) { _notificationnode-> Visit (_renderer, mat4::identity, 0); } if (_displaystats) { showstats (); } Below are the rendered _notificationnode and stats _renderer->render (); _eventdispatcher->dispatchevent (_eventafterdraw); Popmatrix (Matrix_stack_type::matrix_stack_modelview); _totalframes++; Swap buffers if (_openglview) { _openglview->swapbuffers (); }
void Scene::render (renderer* Renderer):
Camera::_visitingcamera = Defaultcamera; Director->pushmatrix (matrix_stack_type::matrix_stack_projection); Director->loadmatrix (Matrix_stack_type::matrix_stack_projection, camera::_visitingcamera-> Getviewprojectionmatrix ()); Visit the scene visit (renderer, mat4::identity, 0); Renderer->render (); Director->popmatrix (matrix_stack_type::matrix_stack_projection);
3. Node traversal
void Node::visit (renderer* Renderer, const MAT4 &parenttransform, uint32_t parentflags):
Quick return if not visible. Children won ' t be drawn. if (!_visible) {return; } uint32_t flags = Processparentflags (Parenttransform, parentflags); IMPORTANT://To ease the migration to v3.0, we still support the MAT4 stack,//It's deprecated and your co De should not rely on it director* Director = Director::getinstance (); Director->pushmatrix (Matrix_stack_type::matrix_stack_modelview); Director->loadmatrix (Matrix_stack_type::matrix_stack_modelview, _modelviewtransform); BOOL Visiblebycamera = Isvisitablebyvisitingcamera (); int i = 0; if (!_children.empty ()) {Sortallchildren (); Draw children ZOrder < 0 for (; I < _children.size (); i++) {Auto node = _children.at (i ); if (node && node->_localzorder < 0) node->visit (renderer, _modelviewtransform, flags); else break; }//Self draw if (Visiblebycamera) This->draw (renderer, _modelviewtransform, flags); for (Auto It=_children.cbegin () +i; it! = _children.cend (); ++it) (*it)->visit (renderer, _modelviewtransform, Flags); } else if (Visiblebycamera) {This->draw (renderer, _modelviewtransform, flags); } director->popmatrix (Matrix_stack_type::matrix_stack_modelview);
Cocos3--1. Engine Run Flow