OpenGL ES 是行動裝置上進行 2D 與 3D 繪圖的輕量解決方案。iOS 的 OpenGL ES 框架中包含了 EAGL,這是一組 C 語言 API,負責把 OpenGL ES 的渲染結果與 Core Animation 圖層、UIKit 視圖整合起來;同時也可以讓 EAGL 渲染到像素緩衝區。
Apple 官方文件網站上與 OpenGL ES 相關的資源共 24 篇,以下依類型整理,方便安排閱讀順序。
指南(Guides)
- OpenGL ES Hardware Platform Guide for iOS — 2013-04-23,首版。說明 iOS 裝置的圖形硬體特性。
- OpenGL ES Programming Guide for iOS — 2014-03-10,小幅修改。從 3D 繪圖到效能調校的總綱,是入門首選。
API 參考(Reference)
- EAGL Functions Reference — 取得 OpenGL ES 版本資訊的介面說明。
- EAGLContext Class Reference — 描述 OpenGL ES 指令的執行目標,iOS 7.1 後補充了多執行緒選項。
- EAGLDrawable Protocol Reference — 可渲染表面的協定定義。
- EAGLSharegroup Class Reference — 共享群組,用於跨 context 共用物件。
- OpenGL ES Framework Reference — 框架整體的參考文件。
範例程式(Sample Code)
- MusicCube — 音樂驅動的立方體視覺化
- PVRTextureLoader — PVR 貼圖載入
- GLTextureAtlas — 貼圖集
- GLPaint — 手繪應用
- GLImageProcessing — 圖形處理效果
- GLGravity — 重力模擬
- GLEssentials — 最基礎的 OpenGL ES 骨架,建議第一個讀
- GLAirplay — AirPlay 鏡像輸出
技術問答(Technical Q&As)
- Removing flickering in OpenGL ES applications — 消除閃爍
- OpenGL ES multithreading and EAGLSharegroup — 多執行緒與共享群組
- QA1679: Deprecated built-in variables in GLSL Shaders — GLSL 中已不建議使用的內建變數
- Creating textures in the PVRTC compression format — 建立 PVRTC 壓縮貼圖
- How to fix OpenGL ES application crashes when moving to the background — 進入背景時崩潰的修法
影片(Video)
- iOS 7 Tech Talks: Advances in OpenGL ES 3.0 — 2014-02-11
- WWDC 2012: Advances in OpenGL and OpenGL ES — 2012-09-19
- WWDC 2012: OpenGL ES Tools and Techniques — 2012-12-13
- WWDC 2013: Advances in OpenGL ES — 2013-09-18
建議的閱讀順序
先看 OpenGL ES Programming Guide for iOS 建立整體概念,接著跑 GLEssentials 這個最小可運行的範例,把渲染迴圈、context 建立、framebuffer 綁定這些流程親手走過一遍。之後再依需求深入:做貼圖相關功能看 PVRTextureLoader 與 GLTextureAtlas,做特效看 GLImageProcessing,需要效能調優則回到硬體平台指南與那幾篇 Technical Q&A。
值得補充的是,Apple 後續推出了 Metal 作為圖形 API,並已在 iOS 12 標記 OpenGL ES 為 deprecated。若是新專案且 target 較新,直接採用 Metal 會是更長遠的選擇;但既有專案仍可維持 OpenGL ES,Apple 目前並未移除該框架。
版權聲明:Copyright © 2013 Apple Inc. All Rights Reserved.