Author Topic: Live Wallpaper and textures  (Read 856 times)

Offline christian

  • byte
  • *
  • Posts: 8
    • View Profile
Live Wallpaper and textures
« on: June 17, 2013, 10:52:41 am »
Hello!
I am trying to add a live wallpaper to my dice rolling application (DnDice, check it out: https://play.google.com/store/apps/details?id=com.christian.bar.dndice).

The problem I am experiencing is with textures: if more than one instance of the renderer/jpct-ae is running (i.e. the one inside the dice app, the live wallpaper preview or the live wallpaper itself, let's call them "instances") the application crashes telling me that I cannot instantiate more than once a texture with the same name. Maybe this is only a symptom of a bigger problem, I don't know...

I tried to put a:
Code: [Select]
if(!textureManager.containsTexture("texture_name"))
textureManager.addTexture("texture_name", texture);
, and the app does not crash anymore, but I cannot see the background texture (but textures on the dice are still there, is this because dice also have shaders and the background texture not?).

Searching in the forum, I found that the textures are bound to a specific context in the graphics memory but inside jpct-ae their are treated as unique, is this correct?
How can I tell jpct-ae to use the same texture with more that one "instance"?
Or, how can I tell to treat every "instance" to use their own textures and instantiate one "texture_name" texture for each "instance"?
Speaking in general, what lines of code do I have to write to let more than one "instance" of an app run without errors?

A lot of people is having problems with live wallpapers, maybe it would be useful to add a sample project/tutorial with a sample live wallpaper (such as a textured cube) to help everyone use this great engine :)
I saw that a lot of live wallpapers use jpct-ae, so the solution is out there, please let me know, you will save a lot of headaches ;D :o

Thank you for your help!
Christian

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Live Wallpaper and textures
« Reply #1 on: June 17, 2013, 09:51:59 pm »
You are actually not supposed to deal with textures in different contexts by adding them twice. The engine keeps one physical copy in main memory but it will upload the data to the gpu to any context that tries to access it. The problem with wallpapers (and/or the this wallpaper framework) that everybody is using, is actually that multiple contexts exist (and are being rendered into) at the same time and THAT isn't a good idea. You have to synchronize this somehow so that it doesn't happen, but i can't tell exactly how. I would love to add a wallpaper example to the wiki but my personal experience with wallpaper is exactly zero. All that i know have i taken from threads here in the forum. Maybe you can PM one who seemed to have managed to get it to work.

Offline christian

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Live Wallpaper and textures
« Reply #2 on: June 18, 2013, 10:19:14 am »
You are actually not supposed to deal with textures in different contexts by adding them twice. The engine keeps one physical copy in main memory but it will upload the data to the gpu to any context that tries to access it. The problem with wallpapers (and/or the this wallpaper framework) that everybody is using, is actually that multiple contexts exist (and are being rendered into) at the same time and THAT isn't a good idea. You have to synchronize this somehow so that it doesn't happen, but i can't tell exactly how. I would love to add a wallpaper example to the wiki but my personal experience with wallpaper is exactly zero. All that i know have i taken from threads here in the forum. Maybe you can PM one who seemed to have managed to get it to work.

Thank you, I will write directly to someone... :)