当在同一个线程中渲染两个不同的表面时,我需要每次调用eglMakeCurrent
以将当前曲面解除绑定到线程并在渲染某个曲面之前将另一个曲面绑定到当前线程,而将表面解除绑定到线程的操作会消耗太多时间!
源码:
int DisplayPicture(...)
{
if (!eglMakeCurrent(m_glesDisplay ,m_glesSurface, m_glesSurface, m_glesContext))
{
return 0;
}
glUseProgram(programObject);
glActiveTexture( GL_TEXTURE0 );
glUniform1i(m_nUniformLocation[0],0);
glBindTexture( GL_TEXTURE_2D, 0);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, nWidth, nHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pData );
....
// Update attribute values.
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, 0, 0, texCoords);
glEnableVertexAttribArray(ATTRIB_TEXCOORD);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
eglSwapBuffers(m_glesDisplay, m_glesSurface);
glUseProgram(0);
return 0;
}
PS:
1.在OpenGLES中使用纹理时,eglMakeCurrent(display, NULL, NULL, NULL)
会耗费很长时间,为什么?
2.在某些设备中,eglMakeCurrent
会在其他设备正常时返回EGL_BAD_ALLOC
,为什么?