We have a game that requires RenderTexture to be called every frame that captures the screen of the game. I was previously using version 3.6 and was getting around 30 fps on windows 8.1 (Microsoft lumia 535). I had to update the engine so that i could start building universal windows 10 apps. I tried every version after 3.6 and they all produces the same result. The RenderTexture slows down the program so much it becomes unplayable. does any one else having problems similar to what we having?
Edit. Restarted a new project to demonstrate the issue.
Hello world.h
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
USING_NS_CC;
class HelloWorld : public cocos2d::Layer
{
cocos2d::Size _WorldSize;
public:
void UpdateRenderer(float dt);
LayerColor * layer1;
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__
and the hellworld.cpp file
#include "HelloWorldScene.h"
USING_NS_CC;
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
auto closeItem = MenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
origin.y + closeItem->getContentSize().height/2));
// create menu, it's an autorelease object
auto menu = Menu::create(closeItem, NULL);
menu->setPosition(Vec2::ZERO);
this->addChild(menu, 1);
/////////////////////////////
// 3. add your codes below...
// added for testing. Creating a Layer color that will hold bunch of sprites for testing.
layer1 = LayerColor::create(Color4B(255, 255, 255, 255), 1, 1);
//added for testing. creating bunch of sprites to test rendertexture.
auto sprite1 = Sprite::create("lvl1prt1.png");
auto sprite2 = Sprite::create("lvl1prt2.png");
auto sprite3 = Sprite::create("lvl1prt3.png");
auto sprite4 = Sprite::create("lvl1prt1Floor.png");
auto sprite5 = Sprite::create("bottomEdge.png");
auto sprite6 = Sprite::create("rightEdge.png");
layer1->addChild(sprite1);
layer1->addChild(sprite2);
layer1->addChild(sprite3);
layer1->addChild(sprite4);
layer1->addChild(sprite5);
layer1->addChild(sprite6);
// add a label shows "Hello World"
// create and initialize a label
auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
// position the label on the center of the screen
label->setPosition(Vec2(origin.x + visibleSize.width / 2,
origin.y + visibleSize.height - label->getContentSize().height));
// add the label as a child to this layer
this->addChild(label, 1);
auto sprite = Sprite::create("HelloWorld.png");
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
this->addChild(layer1, 0);
_WorldSize = Director::getInstance()->getVisibleSize();
//schedule to updateRenderer
SEL_SCHEDULE selector = schedule_selector(HelloWorld::UpdateRenderer);
this->schedule(selector, 1.00 / 60.0);
return true;
}
void HelloWorld::UpdateRenderer(float dt)
{
//calling render texture
auto renderTexture = RenderTexture::create(_WorldSize.width, _WorldSize.height, Texture2D::PixelFormat::RGBA8888);
renderTexture->begin();
layer1->visit(); //rendering layer1 and its children by calling visit.
renderTexture->end();
}
void HelloWorld::menuCloseCallback(Ref* pSender)
{
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
The above code tested as windows 8,1 phone app. Running the above code on pc doesn’t show much issues (perhaps the pc is too good not sure why) However testing on Microsoft Lumia 640 LTE provided a very bad frame rate. there is a huge (about half a 200ms) delay when the rendertexture code is executed. If you run on debug mode you will only deal with delay. However when you try it on Release,
The number of vertices increases for a while and then app crashes.
I get a bunch of exeptions in the output window. for a while
Exception thrown at 0x76E0E22B in Test.WindowsPhone.exe: Microsoft C++ exception: _com_error at memory location 0x03EBF300.
Then i get the following error message
Exception thrown at 0x00F71ECB in Test.WindowsPhone.exe: 0xC0000005: Access violation reading location 0x00000000.
I am not sure if its me me screwing things up or if there is a serious issue with the rendertexture. I used the Version 3.10 on this test. Later on will upload the same code test from Version 3.6