RenderTexture does a different result

UPDATE
I notice that the size of my shape depend on the position on the screen

Hello :wave:

I am writing on this forum today because I have been facing a problem for two weeks and cannot figure out how to fix it.

In my game I created Shapes of different colors, sizes… and I want to store them into a single Sprite in order to reduce the number of Draw calls.

I used RenderTexture to make it work on Windows and when I tried on Android there is some offset, space that appear.

On iOS I must flip but it seems to be worse, buttons are shifted to text.

If anyone could put me on the right way

Thank you :grinning:

Windows

Android

iOS

Shape.cpp

Shape.h

The flip issue when using RenderTexture with the Metal backend renderer when has been logged here, and I really wish it would be addressed.

Now, regarding the text within the buttons on iOS, is it the text that’s shifted down, or the button is shifted up, it’s hard to tell from your screenshot, since it’s not the same scale as the Windows and Android screenshots.

Do you have a small demo project you can upload here as a zip? (without the binary build folder or cocos2d folder to reduce the size)

Have you checked the results of the calculations between the different platforms to see if there are any differences in the items rendered to the RenderTexture?

For the Android compared to Windows, I can see that the Android textures are a little bigger; is that what you’re referring to?

Thank you for your quick reply :grinning_face_with_smiling_eyes:

I created a demo project. I notice that depending on the position of the Shape in the RenderTexture it will appear correctly or not.

Hope you will understand better what I am talking about and succeed in finding a solution

Classes.zip (7.9 KB)

Try commenting out the setAliasTexParameters line in ShapeFrame::createShapeFrame():

	if (!rt)
	{
		rt = RenderTexture::create(4096 / scale, 4096 / scale);
		//rt->getSprite()->getTexture()->setAliasTexParameters();
		rt->retain();
	}

I’m seeing less issues with the borders on the generated images between Windows and Android with that change, so check if it does anything for you.

The problem is still there :frowning_face:

For iOS it’s the button which is shifted up.

This project run and show nothing, may something wrong with it , can you check it?

Hi @huanxinyin

I’m using cocos2d-x v4.0

May you have to change resolution rect or designResolutionSize

Thank you

it work now, but how to understand this test show? it look ok. can you give the error diagram?

@huanxinyin One of the issues mentioned by @ComputerDev has already been raised here: https://github.com/cocos2d/cocos2d-x/issues/20612

The RenderTexture result on iOS (Metal renderer) is different to the result from Windows/Android (OpenGL renderer). The expectation is that RenderTexture should produce the exact same output on all platforms.

The problem is that some space appear, this should be 6px but it’s only 5px but if you put this line at an other position in the scene screen or an other position in the RenderTexture the 6px may appear.

Sans titre

Here on this updated demo I added line, all line are the same SpriteFrame on the TextureRect but result is different as you can see

Sans titre

Classes.zip (8.0 KB)

Thank you

I test on android platform, it look no problem.

On Windows I got this

Sans titre2

I am trying to use RenderTexture to reduce draw calls because I use a lot of DrawNode in my app with GlobalZOrder but if you guys know another way, I will appreciate.

Are you batching your DrawNodes?

I was thinking batching was only for Sprite, that’s why I add those DrawNode into RenderTexture
How can I implement this ?

We had a conversation about it: DrawNode -> needs optimization, frame rate drops dramatically. · Issue #13453 · cocos2d/cocos2d-x · GitHub

Thank you but I have no FPS problem, only draw calls.
I made important optimization on my app with GlobalZOrder and for DrawNode I got the idea to put them into RenderTexture and I can’t use Sprite directly because some size are dynamically.
But may be I will abandon this solution which seems good to me at first sight to come back with higher draw calls
Is it okay to have 60 draw calls from DrawNode because with RenderTexture you have only 1 draw calls but I encountered two problems (iOS and offset) and my update still delayed until I find a solution ?

You can use a single DrawNode to do all the drawing, which would be a single draw call for as many objects as you want to draw with it on the screen. In your current implementation you’re creating a new DrawNode every time you create a shape, which is where you would run into performance problems.

I can’t remember if you can change the global Z per object drawn with the same DrawNode, but it’s something you should be able to test easily.

An example of using a single DrawNode to do something similar is here: Box2D debug overlays with draw node

But if I want to scale a button which is part of DrawNode it’s not possible right ?

If you’re using it just for a UI, then is there any reason you can’t just clear everything and redraw each frame? In doing that, you can do whatever you want with the objects on the screen, even make them look like they’re animating (for example, button scaling when you press it etc.)