Discussion:
OpenGL on multiple threads with sharegroups
Phil Endecott
2010-11-25 16:44:43 UTC
Permalink
Dear All,

I'm porting some iPhone OpenGL code that uses a separate thread for
OpenGL texture loading. To do this, I create a new OpenGL context in
the same "sharegroup" as the main rendering context, and then the
textures loaded in one context are available to the other.

I've not seen any equivalent to this on Android. Is this correct, or
am I missing something?

My code is C++, but as far as I can see the situation is the same for
Java OpenGL code.

Thanks for any suggestions.


Phil.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
String
2010-11-26 05:29:11 UTC
Permalink
Post by Phil Endecott
I'm porting some iPhone OpenGL code that uses a separate thread for
OpenGL texture loading.  To do this, I create a new OpenGL context in
the same "sharegroup" as the main rendering context, and then the
textures loaded in one context are available to the other.
Is that an OpenGL ES feature, or something specific to iOS?

Generally, all your Android threads run in one process, and it's not
hard to share data between them. Might it be possible to save your
OpenGL context from your rendering thread, then use it to create
textures in another thread? One approach would be static vars in your
rendering subclass:

static GL10 glContext;
static int textures[] = new int[3];

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
glContext = gl;
gl.glGenTextures(3, textures, 0);

...
}


Something like that might work, anyway.

String
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Phil Endecott
2010-11-26 09:39:05 UTC
Permalink
Post by String
Is that an OpenGL ES feature, or something specific to iOS?
My understanding is that creating OpenGL contexts is always platform-
specific.

EGL seems to define textures and vertex buffers as shared by default;
see section 2.4 of the EGL spec (http://www.khronos.org/registry/egl/
specs/eglspec.1.4.20101006.pdf). Does Android claim to support EGL?

Earlier I found another post saying that this didn't work, but now I
can't find it...
Post by String
Generally, all your Android threads run in one process, and it's not
hard to share data between them. Might it be possible to save your
OpenGL context from your rendering thread, then use it to create
textures in another thread?
You would need a mutex since there is so much state in the context
(currently bound texture, etc). So it would be easier to move
everything onto one thread.


Thanks, Phil.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Adam Hammer
2010-11-26 11:08:20 UTC
Permalink
I do bitmap loading in another thread, but I do glBindTexture in the
main graphics thread. Works well for me, I load bitmaps stored in zips
delivered by contentproviders into textures.

I think opengl es does have mechanisms for sharing textures across GL
contexts, but the above method should be fine, except for a slight
delay when the actual bindtexture happens.

Adam
Post by Phil Endecott
Dear All,
I'm porting some iPhone OpenGL code that uses a separate thread for
OpenGL texture loading.  To do this, I create a new OpenGL context in
the same "sharegroup" as the main rendering context, and then the
textures loaded in one context are available to the other.
I've not seen any equivalent to this on Android.  Is this correct, or
am I missing something?
My code is C++, but as far as I can see the situation is the same for
Java OpenGL code.
Thanks for any suggestions.
Phil.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Phil Endecott
2010-11-26 12:20:31 UTC
Permalink
Post by Adam Hammer
I do bitmap loading in another thread, but I do glBindTexture in the
main graphics thread. Works well for me, I load bitmaps stored in zips
delivered by contentproviders into textures.
Yes; thanks; I'm actually doing something like that at the moment, and
it's not ideal. (I think you mean calling glTexImage2D(), not just
glBindTexture(), don't you?)
Post by Adam Hammer
I think opengl es does have mechanisms for sharing textures across GL
contexts
Yes. I've investigated some more and eglCreateContext() takes an
EGLContext to share from: "If share_context is not EGL_NO_CONTEXT,
then all shareable data ... will be shared by share_context ... and
the newly created context" (from the EGL spec, section 3.7.1.)

So the question is, can I call eglCreateContext() from my C++ code,
and/or is there a way to access this functionality from Java? Looking
through the Java docs I have found the EGLContext and
EGLContextFactory reference pages, but they are almost totally content-
free. Does Android really implement EGL?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Adam Hammer
2010-12-06 11:26:38 UTC
Permalink
Yes, it does.

http://code.google.com/p/earth-live-wallpaper/source/browse/trunk/+earth-live-wallpaper/SLWP/src/com/seb/SLWP/GLWallpaperService.java?r=37
Post by Phil Endecott
Post by Adam Hammer
I do bitmap loading in another thread, but I do glBindTexture in the
main graphics thread. Works well for me, I load bitmaps stored in zips
delivered by contentproviders into textures.
Yes; thanks; I'm actually doing something like that at the moment, and
it's not ideal.  (I think you mean calling glTexImage2D(), not just
glBindTexture(), don't you?)
Post by Adam Hammer
I think opengl es does have mechanisms for sharing textures across GL
contexts
Yes.  I've investigated some more and eglCreateContext() takes an
EGLContext to share from: "If share_context is not EGL_NO_CONTEXT,
then all shareable data ... will be shared by share_context ... and
the newly created context" (from the EGL spec, section 3.7.1.)
So the question is, can I call eglCreateContext() from my C++ code,
and/or is there a way to access this functionality from Java?  Looking
through the Java docs I have found the EGLContext and
EGLContextFactory reference pages, but they are almost totally content-
free.  Does Android really implement EGL?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Phil Endecott
2010-12-06 12:50:15 UTC
Permalink
Hi Adam,
Post by Adam Hammer
Yes, it does.
Post by Phil Endecott
Does Android really implement EGL?
Anyway, based on this:

http://groups.google.com/group/android-ndk/browse_thread/thread/6d60f6bcc5cec83a
(See Dianne Hackborn's reply dated Dec 1, 6:48 am)

I've decided not to try to create multiple contexts in different
threads for the time being, since they're unlikely to work reliably.


Thanks, Phil.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
Loading...