Home | History | Annotate | Download | only in graphics
      1 page.title=OpenGL
      2 parent.title=Graphics
      3 parent.link=index.html
      4 @jd:body
      5 
      6 <div id="qv-wrapper">
      7   <div id="qv">
      8     <h2>In this document</h2>
      9 
     10     <ol>
     11       <li><a href="#basics">The Basics</a>
     12         <ol>
     13            <li><a href="#packages">OpenGL packages</a></li>
     14         </ol>
     15       <li><a href="#manifest">Declaring OpenGL Requirements</a></li>
     16       </li>
     17       <li><a href="#coordinate-mapping">Mapping Coordinates for Drawn Objects</a>
     18         <ol>
     19           <li><a href="#proj-es1">Projection and camera in ES 1.0</a></li>
     20           <li><a href="#proj-es1">Projection and camera in ES 2.0</a></li>
     21         </ol>
     22       </li>
     23       <li><a href="#compatibility">OpenGL Versions and Device Compatibility</a>
     24         <ol>
     25           <li><a href="#textures">Texture compression support</a></li>
     26           <li><a href="#gl-extension-query">Determining OpenGL Extensions</a></li>
     27         </ol>
     28       </li>
     29       <li><a href="#choosing-version">Choosing an OpenGL API Version</a></li>
     30     </ol>
     31     <h2>Key classes</h2>
     32     <ol>
     33       <li>{@link android.opengl.GLSurfaceView}</li>
     34       <li>{@link android.opengl.GLSurfaceView.Renderer}</li>
     35     </ol>
     36     <h2>Related tutorials</h2>
     37     <ol>
     38       <li><a href="{@docRoot}resources/tutorials/opengl/opengl-es10.html">OpenGL ES 1.0</a></li>
     39       <li><a href="{@docRoot}resources/tutorials/opengl/opengl-es20.html">OpenGL ES 2.0</a></li>
     40     </ol>
     41     <h2>Related samples</h2>
     42     <ol>
     43       <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/GLSurfaceViewActivity.html">GLSurfaceViewActivity</a></li>
     44       <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/GLES20Activity.html">GLES20Activity</a></li>
     45       <li><a href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchRotateActivity.html">TouchRotateActivity</a></li>
     46       <li><a
     47 href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/CompressedTextureActivity.html">Compressed Textures</a></li>
     48     </ol>
     49     <h2>See also</h2>
     50     <ol>
     51       <li><a href="{@docRoot}resources/articles/glsurfaceview.html">Introducing
     52 GLSurfaceView</a></li>
     53       <li><a href="http://www.khronos.org/opengles/">OpenGL ES</a></li>
     54       <li><a href="http://www.khronos.org/opengles/1_X/">OpenGL ES 1.x Specification</a></li>
     55       <li><a href="http://www.khronos.org/opengles/2_X/">OpenGL ES 2.x specification</a></li>
     56     </ol>
     57   </div>
     58 </div>
     59 
     60 <p>Android includes support for high performance 2D and 3D graphics with the Open Graphics Library
     61 (OpenGL), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a
     62 standard software interface for 3D graphics processing hardware. OpenGL ES is a flavor of the OpenGL
     63 specification intended for embedded devices. The OpenGL ES 1.0 and 1.1 API specifications have been
     64 supported since Android 1.0. Beginning with Android 2.2 (API Level 8), the framework supports the
     65 OpenGL ES 2.0 API specification.</p>
     66 
     67 <p class="note"><b>Note:</b> The specific API provided by the Android framework is similar to the
     68   J2ME JSR239 OpenGL ES  API, but is not identical. If you are familiar with J2ME JSR239
     69   specification, be alert for variations.</p>
     70 
     71 
     72 <h2 id="basics">The Basics</h2>
     73 
     74 <p>Android supports OpenGL both through its framework API and the Native Development
     75 Kit (NDK). This topic focuses on the Android framework interfaces. For more information about the
     76 NDK, see the <a href="{@docRoot}sdk/ndk/index.html">Android NDK</a>.
     77 
     78 <p>There are two foundational classes in the Android framework that let you create and manipulate
     79 graphics with the OpenGL ES API: {@link android.opengl.GLSurfaceView} and {@link
     80 android.opengl.GLSurfaceView.Renderer}. If your goal is to use OpenGL in your Android application,
     81 understanding how to implement these classes in an activity should be your first objective.
     82 </p>
     83 
     84 <dl>
     85   <dt><strong>{@link android.opengl.GLSurfaceView}</strong></dt>
     86   <dd>This class is a {@link android.view.View} where you can draw and manipulate objects using
     87     OpenGL API calls and is similar in function to a {@link android.view.SurfaceView}. You can use
     88     this class by creating an instance of {@link android.opengl.GLSurfaceView} and adding your
     89     {@link android.opengl.GLSurfaceView.Renderer Renderer} to it. However, if you want to capture
     90     touch screen events, you should extend the {@link android.opengl.GLSurfaceView} class to
     91     implement the touch listeners, as shown in OpenGL Tutorials for
     92     <a href="{@docRoot}resources/tutorials/opengl/opengl-es10.html#touch">ES 1.0</a>,
     93     <a href="{@docRoot}resources/tutorials/opengl/opengl-es20.html#touch">ES 2.0</a> and the <a
     94 href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchRotateActivity.html"
     95 >TouchRotateActivity</a> sample.</dd>
     96 
     97   <dt><strong>{@link android.opengl.GLSurfaceView.Renderer}</strong></dt>
     98   <dd>This interface defines the methods required for drawing graphics in an OpenGL {@link
     99     android.opengl.GLSurfaceView}. You must provide an implementation of this interface as a
    100     separate class and attach it to your {@link android.opengl.GLSurfaceView} instance using
    101     {@link android.opengl.GLSurfaceView#setRenderer(android.opengl.GLSurfaceView.Renderer)
    102     GLSurfaceView.setRenderer()}.
    103 
    104     <p>The {@link android.opengl.GLSurfaceView.Renderer} interface requires that you implement the
    105       following methods:</p>
    106     <ul>
    107       <li>
    108         {@link
    109     android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition.khronos.opengles.GL10,
    110     javax.microedition.khronos.egl.EGLConfig) onSurfaceCreated()}: The system calls this
    111     method once, when creating the {@link android.opengl.GLSurfaceView}. Use this method to perform
    112     actions that need to happen only once, such as setting OpenGL environment parameters or
    113     initializing OpenGL graphic objects.
    114       </li>
    115       <li>
    116         {@link
    117         android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10)
    118         onDrawFrame()}: The system calls this method on each redraw of the {@link
    119         android.opengl.GLSurfaceView}. Use this method as the primary execution point for
    120         drawing (and re-drawing) graphic objects.</li>
    121       <li>
    122         {@link
    123     android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition.khronos.opengles.GL10,
    124     int, int) onSurfaceChanged()}: The system calls this method when the {@link
    125     android.opengl.GLSurfaceView} geometry changes, including changes in size of the {@link
    126     android.opengl.GLSurfaceView} or orientation of the device screen. For example, the system calls
    127     this method when the device changes from portrait to landscape orientation. Use this method to
    128     respond to changes in the {@link android.opengl.GLSurfaceView} container.
    129       </li>
    130     </ul>
    131     </dd>
    132 </dl>
    133 
    134 <h3 id="packages">OpenGL packages</h3>
    135 <p>Once you have established a container view for OpenGL using {@link
    136 android.opengl.GLSurfaceView} and {@link android.opengl.GLSurfaceView.Renderer}, you can begin
    137 calling OpenGL APIs using the following classes:</p>
    138 
    139 <ul>
    140   <li>OpenGL ES 1.0/1.1 API Packages
    141     <ul>
    142         <li>{@link android.opengl} - This package provides a static interface to the OpenGL ES
    143 1.0/1.1 classes and better performance than the javax.microedition.khronos package interfaces.
    144           <ul>
    145             <li>{@link android.opengl.GLES10}</li>
    146             <li>{@link android.opengl.GLES10Ext}</li>
    147             <li>{@link android.opengl.GLES11}</li>
    148             <li>{@link android.opengl.GLES10Ext}</li>
    149           </ul>
    150         </li>
    151       <li>{@link javax.microedition.khronos.opengles} - This package provides the standard
    152 implementation of OpenGL ES 1.0/1.1.
    153           <ul>
    154             <li>{@link javax.microedition.khronos.opengles.GL10}</li>
    155             <li>{@link javax.microedition.khronos.opengles.GL10Ext}</li>
    156             <li>{@link javax.microedition.khronos.opengles.GL11}</li>
    157             <li>{@link javax.microedition.khronos.opengles.GL11Ext}</li>
    158             <li>{@link javax.microedition.khronos.opengles.GL11ExtensionPack}</li>
    159           </ul>
    160         </li>
    161       </ul>
    162   </li>
    163   <li>OpenGL ES 2.0 API Class
    164     <ul>
    165       <li>{@link android.opengl.GLES20 android.opengl.GLES20} - This package provides the
    166 interface to OpenGL ES 2.0 and is available starting with Android 2.2 (API Level 8).</li>
    167     </ul>
    168   </li>
    169 </ul>
    170 
    171 <p>If you'd like to start building an app with OpenGL right away, have a look at the tutorials for
    172 <a href="{@docRoot}resources/tutorials/opengl/opengl-es10.html">OpenGL ES 1.0</a> or
    173 <a href="{@docRoot}resources/tutorials/opengl/opengl-es20.html">OpenGL ES 2.0</a>!
    174 </p>
    175 
    176 <h2 id="manifest">Declaring OpenGL Requirements</h2>
    177 <p>If your application uses OpenGL features that are not available on all devices, you must include
    178 these requirements in your <a
    179 href="{@docRoot}guide/topics/manifest/manifest-intro.html">AndroidManifest.xml</a></code> file.
    180 Here are the most common OpenGL manifest declarations:</p>
    181 
    182 <ul>
    183   <li><strong>OpenGL ES version requirements</strong> - If your application only supports OpenGL ES
    184 2.0, you must declare that requirement by adding the following settings to your manifest as
    185 shown below.
    186 
    187 <pre>
    188     &lt;!-- Tell the system this app requires OpenGL ES 2.0. --&gt;
    189     &lt;uses-feature android:glEsVersion="0x00020000" android:required="true" /&gt;
    190 </pre>
    191 
    192   <p>Adding this declaration causes the Android Market to restrict your application from being
    193   installed on devices that do not support OpenGL ES 2.0.</p>
    194   </li>
    195   <li><strong>Texture compression requirements</strong> - If your application uses texture
    196 compression formats, you must declare the formats your application supports in your manifest file
    197 using <a href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html">{@code
    198 &lt;supports-gl-texture&gt;}</a>. For more information about available texture compression
    199 formats, see <a href="#textures">Texture compression support</a>.
    200 
    201 <p>Declaring texture compression requirements in your manifest hides your application from users
    202 with devices that do not support at least one of your declared compression types. For more
    203 information on how Android Market filtering works for texture compressions, see the <a
    204 href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html#market-texture-filtering">
    205 Android Market and texture compression filtering</a> section of the {@code
    206 &lt;supports-gl-texture&gt;} documentation.</p>
    207   </li>
    208 </ul>
    209 
    210 
    211 <h2 id="coordinate-mapping">Mapping Coordinates for Drawn Objects</h2>
    212 
    213 <p>One of the basic problems in displaying graphics on Android devices is that their screens can
    214 vary in size and shape. OpenGL assumes a square, uniform coordinate system and, by default, happily
    215 draws those coordinates onto your typically non-square screen as if it is perfectly square.</p>
    216 
    217 <img src="{@docRoot}images/opengl/coordinates.png">
    218 <p class="img-caption">
    219   <strong>Figure 1.</strong> Default OpenGL coordinate system (left) mapped to a typical Android
    220 device screen (right).
    221 </p>
    222 
    223 <p>The illustration above shows the uniform coordinate system assumed for an OpenGL frame on the
    224 left, and how these coordinates actually map to a typical device screen in landscape orientation
    225 on the right. To solve this problem, you can apply OpenGL projection modes and camera views to
    226 transform coordinates so your graphic objects have the correct proportions on any display.</p>
    227 
    228 <p>In order to apply projection and camera views, you create a projection matrix and a camera view
    229 matrix and apply them to the OpenGL rendering pipeline. The projection matrix recalculates the
    230 coordinates of your graphics so that they map correctly to Android device screens. The camera view
    231 matrix creates a transformation that renders objects from a specific eye position.</p>
    232 
    233 <h3 id="proj-es1">Projection and camera view in OpenGL ES 1.0</h3>
    234 <p>In the ES 1.0 API, you apply projection and camera view by creating each matrix and then
    235 adding them to the OpenGL environment.</p>
    236 
    237 <ol>
    238 <li><strong>Projection matrix</strong> - Create a projection matrix using the geometry of the
    239 device screen in order to recalculate object coordinates so they are drawn with correct proportions.
    240 The following example code demonstrates how to modify the {@link
    241 android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition.khronos.opengles.GL10,
    242 int, int) onSurfaceChanged()} method of a {@link android.opengl.GLSurfaceView.Renderer}
    243 implementation to create a projection matrix based on the screen's aspect ratio and apply it to the
    244 OpenGL rendering environment.
    245 
    246 <pre>
    247   public void onSurfaceChanged(GL10 gl, int width, int height) {
    248       gl.glViewport(0, 0, width, height);
    249 
    250       // make adjustments for screen ratio
    251       float ratio = (float) width / height;
    252       gl.glMatrixMode(GL10.GL_PROJECTION);        // set matrix to projection mode
    253       gl.glLoadIdentity();                        // reset the matrix to its default state
    254       gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);  // apply the projection matrix
    255   }
    256 </pre>
    257 </li>
    258 
    259 <li><strong>Camera transformation matrix</strong> - Once you have adjusted the coordinate system
    260 using a projection matrix, you must also apply a camera view. The following example code shows how
    261 to modify the {@link
    262 android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10)
    263 onDrawFrame()} method of a {@link android.opengl.GLSurfaceView.Renderer}
    264 implementation to apply a model view and use the
    265 {@link android.opengl.GLU#gluLookAt(javax.microedition.khronos.opengles.GL10, float, float, float,
    266 float, float, float, float, float, float) GLU.gluLookAt()} utility to create a viewing tranformation
    267 which simulates a camera position.
    268 
    269 <pre>
    270     public void onDrawFrame(GL10 gl) {
    271         ...
    272         // Set GL_MODELVIEW transformation mode
    273         gl.glMatrixMode(GL10.GL_MODELVIEW);
    274         gl.glLoadIdentity();                      // reset the matrix to its default state
    275 
    276         // When using GL_MODELVIEW, you must set the camera view
    277         GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    278         ...
    279     }
    280 </pre>
    281 </li>
    282 </ol>
    283 
    284 <p>For a complete example of how to apply projection and camera views with OpenGL ES 1.0, see the <a
    285 href="{@docRoot}resources/tutorials/opengl/opengl-es10.html#projection-and-views">OpenGL ES 1.0
    286 tutorial</a>.</p>
    287 
    288 
    289 <h3 id="proj-es2">Projection and camera view in OpenGL ES 2.0</h3>
    290 <p>In the ES 2.0 API, you apply projection and camera view by first adding a matrix member to
    291 the vertex shaders of your graphics objects. With this matrix member added, you can then
    292 generate and apply projection and camera viewing matrices to your objects.</p>
    293 
    294 <ol>
    295 <li><strong>Add matrix to vertex shaders</strong> - Create a variable for the view projection matrix
    296 and include it as a multiplier of the shader's position. In the following example vertex shader
    297 code, the included {@code uMVPMatrix} member allows you to apply projection and camera viewing
    298 matrices to the coordinates of objects that use this shader.
    299 
    300 <pre>
    301     private final String vertexShaderCode =
    302 
    303         // This matrix member variable provides a hook to manipulate
    304         // the coordinates of objects that use this vertex shader
    305         "uniform mat4 uMVPMatrix;   \n" +
    306 
    307         "attribute vec4 vPosition;  \n" +
    308         "void main(){               \n" +
    309 
    310         // the matrix must be included as part of gl_Position
    311         " gl_Position = uMVPMatrix * vPosition; \n" +
    312 
    313         "}  \n";
    314 </pre>
    315   <p class="note"><strong>Note:</strong> The example above defines a single transformation matrix
    316 member in the vertex shader into which you apply a combined projection matrix and camera view
    317 matrix. Depending on your application requirements, you may want to define separate projection
    318 matrix and camera viewing matrix members in your vertex shaders so you can change them
    319 independently.</p>
    320 </li>
    321 <li><strong>Access the shader matrix</strong> - After creating a hook in your vertex shaders to
    322 apply projection and camera view, you can then access that variable to apply projection and
    323 camera viewing matrices. The following code shows how to modify the {@link
    324 android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition.khronos.opengles.GL10,
    325 javax.microedition.khronos.egl.EGLConfig) onSurfaceCreated()} method of a {@link
    326 android.opengl.GLSurfaceView.Renderer} implementation to access the matrix
    327 variable defined in the vertex shader above.
    328 
    329 <pre>
    330     public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    331         ...
    332         muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    333         ...
    334     }
    335 </pre>
    336 </li>
    337 <li><strong>Create projection and camera viewing matrices</strong> - Generate the projection and
    338 viewing matrices to be applied the graphic objects. The following example code shows how to modify
    339 the {@link
    340 android.opengl.GLSurfaceView.Renderer#onSurfaceCreated(javax.microedition.khronos.opengles.GL10,
    341 javax.microedition.khronos.egl.EGLConfig) onSurfaceCreated()} and {@link
    342 android.opengl.GLSurfaceView.Renderer#onSurfaceChanged(javax.microedition.khronos.opengles.GL10,
    343 int, int) onSurfaceChanged()} methods of a {@link android.opengl.GLSurfaceView.Renderer}
    344 implementation to create camera view matrix and a projection matrix based on the screen aspect ratio
    345 of the device.
    346 
    347 <pre>
    348     public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    349         ...
    350         // Create a camera view matrix
    351         Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    352     }
    353 
    354     public void onSurfaceChanged(GL10 unused, int width, int height) {
    355         GLES20.glViewport(0, 0, width, height);
    356 
    357         float ratio = (float) width / height;
    358 
    359         // create a projection matrix from device screen geometry
    360         Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
    361     }
    362 </pre>
    363 </li>
    364 
    365 <li><strong>Apply projection and camera viewing matrices</strong> - To apply the projection and
    366 camera view transformations, multiply the matrices together and then set them into the vertex
    367 shader. The following example code shows how modify the {@link
    368 android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10)
    369 onDrawFrame()} method of a {@link android.opengl.GLSurfaceView.Renderer} implementation to combine
    370 the projection matrix and camera view created in the code above and then apply it to the graphic
    371 objects to be rendered by OpenGL.
    372 
    373 <pre>
    374     public void onDrawFrame(GL10 unused) {
    375         ...
    376         // Combine the projection and camera view matrices
    377         Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
    378 
    379         // Apply the combined projection and camera view transformations
    380         GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    381 
    382         // Draw objects
    383         ...
    384     }
    385 </pre>
    386 </li>
    387 </ol>
    388 <p>For a complete example of how to apply projection and camera view with OpenGL ES 2.0, see the <a
    389 href="{@docRoot}resources/tutorials/opengl/opengl-es20.html#projection-and-views">OpenGL ES 2.0
    390 tutorial</a>.</p>
    391 
    392 
    393 <h2 id="compatibility">OpenGL Versions and Device Compatibility</h2>
    394 
    395 <p>The OpenGL ES 1.0 and 1.1 API specifications have been supported since Android 1.0.
    396 Beginning with Android 2.2 (API Level 8), the framework supports the OpenGL ES 2.0 API
    397 specification. OpenGL ES 2.0 is supported by most Android devices and is recommended for new
    398 applications being developed with OpenGL. For information about the relative number of
    399 Android-powered devices that support a given version of OpenGL ES, see the <a
    400 href="{@docRoot}resources/dashboard/opengl.html">OpenGL ES Versions Dashboard</a>.</p>
    401 
    402 
    403 <h3 id="textures">Texture compression support</h3>
    404 <p>Texture compression can significantly increase the performance of your OpenGL application by
    405 reducing memory requirements and making more efficient use of memory bandwidth. The Android
    406 framework provides support for the ETC1 compression format as a standard feature, including a {@link
    407 android.opengl.ETC1Util} utility class and the {@code etc1tool} compression tool (located in the
    408 Android SDK at {@code &lt;sdk&gt;/tools/}). For an example of an Android application that uses
    409 texture compression, see the <a
    410 href="{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/graphics/CompressedTextureActivity.html"
    411 >CompressedTextureActivity</a> code sample.</p>
    412 
    413 <p>To check if the ETC1 format is supported on a device, call the {@link
    414 android.opengl.ETC1Util#isETC1Supported() ETC1Util.isETC1Supported()} method.</p>
    415 
    416 <p class="note"><b>Note:</b> The ETC1 texture compression format does not support textures with an
    417 alpha channel. If your application requires textures with an alpha channel, you should
    418 investigate other texture compression formats available on your target devices.</p>
    419 
    420 <p>Beyond the ETC1 format, Android devices have varied support for texture compression based on
    421 their GPU chipsets and OpenGL implementations. You should investigate texture compression support on
    422 the the devices you are are targeting to determine what compression types your application should
    423 support. In order to determine what texture formats are supported on a given device, you must <a
    424 href="#gl-extension-query">query the device</a> and review the <em>OpenGL extension names</em>,
    425 which identify what texture compression formats (and other OpenGL features) are supported by the
    426 device. Some commonly supported texture compression formats are as follows:</p>
    427 
    428 <ul>
    429   <li><strong>ATITC (ATC)</strong> - ATI texture compression (ATITC or ATC) is available on a
    430 wide variety of devices and supports fixed rate compression for RGB textures with and without
    431 an alpha channel. This format may be represented by several OpenGL extension names, for example:
    432     <ul>
    433       <li>{@code GL_AMD_compressed_ATC_texture}</li>
    434       <li>{@code GL_ATI_texture_compression_atitc}</li>
    435     </ul>
    436   </li>
    437   <li><strong>PVRTC</strong> - PowerVR texture compression (PVRTC) is available on a wide
    438 variety of devices and supports 2-bit and 4-bit per pixel textures with or without an alpha channel.
    439 This format is represented by the following OpenGL extension name:
    440     <ul>
    441       <li>{@code GL_IMG_texture_compression_pvrtc}</li>
    442     </ul>
    443   </li>
    444   <li><strong>S3TC (DXT<em>n</em>/DXTC)</strong> - S3 texture compression (S3TC) has several
    445 format variations (DXT1 to DXT5) and is less widely available. The format supports RGB textures with
    446 4-bit alpha or 8-bit alpha channels. This format may be represented by several OpenGL extension
    447 names, for example:
    448     <ul>
    449       <li>{@code GL_OES_texture_compression_S3TC}</li>
    450       <li>{@code GL_EXT_texture_compression_s3tc}</li>
    451       <li>{@code GL_EXT_texture_compression_dxt1}</li>
    452       <li>{@code GL_EXT_texture_compression_dxt3}</li>
    453       <li>{@code GL_EXT_texture_compression_dxt5}</li>
    454     </ul>
    455   </li>
    456   <li><strong>3DC</strong> - 3DC texture compression (3DC) is a less widely available format that
    457 supports RGB textures with an an alpha channel. This format is represented by the following OpenGL
    458 extension name:</li>
    459     <ul>
    460       <li>{@code GL_AMD_compressed_3DC_texture}</li>
    461     </ul>
    462 </ul>
    463 
    464 <p class="warning"><strong>Warning:</strong> These texture compression formats are <em>not
    465 supported</em> on all devices. Support for these formats can vary by manufacturer and device. For
    466 information on how to determine what texture compression formats are on a particular device, see
    467 the next section.
    468 </p>
    469 
    470 <p class="note"><strong>Note:</strong> Once you decide which texture compression formats your
    471 application will support, make sure you declare them in your manifest using <a
    472 href="{@docRoot}guide/topics/manifest/supports-gl-texture-element.html">&lt;supports-gl-texture&gt;
    473 </a>. Using this declaration enables filtering by external services such as Android Market, so that
    474 your app is installed only on devices that support the formats your app requires. For details, see
    475 <a
    476 href="{@docRoot}guide/topics/graphics/opengl.html#manifest">OpenGL manifest declarations</a>.</p>
    477 
    478 <h3 id="gl-extension-query">Determining OpenGL extensions</h3>
    479 <p>Implementations of OpenGL vary by Android device in terms of the extensions to the OpenGL ES API
    480 that are supported. These extensions include texture compressions, but typically also include other
    481 extensions to the OpenGL feature set.</p>
    482 
    483 <p>To determine what texture compression formats, and other OpenGL extensions, are supported on a
    484 particular device:</p>
    485 <ol>
    486   <li>Run the following code on your target devices to determine what texture compression
    487 formats are supported:
    488 <pre>
    489   String extensions = javax.microedition.khronos.opengles.GL10.glGetString(GL10.GL_EXTENSIONS);
    490 </pre>
    491   <p class="warning"><b>Warning:</b> The results of this call <em>vary by device!</em> You
    492 must run this call on several target devices to determine what compression types are commonly
    493 supported.</p>
    494   </li>
    495   <li>Review the output of this method to determine what OpenGL extensions are supported on the
    496 device.</li>
    497 </ol>
    498 
    499 
    500 <h2 id="choosing-version">Choosing an OpenGL API Version</h2>
    501 
    502 <p>OpenGL ES API version 1.0 (and the 1.1 extensions) and version 2.0 both provide high
    503 performance graphics interfaces for creating 3D games, visualizations and user interfaces. Graphics
    504 programming for the OpenGL ES 1.0/1.1 API versus ES 2.0 differs significantly, and so developers
    505 should carefully consider the following factors before starting development with either API:</p>
    506 
    507 <ul>
    508   <li><strong>Performance</strong> - In general, OpenGL ES 2.0 provides faster graphics performance
    509 than the ES 1.0/1.1 APIs. However, the performance difference can vary depending on the Android
    510 device your OpenGL application is running on, due to differences in the implementation of the OpenGL
    511 graphics pipeline.</li>
    512   <li><strong>Device Compatibility</strong> - Developers should consider the types of devices,
    513 Android versions and the OpenGL ES versions available to their customers. For more information
    514 on OpenGL compatibility across devices, see the <a href="#compatibility">OpenGL Versions and Device
    515 Compatibility</a> section.</li>
    516   <li><strong>Coding Convenience</strong> - The OpenGL ES 1.0/1.1 API provides a fixed function
    517 pipeline and convenience functions which are not available in the ES 2.0 API. Developers who are new
    518 to OpenGL may find coding for OpenGL ES 1.0/1.1 faster and more convenient.</li>
    519   <li><strong>Graphics Control</strong> - The OpenGL ES 2.0 API provides a higher degree
    520 of control by providing a fully programmable pipeline through the use of shaders. With more
    521 direct control of the graphics processing pipeline, developers can create effects that would be
    522 very difficult to generate using the 1.0/1.1 API.</li>
    523 </ul>
    524 
    525 <p>While performance, compatibility, convenience, control and other factors may influence your
    526 decision, you should pick an OpenGL API version based on what you think provides the best experience
    527 for your users.</p>
    528