OpenGL ES 编程指南:简介

logo.png

About OpenGL ES

The Open Graphics Library (OpenGL) is used for visualizing 2D and 3D data. It is a multipurpose open-standard graphics library that supports applications for 2D and 3D digital content creation, mechanical and architectural design, virtual prototyping, flight simulation, video games, and more. You use OpenGL to configure a 3D graphics pipeline and submit data to it. Vertices are transformed and lit, assembled into primitives, and rasterized to create a 2D image. OpenGL is designed to translate function calls into graphics commands that can be sent to underlying graphics hardware. Because this underlying hardware is dedicated to processing graphics commands, OpenGL drawing is typically very fast.

开放图形库(OpenGL)用于2D和3D数据的可视化。 它是一个多用途的开放标准图形库,支持2D和3D数字内容创建,机械和建筑设计,虚拟原型,飞行模拟,视频游戏等应用。 您可以使用OpenGL配置3D图形流水线并提交数据。 顶点被转换和点亮,组合成原始图像,并进行光栅化以创建2D图像。 OpenGL旨在将函数调用转换为可发送到底层图形硬件的图形命令。 因为这个底层硬件专门用于处理图形命令,因此OpenGL绘图通常非常快。

OpenGL for Embedded Systems (OpenGL ES) is a simplified version of OpenGL that eliminates redundant functionality to provide a library that is both easier to learn and easier to implement in mobile graphics hardware.

OpenGL for Embedded Systems(OpenGL ES)是OpenGL的简化版本,消除了冗余功能,从而提供更容易学习和易于在移动图形硬件中实现的库。

[图片上传失败...(image-4c25b6-1529501149806)]

At a Glance

OpenGL ES allows an app to harness the power of the underlying graphics processor. The GPU on iOS devices can perform sophisticated 2D and 3D drawing, as well as complex shading calculations on every pixel in the final image. You should use OpenGL ES if the design requirements of your app call for the most direct and comprehensive access possible to GPU hardware. Typical clients for OpenGL ES include video games and simulations that present 3D graphics.

OpenGL ES允许应用程序利用底层图形处理器的功能。 iOS设备上的GPU可以执行复杂的2D和3D绘图,以及最终图像中每个像素的复杂阴影计算。 您应该使用OpenGL ES,如果您的应用程序的设计要求要求最直接和全面的访问可能对GPU硬件。 OpenGL ES的典型客户端包括视频游戏和3D图形模拟。

OpenGL ES is a low-level, hardware-focused API. Though it provides the most powerful and flexible graphics processing tools, it also has a steep learning curve and a significant effect on the overall design of your app. For apps that require high-performance graphics for more specialized uses, iOS provides several higher-level frameworks:

  • The Sprite Kit framework provides a hardware-accelerated animation system optimized for creating 2D games. (See Sprite Kit Programming Guide.)
  • The Core Image framework provides real-time filtering and analysis for still and video images. (See Core Image Programming Guide.)
  • Core Animation provides the hardware-accelerated graphics rendering and animation infrastructure for all iOS apps, as well as a simple declarative programming model that makes it simple to implement sophisticated user interface animations. (See Core Animation Programming Guide.)

You can add animation, physics-based dynamics, and other special effects to Cocoa Touch user interfaces using features in the UIKit framework.

OpenGL ES是一个低级的,以硬件为重点的API。 虽然它提供了最强大和最灵活的图形处理工具,但它也具有"陡峭的学习曲线",对您的应用程序的整体设计有重大的影响。 对于需要高性能图形用于更专业化应用的应用,iOS提供了几个更高级别的框架:

  • Sprite Kit框架提供了一个为创建2D游戏而优化的硬件加速动画系统。 (请参见“Sprite Kit编程指南”。)
  • Core Image框架为静态和视频图像提供实时过滤和分析。
  • 核心动画为所有iOS应用程序提供了硬件加速的图形渲染和动画基础设施,以及一个简单的声明式编程模型,使得实现复杂的用户界面动画变得简单。
OpenGL ES Is a Platform-Neutral API Implemented in iOS(在iOS中OpenGL ES是平台无关的API)

Because OpenGL ES is a C-based API, it is extremely portable and widely supported. As a C API, it integrates seamlessly with Objective-C Cocoa Touch apps. The OpenGL ES specification does not define a windowing layer; instead, the hosting operating system must provide functions to create an OpenGL ES rendering context, which accepts commands, and a framebuffer, where the results of any drawing commands are written to. Working with OpenGL ES on iOS requires using iOS classes to set up and present a drawing surface and using platform-neutral API to render its contents.

因为OpenGL ES是一个基于C的API,它非常便于集成并得到广泛的支持。 作为C API,它与Objective-C Cocoa Touch应用程序无缝集成。 OpenGL ES规范没有定义窗口层; 相反,托管操作系统必须提供函数来创建可以接受命令的OpenGL ES渲染上下文以及写入任何绘图命令的结果的帧缓冲区。 在iOS上使用OpenGL ES需要使用iOS类来设置和呈现绘图层,并使用平台无关的API来呈现其内容。

Relevant Chapters: Checklist for Building OpenGL ES Apps for iOS, Configuring OpenGL ES Contexts
相关章节

GLKit Provides a Drawing Surface and Animation Support

Views and view controllers, defined by the UIKit framework, control the presentation of visual content on iOS. The GLKit framework provides OpenGL ES–aware versions of these classes. When you develop an OpenGL ES app, you use a GLKView object to render your OpenGL ES content. You can also use a GLKViewController object to manage your view and support animating its contents.

UIKit框架定义的视图和视图控制器控制iOS上的视觉内容的呈现。 GLKit框架提供这些类的OpenGL ES-aware版本。 开发OpenGL ES应用程序时,您可以使用GLKView对象来呈现OpenGL ES内容。 您还可以使用GLKViewController对象来管理视图并支持动画化其内容。

Relevant Chapters: Drawing with OpenGL ES and GLKit

iOS Supports Alternative Rendering Targets(iOS支持替代渲染目标)

Besides drawing content to fill an entire screen or part of a view hierarchy, you can also use OpenGL ES framebuffer objects for other rendering strategies. iOS implements standard OpenGL ES framebuffer objects, which you can use for rendering to an offscreen buffer or to a texture for use elsewhere in an OpenGL ES scene. In addition, OpenGL ES on iOS supports rendering to a Core Animation layer (the CAEAGLLayer class), which you can then combine with other layers to build your app’s user interface or other visual displays.

除了绘制内容以填充整个屏幕或视图层次结构的一部分外,您还可以使用OpenGL ES framebuffer对象进行其他渲染策略。 iOS实现标准的OpenGL ES帧缓冲对象,您可以将其用于渲染到屏幕外缓冲区或纹理,以便在OpenGL ES场景中的其他位置使用。 此外,iOS上的OpenGL ES支持渲染到Core Animation层(CAEAGLLayer类),然后您可以将其与其他图层相结合,构建应用的用户界面或其他视觉显示。

Relevant Chapters: Drawing to Other Rendering Destinations

Apps Require Additional Performance Tuning(应用程序需要额外的性能调优)

Graphics processors are parallelized devices optimized for graphics operations. To get great performance in your app, you must carefully design your app to feed data and commands to OpenGL ES so that the graphics hardware runs in parallel with your app. A poorly tuned app forces either the CPU or the GPU to wait for the other to finish processing commands.

You should design your app to efficiently use the OpenGL ES API. Once you have finished building your app, use Instruments to fine tune your app’s performance. If your app is bottlenecked inside OpenGL ES, use the information provided in this guide to optimize your app’s performance.

Xcode provides tools to help you improve the performance of your OpenGL ES apps.

Graphics processors ( 图形处理器)是针对图形操作优化的并行设备。 为了在应用程序中获得出色的表现,您必须仔细设计应用程序以将数据和命令提供给OpenGL ES,以使图形硬件与您的应用程序并行运行。 调整好的应用程序会强制CPU或GPU等待另一个完成处理命令。

您应该设计您的应用程序以有效地使用OpenGL ES API。 完成应用程式制作完成后,使用Instruments 来调整应用程式的成效。 如果您的应用程序在OpenGL ES中出现瓶颈,请使用本指南中提供的信息来优化应用程序的性能。

Xcode提供了帮助您提高OpenGL ES应用程序性能的工具。

Relevant Chapters: OpenGL ES Design Guidelines, Best Practices for Working with Vertex Data, Best Practices for Working with Texture Data, Best Practices for Shaders, Tuning Your OpenGL ES App

OpenGL ES May Not Be Used in Background Apps(OpenGL ES可能不会用于后台应用程序)

Apps that are running in the background may not call OpenGL ES functions. If your app accesses the graphics processor while it is in the background, it is automatically terminated by iOS. To avoid this, your app should flush any pending commands previously submitted to OpenGL ES prior to being moved into the background and avoid calling OpenGL ES until it is moved back to the foreground.

在后台运行的应用程序可能不会调用OpenGL ES函数。 如果您的应用程序在后台访问图形处理器,则会由iOS自动终止。 为避免这种情况,您的应用程序应该在挂起前提交OpenGL ES刷新命令,然后才能移动到后台,并避免调用OpenGL ES,直到它移回到前台。

Relevant Chapters: Multitasking, High Resolution, and Other iOS Features

OpenGL ES Places Additional Restrictions on Multithreaded Apps(OpenGL ES在多线程应用中的限制)

Designing apps to take advantage of concurrency can be useful to help improve your app’s performance. If you intend to add concurrency to an OpenGL ES app, you must ensure that it does not access the same context from two different threads at the same time.

设计应用程序以利用并发功能可以帮助您提高应用程序的性能。 如果您打算在OpenGL ES应用程序中添加并发性,则必须确保它不会同时从两个不同的线程访问相同的上下文。

Relevant Chapters: Concurrency and OpenGL ES

How to Use This Document

Begin by reading the first three chapters: Checklist for Building OpenGL ES Apps for iOS, Configuring OpenGL ES Contexts, Drawing with OpenGL ES and GLKit. These chapters provide an overview of how OpenGL ES integrates into iOS and all the details necessary to get your first OpenGL ES apps up and running on an iOS device.

If you’re familiar with the basics of using OpenGL ES in iOS, read Drawing to Other Rendering Destinations and Multitasking, High Resolution, and Other iOS Features for important platform-specific guidelines. Developers familiar with using OpenGL ES in iOS versions before 5.0 should study Drawing with OpenGL ES and GLKit for details on new features for streamlining OpenGL ES development.

Finally, read OpenGL ES Design Guidelines, Tuning Your OpenGL ES App, and the following chapters to dig deeper into how to design efficient OpenGL ES apps.
Unless otherwise noted, OpenGL ES code examples in this book target OpenGL ES 3.0. You may need to make changes to use these code examples with other OpenGL ES versions

首先阅读前三章:构建用于iOS的OpenGL ES应用程序的清单,配置OpenGL ES上下文,使用OpenGL ES和GLKit进行绘图。这些章节概述了OpenGL ES如何整合到iOS中,以及在iOS设备上启动和运行第一个OpenGL ES应用程序所需的所有细节。

如果您熟悉在iOS中使用OpenGL ES的基础知识,请阅读绘图到其他呈现目的地和多任务,高分辨率和其他iOS功能,以获取重要的平台特定指南。熟悉在5.0之前的iOS版本中使用OpenGL ES的开发人员应该研究使用OpenGL ES和GLKit绘图,以获得有关简化OpenGL ES开发的新功能的详细信息。

最后,阅读OpenGL ES设计指南,调整OpenGL ES应用程序以及以下章节,深入了解如何设计高效的OpenGL ES应用程序。

除非另有说明,本书中的OpenGL ES代码示例以OpenGL ES 3.0为目标。您可能需要对其他OpenGL ES版本进行更改以使用这些代码示例。

Prerequisites

Before attempting use OpenGL ES, you should already be familiar with general iOS app architecture. See Start Developing iOS Apps Today.

This document is not a complete tutorial or a reference for the cross-platform OpenGL ES API. To learn more about OpenGL ES, consult the references below.

在尝试使用OpenGL ES之前,您应该已经熟悉了一般的iOS应用程序架构。 请参阅今天开始开发iOS应用程序。

本文档不是完整的教程或跨平台OpenGL ES API的参考。 要了解有关OpenGL ES的更多信息,请参阅以下参考。

See Also

OpenGL ES is an open standard defined by the Khronos Group. For more information about the OpenGL ES standard, please consult their web page at http://www.khronos.org/opengles/.

  • OpenGL® ES 3.0 Programming Guide, published by Addison-Wesley, provides a comprehensive introduction to OpenGL ES concepts.
  • OpenGL® Shading Language, Third Edition, also published by Addison-Wesley, provides many shading algorithms useable in your OpenGL ES app. You may need to modify some of these algorithms to run efficiently on mobile graphics processors.
  • OpenGL ES API Registry is the official repository for the OpenGL ES specifications, the OpenGL ES shading language specifications, and documentation for OpenGL ES extensions.
  • OpenGL ES Framework Reference describes the platform-specific functions and classes provided by Apple to integrate OpenGL ES into iOS.
  • iOS Device Compatibility Reference provides more detailed information on the hardware and software features available to your app.
  • GLKit Framework Reference describes a framework provided by Apple to make it easier to develop OpenGL ES 2.0 and 3.0 apps.

OpenGL ES是由Khronos集团定义的开放标准。有关OpenGL ES标准的更多信息,请访问他们的网页http://www.khronos.org/opengles/

  • Addison-Wesley发布的OpenGL®ES 3.0编程指南全面介绍了OpenGL ES的概念。
  • OpenGL®着色语言,第三版,也由Addison-Wesley出版,提供了许多可用于您的OpenGL ES应用程序的着色算法。您可能需要修改其中一些算法才能在移动图形处理器上高效运行。
  • OpenGL ES API注册表是OpenGL ES规范的官方存储库,-
    OpenGL ES着色语言规范以及OpenGL ES扩展的文档。
  • OpenGL ES Framework Reference介绍了Apple将OpenGL ES集成到iOS中提供的平台特定功能和类。
  • iOS设备兼容性参考提供了有关您的应用程序可用的硬件和软件功能的更详细信息。
  • “GLKit框架参考”介绍了由Apple提供的一个框架,可以更轻松地开发OpenGL ES 2.0和3.0应用程序。


    logo.png

推荐阅读更多精彩内容