Just wondering if anyone else has experienced this specific issue.
When a sprite is rendered to a RenderTexture, the output is inconsistent between the Metal and OpenGL renderers (the image is flipped on the Y axis).
For example, this code works on Windows and Android with the OpenGL renderer to show a sprite facing the correct way up (code is just the generated template project with the additions you see below in HelloWorldScene.cpp):
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("HelloWorld.png");
if (sprite == nullptr)
{
problemLoading("'HelloWorld.png'");
}
else
{
sprite->setFlippedY(true);
sprite->setPosition(sprite->getContentSize() / 2);
auto* renderTexture = RenderTexture::create(sprite->getContentSize().width, sprite->getContentSize().height, PixelFormat::RGBA8888);
renderTexture->beginWithClear(0, 0, 0, 0);
sprite->visit();
renderTexture->end();
auto* newSprite = Sprite::createWithTexture(renderTexture->getSprite()->getTexture());
// position the sprite on the center of the screen
newSprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(newSprite, 0);
}
On Windows/Android (OpenGL backend), this is the output:
On Mac OS X and iOS (Metal backend):
It is something the Metal backend implementation that is causing this issue, and while I can hack around it by doing a check for OpenGL in my own code, it really should be fixed in the backend renderer.
The hack would be like this:
...
#if defined(CC_USE_GL) || defined(CC_USE_GLES)
sprite->setFlippedY(true);
#endif
sprite->setPosition(sprite->getContentSize() / 2);
auto* renderTexture = RenderTexture::create(sprite->getContentSize().width, sprite->getContentSize().height, PixelFormat::RGBA8888);
// etc...