# eglMakeCurrent

attach an EGL rendering context to EGL surfaces

## C Specification

`EGLBoolean eglMakeCurrent(` | EGLDisplay display,
| EGLSurface draw,
| EGLSurface read,
| EGLContext context`)`

## Parameters

`display`

  Specifies the EGL display connection.

`draw`

  Specifies the EGL draw surface.

`read`

  Specifies the EGL read surface.

`context`

  Specifies the EGL rendering context to be attached to the surfaces.

## 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 when `context` 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.

## Errors

`EGL_FALSE` is returned on failure, `EGL_TRUE` otherwise. If `EGL_FALSE` is returned, the previously current rendering context and surfaces (if any) remain unchanged.

`EGL_BAD_DISPLAY` is generated if `display` is not an EGL display connection.

`EGL_NOT_INITIALIZED` is generated if `display` has not been initialized.

`EGL_BAD_SURFACE` is generated if `draw` or `read` is not an EGL surface.

`EGL_BAD_CONTEXT` is generated if `context` is not an EGL rendering context.

`EGL_BAD_MATCH` is generated if `draw` or `read` are not compatible with `context`, or if `context` is set to `EGL_NO_CONTEXT` and `draw` or `read` are not set to `EGL_NO_SURFACE`, or if `draw` or `read` are set to `EGL_NO_SURFACE` and `context` is not set to `EGL_NO_CONTEXT`.

`EGL_BAD_ACCESS` is generated if `context` is current to some other thread.

`EGL_BAD_NATIVE_PIXMAP` may be generated if a native pixmap underlying either `draw` or `read` is no longer valid.

`EGL_BAD_NATIVE_WINDOW` may be generated if a native window underlying either `draw` or `read` is no longer valid.

`EGL_BAD_CURRENT_SURFACE` is generated if the previous context has unflushed commands and the previous surface is no longer valid.

`EGL_BAD_ALLOC` may be generated if allocation of ancillary buffers for `draw` or `read` were delayed until `eglMakeCurrent` is called, and there are not enough resources to allocate them.

`EGL_CONTEXT_LOST` is generated if a power management event has occurred. The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering.

## See Also

glReadPixels, glCopyTexImage2D, glCopyTexSubImage2D, eglCreateContext, eglCreatePbufferSurface, eglCreatePixmapSurface, eglCreateWindowSurface, eglGetCurrentContext, eglGetCurrentDisplay, eglGetCurrentSurface, eglGetDisplay, eglInitialize

####

Copyright © 2003-2014 The Khronos Group Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.