Hi!
I need to create a Texture with what is currently on the screen (basically a Screenshot) and then I need to apply a blur effect to that texture so I can put it on the back of the scene and disabled all the other nodes behind of that (We need to improve the number of draw call for our game).
To take the screen shot I’m doing this:
auto winSize = cocos2d::Director::getInstance()->getWinSize();
auto renderTexture = cocos2d::RenderTexture::create(winSize.width, winSize.height,cocos2d::Texture2D::PixelFormat::RGBA8888, GL_DEPTH24_STENCIL8_OES);
cocos2d::Scene* curScene = cocos2d::Director::getInstance()->getRunningScene();
renderTexture->begin();
curScene->visit();
cocos2d::Director::getInstance()->getRenderer()->render();
renderTexture->end();
return renderTexture;
Then I’m setting the Blur shader (I’m using the one on the Cocos2d Test example) using a material
auto renderTexture = ImageUtils::GetScreenTexture();
auto properties = cocos2d::Properties::createNonRefCounted("Materials/BlurMaterial.material");
cocos2d::Material *mat1 = cocos2d::Material::createWithProperties(properties);
renderTexture->setGLProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getGLProgramState());
return renderTexture;
But what worries me is that I need to apply the blur effect just once, for what I understand with my code above it will process the blur for every frame.
In Unity3d, there is an Util method from the Graphic class that helps to do this, basically is a blit where you can specify the material (with the texture already set) the Texture target and the index of the pass. On that way I just apply the blur effect just once. There is something similar on cocos2d?
Kind regards