Пример #1
0
void RenderTexture::onBegin()
{
    //
    Director *director = Director::getInstance();
    Size size = director->getWinSizeInPixels();
    kmGLGetMatrix(KM_GL_PROJECTION, &_oldProjMatrix);
    kmGLMatrixMode(KM_GL_PROJECTION);
    kmGLLoadMatrix(&_projectionMatrix);
    
    kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix);
    kmGLMatrixMode(KM_GL_MODELVIEW);
    kmGLLoadMatrix(&_transformMatrix);
    const Size& texSize = _texture->getContentSizeInPixels();
    if(!_keepMatrix)
    {
        director->setProjection(director->getProjection());

        

        // Calculate the adjustment ratios based on the old and new projections
        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);
    }
    //calculate viewport
    {
        Rect viewport;
        viewport.size.width = _fullviewPort.size.width;
        viewport.size.height = _fullviewPort.size.height;
        float viewPortRectWidthRatio = float(viewport.size.width)/_fullRect.size.width;
        float viewPortRectHeightRatio = float(viewport.size.height)/_fullRect.size.height;
        viewport.origin.x = (_fullRect.origin.x - _rtTextureRect.origin.x) * viewPortRectWidthRatio;
        viewport.origin.y = (_fullRect.origin.y - _rtTextureRect.origin.y) * viewPortRectHeightRatio;
        //glViewport(_fullviewPort.origin.x, _fullviewPort.origin.y, (GLsizei)_fullviewPort.size.width, (GLsizei)_fullviewPort.size.height);
        glViewport(viewport.origin.x, viewport.origin.y, (GLsizei)texSize.width, (GLsizei)texSize.height);
    }

    // Adjust the orthographic projection and viewport
    
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO);
    glBindFramebuffer(GL_FRAMEBUFFER, _FBO);

    //TODO move this to configration, so we don't check it every time
    /*  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 RenderTexture::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 (Configuration::getInstance()->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, _textureCopy->getName(), 0);
        CHECK_GL_ERROR_DEBUG();
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0);
    }
}
Пример #2
0
void GridBase::beforeDraw(void)
{
    // save projection
    Director *director = Director::getInstance();
    _directorProjection = director->getProjection();

    // 2d projection
    //    [director setProjection:Director::Projection::_2D];
    set2DProjection();
    
    Size    size = director->getWinSizeInPixels();
    glViewport(0, 0, (GLsizei)(size.width), (GLsizei)(size.height) );
    _grabber->beforeRender(_texture);
}
Пример #3
0
void GridBase::set2DProjection()
{
    Director *director = Director::getInstance();
    Size    size = director->getWinSizeInPixels();
    
    director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);

    Mat4 orthoMatrix;
    Mat4::createOrthographicOffCenter(0, size.width, 0, size.height, -1, 1, &orthoMatrix);
    director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix);

    director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);

    GL::setProjectionMatrixDirty();
}
Пример #4
0
void GridBase::set2DProjection()
{
    Director *director = Director::getInstance();

    Size    size = director->getWinSizeInPixels();

    glViewport(0, 0, (GLsizei)(size.width), (GLsizei)(size.height) );
    kmGLMatrixMode(KM_GL_PROJECTION);
    kmGLLoadIdentity();

    kmMat4 orthoMatrix;
    kmMat4OrthographicProjection(&orthoMatrix, 0, size.width, 0, size.height, -1, 1);
    kmGLMultMatrix( &orthoMatrix );

    kmGLMatrixMode(KM_GL_MODELVIEW);
    kmGLLoadIdentity();

    GL::setProjectionMatrixDirty();
}
Пример #5
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);
}
Пример #6
0
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);
}
Пример #7
0
bool GridBase::initWithSize(const cocos2d::Size &gridSize, const cocos2d::Rect &rect)
{
    Director *director = Director::getInstance();
    Size s = director->getWinSizeInPixels();
    
    auto POTWide = ccNextPOT((unsigned int)s.width);
    auto POTHigh = ccNextPOT((unsigned int)s.height);
    
    // we only use rgba8888
    Texture2D::PixelFormat format = Texture2D::PixelFormat::RGBA8888;
    
    auto dataLen = POTWide * POTHigh * 4;
    void *data = calloc(dataLen, 1);
    if (! data)
    {
        CCLOG("cocos2d: Grid: not enough memory.");
        this->release();
        return false;
    }
    
    Texture2D *texture = new (std::nothrow) Texture2D();
    texture->initWithData(data, dataLen,  format, POTWide, POTHigh, s);
    
    free(data);
    
    if (! texture)
    {
        CCLOG("cocos2d: Grid: error creating texture");
        return false;
    }
    
    initWithSize(gridSize, texture, false, rect);
    
    texture->release();
    
    return true;
}
Пример #8
0
bool GridBase::initWithSize(const Size& gridSize)
{
    Director *pDirector = Director::getInstance();
    Size s = pDirector->getWinSizeInPixels();

    unsigned long POTWide = ccNextPOT((unsigned int)s.width);
    unsigned long POTHigh = ccNextPOT((unsigned int)s.height);

    // we only use rgba8888
    Texture2DPixelFormat format = kTexture2DPixelFormat_RGBA8888;

    void *data = calloc((int)(POTWide * POTHigh * 4), 1);
    if (! data)
    {
        CCLOG("cocos2d: Grid: not enough memory.");
        this->release();
        return false;
    }

    Texture2D *pTexture = new Texture2D();
    pTexture->initWithData(data, format, POTWide, POTHigh, s);

    free(data);

    if (! pTexture)
    {
        CCLOG("cocos2d: Grid: error creating texture");
        return false;
    }

    initWithSize(gridSize, pTexture, false);

    pTexture->release();

    return true;
}
Пример #9
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    Director* pDirector = gDirector;
    
    GLView* pGLView = pDirector->getOpenGLView();
    if( NULL == pGLView )
    {
        pGLView = GLView::create("game(v1.0.0.0)---test for inner");
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
        pGLView->setFrameSize(1334, 750);
#endif
        
        pDirector->setOpenGLView(pGLView);
    }
    
    // turn on display FPS
    pDirector->setDisplayStats(true);
    
    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);
    
    // resolution information  
    Size size;  
    size= pDirector->getWinSize();
	log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getWinSizeInPixels();  
	log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getVisibleSize();  
	log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height);  

	Point point = pDirector->getVisibleOrigin();  
	log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y);  


	log("***IDONG: Director BS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor());  

	auto framsize = pGLView->getFrameSize();
	auto dwinsize = pDirector->getWinSize();
	auto designsize = Size(SCREEN_WIDTH, SCREEN_HEIGHT);
	auto widthRate = framsize.width/designsize.width;
	auto heightRate = framsize.height/designsize.height;

	auto  resolutionRate = 1.f;
	if(widthRate > heightRate) 
	{
		pGLView->setDesignResolutionSize(designsize.width,
		 designsize.height*heightRate/widthRate, ResolutionPolicy::NO_BORDER);
		 resolutionRate = heightRate/widthRate;
	}
	else
	{
		pGLView->setDesignResolutionSize(designsize.width*widthRate/heightRate, designsize.height,
		 ResolutionPolicy::NO_BORDER);
		 resolutionRate = widthRate/heightRate;
	}

	//pGLView->setDesignResolutionSize(SCREEN_WIDTH, SCREEN_HEIGHT, ResolutionPolicy::FIXED_HEIGHT);

	log("***IDONG:/n");  
	log("***IDONG: Director AS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor());  

	size= pDirector->getWinSize();  
	log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getWinSizeInPixels();  
	log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getVisibleSize();  
	log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height);  

	point = pDirector->getVisibleOrigin();  
	log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y);  

	// ‘ˆº”À—À˜¬∑æ∂
	gFileUtils->addSearchPath("assets");

	// …Ë÷√◊ ‘¥ƒø¬�?
	// ≥ı ºªØ◊ ‘¥ƒø¬�?dumpŒƒº˛…˙≥…ƒø¬�?
	string logfile = "";
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	gGameManager->SetResourceRoot("/mnt/sdcard/com.zm.mszb/");
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	gGameManager->SetResourceRoot("");
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	gGameManager->SetResourceRoot(gFileUtils->getWritablePath());
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
	gGameManager->LogMachineInfo();
	// ø™ º∏¸–�?
	gGameManager->Start();

    return true;
}