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