• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook MathML Module V1.1b1//EN"
3                            "http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd">
4<refentry xml:base="" id="eglIntro">
5    <refentryinfo>
6         <copyright>
7             <year>2003-2014</year>
8             <holder>The Khronos Group Inc.</holder>
9         </copyright>
10    </refentryinfo>
11    <refmeta>
12        <refentrytitle>eglIntro</refentrytitle>
13        <manvolnum>3G</manvolnum>
14    </refmeta>
15    <refnamediv>
16        <refname>eglIntro</refname>
17        <refpurpose>
18            introduction to managing client API rendering through the
19            <acronym>EGL</acronym> API.
20        </refpurpose>
21    </refnamediv>
22    <refsect1 id="overview"><title>Overview</title>
23        <para>
24            The <firstterm>Khronos Native Platform Graphics
25            Interface</firstterm> (EGL) provides a means for rendering
26            using a <firstterm>client API</firstterm> such as OpenGL ES
27            (a 3D renderer for embedded systems), OpenGL (a functional
28            superset of OpenGL ES for desktop systems), and OpenVG (a 2D
29            vector graphics renderer) together with a native window
30            system, such as Microsoft Windows or the X Window System.
31        </para>
32        <para>
33            Depending on its implementation EGL might be more or less
34            tightly integrated into the native window system. Most EGL
35            functions require an EGL display connection, which can be
36            obtained by calling
37            <citerefentry><refentrytitle>eglGetDisplay</refentrytitle></citerefentry>
38            and passing in a native display handle or
39            <constant>EGL_DEFAULT_DISPLAY</constant>. To initialize and
40            query what EGL version is supported on the display
41            connection, call
42            <citerefentry><refentrytitle>eglInitialize</refentrytitle></citerefentry>.
43        </para>
44        <para>
45            Native window systems supporting EGL make a subset of their
46            visuals (which may also referred to as pixel formats, frame
47            buffer configurations, or other similar terms) available for
48            client API rendering. Windows and pixmaps created with these
49            visuals may also be rendered into using the native window
50            system API.
51        </para>
52        <para>
53            An EGL <firstterm>surface</firstterm> extends a native
54            window or pixmap with additional <firstterm>auxillary
55            buffers</firstterm>. These buffers include a color buffer, a
56            depth buffer, a stencil buffer, and an alpha mask buffer.
57            Some or all of the buffers listed are included in each EGL
58            frame buffer configuration.
59        </para>
60        <para>
61            EGL supports rendering into three types of surfaces:
62            windows, pixmaps and pixel buffers (pbuffers). EGL window
63            and pixmap surfaces are associated with corresponding
64            resources of the native window system. EGL pixel buffers are
65            EGL only resources, and do not accept rendering through the
66            native window system.
67        </para>
68        <para>
69            To render using a client API into an EGL surface, you must
70            determine the appropriate EGL frame buffer configuration,
71            which supports the rendering features the application
72            requires.
73            <citerefentry><refentrytitle>eglChooseConfig</refentrytitle></citerefentry>
74            returns an <type>EGLConfig</type> matching the required
75            attributes, if any. A complete list of EGL frame buffer
76            configurations can be obtained by calling
77            <citerefentry><refentrytitle>eglGetConfigs</refentrytitle></citerefentry>.
78            Attributes of a particular EGL frame buffer configuration
79            can be queried by calling
80            <citerefentry><refentrytitle>eglGetConfigAttrib</refentrytitle></citerefentry>.
81        </para>
82        <para>
83            For EGL window and pixmap surfaces, a suitable native window
84            or pixmap with a matching native visual must be created
85            first. For a given EGL frame buffer configuration, the
86            native visual type and ID can be retrieved with a call to
87            <citerefentry><refentrytitle>eglGetConfigAttrib</refentrytitle></citerefentry>.
88            For pixel buffers, no underlying native resource is
89            required.
90        </para>
91        <para>
92            To create an EGL window surface from a native window, call
93            <citerefentry><refentrytitle>eglCreateWindowSurface</refentrytitle></citerefentry>.
94            To create an EGL pixmap surface from a native pixmap, call
95            <citerefentry><refentrytitle>eglCreatePixmapSurface</refentrytitle></citerefentry>.
96            To create a pixel buffer (pbuffer) surface (which has no
97            associated native buffer), call
98            <citerefentry><refentrytitle>eglCreatePbufferSurface</refentrytitle></citerefentry>
99            To create a pixel buffer (pbuffer) surface whose color
100            buffer is provided by an OpenVG <type>VGImage</type>, call
101            <citerefentry><refentrytitle>eglCreatePbufferFromClientBuffer</refentrytitle></citerefentry>.
102            Use
103            <citerefentry><refentrytitle>eglDestroySurface</refentrytitle></citerefentry>
104            to release previously allocated resources.
105        </para>
106        <para>
107            An EGL rendering context is required to bind client API
108            rendering to an EGL surface. An EGL surface and an EGL
109            rendering context must have compatible EGL frame buffer
110            configurations. To create an EGL rendering context, call
111            <citerefentry><refentrytitle>eglCreateContext</refentrytitle></citerefentry>.
112            The type of client API context created (OpenGL ES, OpenVG,
113            etc.) can be changed by first calling
114            <citerefentry><refentrytitle>eglBindAPI</refentrytitle></citerefentry>.
115        </para>
116        <para>
117            An EGL rendering context may be bound to one or two EGL
118            surfaces by calling
119            <citerefentry><refentrytitle>eglMakeCurrent</refentrytitle></citerefentry>.
120            This context/surface(s) association specifies the
121            <firstterm>current context</firstterm> and
122            <firstterm>current surface</firstterm>, and is used by all
123            client API rendering commands for the bound context until
124            <citerefentry><refentrytitle>eglMakeCurrent</refentrytitle></citerefentry>
125            is called with different arguments.
126        </para>
127        <para>
128            Both native and client API commands may be used to operate
129            on certain surfaces, however, the two command streams are
130            not synchronized. Synchronization can be explicitly
131            specified using by calling
132            <citerefentry><refentrytitle>eglWaitCLient</refentrytitle></citerefentry>,
133            <citerefentry><refentrytitle>eglWaitNative</refentrytitle></citerefentry>,
134            and possibly by calling other native window system commands.
135        </para>
136    </refsect1>
137    <refsect1 id="examples"><title>Examples</title>
138        <para>
139            Below is a minimal example of creating an RGBA-format window that
140            allows rendering with OpenGL ES.
141            The window is cleared to yellow when the program runs. For simplicity,
142            the program does not check for any errors.
143        </para>
144<programlisting>
145#include &lt;stdlib.h&gt;
146#include &lt;unistd.h&gt;
147#include &lt;EGL/egl.h&gt;
148#include &lt;GLES/gl.h&gt;
149typedef ... NativeWindowType;
150extern NativeWindowType createNativeWindow(void);
151static EGLint const attribute_list[] = {
152        EGL_RED_SIZE, 1,
153        EGL_GREEN_SIZE, 1,
154        EGL_BLUE_SIZE, 1,
155        EGL_NONE
156};
157int main(int argc, char ** argv)
158{
159        EGLDisplay display;
160        EGLConfig config;
161        EGLContext context;
162        EGLSurface surface;
163        NativeWindowType native_window;
164        EGLint num_config;
165
166        /* get an EGL display connection */
167        display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
168
169        /* initialize the EGL display connection */
170        eglInitialize(display, NULL, NULL);
171
172        /* get an appropriate EGL frame buffer configuration */
173        eglChooseConfig(display, attribute_list, &amp;config, 1, &amp;num_config);
174
175        /* create an EGL rendering context */
176        context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
177
178        /* create a native window */
179        native_window = createNativeWindow();
180
181        /* create an EGL window surface */
182        surface = eglCreateWindowSurface(display, config, native_window, NULL);
183
184        /* connect the context to the surface */
185        eglMakeCurrent(display, surface, surface, context);
186
187        /* clear the color buffer */
188        glClearColor(1.0, 1.0, 0.0, 1.0);
189        glClear(GL_COLOR_BUFFER_BIT);
190        glFlush();
191
192        eglSwapBuffers(display, surface);
193
194        sleep(10);
195        return EXIT_SUCCESS;
196}
197</programlisting>
198    </refsect1>
199    <refsect1 id="usingeglextensions"><title>Using EGL Extensions</title>
200        <para>
201            All supported EGL extensions will have a corresponding definition in
202            <filename>egl.h</filename> and a token in the extensions string returned
203            by
204            <citerefentry><refentrytitle>eglQueryString</refentrytitle></citerefentry>.
205        </para>
206    </refsect1>
207    <refsect1 id="futureeglversions"><title>Future EGL Versions</title>
208        <para>
209            <citerefentry><refentrytitle>eglInitialize</refentrytitle></citerefentry>
210            and
211            <citerefentry><refentrytitle>eglQueryString</refentrytitle></citerefentry>
212            can be used to determine at run-time what version of EGL is available.
213            To check the EGL version at compile-time, test whether
214            <constant>EGL_VERSION_<replaceable>x</replaceable>_<replaceable>y</replaceable></constant>
215            is defined, where <replaceable>x</replaceable> and
216            <replaceable>y</replaceable> are the major and minor version
217            numbers.
218        </para>
219    </refsect1>
220    <refsect1 id="files"><title>Files</title>
221        <variablelist>
222            <varlistentry>
223                <term><filename>GLES/egl.h</filename></term>
224                <listitem><para>
225                    EGL header file
226                </para></listitem>
227            </varlistentry>
228        </variablelist>
229    </refsect1>
230    <refsect1 id="seealso"><title>See Also</title>
231        <para>
232<!--
233            <citerefentry><refentrytitle>glIntro</refentrytitle></citerefentry>,
234            <citerefentry><refentrytitle>glFinish</refentrytitle></citerefentry>,
235            <citerefentry><refentrytitle>glFlush</refentrytitle></citerefentry>,
236-->
237            <citerefentry><refentrytitle>eglBindAPI</refentrytitle></citerefentry>,
238            <citerefentry><refentrytitle>eglChooseConfig</refentrytitle></citerefentry>,
239            <citerefentry><refentrytitle>eglCreateContext</refentrytitle></citerefentry>,
240            <citerefentry><refentrytitle>eglCreatePbufferFromClientBuffer</refentrytitle></citerefentry>,
241            <citerefentry><refentrytitle>eglCreatePbufferSurface</refentrytitle></citerefentry>,
242            <citerefentry><refentrytitle>eglCreatePixmapSurface</refentrytitle></citerefentry>,
243            <citerefentry><refentrytitle>eglCreateWindowSurface</refentrytitle></citerefentry>,
244            <citerefentry><refentrytitle>eglDestroyContext</refentrytitle></citerefentry>,
245            <citerefentry><refentrytitle>eglDestroySurface</refentrytitle></citerefentry>,
246            <citerefentry><refentrytitle>eglGetConfigs</refentrytitle></citerefentry>,
247            <citerefentry><refentrytitle>eglGetDisplay</refentrytitle></citerefentry>,
248            <citerefentry><refentrytitle>eglInitialize</refentrytitle></citerefentry>,
249            <citerefentry><refentrytitle>eglMakeCurrent</refentrytitle></citerefentry>,
250            <citerefentry><refentrytitle>eglQueryString</refentrytitle></citerefentry>,
251            <citerefentry><refentrytitle>eglSwapBuffers</refentrytitle></citerefentry>,
252            <citerefentry><refentrytitle>eglTerminate</refentrytitle></citerefentry>,
253            <citerefentry><refentrytitle>eglWaitGL</refentrytitle></citerefentry>,
254            <citerefentry><refentrytitle>eglWaitNative</refentrytitle></citerefentry>
255        </para>
256    </refsect1>
257    <refsect3 id="Copyright"><title></title>
258        <!-- Content included from copyright.inc.xsl -->
259        <imageobject>
260                <imagedata fileref="KhronosLogo.jpg" format="jpg" />
261        </imageobject>
262        <para />
263    </refsect3>
264</refentry>
265