2012-07-30 15 views

Respuesta

16

Sí, claro está.

En primer lugar es necesario crear un contexto en el de un hilo:

EGLint contextAttrs[] = { 
    EGL_CONTEXT_CLIENT_VERSION, 2, 
    EGL_NONE 
}; 

LOG_INFO("creating context"); 
if (!(m_Context = eglCreateContext(m_Display, m_Config, 0, contextAttrs))) 
{ 
    LOG_ERROR("eglCreateContext() returned error %d", eglGetError()); 
    return false; 
} 

Luego, en el otro hilo se crea un contexto compartido de esta manera:

EGLint contextAttrs[] = 
    { 
     EGL_CONTEXT_CLIENT_VERSION, 2, 
     EGL_NONE 
    }; 

    if (m_Context == 0) 
    { 
     LOG_ERROR("m_Context wasn't initialized for some reason"); 
    } 

    // create a shared context for this thread 
    m_LocalThreadContext = eglCreateContext(m_Display, m_Config, m_Context, contextAttrs); 

Usted, por supuesto, tiene que tener algunos mutex/semáforos para sincronizar cualquier actualización que quieras hacer con GLES. Por ejemplo, usted tiene que hacer un

eglMakeCurrent(m_Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); 

dentro del hilo antes de que el otro hilo puede llamar

if (!eglMakeCurrent(m_Display, m_Surface, m_Surface, m_Context)) 
{ 
    LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError()); 
} 

continuación, puede crear texturas, shaders de carga, etc., ya sea hilo

+0

Hola, sufro de la sincronizacion de 2 hilos opengl Además de makeCurrent, ¿de qué otros debería ocuparme? ¿Hay algunos artículos que introducen este punto? – dragonfly

+0

Para obtener una muestra completa, puede consultar este código fuente: https://github.com/klhurley/EffectsManager/blob/master/src/Android/Renderer.cpp –

Cuestiones relacionadas