http://blog.163.com/luckyjackyt@126/blog/static/1404476132012323105227214

【IOS的OpenGL ES】

【OpenGL ES提供一个程序API来把原始数据提交给硬件加速图形管线去渲染】Graphics commands are consumed by OpenGL to generate images that can be displayed to the user or retrieved for further processing outside of OpenGL ES.【图形命令被OpenGL消耗来生成图像,这些图像显示给用户或存起来等待OpenGL ES外更多的处理】

【OpenGL ES说明书为每个功能定义了精确的行为】Most commands in OpenGL ES perform one of the following activities:【大多数OpenGL ES的命令执行下列行为之一】

  • 【读取OpenGL ES的能力的执行的详细信息】 See【见】 “Determining OpenGL ES Capabilities.”
  • 【说明书定义的可变读写状态】 OpenGL ES state typically represents the current configuration of the graphics pipeline. 【OpenGL ES状态通常表现了图形管道的当前设置】For example, OpenGL ES 1.1 uses state variables extensively to configure lights, materials, and the computations performed by the fixed-function pipeline.【比如,OpenGL ES1.1用状态可变广泛的设置:光、材质和固定功能管线提供的计算】
  •  【创建、修改、销毁OpenGL对象】OpenGL ES objects are not Objective-C objects; they are OpenGL ES resources manipulated through OpenGL ES’s procedural API. 【OpenGL ES对象不是Objective-C对象,他们是通过OpenGL ES程序API操作的OpenGL ES资源】See 【更多信息见】“OpenGL ES Objects Encapsulate Resources on Behalf of Your Application” for more information.
  • Drawing primitives. Vertices are submitted to the pipeline where they are processed, assembled into primitives and rasterized to a framebuffer.【绘制原始数据,顶点被提交给管线,在那,它们被处理、装配成原始数据并且光栅化进一个帧缓存】


Which Version(s) of OpenGL ES Should I Target?【我应该以哪个版本的OpenGL ES为目标】

【当你设计你的OpenGL ES程序时,有个关键问题你必须想清楚,就是你的程序应该支持OpenGL ES2.0还是1.1或都支持】

  • 【OpenGL ES2.0比1.1更灵活更强力,对于新程序是最好地选择】Custom vertex or fragment calculations can be implemented more clearly and concisely in shaders, with better performance. 【自定的顶点或片段计算可以更清楚和简明地在着色器里执行】To perform the same calculations in OpenGL ES 1.1 often requires multiple rendering passes or complex state configurations that obscure the intent of the algorithm.【要在OpenGL ES1.1里执行相同的计算经常需要多重的渲染通道或复杂的状态设置,不易看懂算法的目的】 As your algorithms grow in complexity, shaders convey your calculations more clearly and concisely and with better performance. 【当你的算法变得复杂时,着色器更清晰和简明地传送你的计算,而且有更好的性能】OpenGL ES 2.0 requires more work up front to build your application; you need to recreate some of the infrastructure that OpenGL ES 1.1 provides by default.【OpenGL ES2.0在你创建程序前需要更加精心制定,你需要重建某些基础结构,而这些1.1都默认提供】
  • 【OpenGL ES1.1提供了一个标准固定功能管线,这个管线提供为3D程序提供很好的基础管线行为,从变形和光照顶点到混合片段进帧缓存】 If your needs are simple, OpenGL ES 1.1 requires less coding to add OpenGL ES support to your application. 【如果你的需要是简单的,OpenGL ES1.1需要更少的代码来加入OpenGL ES来支持你的程序】Your application should target OpenGL ES 1.1 if your application needs to support all iOS devices【如果你的程序需要支持所有IOS设备,那应该以OpenGL ES1.1为目标】

【如果你选择执行一个OpenGL ES1.1程序主要是为了旧设备的通用性,那么考虑加一个OpenGL ES2.0的渲染设置,好利用在新IOS设备上发现的更有力的OpenGL ES2.0的图形处理能力】


Important If your application does not support both an OpenGL ES 1.1 and an OpenGL ES 2.0 rendering path, restrict your application to devices that support the version you selected.【重要。如果你的程序不是1.1和2.0都支持,则要限制你的程序对设备版本的支持】See【见】 “Declaring the Required Device Capabilities” in iOS App Programming Guide.



Understanding the OpenGL ES Architecture【理解OpenGL ES的架构】

【OpenGL ES的工作基于很少几条关键原则】To design efficient OpenGL ES applications, you need to understand the underlying architecture.【要设计有效率的OpenGL ES程序,你需要理解底层架构】



Client-Server Model【“客户端-服务器端”模型】

【如图1-1所示,OpenGL ES使用“客户端-服务器端”模型】When your application calls an OpenGL ES function, it talks to an OpenGL ES client.【当你的程序调用一个OpenGL ES功能,它是告诉OpenGL ES客户端的】 The client processes the function call and, where necessary, converts it into commands to deliver to the OpenGL server. 【客户端处理功能调用,并在必要的地方转变成命令送往OpenGL服务器】A client-server model allows the work to process a function call to be divided between the client and the server. 【客户-服务模型允许作业在客户端-服务器间处理一个功能调用】The nature of the client, the server, and the communication path between them is specific to each implementation of OpenGL ES; on an iOS device, the workload is divided between the CPU and a dedicated graphics processor.【客户端、服务器端和它们之间的通讯路径的性质对于每个OpenGL ES的执行是特定的,在一个IOS设备上,工作负荷在CPU和专用图形处理器之间分配】



Figure 1-1  OpenGL ES client-server model

【OpenGL ES客户端-服务器模型】


OpenGL ES Relies on Platform-Specific Libraries For Critical Functionality【OpenGL ES依赖特定平台的关键功能库】

【OpenGL ES说明书定义了OpenGL ES怎样工作,但是没定义管理OpenGL ES与主操作系统之间的合作的功能】Instead, the specification expects each implementation to provide functions to allocate rendering contexts and system framebuffers.【取而代之的是,说明书希望每个执行提供功能来分配渲染内容和系统帧缓存】

【渲染环境为OpenGL ES状态机器存储内部状态】Rendering contexts allow each OpenGL ES application to each maintain a copy of the state data without worrying about other applications. 【渲染环境允许每个OpenGL ES程序保持一个状态数据的拷贝,而不用担心其他程序】See【见】 “Configuring OpenGL ES Contexts.” You can also use multiple rendering contexts in a single application.【你也可以在一个简单的程序里用多重渲染环境】

【系统帧缓存是OpenGL ES绘图命令的终点,通常与主系统的图形子系统有联系。IOS不提供系统帧缓存】 Instead, iOS extends the framebuffer object provided by OpenGL ES to allow framebuffers that share data with Core Animation. 【取而代之,IOS扩展OpenGL ES提供的缓存对象以允许帧缓存与核心动画分享数据】See【更多帧缓存对象的信息见】 “Framebuffer Objects are the Only Rendering Target on iOS” for more information on framebuffer objects and【关于在程序里创建和使用帧缓存的详细讨论见】 “Drawing With OpenGL ES” for a detailed discussion on creating and using framebuffers in your application.



Commands May Be Executed Asynchronously【命令可以不同步扩展】

【OpenGL ES客户端-服务器模型的好处在于,OpenGL ES功能可以在需求的操作完成前把控制返回给程序】If OpenGL ES required every function to complete before returning control to your application, the CPU and GPU would run in lockstep, eliminating many opportunities for parallelism in your application. 【如果OpenGL ES在把控制返回给程序前需要每个功能都完成,则CPU和GPU会顺序运行,从而限制了很多程序里的并发执行的机会】On iOS, deferring execution of drawing commands is quite common. 【在IOS里,延迟绘图命令的执行是非常常见的】By deferring several drawing commands and handling them simultaneously, the graphics hardware can remove hidden surfaces before performing costly fragment calculations.【借助同时延迟并处理几个绘图命令,图形硬件可以在执行高代价片段计算前移除隐藏的面】

【许多OpenGL ES功能隐式或显式地刷新命令到图形硬件】Other OpenGL functions flush commands to the graphics processor and wait until some or all pending commands have completed. 【其他OpenGL功能刷新到图形处理器并等待,直到一些或全部未执行命令完成】Whenever possible, design your application to avoid client-server synchronizations.【尽可能把程序设计成:避免客户端-服务器同步】



Commands Are Executed In Order【命令是顺序执行的】

【OpenGL ES保证调用建立渲染环境的功能的结果起作用,就像它们在客户端程序里调用功能的相同序列里执行】When your application makes a function call to OpenGL ES, your application can assume the results from previous functions are available, even if some of the commands have not finished executing.【当你的程序对OpenGL ES进行功能调用时,你的程序可以承担来自先前的可以得到的功能的结果,即使某些命令还没完成执行】



Parameters are Copied at Call-Time【参数在调用时被复制】

【当你的程序调用一个OpenGL ES功能时,为了允许命令被异步执行,在控制返回程序前,任意为了完成功能调用所需的参数数据,必须被OpenGL ES复制】If a parameter points at an array of vertex data stored in application memory, OpenGL ES must copy the vertex data before returning. 【如果一个参数指向一个数组,这个数组是存在程序内存里的顶点数据的数组,OpenGL ES必须在返回前复制顶点数据】This has a couple of important implications. 【这包括两个重要的含义】First, an application is free to change any memory it owns regardless of the calls it makes to OpenGL ES, because OpenGL ES and your application never access the same memory simultaneously. 【首先,程序是自由变换它拥有的任何内存,而不管它对OpenGL ES所做的调用,因为OpenGL ES和你的程序从来不同时存取相同的内存】Second, copying parameters and reformatting them so that the graphics hardware can read the data adds overhead to every function call. 【第二,复制参数和重新对它们定义格式,以便图形硬件可以读取数据,数据是加在为每个功能调用的开销里】For best performance, your application should define its data in format that are optimized for the graphics hardware, and it should use buffer objects to explicitly manage memory copies between your application and OpenGL ES.【要得到最佳性能,你的程序应该把它的数据定义为专为图形硬件优化的格式,并且应该用更好地缓冲对象来显示的管理程序与OpenGL ES之间的内存复制】



Implementations May Extend the Capabilities Defined in the Specification【OpenGL ES的执行可以扩展说明书中定义的能力】

【OpenGL ES的执行可以用两种方法扩展OpenGL ES说明书】First, the specification sets specific minimum requirements that implementations must meet, such as the size of a texture or the number of texture units that the application may access. 【第一,说明书设置了执行必须满足的专门的最小需求,例如程序可能存取的材质单元的大小或数量】An OpenGL ES implementation is free to support larger values — a larger texture, or more texture units. 【OpenGL ES的执行对支持大数值是自由的,比如大的材质或更多的材质单元】Second, OpenGL ES extensions allow an implementation to provide new OpenGL ES functions and constants. 【第二,OpenGL ES的扩展允许一个执行提供新的OpenGL ES功能和连续的(constants)】Extensions allow an implementation to add entirely new features.【扩展允许一个执行加入全新的特性】 Apple implements many extensions to allow applications to take advantage of hardware features and to help you improve the performance of your applications. 【苹果执行许多扩展来允许程序利用硬件特性并帮助你提高程序性能】The actual hardware limits and the list of extensions offered by each implementation may vary depending on which device your application runs on and the version of iOS running on the device. 【实际的硬件限制和由每个执行提供的扩展列表,可以根据程序运行的硬件和IOS的版本来改变】Your application must test the capabilities at runtime and alter its behavior to match.【你的程序必须测试运行时的能力,并改变性能来匹配】



OpenGL ES Objects Encapsulate Resources on Behalf of Your Application【OpenGL ES对象为了你的程序利益把资源打包】

【对象是不透明的容器,你的程序用它保持设置状态或渲染器需要的数据】Because the only access to objects is through the procedural API, the OpenGL ES implementation can choose different strategies when allocating objects for your application. 【因为唯一对对象的存取是通过程序API的,OpenGL ES的执行可以在给你的程序分配对象时选择不同的策略】It can store your data in a format or memory location that is optimal for the graphics processor.【它可以以一个格式或在一个专为图形优化的存储单元里存储你的数据】Another advantage to objects is that they are reusable, allowing your application to configure the object once and use it multiple times.【对象的另一个好处是他们是可重复使用的,允许你的程序设置对象一次,并多次使用】

【最重要的OpenGL ES对象类型包括】

  • texture is an image that can be sampled by the graphics pipeline.【texture(材质)是一个图片,可以被图形管线抽样】This is typically used to map a color image onto primitives but can also be used to map other data, such as a normal map or pre-calculated lighting information. 【典型的用于原始数据的彩色图片的贴图,也可用于其他数据贴图,比如普通贴图或提前计算好的光影信息】The chapter “Best Practices for Working with Texture Data” discusses critical topics for using textures on iOS.【章节《Best Practices for Working with Texture Data》讨论了在IOS里用贴图的关键题目】
  • buffer object is a block of memory owned by OpenGL ES used to store data for your application. 【buffer(缓存)对象是一块儿OpenGL ES拥有的内存,常用于为你的程序存储数据】Buffers are used to precisely control the process of copying data between your application and OpenGL ES. 【缓存常用于精确地控制你的程序和OpenGL ES之间复制数据】For example, if you provide a vertex array to OpenGL ES, it must copy the data every time you submit a drawing call. 【例如,如果你提供了一个顶点数组给OpenGL ES,它必须在你每次提交绘图调用时复制数据】In contrast, if your application stores its data in a vertex buffer object, the data is copied only when your application sends commands to modify the contents of the vertex buffer object. 【相比之下,如果你的程序把数据存进一个顶点缓存对象里,则数据仅在程序发送命令改变顶点缓存对象的内容时被复制】Using buffers to manage your vertex data can significantly boost the performance of your application.【用缓存管理你的顶点数据可以显著地提升程序的性能】
  • vertex array object holds a configuration for the vertex attributes that are to be read by the graphics pipeline.【vertex array(顶点数组)对象保持对顶点属性的设置,这些属性被图形管线读取】 Many applications require different pipeline configurations for each entity it intends to render. 【许多程序针对每个要渲染的实体需要不同的管线设置】By storing a configuration in a vertex array, you avoid the cost of reconfiguring the pipeline and may allow the implementation to optimize its handling of that particular vertex configuration.【借助把设置存进顶点数组,你节省了重新设置管线的代价,并可以允许程序的执行来优化它对特殊顶点设置的处理】
  • Shader programs, also known as shaders, are also objects. 【shader programs(着色器程序)也叫着色器,也是对象】An OpenGL ES 2.0 application creates vertex and fragment shaders to specify the calculations that are to be performed on each vertex or fragment, respectively.【一个OpenGL ES2.0程序创建顶点和片断着色器,来指定在每个顶点或片断上分别执行的计算】
  • renderbuffer is a simple 2D graphics image in a specified format.【renderbuffer(渲染缓存)是一个简单的指定格式的2D图形图片】This format usually is defined as color, depth or stencil data. 【这个格式通常被定义为颜色、深度或模板数据】Renderbuffers are not usually used in isolation, but are instead used as attachments to a framebuffer.【渲染缓存通常不单独用,而是用于帧缓存的附件】
  • Framebuffer objects are the ultimate destination of the graphics pipeline.【framebuffer(帧缓存)对象是图形管线的最终目的地】A framebuffer object is really just a container that attaches textures and renderbuffers to itself to create a complete configuration needed by the renderer. 【帧缓存对象恰是一个真正的容器,这个容器把材质和渲染缓存贴在自己身上以创建一个完整的渲染需要的设置】A later chapter, “Drawing With OpenGL ES,” describes strategies for creating and using framebuffers in iOS applications.【后面的章节《Drawing With OpenGL ES》讨论了在IOS程序里创建和使用帧缓存的策略】

【虽然OpenGL ES里的每个对象的类型有他自己的功能来操作它,但是所有对象分享一个相似的程序模型】

  1. 【生成一个对象标识】
    【一个标识是一个自然数,用于标明一个确切的对象实例】Whenever you need a new object, call OpenGL ES to create a new identifier. 【当你需要一个新对象时,调用OpenGL ES来创建一个新的标识】Creating the object identifier does not actually allocate an object, it simply allocates a reference to it.【创建对象标识不是实际上分配一个对象,它简单地分配一个引文】
     
  2. 【把你的对象捆绑到OpenGL ES环境】
    【大多数OpenGL ES功能隐式地对对象起作用,而不需要你在每个功能调用时显式地标识对象】You set the object to be configured by binding it to the context. 【你借助把对象捆绑进环境来设置对象】Each object type uses different functions to bind it to the context. 【每个对象用不同的方法来捆绑进环境】The first time you bind an object identifier, OpenGL ES allocates and initializes the object.【第一次捆绑对象标识时,OpenGL ES分配和初始化对象】
     
  3. 【改变对象的状态】
    【你的程序用一个或更多的功能调用来设置对象】For example, after binding a texture object, you typically would configure how the texture is filtered and then load image data into the texture object.【例如,在捆绑一个材质对象后,你通常会设置材质怎样过滤,然后载入图片到材质对象】
    【当它需要新的数据送往图形硬件时,换一个对象可能要潜在地贵的】Where reasonable, create and configure your objects once, and avoid changing them afterwards for the duration of your application.【在适度的地方,创建和设置你的对象一次,并避免后来在整个程序期间换它们】
  4. 【使用渲染用的对象】
    【一旦你已经创建和设置了全部的渲染场景所需的对象,你捆绑管线需要的对象并执行一个或更多的绘图功能】OpenGL ES uses the data stored in the objects to render your primitives. 【OpenGL ES用存在对象里的数据渲染你的原始模型】The results are sent to the bound framebuffer object.【把结果送进捆绑好的帧缓存里】
     
  5. 【删除对象】
    【当一个对象用完后,你的程序应该删除它】When an object is deleted, its contents are destroyed and the object identifier is recycled.【当一个对象被删除了,它的容器就被毁掉,对象标识被回收】



Framebuffer Objects are the Only Rendering Target on iOS【帧缓存对象是IOS里唯一的渲染目标】

【帧缓存对象是渲染命令的终点】OpenGL ES 2.0 provides framebuffer objects as part of the core specification; they are provided on OpenGL ES 1.1 by theOES_framebuffer_object extension. 【OpenGL ES2.0提供帧缓存对象作为核心说明书的部分】Because framebuffer objects are the only rendering target on iOS, Apple guarantees that the OES_framebuffer_object extension will always be provided by every OpenGL ES 1.1 implementation on iOS.【因为帧缓存对象是IOS里唯一的渲染目标,苹果保证OES_framebuffer_object扩展总是会被IOS里的每个OpenGL ES1.1的执行提供】

【借助把图片附在帧缓存上,帧缓存对象提供对颜色、深度和(或)模板数据的存储,如图1-2】The most common image attachment is a renderbuffer object. 【最通常的图片附着是一个渲染缓存对象】However, a OpenGL ES texture can be attached to the color attachment point of a framebuffer instead, allowing image to be rendered directly into a texture. 【然而,一个OpenGL ES材质可以被附在帧缓存的颜色附着点上,取而代之,允许图片被直接渲染进材质】Later, the texture can act as an input to future rendering commands.【再后来,材质可以作为一个对未来渲染命令的输入起作用】



Figure 1-2  Framebuffer with color and depth renderbuffers

【带颜色和深度渲染缓存的帧缓存】


【用下列步骤创建帧缓存】

  1. 【生成并绑定一个帧缓存的对象】
  2. 【生成、捆绑、设置一个图片】
  3. 【把图片贴在其中一个帧缓存的附着点上】
  4. 【对其他图片重复2、3步骤】
  5. 【测试帧缓存的完整性】The rules for completeness are defined in the OpenGL ES specification. 【OpenGL ES的说明书定义了完整性的规则】These rules ensure the framebuffer and its attachments are well-defined.【这些规则确保帧缓存和它的附属物是清晰可辨的】



? 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-02-24)


Did this document help you?  Yes  It's good, but...  Not helpful...


Shop the Apple Online Store (1-800-MY-APPLE), visit an Apple Retail Store, or find a reseller.

Copyright ? 2010 Apple Inc. All rights reserved.