[NDK] OpenGL shared context

Problems with Canvas, OpenGL, etc...

[NDK] OpenGL shared context

Postby Spidyy » Sat Jan 12, 2013 9:24 pm

Hey there,

I'm trying to load gl resources like textures, shaders and mesh on a different thread than the main one (where I do my rendering stuff)

For this, I tried to create use shared context from the EGL lib, but I get an error even if all seems to be working...

I proceed like this :

Syntax: [ Download ] [ Hide ]
Using cpp Syntax Highlighting
  1. EGLConfig m_config; // configuration properly choosed and set
  2. EGLSurface m_surface; // surface properly created
  3. EGLDisplay m_display; // main display
  4.  
  5. // Context attributes
  6. static const EGLint contextAttribList[] = {
  7.                 EGL_CONTEXT_CLIENT_VERSION, 2,
  8.                 EGL_NONE
  9. };
  10.  
  11. EGLContext sharedContext; // The shared context that will never be made current
  12. EGLContext mainContext; // The context of the main thread
  13.  
  14. sharedContext = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, contextAttribList);
  15.  
  16. mainContext = eglCreateContext(m_display, m_config, sharedContext, contextAttribList);
  17. eglMakeCurrent(m_display, m_surface, m_surface, mainContext);
Parsed in 0.006 seconds, using GeSHi 1.0.8.4


Then, later, I create my another context from the other thread, using the same config, display and surface:

Syntax: [ Download ] [ Hide ]
Using cpp Syntax Highlighting
  1. EGLContext otherContext = eglCreateContext(m_display, m_config, sharedContext, contextAttribList);
  2. eglMakeCurrent(m_display, m_surface, m_surface, otherContext); //!\ Generate EGL_BAD_ACCESS error
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


I got an EGL_BAD_ACCESS, but I never made the otherContext current to any existing thread.

I'm using a Galaxy Tab 2.0 7" to do my tests, does anyone encountered the same issue?
Spidyy
Freshman
Freshman
 
Posts: 2
Joined: Sat Jan 12, 2013 9:11 pm

Top

Re: [NDK] OpenGL shared context

Postby Spidyy » Mon Jan 14, 2013 9:41 pm

I dropped the idea to use shared context. It seems each device builder add their own implementation of the shared context, sometimes don't implements them at all. So I'll do all my openGL stuff in the main thread.
Spidyy
Freshman
Freshman
 
Posts: 2
Joined: Sat Jan 12, 2013 9:11 pm

Re: [NDK] OpenGL shared context

Postby jonbonazza » Tue Feb 12, 2013 5:30 pm

What I do is use a Java GLSurfaceview to manage the threading and GL Context, then in each GLSurfaceview callback, I make native calls to my C code, which performs the actual OpenGL calls. This allows me to offload the rendering to another thread.
jonbonazza
Master Developer
Master Developer
 
Posts: 665
Joined: Thu Jul 15, 2010 2:58 pm
Location: WV USA

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 5 guests