Brief introduction to the rendering process of Ccnode and Sprite

Source: Internet
Author: User

When the sprite is created, the texture is loaded and the texture ID is generated. Sprite rewrite (override) draw in node

void Sprite::d Raw (Renderer *renderer, const MAT4 &transform, uint32_t flags)

{

Don ' t do calculate the culling if the transform is 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

_debugdrawnode->clear ();

VEC2 Vertices[4] = {

VEC2 (_quad.bl.vertices.x, _quad.bl.vertices.y),

VEC2 (_quad.br.vertices.x, _quad.br.vertices.y),

VEC2 (_quad.tr.vertices.x, _quad.tr.vertices.y),

VEC2 (_quad.tl.vertices.x, _quad.tl.vertices.y),

};

_debugdrawnode->drawpoly (vertices, 4, True, color4f (1.0, 1.0, 1.0, 1.0));

#endif//cc_sprite_debug_draw

}

}

Add the corresponding vertex information, texture ID, and view matrix to the render queue.

When is the draw function called?

See the Visit function in node

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,

But it's deprecated and your code 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);

FIX me:why need to set _orderofarrival to 0??

Refer to https://github.com/cocos2d/cocos2d-x/pull/6920

Reset for Next Frame

_orderofarrival = 0;

}

Visit first arranges the child nodes according to the ZOrder, calls the draw function of the child node with ZOrder greater than 0, calls its own draw, and then calls the draw function of the child node of the ZOrder less than 0, and finally renders, according to the order of the Render Squadron column, Renders all nodes.

void Director::d rawscene ()

if (_runningscene)

{

Clear Draw Stats

_renderer->cleardrawstats ();

Render the scene

_runningscene->render (_renderer);---------call the visit and draw functions of all nodes, add the node render information to the render queue

_eventdispatcher->dispatchevent (_eventaftervisit);

}


Draw the Notifications node

if (_notificationnode)

{

_notificationnode->visit (_renderer, mat4::identity, 0);

}


if (_displaystats)

{

Showstats ();

}

_renderer->render ();------------------Render all nodes

Brief introduction to the rendering process of Ccnode and Sprite

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.