Name
eglMakeCurrent — attach an EGL rendering context to EGL surfaces
把EGL的渲染上下文贴到EGL的表面上
C Specification
EGLBoolean eglMakeCurrent( | EGLDisplay display, |
EGLSurface draw, | |
EGLSurface read, | |
EGLContext context) ; |
Parameters
-
Specifies the EGL display connection.
-
Specifies the EGL draw surface.
-
Specifies the EGL read surface.
-
Specifies the EGL rendering context to be attached to the surfaces.
display
draw
read
context
Description
eglMakeCurrent
binds context
to the current rendering thread and to the draw
and read
surfaces. draw
is used for all GL operations except for any pixel data read back (glReadPixels, glCopyTexImage2D, and glCopyTexSubImage2D), which is taken from the frame buffer values of read
.
If the calling thread has already a current rendering context, that context is flushed and marked as no longer current.
The first time that context
is made current, the viewport and scissor dimensions are set to the size of the draw
surface. The viewport and scissor are not modified whencontext
is subsequently made current.
To release the current context without assigning a new one, call eglMakeCurrent
with draw
and read
set to EGL_NO_SURFACE
and context
set to EGL_NO_CONTEXT
.
Use eglGetCurrentContext, eglGetCurrentDisplay, and eglGetCurrentSurface to query the current rendering context and associated display connection and surfaces.
首先 第一
在 eglMakeCurrent函数中,有下面这段检查,意思是说,要不然read draw buffer都为空,要不然就都不能为空。
eglapi.c
if (!draw_surf || !read_surf) {
/* surfaces may be NULL if surfaceless */
if (!disp->Extensions.KHR_surfaceless_context)
RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
if ((!draw_surf && draw != EGL_NO_SURFACE) ||
(!read_surf && read != EGL_NO_SURFACE))
RETURN_EGL_ERROR(disp, EGL_BAD_SURFACE, EGL_FALSE);
if (draw_surf || read_surf)
RETURN_EGL_ERROR(disp, EGL_BAD_MATCH, EGL_FALSE);
}
这里ctx表示着当前需要绑定的context,然后draw表示需要读的surface,那么可以看出surface也必须是已经绑定了本个线程的context
里面有一句话。假如draw或者read的surface已经在别的线程被绑定了,那么这里会产生一个错误,那就是EGL_BAD_ACESS
/*
* The spec says
*
* "If ctx is current to some other thread, or if either draw or read are
* bound to contexts in another thread, an EGL_BAD_ACCESS error is
* generated."and at most one context may be bound to a particular surface at a given
* time"
*/
if (draw && draw->CurrentContext && draw->CurrentContext != ctx) {
if (draw->CurrentContext->Binding != t ||
draw->CurrentContext->ClientAPI != ctx->ClientAPI)
return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
}