【翻译】(73)OpenGL
see
http://developer.android.com/guide/topics/graphics/opengl.html
原文见
http://developer.android.com/guide/topics/graphics/opengl.html
(20130318补注:
uniform在gles 2.0的着色器语言中表示与坐标无关的输入量,区别于const(常量),attribute(与坐标有关的输入)和varying(顶点和片段着色器之间的变量)。
)
-------------------------------
OpenGL
OpenGL(注:这里指OpenGL|ES)
(注解的注解:由于OpenGL和OpenGL|ES的矩阵变换、开关设置、着色器、纹理等概念和用法很令我抓狂,故不敢擅自作出更精确和深入的注解。请尽量从实际出发,或者考虑在看此文前先看几本OpenGL入门教材。
下文中示例代码提及的OpenGL|ES的API列举如下,注解仅供参考:
* OpenGL:
* glViewport:
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
设定视口(左下角的x,左下角y,视口宽,视口高)
http://www.opengl.org/sdk/docs/man/xhtml/glViewport.xml
http://www.dreamingwish.com/dream-2012/glviewport.html
* glMatrixMode:
void glMatrixMode(GLenum mode);
设置当前矩阵是哪种矩阵模式(模式如GL_PROJECTION投影矩阵,GL_MODELVIEW模型矩阵,GL_TEXTURE纹理矩阵)
http://www.opengl.org/sdk/docs/man/xhtml/glMatrixMode.xml
* glLoadIdentity:
void glLoadIdentity(void);
用单元矩阵代替当前矩阵
http://www.opengl.org/sdk/docs/man/xhtml/glLoadIdentity.xml
* glFrustumf:
void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);
把当前矩阵乘于一个透视矩阵(左右垂直剪裁平面的坐标,上下水平剪裁平面的坐标,近远深度剪裁平面的坐标)
http://www.opengl.org/sdk/docs/man/xhtml/glFrustum.xml
* glUniformMatrix4fv:
void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
指定当前编程对象的统一变量(被修改的统一值的位置,要被修改的矩阵数量,是否转置矩阵作为加载进统一变量的值,count个值的数组的指针以用于更新被指定的统一变量)
http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
* glGetString:
const GLubyte* glGetString(GLenum name);
返回描述当前GL连接的字符串(符号常量如GL_EXTENSIONS返回被支持GL扩展的空格分隔列表)
http://www.opengl.org/sdk/docs/man/xhtml/glGetString.xml
* GLU:
* gluLookAt:
void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ);
定义一个视口变换(眼睛位置的三维坐标,参考点的三维坐标,up向量的方向)
http://pyopengl.sourceforge.net/documentation/manual/gluLookAt.3G.html
)
-------------------------------
In this document
本文目录
-------------------------------
* The Basics 基础
* OpenGL packages OpenGL包
* Declaring OpenGL Requirements 声明OpenGL要求
* Mapping Coordinates for Drawn Objects 为被绘画的对象映射坐标
* Projection and camera in ES 1.0 ES 1.0中的投影和照相机
* Projection and camera in ES 2.0 ES 2.0中的投影和照相机
* OpenGL Versions and Device Compatibility OpenGL版本和设备兼容性
* Texture compression support 纹理压缩支持
* Determining OpenGL Extensions 确定OpenGL扩展
* Choosing an OpenGL API Version 选择一个OpenGL API版本
Key classes
关键类
* GLSurfaceView
* GLSurfaceView.Renderer
Related tutorials
相关教程
* OpenGL ES 1.0 OpenGL|ES 1.0
* OpenGL ES 2.0 OpenGL|ES 2.0
Related samples
相关示例
* GLSurfaceViewActivity
* GLES20Activity
* TouchRotateActivity
* Compressed Textures 压缩纹理
See also
另见
* Introducing GLSurfaceView 介绍GLSurfaceView
* OpenGL ES OpenGL|ES
* OpenGL ES 1.x Specification OpenGL|ES 1.x规范
* OpenGL ES 2.x specification OpenGL|ES 2.x规范
-------------------------------
Android includes support for high performance 2D and 3D graphics with the Open Graphics Library (OpenGL), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware. OpenGL ES is a flavor of the OpenGL specification intended for embedded devices. The OpenGL ES 1.0 and 1.1 API specifications have been supported since Android 1.0. Beginning with Android 2.2 (API Level 8), the framework supports the OpenGL ES 2.0 API specification.
Android使用开放图形库(OpenGL)包含对高性能二维和三维图形的支持,明确来说,是OpengGL|ES的API。OpenGL是一套跨平台图形API,它指定一个标准软件接口给三维图形处理硬件。OpenGL|ES是一类风格的倾向于嵌入式设备的OpenGL规范。从Android 1.0开始OpenGL|ES 1.0和1.1的API规范已经被支持。从Android 2.2(API级别8)开始,框架支持OpenGL|ES 2.0的API规范。
-------------------------------
Note: The specific API provided by the Android framework is similar to the J2ME JSR239 OpenGL ES API, but is not identical. If you are familiar with J2ME JSR239 specification, be alert for variations.
注意:Android提供的特定API类似于J2ME JSR239 OpenGL ES API,但并不相同。如果你熟悉J2ME JSR239规范,请提防区别之处。(注:J2ME是Java 2 Platform, Micro Edition的缩写,是Java ME的前身。详细请见官网的介绍http://java.sun.com/java2/。JSR239是Java Specification Request 239的缩写,全称为Java Binding for the OpenGL(R) ES API 。详情请搜索Oracle官网的相关文档)
-------------------------------
-------------------------------
The Basics
基础
Android supports OpenGL both through its framework API and the Native Development Kit (NDK). This topic focuses on the Android framework interfaces. For more information about the NDK, see the Android NDK.
Android通过它的框架API和原生开发工具箱(NDK)来支持OpenGL。这个主题关注Android框架的接口。想获得关于NDK的更多信息,请参见Android NDK。
There are two foundational classes in the Android framework that let you create and manipulate graphics with the OpenGL ES API: GLSurfaceView and GLSurfaceView.Renderer. If your goal is to use OpenGL in your Android application, understanding how to implement these classes in an activity should be your first objective.
在Android框架中存在两个基础类,它们让你用OpenGL|ES的API创建和操纵图形:GLSurfaceView和GLSurfaceView.Renderer。如果你的目的是在你的Android应用程序中使用OpenGL,那么理解在一个活动中如何实现这些类是你首要的目标。
GLSurfaceView
GLSurfaceView类
This class is a View where you can draw and manipulate objects using OpenGL API calls and is similar in function to a SurfaceView. You can use this class by creating an instance of GLSurfaceView and adding your Renderer to it. However, if you want to capture touch screen events, you should extend the GLSurfaceView class to implement the touch listeners, as shown in OpenGL Tutorials for ES 1.0, ES 2.0 and the TouchRotateActivity sample.
这个类是一个View,在这里你可以使用OpenGL API调用来绘画和操纵对象,而且在函数(注:功能)方面类似于一个SurfaceView。你可以通过创建GLSurfaceView的一个实例来使用这个类并且添加你的Renderer到它。然而,如果你希望捕捉触屏事件,你应该扩展GLSurfaceView类以实现触碰监听器,如同ES 1.0、ES 2.0的OpenGL教程和TouchRotateActivity示例中所示。
GLSurfaceView.Renderer
GLSurfaceView.Renderer接口类
This interface defines the methods required for drawing graphics in an OpenGL GLSurfaceView. You must provide an implementation of this interface as a separate class and attach it to your GLSurfaceView instance using GLSurfaceView.setRenderer().
这个接口定义在一个OpenGL的GLSurfaceView中绘画图形所需的方法。你必须提供这个接口的一个实现作为一个单独的类并且使用GLSurfaceView.setRenderer()依附它到你的GLSurfaceView实例。
The GLSurfaceView.Renderer interface requires that you implement the following methods:
GLSurfaceView.Renderer接口要求你实现以下方法:
* onSurfaceCreated(): The system calls this method once, when creating the GLSurfaceView. Use this method to perform actions that need to happen only once, such as setting OpenGL environment parameters or initializing OpenGL graphic objects.
* onSurfaceCreated():系统调用这个方法一次,当创建GLSurfaceView时。使用此方法以执行需要只发生一次的动作,诸如设置OpenGL环境参数或初始化OpenGL图形对象。
* onDrawFrame(): The system calls this method on each redraw of the GLSurfaceView. Use this method as the primary execution point for drawing (and re-drawing) graphic objects.
* onDrawFrame():系统在每次GLSurfaceView重绘上调用此方法。使用此方法作为绘画(和重绘)图形对象的主要执行点。
* onSurfaceChanged(): The system calls this method when the GLSurfaceView geometry changes, including changes in size of the GLSurfaceView or orientation of the device screen. For example, the system calls this method when the device changes from portrait to landscape orientation. Use this method to respond to changes in the GLSurfaceView container.
* onSurfaceChanged():系统调用此方法,当GLSurfaceView的几何属性改变,包括GLSurfaceView大小或设备屏幕方向的改变。例如,系统在设备从竖屏改变为宽屏方向时调用此方法。使用此方法以响应GLSurfaceView容器中的改变。
OpenGL packages
OpenGL包
Once you have established a container view for OpenGL using GLSurfaceView and GLSurfaceView.Renderer, you can begin calling OpenGL APIs using the following classes:
一旦你已经使用GLSurfaceView和GLSurfaceView.Renderer建立了一个用于OpenGL的容器视图,你可以使用以下类开始调用OpenGL的API:
* OpenGL ES 1.0/1.1 API Packages
* OpenGL|ES 1.0/1.1 API包
* android.opengl - This package provides a static interface to the OpenGL ES 1.0/1.1 classes and better performance than the javax.microedition.khronos package interfaces.
* android.opengl——这个包提供对应OpenGL|ES 1.0/1.1类的一个静态接口以及比javax.microedition.khronos包的接口更好的性能。
* GLES10
* GLES10Ext
* GLES11
* GLES10Ext
* javax.microedition.khronos.opengles - This package provides the standard implementation of OpenGL ES 1.0/1.1.
* javax.microedition.khronos.opengles——这个包提供OpenGL ES 1.0/1.1的标准实现。
* GL10
* GL10Ext
* GL11
* GL11Ext
* GL11ExtensionPack
* OpenGL ES 2.0 API Class
* OpenGL|ES 2.0的API类
* android.opengl.GLES20 - This package provides the interface to OpenGL ES 2.0 and is available starting with Android 2.2 (API Level 8).
* android.opengl.GLES20——这个包提供对应OpenGL|ES 2.0的接口并且从Android 2.2(API级别8)开始可用。
If you'd like to start building an app with OpenGL right away, have a look at the tutorials for OpenGL ES 1.0 or OpenGL ES 2.0!
如果你喜欢立刻使用OpenGL开始构建一个应用,请看看这个OpenGL|ES 1.0或OpenGL|ES 2.0的教程!
-------------------------------
Declaring OpenGL Requirements
声明OpenGL要求
If your application uses OpenGL features that are not available on all devices, you must include these requirements in your AndroidManifest.xml file. Here are the most common OpenGL manifest declarations:
如果你的应用程序使用不再所有设备上可用的OpenGL特性,你必须在你的AndroidManifest.xml文件中包含这些要求。这里是最一般的OpenGL清单声明:
* OpenGL ES version requirements - If your application only supports OpenGL ES 2.0, you must declare that requirement by adding the following settings to your manifest as shown below.
* OpenGL|ES版本要求——如果你的应用程序只支持OpenGL|ES 2.0,那么你必须如下所示通过添加以下设置到你的清单来声明那个要求。
-------------------------------
<!-- Tell the system this app requires OpenGL ES 2.0. -->
<!-- 告诉系统这个应用需要OpenGL|ES 2.0. -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
-------------------------------
Adding this declaration causes Google Play to restrict your application from being installed on devices that do not support OpenGL ES 2.0.
添加这个声明导致Google Play(注:原Android Market)限制你的应用程序以不会被安装在不支持OpenGL|ES 2.0的设备上。
* Texture compression requirements - If your application uses texture compression formats, you must declare the formats your application supports in your manifest file using <supports-gl-texture>. For more information about available texture compression formats, see Texture compression support.
* 纹理压缩要求——如果你的应用程序使用纹理压缩格式,你必须在你的清单文件中使用<supports-gl-texture>声明你的应用程序支持的格式。想获得关于可用纹理压缩格式的更多信息,请参见纹理压缩支持。
Declaring texture compression requirements in your manifest hides your application from users with devices that do not support at least one of your declared compression types. For more information on how Google Play filtering works for texture compressions, see the Google Play and texture compression filtering section of the <supports-gl-texture> documentation.
在你的清单中声明纹理压缩要求会从不支持你所声明的压缩类型中至少一种的设备的用户中隐藏你的应用程序。想获得关于Google Play的过滤如何工作于纹理压缩的更多信息,请参见<supports-gl-texture>文档中Google Play和纹理压缩过滤章节。
-------------------------------
Mapping Coordinates for Drawn Objects
为被绘画的对象映射坐标
One of the basic problems in displaying graphics on Android devices is that their screens can vary in size and shape. OpenGL assumes a square, uniform coordinate system and, by default, happily draws those coordinates onto your typically non-square screen as if it is perfectly square.
显示图形在Android设备上的一个基本问题是,它们的屏幕可能在尺寸和形状上有区别。OpenGL假设一个正方形、统一的坐标系统,以及默认下适当地绘画那些坐标到你的典型情况下非正方形的屏幕上,好像它是完全地正方的那样。
(图略:
左图:左上(-1.0, 1.0),右上(1.0, 1.0),左下(-1.0, -1.0),右下(1.0, -1.0)
右图:被拉宽
)
Figure 1. Default OpenGL coordinate system (left) mapped to a typical Android device screen (right).
图片1. 默认OpenGL坐标系统(左)被映射到一个典型的Android设备屏幕(右)。
The illustration above shows the uniform coordinate system assumed for an OpenGL frame on the left, and how these coordinates actually map to a typical device screen in landscape orientation on the right. To solve this problem, you can apply OpenGL projection modes and camera views to transform coordinates so your graphic objects have the correct proportions on any display.
上面的图表在左边演示了为一个OpenGL帧而假定的统一坐标系统,以及在右边演示这些坐标实际上如何映射到一个宽屏方向的典型设备屏幕。为了解决此问题,你可以应用OpenGL投影模式以及照相机视口以变换坐标,使你的图形对象在任意显示屏上拥有正确的比例。
In order to apply projection and camera views, you create a projection matrix and a camera view matrix and apply them to the OpenGL rendering pipeline. The projection matrix recalculates the coordinates of your graphics so that they map correctly to Android device screens. The camera view matrix creates a transformation that renders objects from a specific eye position.
为了应用投影和照相机视口,你创建一个投影矩阵和一个照相机视口矩阵,并应用它们到OpenGL渲染管线。投影矩阵重新计算你的图形的坐标以致使它们正确地映射到Android设备屏幕。照相机视口矩阵创建一个变换,它从一个特定的眼睛位置来渲染对象。
Projection and camera view in OpenGL ES 1.0
在OpenGL|ES 1.0中的投影和照相机视口
In the ES 1.0 API, you apply projection and camera view by creating each matrix and then adding them to the OpenGL environment.
在ES 1.0的API中,你通过创建每个矩阵来应用投影和照相机视口,然后添加它们到OpenGL环境。
1. Projection matrix - Create a projection matrix using the geometry of the device screen in order to recalculate object coordinates so they are drawn with correct proportions. The following example code demonstrates how to modify the onSurfaceChanged() method of a GLSurfaceView.Renderer implementation to create a projection matrix based on the screen's aspect ratio and apply it to the OpenGL rendering environment.
1. 投影矩阵——使用设备屏幕的几何信息创建一个投影矩阵,以便重新计算对象坐标以致使它们用正确的比例来绘画。以下示例代码演示如何修改GLSurfaceView.Renderer实现的onSurfaceChanged()方法来基于屏幕的纵横比例创建一个投影矩阵并应用它到OpenGL渲染环境。
-------------------------------
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
// make adjustments for screen ratio
// 为屏幕比例作出调整
float ratio = (float) width / height;
gl.glMatrixMode(GL10.GL_PROJECTION); // set matrix to projection mode 设置矩阵为投影模式
gl.glLoadIdentity(); // reset the matrix to its default state 重置矩阵到它的默认值(注:Identity意思是单元矩阵)
gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); // apply the projection matrix 应用投影矩阵(注:Frustum意思是截锥)
}
-------------------------------
2. Camera transformation matrix - Once you have adjusted the coordinate system using a projection matrix, you must also apply a camera view. The following example code shows how to modify the onDrawFrame() method of a GLSurfaceView.Renderer implementation to apply a model view and use the GLU.gluLookAt() utility to create a viewing tranformation which simulates a camera position.
2. 照相机变换矩阵——一旦你已经使用一个投影矩阵调整了坐标系统,你还必须应用一个照相机视口。以下示例代码演示如何修改一个GLSurfaceView.Renderer实现的onDrawFrame()方法来应用一个模型视图并使用GLU.gluLookAt()工具(注:方法)来创建一个视口变换,它模拟一个照相机位置。
-------------------------------
public void onDrawFrame(GL10 gl) {
...
// Set GL_MODELVIEW transformation mode
// 设置GL_MODELVIEW变换模式
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity(); // reset the matrix to its default state 重置矩阵为它的默认状态
// When using GL_MODELVIEW, you must set the camera view
// 当使用GL_MODELVIEW时,你必须设置照相机视口
GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
...
}
-------------------------------
For a complete example of how to apply projection and camera views with OpenGL ES 1.0, see the OpenGL ES 1.0 tutorial.
想获得如何用OpenGL|ES 1.0来应用投影和照相机视口的一个完整示例,请参见OpenGL|ES 1.0教程。
Projection and camera view in OpenGL ES 2.0
在OpenGL|ES 2.0中的投影和照相机视口
In the ES 2.0 API, you apply projection and camera view by first adding a matrix member to the vertex shaders of your graphics objects. With this matrix member added, you can then generate and apply projection and camera viewing matrices to your objects.
在ES 2.0的API中,你通过首先添加一个矩阵成员到你的图形对象的顶点着色器来应用投影和照相机视口。使用被添加的矩阵成员,然后你可以生成和应用投影和照相机视口矩阵到你的对象。
1. Add matrix to vertex shaders - Create a variable for the view projection matrix and include it as a multiplier of the shader's position. In the following example vertex shader code, the included uMVPMatrix member allows you to apply projection and camera viewing matrices to the coordinates of objects that use this shader.
1. 添加矩阵到顶点着色器——为视口投影矩阵创建一个变量并且包含它作为着色器位置的一个乘法器。在以下示例顶点着色器代码中,被包含的uMVPMatrix成员允许你应用投影和照相机视口矩阵到使用此着色器的对象的坐标。
-------------------------------
private final String vertexShaderCode =
// This matrix member variable provides a hook to manipulate
// the coordinates of objects that use this vertex shader
// 此矩阵成员变量提供一个钩子以操纵使用此顶点着色器(注:是指用于计算顶点二维坐标、纹理坐标和深度缓冲的着色器)
// 对象的坐标
"uniform mat4 uMVPMatrix; \n" +
"attribute vec4 vPosition; \n" +
"void main(){ \n" +
// the matrix must be included as part of gl_Position
// 矩阵必须被包含作为gl_Position的一部分
" gl_Position = uMVPMatrix * vPosition; \n" +
"} \n";
-------------------------------
-------------------------------
Note: The example above defines a single transformation matrix member in the vertex shader into which you apply a combined projection matrix and camera view matrix. Depending on your application requirements, you may want to define separate projection matrix and camera viewing matrix members in your vertex shaders so you can change them independently.
注意:上面的示例在你把一个复杂投影矩阵和照相机视口矩阵应用进去的顶点着色器中定义一个单一变换矩阵成员。依赖于你的应用程序的需要,你可能希望在你的顶点着色器中定义单独的投影矩阵和照相机视口矩阵成员,使你可以独立地改变它们。
-------------------------------
2. Access the shader matrix - After creating a hook in your vertex shaders to apply projection and camera view, you can then access that variable to apply projection and camera viewing matrices. The following code shows how to modify the onSurfaceCreated() method of a GLSurfaceView.Renderer implementation to access the matrix variable defined in the vertex shader above.
2. 访问着色器矩阵——在你的顶点着色器中创建一个钩子以应用投影和照相机视口之后,然后你可以访问那个变量以应用投影和照相机视口矩阵。以下代码演示如何修改一个GLSurfaceView.Renderer实现的onSurfaceCreated()方法以访问定义在以上顶点着色器中的矩阵变量。
-------------------------------
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
...
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
...
}
-------------------------------
3. Create projection and camera viewing matrices - Generate the projection and viewing matrices to be applied the graphic objects. The following example code shows how to modify the onSurfaceCreated() and onSurfaceChanged() methods of a GLSurfaceView.Renderer implementation to create camera view matrix and a projection matrix based on the screen aspect ratio of the device.
3. 创建投影和照相机视口矩阵——生成要被应用到图形对象的投影和视口矩阵。以下示例代码演示如何修改一个GLSurfaceView.Renderer实现的onSurfaceCreated()和onSurfaceChanged()方法以基于设备的屏幕纵横比例来创建照相机视口矩阵和一个投影矩阵。
-------------------------------
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
...
// Create a camera view matrix
// 创建一个照相机视口矩阵
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
float ratio = (float) width / height;
// create a projection matrix from device screen geometry
// 从设备屏幕的几何信息中创建一个投影矩阵
Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
}
-------------------------------
4. Apply projection and camera viewing matrices - To apply the projection and camera view transformations, multiply the matrices together and then set them into the vertex shader. The following example code shows how modify the onDrawFrame() method of a GLSurfaceView.Renderer implementation to combine the projection matrix and camera view created in the code above and then apply it to the graphic objects to be rendered by OpenGL.
4. 应用投影和照相机视口矩阵——为了应用投影和照相机视口变换,把两个矩阵相乘,然后设置它们进顶点着色器。以下示例代码演示如何修改一个GLSurfaceView.Renderer实现的onDrawFrame()方法以组合在上面代码中创建的投影矩阵和照相机视口,然后应用它到要用OpenGL渲染的图形对象。
-------------------------------
public void onDrawFrame(GL10 unused) {
...
// Combine the projection and camera view matrices
// 组合投影和照相机视口矩阵
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
// Apply the combined projection and camera view transformations
// 用于被组合的投影和照相机视口转换
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
// Draw objects
// 绘画对象
...
}
-------------------------------
For a complete example of how to apply projection and camera view with OpenGL ES 2.0, see the OpenGL ES 2.0 tutorial.
想获得如何用OpenGL|ES 2.0来应用投影和照相机视口的一个完整示例,请参见OpenGL|ES 2.0教程。
-------------------------------
OpenGL Versions and Device Compatibility
OpenGL版本和设备兼容性
The OpenGL ES 1.0 and 1.1 API specifications have been supported since Android 1.0. Beginning with Android 2.2 (API Level 8), the framework supports the OpenGL ES 2.0 API specification. OpenGL ES 2.0 is supported by most Android devices and is recommended for new applications being developed with OpenGL. For information about the relative number of Android-powered devices that support a given version of OpenGL ES, see the OpenGL ES Versions Dashboard.
OpenGL|ES 1.0和1.1的API规范从Android 1.0开始已经被支持。从Android 2.2(API级别8)开始,框架支持OpenGL|ES 2.0的API规范。OpenGL|ES 2.0被大多数Android设备支持并且推荐正在用OpenGL开发的新应用程序使用。想获得关于支持一个给定版本的OpenGL|ES的基于Android设备的相对数量,请参见OpenGL|ES版本分布图。
Texture compression support
纹理压缩支持
Texture compression can significantly increase the performance of your OpenGL application by reducing memory requirements and making more efficient use of memory bandwidth. The Android framework provides support for the ETC1 compression format as a standard feature, including a ETC1Util utility class and the etc1tool compression tool (located in the Android SDK at <sdk>/tools/). For an example of an Android application that uses texture compression, see the CompressedTextureActivity code sample.
纹理压缩可以通过降低内存需要以及更高效地利用内存带宽来显著增加你的OpenGL应用程序的性能。Android框架提供对ETC1压缩格式的支持作为一种标准特性,包括一个ETC1Util工具类以及etc1tool压缩工具(位于Android SDK中的<sdk>/tools/目录)。想获得一个使用纹理压缩的Android应用程序示例,请参见CompressedTextureActivity代码示例。
To check if the ETC1 format is supported on a device, call the ETC1Util.isETC1Supported() method.
为了检查在一台设备上是否支持ETC1格式,请调用ETC1Util.isETC1Supported()方法。
-------------------------------
Note: The ETC1 texture compression format does not support textures with an alpha channel. If your application requires textures with an alpha channel, you should investigate other texture compression formats available on your target devices.
注意:ETC1纹理压缩格式不支持带alpha通道的纹理。如果你的应用程序需要带透明通道的纹理,你应该调查在你的目标设备上其他可用的纹理压缩格式。
-------------------------------
Beyond the ETC1 format, Android devices have varied support for texture compression based on their GPU chipsets and OpenGL implementations. You should investigate texture compression support on the the devices you are are targeting to determine what compression types your application should support. In order to determine what texture formats are supported on a given device, you must query the device and review the OpenGL extension names, which identify what texture compression formats (and other OpenGL features) are supported by the device. Some commonly supported texture compression formats are as follows:
在ETC1格式之上,Android设备有对纹理压缩的不同支持,基于它们的GPU芯片组和OpenGL实现。你应该调查在那些你正在(注:此处多了一个are)把目标定在的设备上的纹理压缩支持,以便决定你的应用程序应该支持什么压缩类型。为了确定在一台给定设备上支持什么纹理格式,你必须查询设备并且复审OpenGL扩展名,它标识着该设备支持什么纹理压缩格式(以及其它OpenGL特性)。一些通常被支持的纹理压缩格式如下:
* ATITC (ATC) - ATI texture compression (ATITC or ATC) is available on a wide variety of devices and supports fixed rate compression for RGB textures with and without an alpha channel. This format may be represented by several OpenGL extension names, for example:
* ATITC(ATC)——ATI纹理压缩(ATITC或ATC)在广泛类型的设备上可用并且支持对带与不带alpha通道的RGB纹理的固定比率压缩。此格式可以被几个OpenGL扩展名表示,例如:
* GL_AMD_compressed_ATC_texture
* GL_ATI_texture_compression_atitc
* PVRTC - PowerVR texture compression (PVRTC) is available on a wide variety of devices and supports 2-bit and 4-bit per pixel textures with or without an alpha channel. This format is represented by the following OpenGL extension name:
* PVRTC——PowerVR纹理压缩(PVRTC)在广泛类型的设备上可用并且支持带与不带alpha通道的2位和4位每像素的纹理。此格式被以下OpenGL扩展名表示:
* GL_IMG_texture_compression_pvrtc
* S3TC (DXTn/DXTC) - S3 texture compression (S3TC) has several format variations (DXT1 to DXT5) and is less widely available. The format supports RGB textures with 4-bit alpha or 8-bit alpha channels. This format may be represented by several OpenGL extension names, for example:
* S3TC(DXTn/DXTC)——S3纹理压缩(S3TC)有几个格式变种(DXT1至DXT5)并且较不广泛地可用。该格式支持带4位或8位alpha通道的RGB纹理。此格式可以被几个OpenGL扩展名表示,例如:
* GL_OES_texture_compression_S3TC
* GL_EXT_texture_compression_s3tc
* GL_EXT_texture_compression_dxt1
* GL_EXT_texture_compression_dxt3
* GL_EXT_texture_compression_dxt5
* 3DC - 3DC texture compression (3DC) is a less widely available format that supports RGB textures with an an alpha channel. This format is represented by the following OpenGL extension name:
* 3DC——3DC纹理压缩(3DC)是一种较不广泛可用的格式,它支持带一个(注:此处多了一个an)alpha通道的RGB纹理。此格式被以下OpenGL扩展名表示:
* GL_AMD_compressed_3DC_texture
-------------------------------
Warning: These texture compression formats are not supported on all devices. Support for these formats can vary by manufacturer and device. For information on how to determine what texture compression formats are on a particular device, see the next section.
警告:不是所有设备都支持这些纹理压缩格式。对这些格式的支持可能因厂商和设备而异。想获得关于如何确定在一台特定的设备上有哪些纹理压缩格式,请参见下一章节。
-------------------------------
-------------------------------
Note: Once you decide which texture compression formats your application will support, make sure you declare them in your manifest using <supports-gl-texture> . Using this declaration enables filtering by external services such as Google Play, so that your app is installed only on devices that support the formats your app requires. For details, see OpenGL manifest declarations.
注意:一旦你决定你的应用程序将支持哪些纹理压缩格式,请确保你使用<supports-gl-texture>声明它们在你的清单中。使用此声明使能外部服务诸如Google Play的过滤,以致使你的应用只被安装在支持你的应用必需格式的设备上。详细请参见OpenGL清单声明。
-------------------------------
Determining OpenGL extensions
确定OpenGL扩展
Implementations of OpenGL vary by Android device in terms of the extensions to the OpenGL ES API that are supported. These extensions include texture compressions, but typically also include other extensions to the OpenGL feature set.
OpenGL的实现因Android设备而异,根据被支持的OpenGL|ES API的扩展。这些扩展包括纹理压缩,但典型地还包括对OpenGL特性集的其他扩展。
To determine what texture compression formats, and other OpenGL extensions, are supported on a particular device:
为了确定什么纹理压缩格式,以及其它OpenGL扩展,被一台特定设备支持:
1. Run the following code on your target devices to determine what texture compression formats are supported:
1. 运行以下代码在你的目标设备上以确定什么纹理压缩格式被支持:
-------------------------------
String extensions = javax.microedition.khronos.opengles.GL10.glGetString(GL10.GL_EXTENSIONS);
-------------------------------
-------------------------------
Warning: The results of this call vary by device! You must run this call on several target devices to determine what compression types are commonly supported.
警告:此调用的结果因设备而不同!你必须运行此调用在几台目标设备上以确定哪些压缩类型被普遍地支持。
-------------------------------
2. Review the output of this method to determine what OpenGL extensions are supported on the device.
2. 重新审视此方法的输出以确定在该设备上支持哪些OpenGL扩展。
-------------------------------
Choosing an OpenGL API Version
选择一个OpenGL API版本
OpenGL ES API version 1.0 (and the 1.1 extensions) and version 2.0 both provide high performance graphics interfaces for creating 3D games, visualizations and user interfaces. Graphics programming for the OpenGL ES 1.0/1.1 API versus ES 2.0 differs significantly, and so developers should carefully consider the following factors before starting development with either API:
OpenGL|ES的API版本1.0(以及1.1扩展)和版本2.0都为创建三维游戏、可视化以及用户界面提供高性能图形接口。OpenGL|ES 1.0/1.1的API的图形编程对比ES 2.0是显著地不同的,因此开发者在开始用其中一套API开发之前应该小心考虑以下因素:
* Performance - In general, OpenGL ES 2.0 provides faster graphics performance than the ES 1.0/1.1 APIs. However, the performance difference can vary depending on the Android device your OpenGL application is running on, due to differences in the implementation of the OpenGL graphics pipeline.
* 性能——通常,OpenGL|ES 2.0提供比ES 1.0/1.1的API更快的图形性能。然而,性能的不同可能依赖于你的OpenGL应用程序正在运行在的Android设备而不同,那是因为OpenGL图形管线的实现的不同。
* Device Compatibility - Developers should consider the types of devices, Android versions and the OpenGL ES versions available to their customers. For more information on OpenGL compatibility across devices, see the OpenGL Versions and Device Compatibility section.
* 设备兼容性——开发者应该考虑设备的类型、Android版本以及OpenGL|ES版本对他们的客户的可用。想获得关于OpenGL跨设备的兼容性的更多信息,参见OpenGL把白嫩和设备兼容性章节。
* Coding Convenience - The OpenGL ES 1.0/1.1 API provides a fixed function pipeline and convenience functions which are not available in the ES 2.0 API. Developers who are new to OpenGL may find coding for OpenGL ES 1.0/1.1 faster and more convenient.
* 代码便利性——OpenGL|ES 1.0/1.1的API提供一个固定函数管线和一些便利函数,它们在ES 2.0的API中不可用。对OpenGL不熟悉的开发者可能发现为OpenGL ES 1.0/1.1编码会比较快并且更便利。
* Graphics Control - The OpenGL ES 2.0 API provides a higher degree of control by providing a fully programmable pipeline through the use of shaders. With more direct control of the graphics processing pipeline, developers can create effects that would be very difficult to generate using the 1.0/1.1 API.
* 图形控制——OpenGL|ES 2.0的API通过提供一个贯穿着色器使用的完全可编程管线,提供一个较高程度的控制。使用对图形处理管线的更直接控制,开发者可以创建出很难用1.0/1.1的API生成的效果。
While performance, compatibility, convenience, control and other factors may influence your decision, you should pick an OpenGL API version based on what you think provides the best experience for your users.
虽然性能、兼容性、便利性、控制以及其它因素可能影响你的决定,你仍然应该基于你认为对用户提供最佳体验的东西来选取一个OpenGL的API版本。
Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.
除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。
Android 4.0 r1 - 06 Mar 2012 7:44
-------------------------------
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)
(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:
* ソフトウェア技術ドキュメントを勝手に翻訳
http://www.techdoctranslator.com/android
* Ley's Blog
http://leybreeze.com/blog/
* 农民伯伯
http://www.cnblogs.com/over140/
* Android中文翻译组
http://androidbox.sinaapp.com/
)
相关推荐
OpenGL(Open Graphics Library)是一个跨语言、跨平台的应用程序编程接口(API...由于本书是翻译版本,特别需要注意的是,为了保证知识的准确性,翻译工作应由具备专业背景的译者进行,以减少翻译过程中的错误和遗漏。
作者于2010年8月开始接触OpenGL ES 2.0,并在短时间内将其翻译成中文,旨在帮助国内开发者更好地理解和使用OpenGL ES 2.0。 #### 三、OpenGL ES 2.0的关键特点 - **只定义Common Profile**:OpenGL ES 2.0仅定义了...
OpenGL 3.3教程翻译 OpenGL 3.3 Tutorial Translation ======== 项目简介 Introduction -------- 此项目致力于将Arnaud Masserann等所著在线课程《Tutorials for OpenGL 3.3 and later》翻译为简体中文版。原版英文...
OpenGL教程 OpenGL教程 OpenGL教程 OpenGL教程 OpenGL教程
OpenGL实例 OpenGL实例 OpenGL实例 OpenGL实例 OpenGL实例
OpenGL教材 OpenGL教材 OpenGL教材 OpenGL教材 OpenGL教材
opengl+qt实现鼠标选中模型opengl+qt实现鼠标选中模型opengl+qt实现鼠标选中模型opengl+qt实现鼠标选中模型opengl+qt实现鼠标选中模型opengl+qt实现鼠标选中模型opengl+qt实现鼠标选中模型opengl+qt实现鼠标选中模型...
NeHe OpenGL NeHe OpenGL NeHe OpenGL NeHe OpenGL
OpenGL实例源代码是一种珍贵的学习资源,它包含了多个与OpenGL编程相关的示例,涵盖了从基础到高级的各种技术。OpenGL是一个跨语言、跨平台的图形库,用于渲染2D、3D矢量图形,广泛应用于游戏开发、科学可视化以及...
在这个"【OPENGL】opengl房子设计1"项目中,开发者利用OpenGL技术创建了一个三维的房子模型,这涉及到了许多关键的OpenGL概念和技术。 首先,OpenGL是一个跨语言、跨平台的应用程序编程接口(API),它允许程序员在...
OpenGL是一种强大的图形编程接口,广泛应用于游戏开发、科学可视化、工程设计等领域。它允许程序员直接控制显卡硬件,实现高效且复杂的3D图形渲染。在"OpenGL学习资源.zip"这个压缩包中,很可能是包含了帮助初学者和...
OpenGL 编程指南 本文档为 OpenGL 编程指南,涵盖了 OpenGL 的基础知识、概念、基本程序结构、数据类型、函数名、辅助库、模型建立、变换、颜色、光照、位图和图像、纹理、复杂物体建模、特殊光处理、效果处理、...
OpenGL 基础知识与屏幕输出技术详解 一、OpenGL 基础知识 OpenGL 是一个跨平台的图形应用程序接口(API),用于生成二维和三维图形。它提供了一组与语言无关的 API,允许开发人员使用多种编程语言来创建图形应用...
opengl MutiWindow opengl MutiWindow opengl MutiWindow
OpenGL-Vision OpenGL-Vision OpenGL-Vision
OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试OpenGL 深度测试...
当初为了学习一下WebGL,但没有发现中文资料,连《OpenGL ES 2.0编程指南》也没有中文版(或许 有,但至少我没有找到),所以自己打算整理一下WebGL的相关资料。昨天中午《OpenGL ES 2.0编程 指南》翻译结束。但不...
在Linux系统中,OpenGL是一个广泛使用的图形库,用于创建2D和3D图形。它提供了标准接口,使得开发者能够在不同的操作系统和硬件上编写图形程序。本文将详细介绍如何在Linux环境下安装OpenGL库及其相关的开发工具。 ...
OpenGL编程指南第9版、超级宝典第7版、计算机图形原则和实践第3版以及OpenGL领悟(OpenGL Insights)这四本书是计算机图形学领域的经典之作,尤其对于使用OpenGL进行图形编程的开发者来说,它们提供了丰富的知识和深入...
OpenGL是计算机图形学领域广泛应用的一种接口,它提供了一组用于绘制3D图形的函数,能够帮助程序员在各种操作系统和硬件平台上创建复杂的可视化场景。OpenGL开发库通常包含了大量的函数,这些函数是实现3D图形渲染、...