Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.85k stars 819 forks source link

RenderTexture.draw( arg0 , arg1 ) | Matrix bug ( causes flickering of *FIRST* RenderTexture ) #881

Closed Snky closed 8 years ago

Snky commented 8 years ago

'I definitely found a problem on Starling's side that happens when you draw the same object into a render texture and on the screen and using the matrix parameter of "renderTexture.draw". I'll look into ways to fix that! In the meantime, there's a simple workaround:' -TheFriendlyGhostofDaniel

<_containerTransformationMatrixHelper>.copyFrom( <_container>.transformationMatrix );
<_container>.setRequiresRedraw( ); // <--- workaround !!
<_rendertexture>.draw( <_container>, <_containerTransformationMatrixHelper> );
JohnBlackburne commented 8 years ago

Seeing I think the same problem except I’m not drawing it on screen or anywhere else, just in a RenderTexture. If I draw objects directly to the texture it works, but if they are contained in a Sprite then I see nothing unless I call setRequiresRedraw() on the Sprite before drawing. I too pass a Matrix rather than set the x and y on the object(s).

PrimaryFeather commented 8 years ago

Originally, I thought I might find a more elegant fix for this; but the proposed workaround is probably the best that can be done. I added that directly to the "draw" method.

Both of you, please try it out and let me know if that works for you! Thanks in advance. :smile:

Snky commented 8 years ago

I am sorry to say that I do not actually have this issue anymore(pre-today's patch); I update Starling's files every time there is a commit, not sure if I fixed something on my end or if it was due to an upgraded Starling file (statsDisplay was behaving a bit irregular in regards to the project I uploaded to you(I know that is one thing that was upgraded, and could be related to the flickering bug disappearing), if you would like me to compare my current setup to the one which I had uploaded to you, to find out what fixed the bug(pre-today's patch) just let me know, I would be more than happy too.

<_containerTransformationMatrixHelper>.copyFrom(<_container>.transformationMatrix);
<_containerTransformationMatrixHelper>.identify();
<_containerTransformationMatrixHelper>.invert();
<_containerTransformationMatrixHelper>.translate(tx, ty);
<_rendertexture>.draw(<_container>);//, <_containerTransformationMatrixHelper>);

This code does not produce flickering anymore. (-1, persistent = false, RGB_PACKED, NO RequiresRedraw(image), NO excludeFromCache(image), NO arg1)

I have not pulled any new Starling files for a few days. Unfortunately, since I did not mention this earlier, you have put the work around in as the current solution for everyone, although, now I am a bit concerned I may have got you to change something that I somehow fixed without the workaround; is there any performance difference from the code above compared to passing in the matrix to the second argument?

It also seems someone else had a similar issue, so maybe there's some truth to this issue after all(hopefully, otherwise, oops).

JohnBlackburne commented 8 years ago

Yes, fixes it for me, unsurprisingly as it’s essentially the same fix I used. I don’t know if it is only needed only for containers, but I can’t see it being a performance issue either way.

PrimaryFeather commented 8 years ago

Thanks for trying it out, guys!

is there any performance difference from the code above compared to passing in the matrix to the second argument?

No, the difference is negligible, don't worry about it.

Yes, fixes it for me, unsurprisingly as it’s essentially the same fix I used. I don’t know if it is only needed only for containers, but I can’t see it being a performance issue either way.

Yes, I didn't suspect any problems, since it's really exactly the same as the workaround I proposed. Nevertheless, thanks a lot for trying it out!

Let me know if you run into anything else. Cheers!