Пример #1
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();
}
Пример #2
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();
}
Пример #3
0
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();
}
Пример #4
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();
}
Пример #5
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();
}
Пример #6
0
void CCRenderTexture::begin()
{
    kmGLMatrixMode(KM_GL_PROJECTION);
	kmGLPushMatrix();
	kmGLMatrixMode(KM_GL_MODELVIEW);
    kmGLPushMatrix();
    
    CCDirector *director = CCDirector::sharedDirector();
    director->setProjection(director->getProjection());

    const CCSize& texSize = m_pTexture->getContentSizeInPixels();

    // Calculate the adjustment ratios based on the old and new projections
    CCSize size = director->getWinSizeInPixels();
    float widthRatio = size.width / texSize.width;
    float heightRatio = size.height / texSize.height;

    // Adjust the orthographic projection and viewport
    glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height);


    kmMat4 orthoMatrix;
    kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio,  (float)1.0 / widthRatio,
        (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
    kmGLMultMatrix(&orthoMatrix);

    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_nOldFBO);
    glBindFramebuffer(GL_FRAMEBUFFER, m_uFBO);
    
    /*  Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of CCRenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers.
     */
    if (CCConfiguration::sharedConfiguration()->checkForGLExtension("GL_QCOM"))
    {
        // -- bind a temporary texture so we can clear the render buffer without losing our texture
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTextureCopy->getName(), 0);
        CHECK_GL_ERROR_DEBUG();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0);
    }
}
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();
}
Пример #8
0
void RenderTexture::begin()
{
    kmGLMatrixMode(KM_GL_PROJECTION);
    kmGLPushMatrix();
    kmGLGetMatrix(KM_GL_PROJECTION, &_projectionMatrix);
    
    kmGLMatrixMode(KM_GL_MODELVIEW);
    kmGLPushMatrix();
    kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix);
    
    if(!_keepMatrix)
    {
        Director *director = Director::getInstance();
        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;
        
        kmMat4 orthoMatrix;
        kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio,  (float)1.0 / widthRatio,
                                     (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 );
        kmGLMultMatrix(&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);
}
Пример #9
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();
}
Пример #10
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();
}
Пример #11
0
KDvoid Level1Scene::draw ( KDvoid )
{
	CCLayer::draw ( );

    ccGLEnableVertexAttribs ( kCCVertexAttribFlag_Position );

    kmGLPushMatrix ( );

	m_pWorld->DrawDebugData ( );

    kmGLPopMatrix  ( );

    CHECK_GL_ERROR_DEBUG ( );
}
Пример #12
0
    void visit()
    {
        kmGLPushMatrix();
		#if CC_TARGET_PLATFORM != CC_PLATFORM_WINRT
        glEnable(GL_SCISSOR_TEST);
		#endif
        CCEGLView::sharedOpenGLView()->setScissorInPoints(this->getCenterX() - Options::CAMERA_CENTER_X, this->getCenterY() + (this->mHeight / 2) - (this->mHeight * this->p / 100), Options::CAMERA_WIDTH, this->mHeight + Utils::coord(150));
        
        Entity::visit();
		#if CC_TARGET_PLATFORM != CC_PLATFORM_WINRT
        glDisable(GL_SCISSOR_TEST);
		#endif
        kmGLPopMatrix();
    }
Пример #13
0
void HelloWorld::draw()
{
    CCLayer::draw();
    
    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
    
    kmGLPushMatrix();
    
//    m_test->m_world->DrawDebugData();
    
    kmGLPopMatrix();
    
    CHECK_GL_ERROR_DEBUG();
}
Пример #14
0
void Box2DView::draw()
{
    Layer::draw();

    GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION );

    kmGLPushMatrix();

    m_test->m_world->DrawDebugData();

    kmGLPopMatrix();

    CHECK_GL_ERROR_DEBUG();
}
Пример #15
0
	void Cocos2dRenderManager::begin()
	{
		kmGLMatrixMode(KM_GL_PROJECTION);
		kmGLPushMatrix();

		//kmGLLoadIdentity();

		//kmMat4 mat;
		//kmGLGetMatrix(KM_GL_PROJECTION, &mat);
		//mat.mat[0] = 600;
		//mat.mat[5] = 600;
		//kmGLLoadMatrix(&mat);

		kmGLMatrixMode(KM_GL_MODELVIEW);
		kmGLPushMatrix();

		//kmGLLoadIdentity();

		//kmGLGetMatrix(KM_GL_MODELVIEW, &mat);
		//mat.mat[12] = 0;
		//mat.mat[13] = 0;
		//mat.mat[15] = 0;
		//kmGLLoadMatrix(&mat);
	}
Пример #16
0
void Box2DDebugDrawLayer::draw()
{
   if(_world != NULL)
   {
      CCLayer::draw();
      
      ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
      
      kmGLPushMatrix();
      
      _world->DrawDebugData();
      
      kmGLPopMatrix();
   }
}
Пример #17
0
void Label::visit()
{
    if (! _visible)
    {
        return;
    }
    
    kmGLPushMatrix();

    transform();
    draw();

    kmGLPopMatrix();

    setOrderOfArrival(0);
}
void GHDebugDrawLayer::draw()
{
	
#ifdef GH_DEBUG
	ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
	kmGLPushMatrix();
	
    //Iterate over the bodies in the physics world
    for (b2Body* body = m_world->GetBodyList(); body; body = body->GetNext())
    {
        GHDebugDrawLayer::DebugDrawBody(body, mShaderProgram ,mColorLocation);
    }
    
	kmGLPopMatrix();
#endif
}
Пример #19
0
void ClippingNodeRect::visit()
{
    kmGLPushMatrix();
    glEnable(GL_SCISSOR_TEST);


    auto glView = cocos2d::Director::getInstance()->getOpenGLView();
    glView->setScissorInPoints(
        getPositionX(), getPositionY(),
        getContentSize().width, getContentSize().height
    );
    Node::visit();

    glDisable(GL_SCISSOR_TEST);
    kmGLPopMatrix();
}
Пример #20
0
void cxEngineDraw()
{
    CX_RETURN(isExit);
    cxEngine engine = cxEngineInstance();
    CX_RETURN(!engine->isInit || engine->isPause);
    cxOpenGLClear();
    cxAutoPoolBegin();
    cxDouble now = cxTimestamp();
    engine->frameDelta = now - engine->lastTime;
    CX_SIGNAL_FIRE(engine->onUpdate, CX_FUNC_TYPE(cxAny,cxFloat),CX_SLOT_OBJECT,engine->frameDelta);
    kmGLPushMatrix();
    cxViewDraw(engine->window);
    kmGLPopMatrix();
    engine->lastTime = now;
    cxAutoPoolClean();
}
void IsometryNode::visit()
{
    //setPosition(CCPointMake(0, 500));
    //CCNode::visit();
    //Stats();
    if(getShaderProgram() == nullptr)
    {
        setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
    }
    
    CC_PROFILER_START_CATEGORY(kCCProfilerCategoryBatchSprite, "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 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();
    }
    
    sortAllChildren();
    transform();

    draw();
    
    if (m_pGrid && m_pGrid->isActive())
    {
        m_pGrid->afterDraw(this);
    }
    
    kmGLPopMatrix();
    setOrderOfArrival(0);
    
    CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryBatchSprite, "CCSpriteBatchNode - visit");
}
Пример #22
0
void Box2DTestLayer::draw()
{
    //
    // IMPORTANT:
    // This is only for debug purposes
    // It is recommend to disable it
    //
    Layer::draw();

    GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION );

    kmGLPushMatrix();

    world->DrawDebugData();

    kmGLPopMatrix();
}
Пример #23
0
void GameScene::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
    // Standard Cocos2d method
    if (!world)
    {
        return;
    }
    
    // debug draw display will be on top of anything else
    
    Layer::draw(renderer, transform, transformUpdated);
    
    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
    kmGLPushMatrix();
    world->DrawDebugData();
    kmGLPopMatrix();
}
Пример #24
0
void ToyLayer::draw()
{
		//
		// IMPORTANT:
		// This is only for debug purposes
		// It is recommend to disable it
		//
		CCLayer::draw();

		ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

		kmGLPushMatrix();

		world->DrawDebugData();

		kmGLPopMatrix();
}
void HelloWorld::draw(cocos2d::Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{
    Layer::draw(renderer, transform, transformUpdated);
    
    
    kmGLPushMatrix();
    kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV);
   
    
    //send custom command to tell the renderer to call opengl commands
    _customCommand.init(_globalZOrder);
    _customCommand.func = CC_CALLBACK_0(HelloWorld::onDraw, this);
    renderer->addCommand(&_customCommand);
    
    
    kmGLPopMatrix();
}
Пример #26
0
// small visit for only one sprite
void UnloadableSpriteNode::visit()
{
	// quick return if not visible
	if (!this->isVisible()) return;
	
    if (!this->_sprite) return;
    
    drawing = true;
    kmGLPushMatrix();
	
    this->transform();
    if (this->_sprite!=NULL) {
        this->_sprite->visit();
	}
    kmGLPopMatrix();
    drawing = false;
}
Пример #27
0
void BatchNode::visit()
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }
    kmGLPushMatrix();

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

    // reset for next frame
    _orderOfArrival = 0;

    kmGLPopMatrix();
}
Пример #28
0
void CABatchView::visit(void)
{
    CC_PROFILER_START_CATEGORY(kCCProfilerCategoryBatchSprite, "CABatchView - visit");

    CC_RETURN_IF(!m_bVisible);
    
    kmGLPushMatrix();
    sortAllSubview();
    transform();

    draw();

    kmGLPopMatrix();
    setOrderOfArrival(0);

    CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryBatchSprite, "CABatchView - visit");

}
Пример #29
0
void PropertyLayer::draw()
{
		//
		// IMPORTANT:
		// This is only for debug purposes
		// It is recommend to disable it
		//
		CCLayer::draw();

		ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

		kmGLPushMatrix();

		world->DrawDebugData();

		kmGLPopMatrix();

		//TODO : draw something here.

		/*
		//draw inputs
		if (this->nodeArray == NULL)
		{
				return;
		}

		glLineWidth(2);
		ccDrawColor4B(124,1,1,128);

		int count = this->nodeArray->count();
		for (int i = 0; i < count; i++)
		{
				PropertyInput *input = (PropertyInput*)this->nodeArray->objectAtIndex(i);
				if (input->isVisible() == false)
				{
						continue;
				}

				CCPoint start = input->text->getPosition();
				CCPoint end = ccp(start.x + input->inputRect.width, start.y + input->inputRect.height);
				cocos2d::ccDrawRect(start ,end);
		}
		*/
}
Пример #30
0
void SPX_TileElement::Render(SPX_Sprite* sprite, float x, float y)
{
	SPX_Data* data = sprite->data;

	SPX_Skin& skin = sprite->skin;
	SPX_TileSet& tileSet = data->tileSetList[tileSetIndex];
	SPX_Tile& tile = tileSet.tileList[tileIndex];
	SPX_Bitmap& bitmap = data->bitmapList[tileSet.bitmapIndex];
	SPX_Rect& rect = tile.rect;
	SPX_ISpriteEvent* eventProc = sprite->eventProc;

	//glPushMatrix();
	kmGLPushMatrix();

	x += this->x;
	y += this->y;

	if(eventProc != NULL)
	{
		eventProc->OnStartElementDraw(sprite, this);
	}


	if(bitmap.texture != NULL)
	{
		SPX_RenderTexture(bitmap.texture, rect.x1, rect.y1, rect.x2, rect.y2, transform, x, y);
	}
	else
	{
		SPX_Texture* skinTexture = skin.textureList[tileSet.bitmapIndex];
		if(skinTexture != NULL)
		{
			SPX_RenderTexture(skinTexture, rect.x1, rect.y1, rect.x2, rect.y2, transform, x, y);
		}
	}

	if(eventProc != NULL)
	{
		eventProc->OnEndElementDraw(sprite, this);
	}

	//glPopMatrix();
	kmGLPopMatrix();
}