由於本文的內容過長,在Chrome瀏覽器下可能不能完全顯示,建議使用IE或者FireFox閱讀本文。
來源請注明,本文永久地址為http://www.cnblogs.com/vertexshader/articles/2917540.html
OpenGL®作為業界最為廣泛使用的2D和3D圖形接口標准,應用在成千上萬的各式各樣的計算機的程序中。從初期的嶄露頭角,到與Direct3D激烈競爭,后經歷黯淡被Khronos接手又發揚光大,已經歷經波折發展了20年。由於過去的黯淡,至今甚至仍有人站在錯誤的時間角度認為它是落后的——它從未停止它前進的步伐,這篇文章就來簡述OpenGL的版本歷史和發展。
OpenGL 1.0
發布時間: 1992年1月
OpenGL的最早版本OpenGL 1.0由Mark Segal和Kurt Akeley發布於1992年1月。從這之后,OpenGL每隔一段時間都會發布一個新版本的規范,這些規范定義了一些顯卡必須支持的新擴展。這就決定了OpenGL的每個版本其實就是由各個擴展組成的,當硬件的驅動全部支持相應的擴展的時候,相應的OpenGL版本就被支持了。
OpenGL 1.1
發布時間:1997年1月
擴展 |
特性增加 |
Vertex arrays |
|
Polygon offset |
|
Logical operation |
|
Internal texture formats, texture proxy, and texture env |
|
Copy texture and subtexture from framebuffer |
|
Texture object |
時隔5年OpenGL才發布新的版本OpenGL 1.1,而Direct3D的出現(尤其是紅色警戒的大賣)使得OpenGL感覺到了壓力。頂點數組(Vertex arrays)的出現取代了glVertex*這類立即模式繪圖函數,多個數據可以被一個函數調用繪制了,降低了調用函數帶來的CPU循環開銷;polygon offset解決了z-fighting和stitching的問題;在pre-fragment operation開始支持邏輯操作(logic operation);紋理方面開始支持紋理代理(texture proxy)和紋理環境映射(texture environment),以及從幀緩沖(frameuffer)復制像素至texture或者subtexture;紋理對象(texture object)的出現改變了過去只能使用顯示表(display list)來靜態地使用紋理的方法,現在紋理和參數(texture parameter)能被改變了。
OpenGL 1.2
發布時間:1998年3月16日
擴展 |
特性 |
Three-dimensional texture |
|
BGR or BGRA pixel format |
|
Packed pixel formats |
|
Normal rescaling |
|
Separate specular color |
|
Texture coordinate edge clamping |
|
Texture LOD control |
|
Vertex array draw element range |
這個版本的OpenGL開始支持可以用於體渲染(volume rendering)和體紋理(solid texture)的texture 3D;BGRA和BGA的出現主要是為了兼容某些平台和硬件;包裝像素(pack pixel)的出現使得像素可以在不同的對象之間進行像素傳輸(pixel transfer),這也就是像素緩沖對象(pixel buffer object)的前身;GL_SGIS_texture_edge_clamp擴展的出現將texture coordinate規范在[0,1]這個區間;GL_SGIS_Texture_lod擴展則帶來了重要的MipMap技術,可以通過對紋理參數(texture parameter)的控制來完成對MipMap的控制。
OpenGL 1.2.1
發布時間:1998年10月14日
這個版本的OpenGL沒有什么重大的改變,但是專門介紹了ARB擴展的概念。ARB擴展是經過OpenGL ARB認證的擴展,這樣的擴展將被廣泛地實現。
OpenGL 1.3
發布時間:2001年8月14日
擴展 |
特性增加 |
compressed texture format |
|
texture cube |
|
GL_ARB_multitexture(removed) |
multi-texture |
Texture add env mode, texture combine env mode, texture dot3 env mode |
|
Texture border clamp |
|
transpose matrix |
這個版本開始支持壓縮紋理(compressed texture),可以有效地減少存儲和帶寬的壓力,現在廣泛的應用於各種對存儲大小和帶寬敏感的手持設備上;立方體紋理(texture cube)的出現主要用於在天空盒(skybox)、動態反射(dynamic reflection)等技術上;而multisample的出現讓OpenGL可以支持紋理和Framebuffer的MSAA抗鋸齒技術,代替了過去在光柵化狀態(rasterizer state)中趨近無用的抗鋸齒設置。
OpenGL 1.4
發布版本:2002年7月24日
擴展 |
特性增加 |
Automatic mipmap generation |
|
Blend squaring |
|
Depth texture adn shadows |
|
Fog coordinate |
|
Multi draw arrays |
|
Point parameters |
|
Secondary color |
|
Separate blend functions |
|
Stencil warp |
|
Texture crossbar env mode |
|
Texture mirrored repeat |
|
Window raster position |
這個版本開始支持紋理自動生成Mipmap; 以及關於point光柵化的parameter。
OpenGL 1.5
發布時間:2003年7月29日
擴展 |
特性增加 |
Buffer object |
|
Occlusion query |
|
Shadow functions |
這個版本出現了緩沖對象(buffer object),徹底取代了過去的頂點數組(vertex array)和立即模式,頂點數據可以從客戶端內存(client's memory)上傳到服務端內存(server's memory)了;同時添加了非常重要的遮擋查詢(occlusion query)。
OpenGL 2.0
發布時間:2004年9月7日
擴展 |
特性增加 |
OpenGL Shading Language 1.00 |
|
Multiple render targets |
|
Non-power-of-two textures |
|
Point sprites |
|
Separate stencil |
OpenGL終於有了自己的着色語言(shading language),ARB選擇了3Dlabs的Dave設計的着色語言成為OpenGL原生的着色語言,同時OpenGL也開始有了頂點着色器(vertex shader)和片元着色器(fragment shader),導致這個階段的OpenGL出現了固定管線和可編程管線並存的情況;OpenGL的片元着色器輸出(fragment shader output)現在也可以輸出到幀緩沖(framebuffer)的多個渲染目標(render target)上去了;同時OpenGL的紋理也不再有2^n大小的限制。
OpenGL 2.1
發布時間:2006年7月2日
擴展 |
特性增加 |
Pixel buffer objects |
|
sRGB textures |
這個版本增加了像素緩沖對象(pxiel buffer object),用來更快地像素傳輸(pixel tansfer)的工作,支持將像素從紋理對象(texture object)和幀緩沖對象(framebuffer object)包裝到(pack)像素緩沖對象(pixel buffer object),或者從像素緩沖對象解包裝到紋理對象和幀緩沖對象,另外像素緩沖對象也可以像普通的緩沖對象(buffer object)一樣被映射(map)更新數據,通過DMA的方式更加快地傳輸紋理;同時支持sRGB格式的紋理對象。
代號Longs Peak和OpenGL 3.0爭議
在OpenGL 3.0發布之前,這個版本的代號叫做Longs Peak,包含了很多大量修改OpenGL的工作方式以及根本性改變API的調用方式等內容。2008年8月11日OpenGL 3.0發布,這個版本的OpenGL開始分core profile和compatibility profile,並且Khronos Group希望只支持core profile,這個革新性的規范引起一片嘩然,許多廠商明確表示不會接受這個建議,並表示會繼續支持許多被划入compatibility profile的擴展,迫於壓力compatibility profile被改為是可選的。OpenGL 3.0的出現改變了過去OpenGL一定會向下兼容的特性,在一定程度上簡化了API的臃腫以及增加了API的靈活度。
OpenGL 3.0
發布日期:2008年8月11日
擴展 |
特性增加 |
New functions for shading language |
|
Framebuffer objects, along with blitting, multisample renderbuffer objects, and packed depth/stencil image formats |
|
Framebuffer blit |
|
Floating-point color and depth internal formats for textures and render buffers |
|
Red-Green texture compression |
|
Transform feedback |
|
Vertex array objects |
|
Conditional rendering |
|
Intergral image formats |
這個版本的OpenGL變化非常的大,開始分core profile和compatibility profile,core profile擴展的實現決定了所支持的OpenGL版本。下面列出這個版本之后可能會被棄用的很多特性:
- Application-generated object names
- Color index mode
- Shading language 1.10 and 1.20
- Begin/End primitive specification
- Edge flags
- Fixed function vertex processing
- Client-side vertex arrays
- Rectangles
- Current raster position
- Two-sided color selection
- Non-sprite points
- Wide linee and line strip
- Quadrilateral and polygon primitives
- Sepatate polygon draw mode
- Polygon stripple
- Pixel transger modes and operations
- Pixel drawing
- Bitmaps
- Legacy OpenGL 1.0 pixel formats
- Legacy pixel formats
- Depth texture mode
- Texture wrap mode CLAMP
- Texture borders
- Automatic mipmap generation
- Fixed function fragment processing
- Alpha test
- Accumulation buffers
- Context framebuffer size queries
- Evaluators
- Selection and feedback mode
- Display lists
- Hints
- Attribute stacks
- Unified extension string
這個版本正式把幀緩沖對象(framebuffer object)划入core profile,現在OpenGL也具有離線的幀緩沖了,就像Direct3D的output-merger stage專門管理render target和接收fragment shader的輸出;增加了許多GLSL的函數,尤其是texture方面的;幀緩沖對象之間可以互相拷貝像素到持有的不同的render target,是性能上的提升;增加了浮點型和整型的texture和depth的image format;另外也增加了RGTC這個自帶的紋理壓縮模式;最為重要的增加就是transform feedback,數據可以經過vertex shader和geometry shader之后,又輸出回buffer而不經過rasterization以及之后的階段,在物理和粒子的計算上面非常的有用;增加的vertex array object方便管理buffer object以及vertex attrib pointer和其開啟/關閉狀態,不必每次在渲染前都要設置一遍了;增加了重要的條件渲染(conditional rendering)。
OpenGL 3.1
發布日期:2009年3月24日
擴展 |
特性增加 |
Instanced rendering |
|
Data copying between buffer objects |
|
Buffer texture |
|
Rectangle texture |
|
Uniform buffer object |
|
Primitive restart |
有了Instanced rendering,減輕了同類物體繪制所占有的帶寬壓力;Copy buffer的出現,是讓數據在client端進行拷貝,也是一種性能的優化;Buffer texture其實是讓buffer object像texture那樣被訪問,在某些特殊的場合有意想不到的用途;不得不談的就是uniform buffer object,過去OpenGL上傳uniform數據需要靠glUniform*的函數進行上傳,而OpenGL每個函數的調用所消耗的CPU循環都非常的大,頻繁地調用glUniform*會帶來很大的性能問題,而且到后期這些單個的uniform也會被保存至OpenGL管理的default uniform buffer中,現在開放了uniform buffer object,通過map/unmap更新數據,函數調用開銷明顯地減少。
OpenGL 3.2
發布日期:2009年8月3日
擴展 |
特性增加 |
Geometry shaders, input/output interface block |
|
Fence sync objects |
|
D3D compatible color vertex component ordering |
|
Draw command allowing modification of the base vertex index |
|
Seamless cube map filtering |
|
Multisampled textures andd texture samplers for specific sample locations |
|
Shader fragment coordinate conventions control |
|
Provoking vertex control |
|
Fragment depth clamping |
這個版本最重磅的支持就是幾何着色器(geometry shader), 可以用來生成新的圖元類型(點、線和三角形),后期重要的tessellation等技術都會使用到它;還有一個就是Texture正式支持multisample,可以作為render target來進行framebuffer object上的抗鋸齒,而不是經過的WGL_ARB_multisample和GLX_ARB_multisample進行窗口的抗鋸齒。
OpenGL 3.3
發布日期:2010年3月11日
擴展 |
特性增加 |
Dual-source blending |
|
Shader-defined locationfor attributes and fragment shader outputs |
|
Simple boolean occlusion query |
|
Sampler objects |
|
Texture swizzle |
|
Timer queries |
|
Instanced arrays |
|
new texture format for unsigned_10_10_10_2 and new vertex attributes for 2_10_10_10 |
這個版本是shader model 4.0的OpenGL的最終版本,這個版本改變了程序需要查詢輸入變量(attribute)的location的方式,可以像HLSL指定semantic一樣在shader里指定layout,減少了相應API的調用;同時將texture object和sampler state解耦,增加了sampler object,sampler object也可以綁定到ACTIVE_TEXTURE上了。
OpenGL 4.0
發布日期:2010年3月11日
擴展 |
特性增加 |
Tessellation control and evaluation shaders |
|
OpenGL Shading Language 4.00 |
|
Request minimum number of fragment inputs |
|
Individual blend equations for each color output |
|
Draw instanced arrays indirect |
|
Transform feedback objects and multiple feedback stream output |
這個版本和OpenGL 3.3同時發布,增加了令人興奮的Tessellation Shader;Shader Language 4.00的subroutine提供了在運行時刻不需要切換着色器或者是重新編譯或者使用if判斷選擇不同功能的方法,降低了切換着色器程序所帶來的巨大開銷(切換着色器的CPU循環消耗真的非常的驚人);另外GL_ARB_draw_buffers_blend讓fragment shader輸出的每條buffer都可以完成各自的pre-fragment operaion,而不是像過去那樣每條都完成相同的pre-fragment operation;GL_ARB_transform_feedback2和GL_ARB_transform_feedback3提供了transform feedback object,以及transform feedback相關的控制(比如pause之類),也把transform feedback當做一個對象來進行處理。
OpenGL 4.1
發布日期:2010年7月26日
擴展 |
特性增加 |
Pulling missing functionality from OpenGL ES 2.0 into OpenGL |
|
Query and load a binary blob for program objects |
|
Ability to bind programs individually to programmable stages |
|
Multiple viewports for the same rendering surface, or one per surface |
|
Documents precision requirements for several FP operaions |
|
Provoids 64-bit floating-point component vertex shader inputs |
這個版本把OpenGL ES的一些功能划入core profile的范圍,一方面反映出了OpenGL ES巨大的成功;GL_ARB_get_program_binary提供了可以將shader事先編譯好序列化進入二進制文件,避免了運行時進行編譯的方法;這個版本也提供了64位的浮點型輸入變量,提升了數據精度。
OpenGL 4.2
發布日期:2011年8月8日
擴展 |
特性增加 |
Allows instanced rendering with a starting instance value |
|
Allows for sub-rectangle selections when transferring compressed texture data |
|
Allos querying of the aligment for pointers returned from buffer object mapping operations |
|
Allows the user to detect the maximum number of samples possible for a particular image format and texture type |
|
Allows querying of the alignment for pointers returned from buffer object mapping operations |
|
Allows the setting of Uniform Buffer Object and sampler binding points directly from GLSL, among many other small changes |
|
Allows texture objects to have immutable storage, and allocating all mipmap levels and images in one call. The storage becomes immutable, but the contents of the storage are not |
|
Allows instanced rendering of data written by transform feedback operations |
|
Allows atomically incrementing/decrementing and fetching of buffer object memory locations from shaders |
|
Allows shaders to read and write images, with few but difficult restrictions |
|
Allows the use of certain advanced compression formats |
這個版本比較好的改動就是現在也支持Compressed pixel format transfer了,而過去這是不允許的;另外提供了immutable texture,可以調用一次API創建texture object而不是像過去一樣要頻繁地調用API;還有一個就是GL_ARB_texture_compression_bptc,以及compatibility profile的GL_EXT_texture_compression_s3tc,讓OpenGL開始支持所有的Block Compression格式。
OpenGL 4.3
發布日期:2012年8月6日
擴展 |
特性增加 |
GLSL multidimensional arrays |
|
Clear Buffer Objects to specific values, ala memset |
|
Arbitrary Compute Shaders |
|
Arbitrary image copying |
|
Debug messaging |
|
Compatibility with OpenGL ES 3.0 |
|
Specifying uniform locations in a shader |
|
Rendering to a Framebuffer Object that has no attachments |
|
Generalized queries for information about Image Formats |
|
Texture, buffer object, and framebuffer invalidation |
|
Issuing multiple indirect rendering commands from a single drawing command |
|
Improved API for getting info about program object interfaces |
|
Buffer object read-write access from shader, via a uniform-block style mechanism |
|
Get size of images from GLSL |
|
Accessing the stencil values from a depth/stencil texture |
|
Layer and viewport indices available from the fragment shader |
|
GLSL can detect the available mipmap pyramid of a sampler or image |
|
Immutable storage for multisample textures |
|
The ability to create a new texture, with a new internal format, that references an existing texture's storage |
|
Separation of vertex format from buffer object |
|
More robustness of API |
擴展 |
特性增加 |
Allows buffer objects to have immutable storage, and allocating all data in one call. |
|
Clear texture Objects to specific values. |
|
Add more functionality to layout qualifiers in OpenGL Shading Language. |
|
Allowing applications to bind or unbind a set of objects in one call. |
|
Introduces a mechanism whereby the result of a query object may be retrieved into a buffer object instead of client memory. |
|
Extends the set of texture warp mdes to include an additional mode that effectively uses a texture map twice as large as the original image in which the additional half of the new image is a mirror image of the original image. |
|
Accept STENCIL_INDEX8 as a texture internal format. |
|
New vertex attribute data format. |
|
Allows application to write generic compute shader that operate on work groups with arbitrary dimensions. |
|
Add "parameter buffer" which is a target allowing buffers to store parameters for certain drawing commands. |
|
Allow a implementation to provide a per-texture setting for enabling seamless sampling from cube maps. |
|
Add a built-in variable gl_DrawID in OpenGL Shading Language. |
|
Add new built-in functions to compute the cmpoite of a set of boolean conditions across a group of shader invocations. |
附錄
OpenGL 4.4 pipeline
Q&A:
Q:OpenGL已經落伍了,更新的也非常的慢,再努力幾年也趕不上技術雄厚的Direct3D。
A:近幾年Khronos Group接手OpenGL之后,發展速度迅猛,新版本的OpenGL已經更新到了OpenGL 4.4,其功能略超過Direct3D 11,且被Nvidia和AMD主流顯卡全面支持;值得注意的是有96.8%手持設備都只使用桌面OpenGL的子集OpenGL ES作為他們的圖形編程接口;許多家用游戲機也使用OpenGL作為其圖形的編程接口。OpenGL已經重新回到主流的地位,我想或許你的教科書真的是太老了!
Q:OpenGL的功能會比Direct3D少,且OpenGL的速度不如Direct3D來得快。
A:PC上的OpenGL和Direct3D工作在同樣的硬件上,他們的功能是基本一致的,另外你應該看看這個。
Q:從哪里才能下載到OpenGL的SDK?
A:OpenGL並沒有SDK,想要啟用高級OpenGL都是通過獲取相應的函數指針來完成的,當然必須由顯卡的驅動支持才行。不過有些庫可以幫你完成這類繁瑣的工作,比如GLEW。
Q:OpenGL的擴展是什么?
A:OpenGL功能的實現都是靠一個個擴展實現的,如果實現了OpenGL版本規范規定的擴展,那么就是實現了相應的OpenGL擴展。
Q:我如何知道我的設備支持了多少OpenGL擴展以及什么OpenGL擴展?
A:在編程中你可以使用特定的庫比如GLEW檢測相應的擴展是否被支持;你也可以下載OpenGL Extensions Viewer直觀的查看支持的OpenGL的特性和擴展,這個軟件也有多個平台的版本。
Q:感覺OpenGL的文檔都太不詳細了,我在搜索引擎里搜索的結果都很令人失望。
A:詳細的OpenGL文檔都在其官網里:①OpenGL Registry里面有上百個OpenGL擴展的文檔;②OpenGL Reference Page里面有各個函數的使用方法;③OpenGL Reference Card能幫助你宏觀地了解OpenGL的所有主要函數;④OpenGL Specification其實是擴展文檔的集合,不過也是非常的詳細和有用。
Q:什么是Core Profile和Compatibility Profile?
A:在OpenGL的發展歷程中,總是兼顧向下兼容的特性,但是到了一定的程度之后,這些舊有的OpenGL API不再適應時代的需要,還有一些擴展並不是驅動一定要實現的擴展,這些被統一划入可選的Compatibility Profile;而由OpenGL規范規定必須支持的擴展,則是Core Profile,想要支持先進的OpenGL,相應的Core Profile擴展必須被實現。
Q:有什么好的入門書籍可以介紹嗎?
A:《OpenGL Superbible》和《OpenGL Shading Language Cookbook》以及《OpenGL Insights》都非常的不錯。
Q:OpenGL如何進行Debug,DirectX的PIX真的很好用呢。
A:現在支持GLSL和OpenGL跟步調試的只有Nvidia的Nsight,只支持Nvidia的顯卡;其他的基本都是track,不支持GLSL的跟步調試,比如AMD的GPUPerfClient以及gDEBugger。還有AMD的GPU ShaderAnalyzer也非常的不錯,能看到相應的GLSL匯編代碼。
Q:OpenGL有多少引擎支持呢!
A:基本主流的引擎都會在上層抽象一層,然后都有用OpenGL和Direct3D分別實現的模塊;絕大部分的主流引擎都留有了OpenGL的實現。
Q:網上很多Tutorias都很老了,Nehe也落伍了,有沒有比較好的Tutorias呢?
A:當然有!看看這個。
Q:學OpenGL來錢快不快?
A:建議去新XX學廚師。
后記
在khronos Group接手OpenGL之后,OpenGL的API的進化方向也漸漸地和Direct3D一致了,其深層次原因是因為硬件進化趨勢的一致性,在API的使用上OpenGL也漸漸地和Direct3D更加的相似了,在OpenGL 4.4的環境下,基本可以“還原”出和Direct3D 11一樣的接口,從Direct3D11移植到OpenGL程序不再是一件難事。