question about saving the context

49 views
Skip to first unread message

James

unread,
Mar 1, 2012, 5:00:49 PM3/1/12
to GLWallpaperService
I'm developing a LWP which uses a number of textures. So far, I have
been loading my textures in the onSurfaceCreated method. However, i'd
expect this code to be called rather often, and it is taking upwards
of 400ms to decode my bitmaps each time.

If I understand correctly, once you create a texture in openGL it is
saved to the context? That means if I keep the context, I will not
have to reload the images in the onSurfaceCreate method. I also
understand that there is code to keep the context in the latest
version of GLWallpaperservice. Please tell me if I'm wrong

I have a few questions though.

Where abouts in the code is best to load bitmaps and create textures
then?
How can you tell if the context has been saved - so you know if you
need to load the images again?

Lastly, I just want to say well done on the code it's awesome. I can't
believe there is no official openGL wallpaper support.

Jeff Sorrentino

unread,
Mar 1, 2012, 6:11:00 PM3/1/12
to glwallpap...@googlegroups.com
You ONLY need to reload the textures if you lose the EGL context.

Here's an easy way to check, based off my current published wallpapers:


Let me know if this is what you were looking for ;-)

JS

Code Snippet:

GL10 _gl;


public void onSurfaceChanged(GL10 gl, int width, int height) {
Log.d(TAG, "SorenRenderer:onSurfaceChanged");
    this.width  = width;
    this.height = height;
   
    if( !setGL( gl ) ) {
// You need to fully reload textures here.
}
else {
// Run normally, no reload
}

// Only reinit when the gl context is lost.
public boolean setGL( GL10 $gl ) {
if ( $gl == _gl ) {
Log.d(SorenService.TAG, "Using same gl context.");
return true;
}
Log.d(SorenService.TAG, "Using new gl context.");
_gl = $gl;
return false;
}

Use it in your 
--
Jeff Sorrentino
je...@soren.com

James Wozniak

unread,
Mar 3, 2012, 4:13:11 PM3/3/12
to glwallpap...@googlegroups.com
Thanks Jeff, this is exactly  what I was looking for :)

Josh Gooderham

unread,
Mar 3, 2012, 4:45:02 PM3/3/12
to glwallpap...@googlegroups.com

Wozniak eh? Any relation to Steve?

James Wozniak

unread,
Mar 4, 2012, 9:08:16 AM3/4/12
to glwallpap...@googlegroups.com
Unfortunately not, although I do get asked that quite a lot! 
Reply all
Reply to author
Forward
0 new messages