示例#1
0
void RawStencilBufferTest::draw()
{
    auto winPoint = Point(Director::getInstance()->getWinSize());

    auto planeSize = winPoint * (1.0 / _planeCount);

    Renderer *renderer = Director::getInstance()->getRenderer();
    size_t neededCmdSize = _planeCount * 2 + 2;
    if(_renderCmds.size() != neededCmdSize)
    {
        _renderCmds.resize(neededCmdSize);
    }

    auto iter = _renderCmds.begin();

    iter->init(_globalZOrder);
    iter->func = CC_CALLBACK_0(RawStencilBufferTest::onEnableStencil, this);
    renderer->addCommand(&(*iter));
    ++iter;



    for (int i = 0; i < _planeCount; i++) {

        auto stencilPoint = planeSize * (_planeCount - i);
        stencilPoint.x = winPoint.x;

        auto spritePoint = planeSize * i;
        spritePoint.x += planeSize.x / 2;
        spritePoint.y = 0;
        _sprites.at(i)->setPosition( spritePoint );

        iter->init(_globalZOrder);
        iter->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawClip, this, i, stencilPoint);
        renderer->addCommand(&(*iter));
        ++iter;

        kmGLPushMatrix();
        this->transform();
        _sprites.at(i)->visit();
        kmGLPopMatrix();

        iter->init(_globalZOrder);
        iter->func = CC_CALLBACK_0(RawStencilBufferTest::onBeforeDrawSprite, this, i, winPoint);
        renderer->addCommand(&(*iter));
        ++iter;

        kmGLPushMatrix();
        this->transform();
        _sprites.at(i)->visit();
        kmGLPopMatrix();
    }

    iter->init(_globalZOrder);
    iter->func = CC_CALLBACK_0(RawStencilBufferTest::onDisableStencil, this);
    renderer->addCommand(&(*iter));

}
示例#2
0
void RenderTexture::end()
{
    Director *director = Director::getInstance();
    
    glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO);

    // restore viewport
    director->setViewport();

    kmGLMatrixMode(KM_GL_PROJECTION);
	kmGLPopMatrix();
	kmGLMatrixMode(KM_GL_MODELVIEW);
	kmGLPopMatrix();
}
示例#3
0
void CCRenderTexture::end()
{
    CCDirector *director = CCDirector::sharedDirector();
    
    glBindFramebuffer(GL_FRAMEBUFFER, m_nOldFBO);

    // restore viewport
    director->setViewport();

    kmGLMatrixMode(KM_GL_PROJECTION);
	kmGLPopMatrix();
	kmGLMatrixMode(KM_GL_MODELVIEW);
	kmGLPopMatrix();
}
// override visit.
// Don't call visit on it's children
void ParticleBatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
    // CAREFUL:
    // This visit is almost identical to Node#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;
    }

    bool dirty = parentTransformUpdated || _transformUpdated;
    if(dirty)
        _modelViewTransform = transform(parentTransform);
    _transformUpdated = false;

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);

    draw(renderer, _modelViewTransform, dirty);

    kmGLPopMatrix();
}
示例#5
0
// override visit
// don't call visit on it's children
void SpriteBatchNode::visit(void)
{
    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;
    }

    kmGLPushMatrix();

    sortAllChildren();
    transform();

    draw();

    kmGLPopMatrix();
    setOrderOfArrival(0);

    CC_PROFILER_STOP_CATEGORY(kProfilerCategoryBatchSprite, "CCSpriteBatchNode - visit");
}
示例#6
0
void LiquidScene::draw() {
    Layer::draw();
    glEnableVertexAttribArray(0);
    kmGLPushMatrix();
    world->DrawDebugData();
    kmGLPopMatrix();
}
void CCBatchNode::visit()
{
    m_drawOrder = ++g_drawOrder;

    // quick return if not visible. children won't be drawn.
    if (!m_bVisible)
    {
        return;
    }
    kmGLPushMatrix();

    if (m_pGrid && m_pGrid->isActive())
    {
        m_pGrid->beforeDraw();
    }

    transform();
    sortAllChildren();
    draw();

    // reset for next frame
    m_uOrderOfArrival = 0;

    if (m_pGrid && m_pGrid->isActive())
    {
        m_pGrid->afterDraw(this);
    }

    kmGLPopMatrix();
}
示例#8
0
void RenderTexture::visit()
{
    // override visit.
	// Don't call visit on its children
    if (!_visible)
    {
        return;
    }
	
	kmGLPushMatrix();
	
    if (_grid && _grid->isActive())
    {
        _grid->beforeDraw();
        transformAncestors();
    }
    
    transform();
    _sprite->visit();
    draw();
	updateEventPriorityIndex();
    
    if (_grid && _grid->isActive())
    {
        _grid->afterDraw(this);
    }
	
	kmGLPopMatrix();

    _orderOfArrival = 0;
}
示例#9
0
void B2DLayer::draw(){
	CCLayer::draw();
	ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
	kmGLPushMatrix();
	world->DrawDebugData();
	kmGLPopMatrix();
}
示例#10
0
void BatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
    // quick return if not visible. children won't be drawn.
    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 kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);

    sortAllChildren();
    draw(renderer, _modelViewTransform, dirty);

    // reset for next frame
    _orderOfArrival = 0;

    kmGLPopMatrix();
}
示例#11
0
void RenderTexture::end()
{
    _endCommand.init(_globalZOrder);
    _endCommand.func = CC_CALLBACK_0(RenderTexture::onEnd, this);

    Renderer *renderer = Director::getInstance()->getRenderer();
    renderer->addCommand(&_endCommand);
    renderer->popGroup();
    
    kmGLMatrixMode(KM_GL_PROJECTION);
    kmGLPopMatrix();
    
    kmGLMatrixMode(KM_GL_MODELVIEW);
    kmGLPopMatrix();

}
示例#12
0
void CCRenderTexture::visit()
{
    // override visit.
	// Don't call visit on its children
    if (!m_bVisible)
    {
        return;
    }
	
	kmGLPushMatrix();
	
    if (m_pGrid && m_pGrid->isActive())
    {
        m_pGrid->beforeDraw();
        transformAncestors();
    }
    
    transform();
    m_pSprite->visit();
    draw();
	
    if (m_pGrid && m_pGrid->isActive())
    {
        m_pGrid->afterDraw(this);
    }
	
	kmGLPopMatrix();

    m_uOrderOfArrival = 0;
}
示例#13
0
// override visit.
// Don't call visit on it's children
void CCParticleBatchNode::visit()
{
    // CAREFUL:
    // This visit is almost identical to CCNode#visit
    // with the exception that it doesn't call visit on it's children
    //
    // The alternative is to have a void CCSprite#visit, but
    // although this is less maintainable, is faster
    //
    if (!m_bVisible)
    {
        return;
    }

    kmGLPushMatrix();

    if ( m_pGrid && m_pGrid->isActive())
    {
        m_pGrid->beforeDraw();
        transformAncestors();
    }

    transform();

    draw();

    if ( m_pGrid && m_pGrid->isActive())
    {
        m_pGrid->afterDraw(this);
    }

    kmGLPopMatrix();
}
示例#14
0
void RenderTexture::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
    // override visit.
	// Don't call visit on its children
    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 kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);

    _sprite->visit(renderer, _modelViewTransform, dirty);
    draw(renderer, _modelViewTransform, dirty);
    
	kmGLPopMatrix();

    _orderOfArrival = 0;
}
void TestColliderDetector::draw()
{
	ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
	kmGLPushMatrix();
	world->DrawDebugData();
	kmGLPopMatrix();
}
示例#16
0
void ClippingNode::drawFullScreenQuadClearStencil()
{
    kmGLMatrixMode(KM_GL_MODELVIEW);
    kmGLPushMatrix();
    kmGLLoadIdentity();
    
    kmGLMatrixMode(KM_GL_PROJECTION);
    kmGLPushMatrix();
    kmGLLoadIdentity();
    
    DrawPrimitives::drawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1));
    
    kmGLMatrixMode(KM_GL_PROJECTION);
    kmGLPopMatrix();
    kmGLMatrixMode(KM_GL_MODELVIEW);
    kmGLPopMatrix();
}
示例#17
0
void Box2DLayer::draw() {
	GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION);
	kmGLPushMatrix();
	
	world_.DrawDebugData();
	
	kmGLPopMatrix();
}
示例#18
0
void BuoyancyScene::draw()
{
	CCLayer::draw();
	ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
	kmGLPushMatrix();
	physics->drawDebugData();
	kmGLPopMatrix();
	CHECK_GL_ERROR_DEBUG();
}
示例#19
0
void Label::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
    if (! _visible || _originalUTF8String.empty())
    {
        return;
    }
    if (_fontDirty)
    {
        updateFont();
    }
    if (_contentDirty)
    {
        updateContent();
    }

    bool dirty = parentTransformUpdated || _transformUpdated;

    if (_shadowEnabled && _shadowBlurRadius <= 0 && (_shadowDirty || dirty))
    {
        _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(dirty)
    {
        _modelViewTransform = transform(parentTransform);
    }
    _transformUpdated = false;

    // IMPORTANT:
    // To ease the migration to v3.0, we still support the kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);

    if (_textSprite)
    {
        drawTextSprite(renderer,dirty);
    }
    else
    {
        draw(renderer, _modelViewTransform, dirty);
    }

    kmGLPopMatrix();
    
    setOrderOfArrival(0);
}
void RawStencilBufferTest::draw()
{    
    auto winPoint = Point(Director::getInstance()->getWinSize());
    
    auto planeSize = winPoint * (1.0 / _planeCount);
    
    glEnable(GL_STENCIL_TEST);
    CHECK_GL_ERROR_DEBUG();
        
    for (int i = 0; i < _planeCount; i++) {
        
        auto stencilPoint = planeSize * (_planeCount - i);
        stencilPoint.x = winPoint.x;
        
        auto spritePoint = planeSize * i;
        spritePoint.x += planeSize.x / 2;
        spritePoint.y = 0;
        _sprite->setPosition( spritePoint );

        this->setupStencilForClippingOnPlane(i);
        CHECK_GL_ERROR_DEBUG();

        DrawPrimitives::drawSolidRect(Point::ZERO, stencilPoint, Color4F(1, 1, 1, 1));
        
        kmGLPushMatrix();
        this->transform();
        _sprite->visit();
        kmGLPopMatrix();
        
        this->setupStencilForDrawingOnPlane(i);
        CHECK_GL_ERROR_DEBUG();
        
		GL::blendFunc(BlendFunc::ALPHA_NON_PREMULTIPLIED.src, BlendFunc::ALPHA_NON_PREMULTIPLIED.dst);
        DrawPrimitives::drawSolidRect(Point::ZERO, winPoint, _planeColor[i]);
        
        kmGLPushMatrix();
        this->transform();
        _sprite->visit();
        kmGLPopMatrix();
    }
    
    glDisable(GL_STENCIL_TEST);
    CHECK_GL_ERROR_DEBUG();
}
示例#21
0
void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
    Layer::draw(renderer, transform, flags);
    
    // Draw debug for Box2D.
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position);
    kmGLPushMatrix();
    m_world->DrawDebugData();
    kmGLPopMatrix();
}
示例#22
0
void RawStencilBufferTest::draw()
{    
    CCPoint winPoint = ccpFromSize(CCDirector::sharedDirector()->getWinSize());
    
    CCPoint planeSize = ccpMult(winPoint, 1.0 / _planeCount);
    
    glEnable(GL_STENCIL_TEST);
    CHECK_GL_ERROR_DEBUG();
        
    for (int i = 0; i < _planeCount; i++) {
        
        CCPoint stencilPoint = ccpMult(planeSize, _planeCount - i);
        stencilPoint.x = winPoint.x;
        
        CCPoint spritePoint = ccpMult(planeSize, i);
        spritePoint.x += planeSize.x / 2;
        spritePoint.y = 0;
        m_pSprite->setPosition( spritePoint );

        this->setupStencilForClippingOnPlane(i);
        CHECK_GL_ERROR_DEBUG();

        ccDrawSolidRect(CCPointZero, stencilPoint, ccc4f(1, 1, 1, 1));
        
        kmGLPushMatrix();
        this->transform();
        m_pSprite->visit();
        kmGLPopMatrix();
        
        this->setupStencilForDrawingOnPlane(i);
        CHECK_GL_ERROR_DEBUG();
        
        ccDrawSolidRect(CCPointZero, winPoint, _planeColor[i]);
        
        kmGLPushMatrix();
        this->transform();
        m_pSprite->visit();
        kmGLPopMatrix();
    }
    
    glDisable(GL_STENCIL_TEST);
    CHECK_GL_ERROR_DEBUG();
}
void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
	Layer::draw(renderer, transform, flags);
	GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION);

	kmGLPushMatrix();

	_world->DrawDebugData();

	kmGLPopMatrix();
}
示例#24
0
void HelloWorld::onDraw(const kmMat4 &transform, bool transformUpdated)
{
    kmGLPushMatrix();
    kmGLLoadMatrix(&transform);
    
    GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION );
    world->DrawDebugData();
    CHECK_GL_ERROR_DEBUG();
    
    kmGLPopMatrix();
}
示例#25
0
void Box2DView::onDraw(const kmMat4 &transform, bool transformUpdated)
{
    kmGLPushMatrix();
    kmGLLoadMatrix(&transform);

    GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION );
    m_test->Step(&settings);
    m_test->m_world->DrawDebugData();
    CHECK_GL_ERROR_DEBUG();
    
    kmGLPopMatrix();
}
示例#26
0
void GiftListView::visit()
{
	kmGLPushMatrix();
	glEnable(GL_SCISSOR_TEST);
	CCSprite* marksp = (CCSprite*)mPageMarkers.objectAtIndex(0);
	CCPoint lbPoint = this->convertToWorldSpace(ccp(0,-marksp->getContentSize().height*2+mMarkPosOffset.y-mItemIntervalV));
	CCPoint trPoint = this->convertToWorldSpace(ccp(getContentSize().width+mItemIntervalH, getContentSize().height+20+mItemIntervalV ) );
	CCEGLView::sharedOpenGLView()->setScissorInPoints(lbPoint.x, lbPoint.y, abs(trPoint.x-lbPoint.x), abs(trPoint.y-lbPoint.y));
	CCNode::visit();
	glDisable(GL_SCISSOR_TEST);
	kmGLPopMatrix();
}
void CC3DSprite::visit( void )
{
	m_drawOrder = ++g_drawOrder;
	// quick return if not visible. children won't be drawn.
	if (!m_bVisible) return;
	kmGLPushMatrix();

	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->getZOrder() < 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;

	kmGLPopMatrix();
}
示例#28
0
void Node::visit(Renderer* renderer, const kmMat4 &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 kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);

    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, 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);
    }

    // reset for next frame
    _orderOfArrival = 0;
 
    kmGLPopMatrix();
}
示例#29
0
void ScrollView::visit()
{
	// quick return if not visible
	if (!isVisible())
    {
		return;
    }

	kmGLPushMatrix();

	this->transform();
    this->beforeDraw();

	if (!_children.empty())
    {
		int i=0;
		
		// draw children zOrder < 0
		for( ; i < _children.size(); i++ )
        {
			Node *child = _children.at(i);
			if ( child->getZOrder() < 0 )
            {
				child->visit();
			}
            else
            {
				break;
            }
		}
		
		// this draw
		this->draw();
        
		// draw children zOrder >= 0
		for( ; i < _children.size(); i++ )
        {
			Node *child = _children.at(i);
			child->visit();
		}
        
	}
    else
    {
		this->draw();
    }

    this->afterDraw();

	kmGLPopMatrix();
}
示例#30
0
void CARenderImage::end()
{
    GLubyte *pBuffer = pBuffer = new GLubyte[m_uPixelsWide * m_uPixelsHigh * 4];
    GLubyte *pTempData = new GLubyte[m_uPixelsWide * m_uPixelsHigh * 4];
    
    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glReadPixels(0, 0, m_uPixelsWide, m_uPixelsHigh, GL_RGBA, GL_UNSIGNED_BYTE, pTempData);
    glBindFramebuffer(GL_FRAMEBUFFER, m_nOldFBO);

    CAApplication::getApplication()->setViewport();

    kmGLMatrixMode(KM_GL_PROJECTION);
	kmGLPopMatrix();
	kmGLMatrixMode(KM_GL_MODELVIEW);
	kmGLPopMatrix();

    m_pImage = new CAImage();
    m_pImage->initWithRawData(pTempData, CAImage::PixelFormat_RGBA8888, m_uPixelsWide, m_uPixelsHigh);
    m_pImageView->setImage(m_pImage);
    
    CC_SAFE_DELETE_ARRAY(pBuffer);
    CC_SAFE_DELETE_ARRAY(pTempData);
}