void RenderTexture::begin() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); _projectionMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _transformMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); if(!_keepMatrix) { director->setProjection(director->getProjection()); const Size& texSize = _texture->getContentSizeInPixels(); // Calculate the adjustment ratios based on the old and new projections Size size = director->getWinSizeInPixels(); float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; Mat4 orthoMatrix; Mat4::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); } _groupCommand.init(_globalZOrder); Renderer *renderer = Director::getInstance()->getRenderer(); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); _beginCommand.init(_globalZOrder); _beginCommand.func = CC_CALLBACK_0(RenderTexture::onBegin, this); Director::getInstance()->getRenderer()->addCommand(&_beginCommand); }
void HelloWorld::onDraw(const Mat4 &transform, uint32_t flags) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION); _world->DrawDebugData(); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void StencilStateManager::drawFullScreenQuadClearStencil() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when setting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); Vec2 vertices[] = { Vec2(-1.0f, -1.0f), Vec2(1.0f, -1.0f), Vec2(1.0f, 1.0f), Vec2(-1.0f, 1.0f) }; auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR); int colorLocation = glProgram->getUniformLocation("u_color"); CHECK_GL_ERROR_DEBUG(); Color4F color(1, 1, 1, 1); glProgram->use(); glProgram->setUniformsForBuiltins(); glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1); glBindBuffer(GL_ARRAY_BUFFER, 0); GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION ); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) { Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); DrawNode* drawNode = DrawNode::create(); if (_debugSlots) { // Slots. // DrawPrimitives::setDrawColor4B(0, 0, 255, 255); glLineWidth(1); Vec2 points[4]; V3F_C4B_T2F_Quad quad; for (int i = 0, n = _skeleton->slotsCount; i < n; i++) { spSlot* slot = _skeleton->drawOrder[i]; if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue; spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices); points[0] = Vec2(_worldVertices[0], _worldVertices[1]); points[1] = Vec2(_worldVertices[2], _worldVertices[3]); points[2] = Vec2(_worldVertices[4], _worldVertices[5]); points[3] = Vec2(_worldVertices[6], _worldVertices[7]); drawNode->drawPoly(points, 4, true, Color4F::BLUE); } } if (_debugBones) { // Bone lengths. glLineWidth(2); for (int i = 0, n = _skeleton->bonesCount; i < n; i++) { spBone *bone = _skeleton->bones[i]; float x = bone->data->length * bone->a + bone->worldX; float y = bone->data->length * bone->c + bone->worldY; drawNode->drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y), Color4F::RED); } // Bone origins. auto color = Color4F::BLUE; // Root bone is blue. for (int i = 0, n = _skeleton->bonesCount; i < n; i++) { spBone *bone = _skeleton->bones[i]; drawNode->drawPoint(Vec2(bone->worldX, bone->worldY), 4, color); if (i == 0) color = Color4F::GREEN; } } drawNode->draw(renderer, transform, transformFlags); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Sprite3D::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. if (!_visible) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); flags |= FLAGS_RENDER_AS_3D; // 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->getLocalZOrder() < 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); }
void LineContainer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags){ //super.draw Node::draw(renderer, transform, flags); //pre-render Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); //Create commands _customEnergyBar.func = CC_CALLBACK_0(LineContainer::drawEnergyBar, this, transform, flags); _customPivotLine.func = CC_CALLBACK_0(LineContainer::drawPivotLine, this, transform, flags); //add to renderer renderer->addCommand(&_customEnergyBar); renderer->addCommand(&_customPivotLine); }
void SudokuBox::onDraw(const Mat4& transform) { //if the grid has only one row/col, dont draw the grid, because the grid maybe make player be confused. if (m_stagedata.rows_per_grid <= 1 || m_stagedata.cols_per_grid <= 1) return; int rows = m_stagedata.grids_in_row; int cols = m_stagedata.grids_in_col; if (rows <= 0 || cols <= 0) return; Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); CHECK_GL_ERROR_DEBUG(); //draw the grid with difference colors. Color4B gridColors[] = { Color4B(0, 255, 255, 255), Color4B(255, 0, 255, 255) }; int linW = 3; glLineWidth(linW); Size size = getContentSize(); float width = size.width / cols; float height = size.height / rows; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { Color4B cl = gridColors[(j+(i%2))%2]; DrawPrimitives::setDrawColor4B(cl.r, cl.g, cl.b, cl.a); Vec2 vertices[] = { Vec2(width*j+linW, height*i+linW), Vec2(width*j+linW, height*(i+1)-linW), Vec2(width*(j+1)-linW, height*(i+1)-linW), Vec2(width*(j+1)-linW, height*i+linW) }; DrawPrimitives::drawPoly(vertices, 4, true); } } CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void GameLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { Layer::draw(renderer, transform, flags); //PhysicsWorldManager::getInstance()->draw(); GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(GameLayer::onDraw, this); renderer->addCommand(&_customCommand); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void StayingBlobSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t transformFlags) { if(_bodies.size() == 0)return; Vec2 vertices[NUM_SEGMENTS]; Vec2 opos = this->getPosition(); for(int i = 0; i < _bodies.size(); i++) { b2PolygonShape *shape = (b2PolygonShape *) _bodies[i]->GetFixtureList()->GetShape(); b2Vec2 point; if(i < NUM_SEGMENTS / 4) point = _bodies[i]->GetWorldVector(shape->GetVertex(0)); else if(i < NUM_SEGMENTS * 2/4) point = _bodies[i]->GetWorldVector(shape->GetVertex(1)); else if(i < NUM_SEGMENTS * 3/4) point = _bodies[i]->GetWorldVector(shape->GetVertex(2)); else if(i < NUM_SEGMENTS) point = _bodies[i]->GetWorldVector(shape->GetVertex(3)); b2Vec2 pos = _bodies[i]->GetPosition(); vertices[i].x = (point.x + pos.x)*PTM_RATIO - opos.x; vertices[i].y = (point.y + pos.y)*PTM_RATIO - opos.y; } Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); //glLineWidth( 5.0f ); //ccDrawColor4F(1.f, 0.125f, 0.15625f, 1); // tiny side burns (...Guesss that one way to call it) // for(int i = 0; i < _bodies.size(); i++) { // Vec2 target = (center - vertices[i]) * nub_pos; // target += center; // DrawPrimitives::drawSolidCircle(vertices[i], nub_size, CC_DEGREES_TO_RADIANS(360), 30); // } // draw the body //DrawPrimitives::drawSolidPoly(vertices, NUM_SEGMENTS, blobColor); DrawPrimitives::drawSolidPoly(vertices, NUM_SEGMENTS, Color4F(1, 1, 1, 1)); _face->setPosition(this->getCenter() + Vec2(-30, -100)*_face->getScale()); updateEye(); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void GameLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { // // IMPORTANT: // This is only for debug purposes // It is recommend to disable it // Layer::draw(renderer, transform, flags); GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(1000); _customCommand.func = CC_CALLBACK_0(GameLayer::onDraw, this,transform); renderer->addCommand(&_customCommand); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Debug::onDraw(const Mat4 &transform, bool transformUpdated) { // ÀûÓÃStack»º´æ Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); CHECK_GL_ERROR_DEBUG(); // »±ß¿ò DrawPrimitives::setDrawColor4B(255, 255, 255, 255); glLineWidth(4); Vec2 vertices[] = { Vec2(1, 1), Vec2(1, visibleSize.height - 1), Vec2(visibleSize.width - 1, visibleSize.height - 1), Vec2(visibleSize.width - 1, 1) }; DrawPrimitives::drawPoly(vertices, 4, true); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void LabelAtlas::drawDebugData(const Mat4& transform, bool transformUpdated) { Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); auto size = getContentSize(); Vec2 vertices[4]= { Vec2::ZERO, Vec2(size.width, 0), Vec2(size.width, size.height), Vec2(0, size.height) }; DrawPrimitives::drawPoly(vertices, 4, true); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void VideoPlayer::drawDebugData() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when setting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); auto size = getContentSize(); Point vertices[4]= { Point::ZERO, Point(size.width, 0), Point(size.width, size.height), Point(0, size.height) }; DrawPrimitives::drawPoly(vertices, 4, true); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
// override visit // don't call visit on it's children void SpriteBatchNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { CC_PROFILER_START_CATEGORY(kProfilerCategoryBatchSprite, "CCSpriteBatchNode - visit"); // CAREFUL: // This visit is almost identical to CocosNode#visit // with the exception that it doesn't call visit on it's children // // The alternative is to have a void Sprite#visit, but // although this is less maintainable, is faster // if (! _visible) { return; } sortAllChildren(); uint32_t flags = processParentFlags(parentTransform, parentFlags); if (isVisitableByVisitingCamera()) { // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is 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); draw(renderer, _modelViewTransform, flags); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); CC_PROFILER_STOP_CATEGORY(kProfilerCategoryBatchSprite, "CCSpriteBatchNode - visit"); } }
void Box2DTest::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { // // IMPORTANT: // This is only for debug purposes // It is recommend to disable it // Scene::draw(renderer, transform, flags); #if CC_ENABLE_BOX2D_INTEGRATION GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(Box2DTest::onDraw, this); renderer->addCommand(&_customCommand); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); #endif }
void B2DebugDrawLayer::draw(Renderer *renderer, const Mat4& transform, bool transformUpdated) { // // IMPORTANT: // This is only for debug purposes // It is recommend to disable it // Layer::draw(renderer, transform, transformUpdated); GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(B2DebugDrawLayer::onDraw, this); renderer->addCommand(&_customCommand); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void DrawPrimitivesTest::onDraw(const Mat4 &transform, uint32_t flags) { Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); //draw CHECK_GL_ERROR_DEBUG(); // draw a simple line // The default state is: // Line Width: 1 // color: 255,255,255,255 (white, non-transparent) // Anti-Aliased // glEnable(GL_LINE_SMOOTH); DrawPrimitives::drawLine( VisibleRect::leftBottom(), VisibleRect::rightTop() ); CHECK_GL_ERROR_DEBUG(); // line: color, width, aliased // glLineWidth > 1 and GL_LINE_SMOOTH are not compatible // GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone // glDisable(GL_LINE_SMOOTH); glLineWidth( 5.0f ); DrawPrimitives::setDrawColor4B(255,0,0,255); DrawPrimitives::drawLine( VisibleRect::leftTop(), VisibleRect::rightBottom() ); CHECK_GL_ERROR_DEBUG(); // TIP: // If you are going to use always thde same color or width, you don't // need to call it before every draw // // Remember: OpenGL is a state-machine. // draw big point in the center DrawPrimitives::setPointSize(64); DrawPrimitives::setDrawColor4B(0,0,255,128); DrawPrimitives::drawPoint( VisibleRect::center() ); CHECK_GL_ERROR_DEBUG(); // draw 4 small points Vec2 points[] = { Vec2(60,60), Vec2(70,70), Vec2(60,70), Vec2(70,60) }; DrawPrimitives::setPointSize(4); DrawPrimitives::setDrawColor4B(0,255,255,255); DrawPrimitives::drawPoints( points, 4); CHECK_GL_ERROR_DEBUG(); // draw a green circle with 10 segments glLineWidth(16); DrawPrimitives::setDrawColor4B(0, 255, 0, 255); DrawPrimitives::drawCircle( VisibleRect::center(), 100, 0, 10, false); CHECK_GL_ERROR_DEBUG(); // draw a green circle with 50 segments with line to center glLineWidth(2); DrawPrimitives::setDrawColor4B(0, 255, 255, 255); DrawPrimitives::drawCircle( VisibleRect::center(), 50, CC_DEGREES_TO_RADIANS(90), 50, true); CHECK_GL_ERROR_DEBUG(); // draw a pink solid circle with 50 segments glLineWidth(2); DrawPrimitives::setDrawColor4B(255, 0, 255, 255); DrawPrimitives::drawSolidCircle( VisibleRect::center() + Vec2(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 1.0f, 1.0f); CHECK_GL_ERROR_DEBUG(); // open yellow poly DrawPrimitives::setDrawColor4B(255, 255, 0, 255); glLineWidth(10); Vec2 vertices[] = { Vec2(0,0), Vec2(50,50), Vec2(100,50), Vec2(100,100), Vec2(50,100) }; DrawPrimitives::drawPoly( vertices, 5, false); CHECK_GL_ERROR_DEBUG(); // filled poly glLineWidth(1); Vec2 filledVertices[] = { Vec2(0,120), Vec2(50,120), Vec2(50,170), Vec2(25,200), Vec2(0,170) }; DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) ); // closed purble poly DrawPrimitives::setDrawColor4B(255, 0, 255, 255); glLineWidth(2); Vec2 vertices2[] = { Vec2(30,130), Vec2(30,230), Vec2(50,200) }; DrawPrimitives::drawPoly( vertices2, 3, true); CHECK_GL_ERROR_DEBUG(); // draw quad bezier path DrawPrimitives::drawQuadBezier(VisibleRect::leftTop(), VisibleRect::center(), VisibleRect::rightTop(), 50); CHECK_GL_ERROR_DEBUG(); // draw cubic bezier path DrawPrimitives::drawCubicBezier(VisibleRect::center(), Vec2(VisibleRect::center().x+30,VisibleRect::center().y+50), Vec2(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100); CHECK_GL_ERROR_DEBUG(); //draw a solid polygon Vec2 vertices3[] = {Vec2(60,160), Vec2(70,190), Vec2(100,190), Vec2(90,160)}; DrawPrimitives::drawSolidPoly( vertices3, 4, Color4F(1,1,0,1) ); // restore original values glLineWidth(1); DrawPrimitives::setDrawColor4B(255,255,255,255); DrawPrimitives::setPointSize(1); CHECK_GL_ERROR_DEBUG(); //end draw director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { if (!_visible || !hasContent()) return; uint32_t flags = processParentFlags(parentTransform, parentFlags); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when setting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); //Add group command _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); _beforeVisitCmd.init(_globalZOrder); _beforeVisitCmd.func = CC_CALLBACK_0(StencilStateManager::onBeforeVisit, _stencilStateManager); renderer->addCommand(&_beforeVisitCmd); auto alphaThreshold = this->getAlphaThreshold(); if (alphaThreshold < 1) { #if CC_CLIPPING_NODE_OPENGLES // since glAlphaTest do not exists in OES, use a shader that writes // pixel only if greater than an alpha threshold GLProgram *program = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV); GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE); // set our alphaThreshold program->use(); program->setUniformLocationWith1f(alphaValueLocation, alphaThreshold); // we need to recursively apply this shader to all the nodes in the stencil node // FIXME: we should have a way to apply shader to all nodes without having to do this setProgram(_stencil, program); #endif } _stencil->visit(renderer, _modelViewTransform, flags); _afterDrawStencilCmd.init(_globalZOrder); _afterDrawStencilCmd.func = CC_CALLBACK_0(StencilStateManager::onAfterDrawStencil, _stencilStateManager); renderer->addCommand(&_afterDrawStencilCmd); int i = 0; bool visibleByCamera = isVisitableByVisitingCamera(); if(!_children.empty()) { sortAllChildren(); // draw children zOrder < 0 for(auto size = _children.size(); i < size; ++i) { auto node = _children.at(i); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, flags); else break; } // self draw if (visibleByCamera) this->draw(renderer, _modelViewTransform, flags); for(auto it=_children.cbegin()+i, itCend = _children.cend(); it != itCend; ++it) (*it)->visit(renderer, _modelViewTransform, flags); } else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, flags); } _afterVisitCmd.init(_globalZOrder); _afterVisitCmd.func = CC_CALLBACK_0(StencilStateManager::onAfterVisit, _stencilStateManager); renderer->addCommand(&_afterVisitCmd); renderer->popGroup(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void NodeGrid::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. if (!_visible) { return; } bool dirty = (parentFlags & FLAGS_TRANSFORM_DIRTY) || _transformUpdated; if(dirty) _modelViewTransform = this->transform(parentTransform); _transformUpdated = false; _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when setting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); Director::Projection beforeProjectionType = Director::Projection::DEFAULT; if(_nodeGrid && _nodeGrid->isActive()) { beforeProjectionType = Director::getInstance()->getProjection(); _nodeGrid->set2DProjection(); } _gridBeginCommand.init(_globalZOrder); _gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this); renderer->addCommand(&_gridBeginCommand); if(_gridTarget) { _gridTarget->visit(renderer, _modelViewTransform, dirty); } int i = 0; bool visibleByCamera = isVisitableByVisitingCamera(); if(!_children.empty()) { sortAllChildren(); // draw children zOrder < 0 for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, dirty); else break; } // self draw,currently we have nothing to draw on NodeGrid, so there is no need to add render command if (visibleByCamera) this->draw(renderer, _modelViewTransform, dirty); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) { (*it)->visit(renderer, _modelViewTransform, dirty); } } else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, dirty); } // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); if(_nodeGrid && _nodeGrid->isActive()) { // restore projection director->setProjection(beforeProjectionType); } _gridEndCommand.init(_globalZOrder); _gridEndCommand.func = CC_CALLBACK_0(NodeGrid::onGridEndDraw, this); renderer->addCommand(&_gridEndCommand); renderer->popGroup(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void SkeletonRenderer::drawSkeleton (const Mat4 &transform, uint32_t transformFlags) { getGLProgramState()->apply(transform); Color3B nodeColor = getColor(); _skeleton->r = nodeColor.r / (float)255; _skeleton->g = nodeColor.g / (float)255; _skeleton->b = nodeColor.b / (float)255; _skeleton->a = getDisplayedOpacity() / (float)255; int additive = -1; Color4B color; const float* uvs = nullptr; int verticesCount = 0; const int* triangles = nullptr; int trianglesCount = 0; float r = 0, g = 0, b = 0, a = 0; for (int i = 0, n = _skeleton->slotsCount; i < n; i++) { spSlot* slot = _skeleton->drawOrder[i]; if (!slot->attachment) continue; Texture2D *texture = nullptr; switch (slot->attachment->type) { case SP_ATTACHMENT_REGION: { spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices); texture = getTexture(attachment); uvs = attachment->uvs; verticesCount = 8; triangles = quadTriangles; trianglesCount = 6; r = attachment->r; g = attachment->g; b = attachment->b; a = attachment->a; break; } case SP_ATTACHMENT_MESH: { spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment; spMeshAttachment_computeWorldVertices(attachment, slot, _worldVertices); texture = getTexture(attachment); uvs = attachment->uvs; verticesCount = attachment->verticesCount; triangles = attachment->triangles; trianglesCount = attachment->trianglesCount; r = attachment->r; g = attachment->g; b = attachment->b; a = attachment->a; break; } case SP_ATTACHMENT_SKINNED_MESH: { spSkinnedMeshAttachment* attachment = (spSkinnedMeshAttachment*)slot->attachment; spSkinnedMeshAttachment_computeWorldVertices(attachment, slot, _worldVertices); texture = getTexture(attachment); uvs = attachment->uvs; verticesCount = attachment->uvsCount; triangles = attachment->triangles; trianglesCount = attachment->trianglesCount; r = attachment->r; g = attachment->g; b = attachment->b; a = attachment->a; break; } default: ; } if (texture) { if (slot->data->additiveBlending != additive) { _batch->flush(); GL::blendFunc(_blendFunc.src, slot->data->additiveBlending ? GL_ONE : _blendFunc.dst); additive = slot->data->additiveBlending; } color.a = _skeleton->a * slot->a * a * 255; float multiplier = _premultipliedAlpha ? color.a : 255; color.r = _skeleton->r * slot->r * r * multiplier; color.g = _skeleton->g * slot->g * g * multiplier; color.b = _skeleton->b * slot->b * b * multiplier; _batch->add(texture, _worldVertices, uvs, verticesCount, triangles, trianglesCount, &color); } } _batch->flush(); if (_debugSlots || _debugBones) { Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); if (_debugSlots) { // Slots. DrawPrimitives::setDrawColor4B(0, 0, 255, 255); glLineWidth(1); Vec2 points[4]; V3F_C4B_T2F_Quad quad; for (int i = 0, n = _skeleton->slotsCount; i < n; i++) { spSlot* slot = _skeleton->drawOrder[i]; if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue; spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices); points[0] = Vec2(_worldVertices[0], _worldVertices[1]); points[1] = Vec2(_worldVertices[2], _worldVertices[3]); points[2] = Vec2(_worldVertices[4], _worldVertices[5]); points[3] = Vec2(_worldVertices[6], _worldVertices[7]); DrawPrimitives::drawPoly(points, 4, true); } } if (_debugBones) { // Bone lengths. glLineWidth(2); DrawPrimitives::setDrawColor4B(255, 0, 0, 255); for (int i = 0, n = _skeleton->bonesCount; i < n; i++) { spBone *bone = _skeleton->bones[i]; float x = bone->data->length * bone->m00 + bone->worldX; float y = bone->data->length * bone->m10 + bone->worldY; DrawPrimitives::drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y)); } // Bone origins. DrawPrimitives::setPointSize(4); DrawPrimitives::setDrawColor4B(0, 0, 255, 255); // Root bone is blue. for (int i = 0, n = _skeleton->bonesCount; i < n; i++) { spBone *bone = _skeleton->bones[i]; DrawPrimitives::drawPoint(Vec2(bone->worldX, bone->worldY)); if (i == 0) DrawPrimitives::setDrawColor4B(0, 255, 0, 255); } } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } }
void Scale9Sprite::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 is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); int i = 0; // used by _children int j = 0; // used by _protectedChildren sortAllChildren(); sortAllProtectedChildren(); // // draw children and protectedChildren zOrder < 0 // for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, flags); else break; } if (_scale9Enabled) { for( ; j < _protectedChildren.size(); j++ ) { auto node = _protectedChildren.at(j); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, flags); else break; } } else { if (_scale9Image && _scale9Image->getLocalZOrder() < 0 ) { _scale9Image->visit(renderer, _modelViewTransform, flags); } } // // draw self // if (isVisitableByVisitingCamera()) this->draw(renderer, _modelViewTransform, flags); // // draw children and protectedChildren zOrder >= 0 // if (_scale9Enabled) { for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); } else { if (_scale9Image && _scale9Image->getLocalZOrder() >= 0 ) { _scale9Image->visit(renderer, _modelViewTransform, flags); } } for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void ScrollView::visit(Renderer *renderer, const Matrix &parentTransform, bool parentTransformUpdated) { // quick return if not visible if (!isVisible()) { return; } bool dirty = parentTransformUpdated || _transformUpdated; if(dirty) _modelViewTransform = this->transform(parentTransform); _transformUpdated = false; // IMPORTANT: // To ease the migration to v3.0, we still support the Matrix stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); this->beforeDraw(); if (!_children.empty()) { int i=0; // draw children zOrder < 0 for( ; i < _children.size(); i++ ) { Node *child = _children.at(i); if ( child->getLocalZOrder() < 0 ) { child->visit(renderer, _modelViewTransform, dirty); } else { break; } } // this draw this->draw(renderer, _modelViewTransform, dirty); // draw children zOrder >= 0 for( ; i < _children.size(); i++ ) { Node *child = _children.at(i); child->visit(renderer, _modelViewTransform, dirty); } } else { this->draw(renderer, _modelViewTransform, dirty); } this->afterDraw(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, bool parentTransformUpdated) { if(!_visible) return; bool dirty = parentTransformUpdated || _transformUpdated; if(dirty) _modelViewTransform = transform(parentTransform); _transformUpdated = false; // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); //Add group command _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); _beforeVisitCmd.init(_globalZOrder); _beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this); renderer->addCommand(&_beforeVisitCmd); if (_alphaThreshold < 1) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) #else // since glAlphaTest do not exists in OES, use a shader that writes // pixel only if greater than an alpha threshold GLProgram *program = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV); GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE); // set our alphaThreshold program->use(); program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold); // we need to recursively apply this shader to all the nodes in the stencil node // XXX: we should have a way to apply shader to all nodes without having to do this setProgram(_stencil, program); #endif } _stencil->visit(renderer, _modelViewTransform, dirty); _afterDrawStencilCmd.init(_globalZOrder); _afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this); renderer->addCommand(&_afterDrawStencilCmd); int i = 0; if(!_children.empty()) { sortAllChildren(); // draw children zOrder < 0 for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, dirty); else break; } // self draw this->draw(renderer, _modelViewTransform, dirty); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, dirty); } else { this->draw(renderer, _modelViewTransform, dirty); } _afterVisitCmd.init(_globalZOrder); _afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this); renderer->addCommand(&_afterVisitCmd); renderer->popGroup(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
//裁切 void CNFServerChangeScrollLayer::visit(Renderer *renderer, const Mat4& parentTransform, uint32_t parentFlags) { 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 is 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(); glEnable(GL_SCISSOR_TEST); Size size=Director::getInstance()->getOpenGLView()->getFrameSize(); float fScaleX=size.width/SCREEN_WIDTH; float fScaleY=size.height/SCREEN_HEIGHT; glScissor(m_DisPlayRect.origin.x*fScaleX,m_DisPlayRect.origin.y*fScaleY,m_DisPlayRect.size.width*fScaleX,m_DisPlayRect.size.height*fScaleY); int i = 0; if(!_children.empty()) { sortAllChildren(); // draw children zOrder < 0 for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if ( node && node->getLocalZOrder() < 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); glDisable(GL_SCISSOR_TEST); }
void Label::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { if (! _visible || _originalUTF8String.empty()) { return; } if (_systemFontDirty || _contentDirty) { updateContent(); } uint32_t flags = processParentFlags(parentTransform, parentFlags); if (_shadowEnabled && _shadowBlurRadius <= 0 && (_shadowDirty || (flags & FLAGS_DIRTY_MASK))) { _position.x += _shadowOffset.width; _position.y += _shadowOffset.height; _transformDirty = _inverseDirty = true; _shadowTransform = transform(parentTransform); _position.x -= _shadowOffset.width; _position.y -= _shadowOffset.height; _transformDirty = _inverseDirty = true; _shadowDirty = false; } if (!isVisitableByVisitingCamera()) { return; } // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); if (_textSprite) { if (_shadowNode) { _shadowNode->visit(renderer, _modelViewTransform, parentFlags); } _textSprite->visit(renderer, _modelViewTransform, parentFlags); } else { draw(renderer, _modelViewTransform, flags); } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); }
void ProtectedNode::visit(Renderer* renderer, const Matrix &parentTransform, bool parentTransformUpdated) { // quick return if not visible. children won't be drawn. if (!_visible) { return; } bool dirty = _transformUpdated || parentTransformUpdated; if(dirty) _modelViewTransform = this->transform(parentTransform); _transformUpdated = false; // IMPORTANT: // To ease the migration to v3.0, we still support the Matrix stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); int i = 0; // used by _children int j = 0; // used by _protectedChildren sortAllChildren(); sortAllProtectedChildren(); // // draw children and protectedChildren zOrder < 0 // for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, dirty); else break; } for( ; j < _protectedChildren.size(); j++ ) { auto node = _protectedChildren.at(j); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, dirty); else break; } // // draw self // this->draw(renderer, _modelViewTransform, dirty); // // draw children and protectedChildren zOrder >= 0 // for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, dirty); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, dirty); // reset for next frame _orderOfArrival = 0; director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void RoleLayer::onDraw(const cocos2d::Mat4& transform, uint32_t flags){ //CCLOG("RoleLayer::onDraw"); Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); //glLineWidth( 5.0f ); /* //画点 DrawPrimitives::setPointSize(20); DrawPrimitives::setDrawColor4B(255,0,0,255); DrawPrimitives::drawPoint(VisibleRect::center()); //画多个点 Vec2 points[] = { Vec2(60,60), Vec2(70,70), Vec2(60,70), Vec2(70,60) }; DrawPrimitives::setPointSize(4); DrawPrimitives::setDrawColor4B(0,255,255,255); DrawPrimitives::drawPoints( points, 4); */ /* //画线, //参数:起点,终点 DrawPrimitives::drawLine( VisibleRect::leftBottom(), VisibleRect::rightTop() ); DrawPrimitives::drawLine(Vec2(0,0), Vec2(100,100)); */ /* //花多边形直至圆 glLineWidth(1.0f); DrawPrimitives::setDrawColor4B(0, 255, 0, 255); //参数:圆心,半径,起始弧度(逆时针为正),线段数,是否画半径,x轴缩放,y轴缩放 DrawPrimitives::drawCircle( VisibleRect::center(), 100, CC_DEGREES_TO_RADIANS(90), 1000,true,1,1); DrawPrimitives::setDrawColor4B(255, 255, 0, 255); DrawPrimitives::drawCircle( VisibleRect::center(), 120, 0, 10,false); //画实心多边形直至圆 glLineWidth(2); DrawPrimitives::setDrawColor4B(0, 0, 255, 255); DrawPrimitives::drawSolidCircle( VisibleRect::center() + Vec2(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 1.0f, 1.0f); */ /* // open yellow poly //用点连线 DrawPrimitives::setDrawColor4B(255, 255, 0, 255); glLineWidth(10); Vec2 vertices[] = { Vec2(0,0), Vec2(50,50), Vec2(100,50), Vec2(100,100), Vec2(50,100) }; //参数:点集合,点数量,是否封闭(首尾相连) DrawPrimitives::drawPoly( vertices, 5, false); DrawPrimitives::setDrawColor4B(255, 0, 255, 255); glLineWidth(2); Vec2 vertices2[] = { Vec2(30,130), Vec2(30,230), Vec2(50,200) }; DrawPrimitives::drawPoly( vertices2, 3, true); //用点连线并填充成面 glLineWidth(1); DrawPrimitives::setDrawColor4B(255, 0, 255, 255); Vec2 filledVertices[] = { Vec2(0,120), Vec2(50,120), Vec2(50,170), Vec2(25,200), Vec2(0,170) }; DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) ); */ /* //画矩形 //参数:左下点,右下点 DrawPrimitives::setDrawColor4B(255, 0, 255, 255); DrawPrimitives::drawRect(Vec2(1,1), Vec2(100,200)); DrawPrimitives::drawSolidRect(Vec2(200,200), Vec2(300, 300), Color4F(1,0.5,0,1)); */ /* //二次贝塞尔曲线 //参数:起点,控制点,终点,线段数 DrawPrimitives::drawQuadBezier(VisibleRect::leftTop(), VisibleRect::center(), VisibleRect::rightTop(), 50); //三次贝塞尔曲线 //参数:起点,控制点1,控制点2,终点 ,线段数 DrawPrimitives::drawCubicBezier(VisibleRect::center(), Vec2(VisibleRect::center().x+130,VisibleRect::center().y+150), Vec2(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100); */ glLineWidth(2); DrawPrimitives::setDrawColor4B(0,255,255,255); DrawPrimitives::drawCircle(Vec2(0,0), 38, 0, 50, false); // restore original values glLineWidth(1); DrawPrimitives::setDrawColor4B(255,255,255,255); DrawPrimitives::setPointSize(1); //end draw director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Layout::stencilClippingVisit(Renderer *renderer, const Mat4& parentTransform, uint32_t parentFlags) { 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 is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); //Add group command _groupCommand.init(_globalZOrder); renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); _beginStencilCommand.init(_globalZOrder, false, 1, _clippingStencil); renderer->addCommand(&_beginStencilCommand); _clippingStencil->visit(renderer, _modelViewTransform, flags); _afterStencilCommand.init(_globalZOrder); renderer->addCommand(&_afterStencilCommand); int i = 0; // used by _children int j = 0; // used by _protectedChildren sortAllChildren(); sortAllProtectedChildren(); // // draw children and protectedChildren zOrder < 0 // for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, flags); else break; } for( ; j < _protectedChildren.size(); j++ ) { auto node = _protectedChildren.at(j); if ( node && node->getLocalZOrder() < 0 ) node->visit(renderer, _modelViewTransform, flags); else break; } // // draw self // this->draw(renderer, _modelViewTransform, flags); // // draw children and protectedChildren zOrder >= 0 // for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); _endStencilCommand.init(_globalZOrder); renderer->addCommand(&_endStencilCommand); renderer->popGroup(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Skeleton::onDraw(const Mat4 &transform, uint32_t flags) { getGLProgram()->use(); getGLProgram()->setUniformsForBuiltins(transform); GL::blendFunc(blendFunc.src, blendFunc.dst); Color3B color = getColor(); skeleton->r = color.r / (float)255; skeleton->g = color.g / (float)255; skeleton->b = color.b / (float)255; skeleton->a = getOpacity() / (float)255; if (premultipliedAlpha) { skeleton->r *= skeleton->a; skeleton->g *= skeleton->a; skeleton->b *= skeleton->a; } int additive = 0; TextureAtlas* textureAtlas = 0; V3F_C4B_T2F_Quad quad; quad.tl.vertices.z = 0; quad.tr.vertices.z = 0; quad.bl.vertices.z = 0; quad.br.vertices.z = 0; for (int i = 0, n = skeleton->slotCount; i < n; i++) { spSlot* slot = skeleton->drawOrder[i]; if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue; spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; TextureAtlas* regionTextureAtlas = getTextureAtlas(attachment); if (slot->data->additiveBlending != additive) { if (textureAtlas) { textureAtlas->drawQuads(); textureAtlas->removeAllQuads(); } additive = !additive; GL::blendFunc(blendFunc.src, additive ? GL_ONE : blendFunc.dst); } else if (regionTextureAtlas != textureAtlas && textureAtlas) { textureAtlas->drawQuads(); textureAtlas->removeAllQuads(); } textureAtlas = regionTextureAtlas; setFittedBlendingFunc(textureAtlas); ssize_t quadCount = textureAtlas->getTotalQuads(); if (textureAtlas->getCapacity() == quadCount) { textureAtlas->drawQuads(); textureAtlas->removeAllQuads(); if (!textureAtlas->resizeCapacity(textureAtlas->getCapacity() * 2)) return; } spRegionAttachment_updateQuad(attachment, slot, &quad, premultipliedAlpha); textureAtlas->updateQuad(&quad, quadCount); } if (textureAtlas) { textureAtlas->drawQuads(); textureAtlas->removeAllQuads(); } if(debugBones || debugSlots) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); if (debugSlots) { // Slots. DrawPrimitives::setDrawColor4B(0, 0, 255, 255); glLineWidth(1); Vec2 points[4]; V3F_C4B_T2F_Quad tmpQuad; for (int i = 0, n = skeleton->slotCount; i < n; i++) { spSlot* slot = skeleton->drawOrder[i]; if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue; spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; spRegionAttachment_updateQuad(attachment, slot, &tmpQuad); points[0] = Vec2(tmpQuad.bl.vertices.x, tmpQuad.bl.vertices.y); points[1] = Vec2(tmpQuad.br.vertices.x, tmpQuad.br.vertices.y); points[2] = Vec2(tmpQuad.tr.vertices.x, tmpQuad.tr.vertices.y); points[3] = Vec2(tmpQuad.tl.vertices.x, tmpQuad.tl.vertices.y); DrawPrimitives::drawPoly(points, 4, true); } } if (debugBones) { // Bone lengths. glLineWidth(2); DrawPrimitives::setDrawColor4B(255, 0, 0, 255); for (int i = 0, n = skeleton->boneCount; i < n; i++) { spBone *bone = skeleton->bones[i]; float x = bone->data->length * bone->m00 + bone->worldX; float y = bone->data->length * bone->m10 + bone->worldY; DrawPrimitives::drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y)); } // Bone origins. DrawPrimitives::setPointSize(4); DrawPrimitives::setDrawColor4B(0, 0, 255, 255); // Root bone is blue. for (int i = 0, n = skeleton->boneCount; i < n; i++) { spBone *bone = skeleton->bones[i]; DrawPrimitives::drawPoint(Vec2(bone->worldX, bone->worldY)); if (i == 0) DrawPrimitives::setDrawColor4B(0, 255, 0, 255); } } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } }