102f4aeb0Sopenharmony_ci<?xml version="1.0" encoding="UTF-8"?>
202f4aeb0Sopenharmony_ci<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook MathML Module V1.1b1//EN"
302f4aeb0Sopenharmony_ci                            "http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd">
402f4aeb0Sopenharmony_ci<refentry xml:base="" id="eglIntro">
502f4aeb0Sopenharmony_ci    <refentryinfo>
602f4aeb0Sopenharmony_ci         <copyright>
702f4aeb0Sopenharmony_ci             <year>2003-2014</year>
802f4aeb0Sopenharmony_ci             <holder>The Khronos Group Inc.</holder>
902f4aeb0Sopenharmony_ci         </copyright>
1002f4aeb0Sopenharmony_ci    </refentryinfo>
1102f4aeb0Sopenharmony_ci    <refmeta>
1202f4aeb0Sopenharmony_ci        <refentrytitle>eglIntro</refentrytitle>
1302f4aeb0Sopenharmony_ci        <manvolnum>3G</manvolnum>
1402f4aeb0Sopenharmony_ci    </refmeta>
1502f4aeb0Sopenharmony_ci    <refnamediv>
1602f4aeb0Sopenharmony_ci        <refname>eglIntro</refname>
1702f4aeb0Sopenharmony_ci        <refpurpose>
1802f4aeb0Sopenharmony_ci            introduction to managing client API rendering through the
1902f4aeb0Sopenharmony_ci            <acronym>EGL</acronym> API.
2002f4aeb0Sopenharmony_ci        </refpurpose>
2102f4aeb0Sopenharmony_ci    </refnamediv>
2202f4aeb0Sopenharmony_ci    <refsect1 id="overview"><title>Overview</title>
2302f4aeb0Sopenharmony_ci        <para>
2402f4aeb0Sopenharmony_ci            The <firstterm>Khronos Native Platform Graphics
2502f4aeb0Sopenharmony_ci            Interface</firstterm> (EGL) provides a means for rendering
2602f4aeb0Sopenharmony_ci            using a <firstterm>client API</firstterm> such as OpenGL ES
2702f4aeb0Sopenharmony_ci            (a 3D renderer for embedded systems), OpenGL (a functional
2802f4aeb0Sopenharmony_ci            superset of OpenGL ES for desktop systems), and OpenVG (a 2D
2902f4aeb0Sopenharmony_ci            vector graphics renderer) together with a native window
3002f4aeb0Sopenharmony_ci            system, such as Microsoft Windows or the X Window System.
3102f4aeb0Sopenharmony_ci        </para>
3202f4aeb0Sopenharmony_ci        <para>
3302f4aeb0Sopenharmony_ci            Depending on its implementation EGL might be more or less
3402f4aeb0Sopenharmony_ci            tightly integrated into the native window system. Most EGL
3502f4aeb0Sopenharmony_ci            functions require an EGL display connection, which can be
3602f4aeb0Sopenharmony_ci            obtained by calling
3702f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglGetDisplay</refentrytitle></citerefentry>
3802f4aeb0Sopenharmony_ci            and passing in a native display handle or
3902f4aeb0Sopenharmony_ci            <constant>EGL_DEFAULT_DISPLAY</constant>. To initialize and
4002f4aeb0Sopenharmony_ci            query what EGL version is supported on the display
4102f4aeb0Sopenharmony_ci            connection, call
4202f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglInitialize</refentrytitle></citerefentry>.
4302f4aeb0Sopenharmony_ci        </para>
4402f4aeb0Sopenharmony_ci        <para>
4502f4aeb0Sopenharmony_ci            Native window systems supporting EGL make a subset of their
4602f4aeb0Sopenharmony_ci            visuals (which may also referred to as pixel formats, frame
4702f4aeb0Sopenharmony_ci            buffer configurations, or other similar terms) available for
4802f4aeb0Sopenharmony_ci            client API rendering. Windows and pixmaps created with these
4902f4aeb0Sopenharmony_ci            visuals may also be rendered into using the native window
5002f4aeb0Sopenharmony_ci            system API.
5102f4aeb0Sopenharmony_ci        </para>
5202f4aeb0Sopenharmony_ci        <para>
5302f4aeb0Sopenharmony_ci            An EGL <firstterm>surface</firstterm> extends a native
5402f4aeb0Sopenharmony_ci            window or pixmap with additional <firstterm>auxillary
5502f4aeb0Sopenharmony_ci            buffers</firstterm>. These buffers include a color buffer, a
5602f4aeb0Sopenharmony_ci            depth buffer, a stencil buffer, and an alpha mask buffer.
5702f4aeb0Sopenharmony_ci            Some or all of the buffers listed are included in each EGL
5802f4aeb0Sopenharmony_ci            frame buffer configuration.
5902f4aeb0Sopenharmony_ci        </para>
6002f4aeb0Sopenharmony_ci        <para>
6102f4aeb0Sopenharmony_ci            EGL supports rendering into three types of surfaces:
6202f4aeb0Sopenharmony_ci            windows, pixmaps and pixel buffers (pbuffers). EGL window
6302f4aeb0Sopenharmony_ci            and pixmap surfaces are associated with corresponding
6402f4aeb0Sopenharmony_ci            resources of the native window system. EGL pixel buffers are
6502f4aeb0Sopenharmony_ci            EGL only resources, and do not accept rendering through the
6602f4aeb0Sopenharmony_ci            native window system.
6702f4aeb0Sopenharmony_ci        </para>
6802f4aeb0Sopenharmony_ci        <para>
6902f4aeb0Sopenharmony_ci            To render using a client API into an EGL surface, you must
7002f4aeb0Sopenharmony_ci            determine the appropriate EGL frame buffer configuration,
7102f4aeb0Sopenharmony_ci            which supports the rendering features the application
7202f4aeb0Sopenharmony_ci            requires.
7302f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglChooseConfig</refentrytitle></citerefentry>
7402f4aeb0Sopenharmony_ci            returns an <type>EGLConfig</type> matching the required
7502f4aeb0Sopenharmony_ci            attributes, if any. A complete list of EGL frame buffer
7602f4aeb0Sopenharmony_ci            configurations can be obtained by calling
7702f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglGetConfigs</refentrytitle></citerefentry>.
7802f4aeb0Sopenharmony_ci            Attributes of a particular EGL frame buffer configuration
7902f4aeb0Sopenharmony_ci            can be queried by calling
8002f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglGetConfigAttrib</refentrytitle></citerefentry>.
8102f4aeb0Sopenharmony_ci        </para>
8202f4aeb0Sopenharmony_ci        <para>
8302f4aeb0Sopenharmony_ci            For EGL window and pixmap surfaces, a suitable native window
8402f4aeb0Sopenharmony_ci            or pixmap with a matching native visual must be created
8502f4aeb0Sopenharmony_ci            first. For a given EGL frame buffer configuration, the
8602f4aeb0Sopenharmony_ci            native visual type and ID can be retrieved with a call to
8702f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglGetConfigAttrib</refentrytitle></citerefentry>.
8802f4aeb0Sopenharmony_ci            For pixel buffers, no underlying native resource is
8902f4aeb0Sopenharmony_ci            required.
9002f4aeb0Sopenharmony_ci        </para>
9102f4aeb0Sopenharmony_ci        <para>
9202f4aeb0Sopenharmony_ci            To create an EGL window surface from a native window, call
9302f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreateWindowSurface</refentrytitle></citerefentry>.
9402f4aeb0Sopenharmony_ci            To create an EGL pixmap surface from a native pixmap, call
9502f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreatePixmapSurface</refentrytitle></citerefentry>.
9602f4aeb0Sopenharmony_ci            To create a pixel buffer (pbuffer) surface (which has no
9702f4aeb0Sopenharmony_ci            associated native buffer), call
9802f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreatePbufferSurface</refentrytitle></citerefentry>
9902f4aeb0Sopenharmony_ci            To create a pixel buffer (pbuffer) surface whose color
10002f4aeb0Sopenharmony_ci            buffer is provided by an OpenVG <type>VGImage</type>, call
10102f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreatePbufferFromClientBuffer</refentrytitle></citerefentry>.
10202f4aeb0Sopenharmony_ci            Use
10302f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglDestroySurface</refentrytitle></citerefentry>
10402f4aeb0Sopenharmony_ci            to release previously allocated resources.
10502f4aeb0Sopenharmony_ci        </para>
10602f4aeb0Sopenharmony_ci        <para>
10702f4aeb0Sopenharmony_ci            An EGL rendering context is required to bind client API
10802f4aeb0Sopenharmony_ci            rendering to an EGL surface. An EGL surface and an EGL
10902f4aeb0Sopenharmony_ci            rendering context must have compatible EGL frame buffer
11002f4aeb0Sopenharmony_ci            configurations. To create an EGL rendering context, call
11102f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreateContext</refentrytitle></citerefentry>.
11202f4aeb0Sopenharmony_ci            The type of client API context created (OpenGL ES, OpenVG,
11302f4aeb0Sopenharmony_ci            etc.) can be changed by first calling
11402f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglBindAPI</refentrytitle></citerefentry>.
11502f4aeb0Sopenharmony_ci        </para>
11602f4aeb0Sopenharmony_ci        <para>
11702f4aeb0Sopenharmony_ci            An EGL rendering context may be bound to one or two EGL
11802f4aeb0Sopenharmony_ci            surfaces by calling
11902f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglMakeCurrent</refentrytitle></citerefentry>.
12002f4aeb0Sopenharmony_ci            This context/surface(s) association specifies the
12102f4aeb0Sopenharmony_ci            <firstterm>current context</firstterm> and
12202f4aeb0Sopenharmony_ci            <firstterm>current surface</firstterm>, and is used by all
12302f4aeb0Sopenharmony_ci            client API rendering commands for the bound context until
12402f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglMakeCurrent</refentrytitle></citerefentry>
12502f4aeb0Sopenharmony_ci            is called with different arguments.
12602f4aeb0Sopenharmony_ci        </para>
12702f4aeb0Sopenharmony_ci        <para>
12802f4aeb0Sopenharmony_ci            Both native and client API commands may be used to operate
12902f4aeb0Sopenharmony_ci            on certain surfaces, however, the two command streams are
13002f4aeb0Sopenharmony_ci            not synchronized. Synchronization can be explicitly
13102f4aeb0Sopenharmony_ci            specified using by calling
13202f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglWaitCLient</refentrytitle></citerefentry>,
13302f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglWaitNative</refentrytitle></citerefentry>,
13402f4aeb0Sopenharmony_ci            and possibly by calling other native window system commands.
13502f4aeb0Sopenharmony_ci        </para>
13602f4aeb0Sopenharmony_ci    </refsect1>
13702f4aeb0Sopenharmony_ci    <refsect1 id="examples"><title>Examples</title>
13802f4aeb0Sopenharmony_ci        <para>
13902f4aeb0Sopenharmony_ci            Below is a minimal example of creating an RGBA-format window that
14002f4aeb0Sopenharmony_ci            allows rendering with OpenGL ES.
14102f4aeb0Sopenharmony_ci            The window is cleared to yellow when the program runs. For simplicity,
14202f4aeb0Sopenharmony_ci            the program does not check for any errors.
14302f4aeb0Sopenharmony_ci        </para>
14402f4aeb0Sopenharmony_ci<programlisting>
14502f4aeb0Sopenharmony_ci#include &lt;stdlib.h&gt;
14602f4aeb0Sopenharmony_ci#include &lt;unistd.h&gt;
14702f4aeb0Sopenharmony_ci#include &lt;EGL/egl.h&gt;
14802f4aeb0Sopenharmony_ci#include &lt;GLES/gl.h&gt;
14902f4aeb0Sopenharmony_citypedef ... NativeWindowType;
15002f4aeb0Sopenharmony_ciextern NativeWindowType createNativeWindow(void);
15102f4aeb0Sopenharmony_cistatic EGLint const attribute_list[] = {
15202f4aeb0Sopenharmony_ci        EGL_RED_SIZE, 1,
15302f4aeb0Sopenharmony_ci        EGL_GREEN_SIZE, 1,
15402f4aeb0Sopenharmony_ci        EGL_BLUE_SIZE, 1,
15502f4aeb0Sopenharmony_ci        EGL_NONE
15602f4aeb0Sopenharmony_ci};
15702f4aeb0Sopenharmony_ciint main(int argc, char ** argv)
15802f4aeb0Sopenharmony_ci{
15902f4aeb0Sopenharmony_ci        EGLDisplay display;
16002f4aeb0Sopenharmony_ci        EGLConfig config;
16102f4aeb0Sopenharmony_ci        EGLContext context;
16202f4aeb0Sopenharmony_ci        EGLSurface surface;
16302f4aeb0Sopenharmony_ci        NativeWindowType native_window;
16402f4aeb0Sopenharmony_ci        EGLint num_config;
16502f4aeb0Sopenharmony_ci
16602f4aeb0Sopenharmony_ci        /* get an EGL display connection */
16702f4aeb0Sopenharmony_ci        display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
16802f4aeb0Sopenharmony_ci
16902f4aeb0Sopenharmony_ci        /* initialize the EGL display connection */
17002f4aeb0Sopenharmony_ci        eglInitialize(display, NULL, NULL);
17102f4aeb0Sopenharmony_ci
17202f4aeb0Sopenharmony_ci        /* get an appropriate EGL frame buffer configuration */
17302f4aeb0Sopenharmony_ci        eglChooseConfig(display, attribute_list, &amp;config, 1, &amp;num_config);
17402f4aeb0Sopenharmony_ci
17502f4aeb0Sopenharmony_ci        /* create an EGL rendering context */
17602f4aeb0Sopenharmony_ci        context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
17702f4aeb0Sopenharmony_ci
17802f4aeb0Sopenharmony_ci        /* create a native window */
17902f4aeb0Sopenharmony_ci        native_window = createNativeWindow();
18002f4aeb0Sopenharmony_ci
18102f4aeb0Sopenharmony_ci        /* create an EGL window surface */
18202f4aeb0Sopenharmony_ci        surface = eglCreateWindowSurface(display, config, native_window, NULL);
18302f4aeb0Sopenharmony_ci
18402f4aeb0Sopenharmony_ci        /* connect the context to the surface */
18502f4aeb0Sopenharmony_ci        eglMakeCurrent(display, surface, surface, context);
18602f4aeb0Sopenharmony_ci
18702f4aeb0Sopenharmony_ci        /* clear the color buffer */
18802f4aeb0Sopenharmony_ci        glClearColor(1.0, 1.0, 0.0, 1.0);
18902f4aeb0Sopenharmony_ci        glClear(GL_COLOR_BUFFER_BIT);
19002f4aeb0Sopenharmony_ci        glFlush();
19102f4aeb0Sopenharmony_ci
19202f4aeb0Sopenharmony_ci        eglSwapBuffers(display, surface);
19302f4aeb0Sopenharmony_ci
19402f4aeb0Sopenharmony_ci        sleep(10);
19502f4aeb0Sopenharmony_ci        return EXIT_SUCCESS;
19602f4aeb0Sopenharmony_ci}
19702f4aeb0Sopenharmony_ci</programlisting>
19802f4aeb0Sopenharmony_ci    </refsect1>
19902f4aeb0Sopenharmony_ci    <refsect1 id="usingeglextensions"><title>Using EGL Extensions</title>
20002f4aeb0Sopenharmony_ci        <para>
20102f4aeb0Sopenharmony_ci            All supported EGL extensions will have a corresponding definition in
20202f4aeb0Sopenharmony_ci            <filename>egl.h</filename> and a token in the extensions string returned
20302f4aeb0Sopenharmony_ci            by
20402f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglQueryString</refentrytitle></citerefentry>.
20502f4aeb0Sopenharmony_ci        </para>
20602f4aeb0Sopenharmony_ci    </refsect1>
20702f4aeb0Sopenharmony_ci    <refsect1 id="futureeglversions"><title>Future EGL Versions</title>
20802f4aeb0Sopenharmony_ci        <para>
20902f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglInitialize</refentrytitle></citerefentry>
21002f4aeb0Sopenharmony_ci            and
21102f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglQueryString</refentrytitle></citerefentry>
21202f4aeb0Sopenharmony_ci            can be used to determine at run-time what version of EGL is available.
21302f4aeb0Sopenharmony_ci            To check the EGL version at compile-time, test whether
21402f4aeb0Sopenharmony_ci            <constant>EGL_VERSION_<replaceable>x</replaceable>_<replaceable>y</replaceable></constant>
21502f4aeb0Sopenharmony_ci            is defined, where <replaceable>x</replaceable> and
21602f4aeb0Sopenharmony_ci            <replaceable>y</replaceable> are the major and minor version
21702f4aeb0Sopenharmony_ci            numbers.
21802f4aeb0Sopenharmony_ci        </para>
21902f4aeb0Sopenharmony_ci    </refsect1>
22002f4aeb0Sopenharmony_ci    <refsect1 id="files"><title>Files</title>
22102f4aeb0Sopenharmony_ci        <variablelist>
22202f4aeb0Sopenharmony_ci            <varlistentry>
22302f4aeb0Sopenharmony_ci                <term><filename>GLES/egl.h</filename></term>
22402f4aeb0Sopenharmony_ci                <listitem><para>
22502f4aeb0Sopenharmony_ci                    EGL header file
22602f4aeb0Sopenharmony_ci                </para></listitem>
22702f4aeb0Sopenharmony_ci            </varlistentry>
22802f4aeb0Sopenharmony_ci        </variablelist>
22902f4aeb0Sopenharmony_ci    </refsect1>
23002f4aeb0Sopenharmony_ci    <refsect1 id="seealso"><title>See Also</title>
23102f4aeb0Sopenharmony_ci        <para>
23202f4aeb0Sopenharmony_ci<!--
23302f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>glIntro</refentrytitle></citerefentry>,
23402f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>glFinish</refentrytitle></citerefentry>,
23502f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>glFlush</refentrytitle></citerefentry>,
23602f4aeb0Sopenharmony_ci-->
23702f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglBindAPI</refentrytitle></citerefentry>,
23802f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglChooseConfig</refentrytitle></citerefentry>,
23902f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreateContext</refentrytitle></citerefentry>,
24002f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreatePbufferFromClientBuffer</refentrytitle></citerefentry>,
24102f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreatePbufferSurface</refentrytitle></citerefentry>,
24202f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreatePixmapSurface</refentrytitle></citerefentry>,
24302f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglCreateWindowSurface</refentrytitle></citerefentry>,
24402f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglDestroyContext</refentrytitle></citerefentry>,
24502f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglDestroySurface</refentrytitle></citerefentry>,
24602f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglGetConfigs</refentrytitle></citerefentry>,
24702f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglGetDisplay</refentrytitle></citerefentry>,
24802f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglInitialize</refentrytitle></citerefentry>,
24902f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglMakeCurrent</refentrytitle></citerefentry>,
25002f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglQueryString</refentrytitle></citerefentry>,
25102f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglSwapBuffers</refentrytitle></citerefentry>,
25202f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglTerminate</refentrytitle></citerefentry>,
25302f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglWaitGL</refentrytitle></citerefentry>,
25402f4aeb0Sopenharmony_ci            <citerefentry><refentrytitle>eglWaitNative</refentrytitle></citerefentry>
25502f4aeb0Sopenharmony_ci        </para>
25602f4aeb0Sopenharmony_ci    </refsect1>
25702f4aeb0Sopenharmony_ci    <refsect3 id="Copyright"><title></title>
25802f4aeb0Sopenharmony_ci        <!-- Content included from copyright.inc.xsl -->
25902f4aeb0Sopenharmony_ci        <imageobject>
26002f4aeb0Sopenharmony_ci                <imagedata fileref="KhronosLogo.jpg" format="jpg" />
26102f4aeb0Sopenharmony_ci        </imageobject>
26202f4aeb0Sopenharmony_ci        <para />
26302f4aeb0Sopenharmony_ci    </refsect3>
26402f4aeb0Sopenharmony_ci</refentry>
265