Graphics

Reply

Re: Texture2D background loading during runtime

This is a very random thing to try... but... maybe you could create an Image(mybytearray) on the load thread? Then call Decode() on it (also on load thread).

Then you can create a new empty Texture2D(width, height) and call Texture2D.SetPixels and pass in the byte array from Image.ToBuffer() (I think this will work!).

I know this is a very roundabout way of doing things, but if the stall is the decoding of the PNG file then being able to do that on the load thread might help.

Please use plain text.

Level 1

Level 1
tomatenbrei
Posts: 19
Registered: ‎10-09-2010
Message 12 of 39 (226 Views)

Re: Texture2D background loading during runtime

I profiled (if this is what its called) the main method for "loading" an image (create) and this is what I came up with:

public void create(GameHandler gh,float scale)
		{
Sce.Pss.HighLevel.GameEngine2D.Base.Timer t = new Sce.Pss.HighLevel.GameEngine2D.Base.Timer();
             t.Reset();

Console.WriteLine(t.Milliseconds().ToString());
TextureInfo ti = new TextureInfo(new Texture2D(filename,false));
Console.WriteLine(t.Milliseconds().ToString()); index = gh.newsprite(ti,position,scale);
Console.WriteLine(t.Milliseconds().ToString()); }

 


And here are some resulting timer data-sets (With all black 1000x1000 blocks):
Playstation Suite Simulator:
0.0008
35.7639
35.8201

0.0017
37.869
37.9349

0.0008
36.4676
36.5237

0.0013
36.1609
36.2367

On my Vita:
2.047
188.731
215.77

00.003
180.607
180.997

10.002
174.982
175.347

20.001
176.699
177.089

________________________________

Also interesting to see is that the vita seems to load much slower than the Simulator. And now i know that it is not the fault of my "GameHandler" :smileyvery-happy: weeew. But well.. how to continue?

Please use plain text.

Re: Texture2D background loading during runtime

Hi:

 

Excellent !! ,now let me ask which call it's  this one:

 

0.0017
37.869
37.9349

 

?

 

cheers

Please use plain text.

Level 1

Level 1
tomatenbrei
Posts: 19
Registered: ‎10-09-2010
Message 14 of 39 (217 Views)

Re: Texture2D background loading during runtime

@noggsy:
sounds quite of allright, i'll try this later on.

@AlexMcDev:
what do you mean with "which call it's this one" it was the secund test load of a 1000x1000px whole black png file using the code i got above with the "Playstation Suite Simulator".

Please use plain text.

Re: Texture2D background loading during runtime

Hi:

 

Ok. now I have a better understanding, good you have this difference between your nesrpite call:

0.0659

0.0562

0.0758

 

thats good, but between the TExtureInfo and your call it's to much!!, since that texture info seems to be equal for the three big texture try to call it outside the thread. Only in the initialization of everything you have and then share it. try like this. Because there probably it's doing a context switch/ HW interrup.

 

Cheers,

 

PS: if not clear let me know.

Please use plain text.

Re: Texture2D background loading during runtime

Hi:

 

To clarify (soory I'm at work right now I'm not paying attention) new Texture() if unavoidable so that time it's imposible to change but change it to TextureInfo(filename), Anyways I think that part you will not have another solution than left it. U don't have the TextureInfoCode, well thats not 100% true. Another thing check next thing, Remove Texture info and left only the Texture2D to see if you have some ms gain.

 

 

cheers,

Please use plain text.

Level 1

Level 1
tomatenbrei
Posts: 19
Registered: ‎10-09-2010
Message 17 of 39 (185 Views)

Betreff: Texture2D background loading during runtime

I am trying to follow noggsy's suggestion on how to solve my problem:

This is what I came up with:

byte[] bytearray;

                private void loadbytearray()
		{
		    System.IO.FileStream fs = System.IO.File.Open(filename,System.IO.FileMode.Open);

			byte[] b = new byte[fs.Length];

			fs.Read(b,0,b.Length);
			fs.Close();

			Sce.Pss.Core.Imaging.Image image = new Sce.Pss.Core.Imaging.Image(b);
			image.Decode();

		    bytearray = image.ToBuffer();
	
			loaded = true;
			image.Dispose();
			image = null;

		}
		private Texture2D bytearraytotexture2d()
		{
			Texture2D texture = new Texture2D(1000,1000,false,PixelFormat.Rgba);
			texture.SetPixels(0,bytearray);
			bytearray = null;
			
			return texture;
		}
		public void create(GameHandler gh,float scale)
		{
			Sce.Pss.HighLevel.GameEngine2D.Base.Timer t = new Sce.Pss.HighLevel.GameEngine2D.Base.Timer();
			t.Reset();
			Console.WriteLine(t.Milliseconds().ToString());
			loadbytearray();
			Console.WriteLine(t.Milliseconds().ToString());
			draw(gh);
			Console.WriteLine(t.Milliseconds().ToString());
		}
		public void draw(GameHandler gh)
		{
			index = gh.newsprite(new TextureInfo(bytearraytotexture2d()),position,1f);
		}

 Calling "create" does now load textures in a "complete diffrerent" way than before and im really happy with the timer results, but look at them on your own:
(This time just on one device because im too lazy haha)

Playstation Suite Simulator:
0.0008
70.8607
75.6543

0.0009
74.1187
78.9819

0.0008
48.902
53.6447

0.0012
64.6147
69.1027

____________________________
The total difference is that this method is way faster and i know that i can handle "loadbytearray" in another thread - resulting would be a ingame lag about 2-3 millisecunds for loading 1000x1000px whole black images. But I got problems with handling this in a secund thread, any suggestions?

Please use plain text.

Level 1

Level 1
tomatenbrei
Posts: 19
Registered: ‎10-09-2010
Message 18 of 39 (184 Views)

Betreff: Texture2D background loading during runtime

ignore that "loaded = true" in loadbytearray(). I forgot to delete that line after i failed at trying to handle multi-threading.

Please use plain text.

Betreff: Texture2D background loading during runtime

Hi:

 

XD, good, but let me ask something, you are happy because yoir first implementation it's better than this one right?

 

Cheers,

 

PS: The time it's worts in the last.

Please use plain text.

Level 1

Level 1
tomatenbrei
Posts: 19
Registered: ‎10-09-2010
Message 20 of 39 (178 Views)

Betreff: Texture2D background loading during runtime

No im happy because my first one wasnt handleable in an other thread than the main thread and this one is :smileyhappy:

But.. without extra threading, while workling on my pc, the Psapp suddenly broke. I put some control System.Console.Writeline() stuff inside my code and I finally saw that my app breaks at Frame 6501 on  Sce.Pss.HighLevel.GameEngine2D.Director.Instance.Render(); without any really reason. It just breaks o_O 

Please use plain text.
This widget could not be displayed.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。






Recent News