周一到周五,每天一篇,北京時(shí)間早上7點(diǎn)準(zhǔn)時(shí)更新~
為陽(yáng)信等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及陽(yáng)信網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、陽(yáng)信網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!All of the examples shown in this book so far have relied on the core functionality of OpenGL(到目前為止的案例都是基于OpenGL的核心標(biāo)準(zhǔn)的). However, one of OpenGL’s greatest strengths is that it can be extended and enhanced by hardware manufacturers, operating system vendors, and even publishers of tools and debuggers(然而還有一些擴(kuò)展的API是某部分廠商的硬件獨(dú)特的特性,可能是在標(biāo)準(zhǔn)API里是沒(méi)有的). Extensions can have many different effects on OpenGL functionality(這些擴(kuò)展的特性可能會(huì)帶來(lái)很不一樣的影響)
An extension is any addition to a core version of OpenGL(擴(kuò)展是指對(duì)核心版本API的額外補(bǔ)充). Extensions are listed in the OpenGL extension registry on the OpenGL Web site(擴(kuò)展列表在OpenGL的網(wǎng)站上有展示). These extensions are written as a list of differences from a particular version of the OpenGL specification, and note what that version of OpenGL is(這些擴(kuò)展的實(shí)現(xiàn)與某個(gè)特定版本的OpenGL標(biāo)準(zhǔn)可能不一致,你需要注意擴(kuò)展是哪個(gè)版本的OpenGL擴(kuò)展). That means the text of the extensions describes how the core OpenGL specification must be changed if the extension is supported(也就是說(shuō),擴(kuò)展描述了如果你啟動(dòng)了擴(kuò)展,OpenGL的實(shí)現(xiàn)會(huì)變成什么樣子). However, popular and generally useful extensions are normally “promoted” into the core versions of OpenGL(不過(guò),很多有用的擴(kuò)展一般都會(huì)最終被納入核心標(biāo)準(zhǔn)中去); thus, if you are running the latest and greatest version of OpenGL, there might not be that many extensions that are interesting but not part of the core profile(也就是說(shuō),每次OpenGL更新到最新版本的時(shí)候,以前那些擴(kuò)展可能就不存在了,而是被納入了新版本OpenGL的標(biāo)準(zhǔn)里). A complete list of the extensions that were promoted to each version of OpenGL and a brief synopsis of what they do is included in Appendix C, “OpenGL Features and Versions.”(一個(gè)完整的擴(kuò)展列表以及他們的其他相關(guān)信息在附錄C里)
There are three major classifications of extensions: vendor, EXT, and ARB(主要有三種擴(kuò)展:廠商、EXT、ARB). Vendor extensions are written and implemented on one vendor’s hardware(廠商的擴(kuò)展是在廠商自己的硬件上實(shí)現(xiàn)的). Initials representing the specific vendor are usually part of the extension name—“AMD” for Advanced Micro Devices or “NV” for NVIDIA, for example(通常實(shí)現(xiàn)的表述包含了廠商的名字,比如AMD就代表著Advanced Micro Devices,NV代表的是NVIDIA). It is possible that more than one vendor might support a specific vendor extension, especially if it becomes widely accepted(也可能存在多個(gè)廠商實(shí)現(xiàn)同一個(gè)廠商的擴(kuò)展的情況,特別是如果那個(gè)擴(kuò)展被廣泛接受的時(shí)候). EXT extensions are written together by two or more vendors(EXT擴(kuò)展是被兩個(gè)以上的廠商實(shí)現(xiàn)的擴(kuò)展). They often start their lives as vendor-specific extensions, but if another vendor is interested in implementing the extension, perhaps with minor changes, it may collaborate with the original authors to produce an EXT version(一般情況下,可能起初只有一個(gè)廠商的擴(kuò)展,后來(lái)又有其他廠商對(duì)此感興趣,且想對(duì)其進(jìn)行細(xì)微調(diào)整,所以他們就聯(lián)合起來(lái)搞了,搞出來(lái)的擴(kuò)展就是EXT擴(kuò)展). ARB extensions are an official part of OpenGL because they are approved by the OpenGL governing body, the Architecture Review Board (ARB)(ARB擴(kuò)展是OpenGL的官方Architecture Review Board所推動(dòng)的擴(kuò)展). These extensions are often supported by most or all major hardware vendors and may also have started out as vendor or EXT extensions(ARB擴(kuò)展經(jīng)常被大部分或者全部硬件廠商所支持,它們也可能源自廠商的擴(kuò)展或者是EXT擴(kuò)展)
This extension process may sound confusing at first(剛開(kāi)始聽(tīng)到擴(kuò)展的推動(dòng)過(guò)程的時(shí)候可能會(huì)感到疑惑). Hundreds of extensions currently are available!(上百個(gè)擴(kuò)展現(xiàn)在是可以被使用的) But new versions of OpenGL are often constructed from extensions programmers have found useful(新的OpenGL版本往往是從有用的擴(kuò)展進(jìn)行構(gòu)建的). In this way each extension gets its time in the sun(這樣一來(lái),每一個(gè)擴(kuò)展都有見(jiàn)到陽(yáng)光的那一天). The ones that shine can be promoted to core(那些很屌的擴(kuò)展則會(huì)被放到核心OpenGL標(biāo)準(zhǔn)里去); the ones that are less useful are not considered(那些不怎么實(shí)用的則不會(huì)被考慮). This “natural selection” process helps to ensure only the most useful and important new features make it into a core version of OpenGL(自然選擇能幫助來(lái)篩選出那些最有用和最重要的新特性)
A useful tool to determine which extensions are supported in your computer’s OpenGL implementation is Realtech VR’s OpenGL Extensions Viewer. It is freely available from the Realtech VR Web site (see Figure 3.6)(一個(gè)可以探測(cè)你電腦所支持的擴(kuò)展的工具叫Realtech VR’s OpenGL Extensions Viewer,如圖3.6所示,它是免費(fèi)的)
Enhancing OpenGL with Extensions(使用擴(kuò)展增強(qiáng)OpenGL)
Before using any extensions, you must make sure that they’re supported by the OpenGL implementation that your application is running on(在使用擴(kuò)展之前,你需要確定,這個(gè)擴(kuò)展在你當(dāng)前運(yùn)行的的設(shè)備上是被支持的). To find out which extensions OpenGL supports, there are two functions that you can use. First, to determine the number of supported extensions, you can call glGetIntegerv() with the GL_NUM_EXTENSIONS parameter(你可以通過(guò)glGetIntegerv(GL_NUM_EXTENSIONS,*)來(lái)獲取當(dāng)前環(huán)境支持的擴(kuò)展的個(gè)數(shù)). Next, you can find out the name of each of the supported extensions by calling(然后你可以通過(guò)下面的API獲取每個(gè)擴(kuò)展的名字)
const GLubyte* glGetStringi(GLenum name,GLuint index);
You should pass GL_EXTENSIONS as the name parameter, and a value between 0 and 1 less than the number of supported extensions in index(第一個(gè)參數(shù)要傳GL_EXTENSIONS,第二個(gè)參數(shù)是第幾個(gè)擴(kuò)展,這個(gè)值要小于上一步獲得的擴(kuò)展個(gè)數(shù)). The function returns the name of the extension as a string(這個(gè)函數(shù)返回一個(gè)擴(kuò)展的名字). To see if a specific extension is supported, you can simply query the number of extensions, and then loop through each supported extension and compare its name to the one you’re looking for(為了知道一個(gè)擴(kuò)展是否被支持,你可以先拿到所有擴(kuò)展的名字,然后在名字里找找看,是否存在你想查詢的那個(gè)). The book’s source code comes with a simple function that does this for you(在本課程中,我們就封裝了這樣一個(gè)方法). sb7IsExtensionSupported() has the prototype(它的名字叫sb7IsExtensionSupported,函數(shù)定義如下)
int sb7IsExtensionSupported(const char * extname);
This function is declared in the header, takes the name of an extension, and returns non-zero if it is supported by the current OpenGL context and zero if it is not(這個(gè)函數(shù)申明在sb7ext.h中,如果被查詢的擴(kuò)展被支持,則返回非0,否則返回0). Your application should always check for support for extensions you wish to use before using them(你的程序要在使用擴(kuò)展前檢查擴(kuò)展是否被支持)
Extensions generally add to OpenGL in some combination of four different ways(擴(kuò)展通常由四種方式的某種組合添加到OpenGL中):
They can make things legal that weren’t before, by simply removing restrictions from the OpenGL specification.(他們可以通過(guò)移除一些OpenGL的限制使得以前不合法的事情合法)
They can add tokens or extend the range of values that can be passed as parameters to existing functions.(他們相對(duì)于現(xiàn)存的函數(shù),可以接受范圍更廣的參數(shù)或者token)
They can extend GLSL to add functionality, built-in functions, variables, or data types.(他們可以通過(guò)添加功能,內(nèi)置變量或者什么數(shù)據(jù)類(lèi)型來(lái)增強(qiáng)GLSL)
They can add entirely new functions to OpenGL itself(他們?yōu)镺penGL增加了的嶄新的函數(shù))
In the first case, where things that once were considered errors no longer are, your application doesn’t need to do anything besides start using the newly allowed behavior (once you have determined that the extension is supported, of course)(第一種情況下,以前被認(rèn)為是錯(cuò)誤的調(diào)用會(huì)變得正確,除了使用新被允許的行為,你不需要修改你的程序). Likewise, for the second case, you can just start using the new token values in the relevant functions, presuming that you have their values(同樣,對(duì)于第二種情況,如果你有這些參數(shù)的話,你可以開(kāi)始在相關(guān)的API中使用新的參數(shù)). The values of the tokens are in the extension specifications, so you can look them up there if they are not included in your system’s header files.(如果你在系統(tǒng)的頭文件里找不到的話,這些參數(shù)在擴(kuò)展的文檔里)
To enable use of extensions in GLSL, you must first include a line at the beginning of shaders that use them to tell the compiler that you’re going to need their features(為了使用那些GLSL里的擴(kuò)展,你需要在GLSL中告訴編譯器,你需要使用到那些特性). For example, to enable the hypothetical GL_ABC_foobar_feature extension in GLSL,include the following in the beginning of your shader(比如,要使用GL_ABC_foobar_feature擴(kuò)展,你需要在你的shader里寫(xiě)上下面這句話):
#extension GL_ABC_foobar_feature : enable
This tells the compiler that you intend to use the extension in your shader(這句話告訴編譯器,你要在shader里使用這個(gè)特性). If the compiler knows about the extension, it will let you compile the shader, even if the underlying hardware doesn’t support the feature(如果編譯器知道這個(gè)特性,即便底層硬件不支持,編譯器也可以編譯出正確的GPU程序). If this is the case, the compiler should issue a warning if it sees that the extension is actually being used(如果是這種情況的話,如果這個(gè)特性確實(shí)被shader使用了,編譯器應(yīng)該發(fā)出警告). Typically, extensions to GLSL will add preprocessor tokens to indicate their presence(通常來(lái)講,GLSL的擴(kuò)展會(huì)被進(jìn)行預(yù)處理,從而確定他們的表現(xiàn)). For example, GL_ABC_foobar_feature will implicitly include(比如GL_ABC_foobar_feature將被隱式包含)
#define GL_ABC_foobar_feature 1
This means that you could write code such as(這句話就表明,你可以寫(xiě)如下的代碼)
#if GL_ABC_foobar_feature
// Use functions from the foobar extension
#else
// Emulate or otherwise work around the missing functionality
#endif
This allows you to conditionally compile or execute functionality that is part of an extension that may or may not be supported by the underlying OpenGL implementation. If your shader absolutely requires support for an extension and will not work at all without it, you can instead include this more assertive code:
#extension GL_ABC_foobar_feature : require
If the OpenGL implementation does not support the GL_ABC_foobar_feature extension, then it will fail to compile the shader and report an error on the line including the #extension directive(如果OpenGL的實(shí)現(xiàn)不支持GL_ABC_foobar_feature擴(kuò)展,編譯shader時(shí)將會(huì)失敗,并報(bào)出錯(cuò)誤在哪里). In effect, GLSL extensions are opt-in features, and applications must tell compilers up front which extensions they intend to use(實(shí)際上GLSL擴(kuò)展是具有選擇性特性的,應(yīng)用程序應(yīng)該告訴編譯器他們想使用什么樣的擴(kuò)展)
Next we come to extensions that introduce new functions to OpenGL(接下來(lái),我們看看那些為OpenGL添加了新函數(shù)的擴(kuò)展). On most platforms, you don’t have direct access to the OpenGL driver and extension functions don’t just magically appear as available to your applications to call(在大多數(shù)平臺(tái)上,你無(wú)法直接訪問(wèn)OpenGL的驅(qū)動(dòng),擴(kuò)展函數(shù)不會(huì)那么神奇的直接就可以被你的程序訪問(wèn)). Rather, you must ask the OpenGL driver for a function pointer that represents the function you want to call(更多的是,你需要找OpenGL的驅(qū)動(dòng)要到你想要訪問(wèn)的函數(shù)的指針). Function pointers are generally declared in two parts;(函數(shù)指針通常被定義成兩個(gè)部分) the first is the definition ofthe function pointer type, and the second is the function pointer variable itself.(第一個(gè)部分是函數(shù)的指針類(lèi)型,第二個(gè)部分是函數(shù)指針本身) Consider this code as an example:(例如下面的)
typedef void
(APIENTRYP PFNGLDRAWTRANSFORMFEEDBACKPROC) (GLenum mode,GLuint id);
PFNGLDRAWTRANSFORMFEEDBACKPROC glDrawTransformFeedback = NULL;
This declares the PFNGLDRAWTRANSFORMFEEDBACKPROC type as a pointer to a function taking GLenum and GLuint parameters(這就定義了PFNGLDRAWTRANSFORMFEEDBACKPROC類(lèi)型的函數(shù)指針,且這個(gè)函數(shù)接受一個(gè)GLenum和GLuint的參數(shù)). Next, it declares the glDrawTransformFeedback variable as an instance of this type(然后,它定義了該函數(shù)指針類(lèi)型的實(shí)際的變量). In fact, on many platforms, the declaration of the glDrawTransformFeedback() function is actually just like this(實(shí)際上,在很多平臺(tái)上,就如同剛才展示的這樣,glDrawTransformFeedback就是這么定義的). This seems pretty complicated, but fortunately the following header files include declarations of all of the function prototypes, function pointer types, and token values introduced by all registered OpenGL extensions(這看上去非常的復(fù)雜,但是幸運(yùn)的是,下面的這個(gè)頭文件定義了所有的函數(shù)類(lèi)型,函數(shù)指針的類(lèi)型以及那些參數(shù)):
#include
#include
#include
These files can be found at the OpenGL extension registry Web site(這些可以在OpenGL擴(kuò)展的網(wǎng)站上找到). The glext.h header contains both standard OpenGL extensions and many vendor-specific OpenGL extensions(glext.h包含了標(biāo)準(zhǔn)的OpenGL擴(kuò)展和很多廠商的擴(kuò)展), the wglext.h header contains a number of extensions that are Windows specific(wglext.h包含的是Windows上支持的擴(kuò)展), and the glxext.h header contains definitions that are X specific (glxext.h包含的是X擴(kuò)展,X指代的是Linux或者是Unix系的窗口系統(tǒng))(X is the windowing system used on Linux and many other UNIX derivatives and implementations)
The method for querying the address of extension functions is actually platform specific(查詢擴(kuò)展函數(shù)的訪問(wèn)地址會(huì)因平臺(tái)而異). The book’s application framework wraps up these intricacies into a handy function that is declared in the header file(本書(shū)的框架把這些方法打包進(jìn)了sb7ext.h的一個(gè)函數(shù)里去了). The function sb7GetProcAddress() has this prototype(這個(gè)函數(shù)叫sb7GetProcAddress,它的定義如下):
void sb7GetProcAddress(const char funcname);
Here, funcname is the name of the extension function that you wish to use(這里funcname是擴(kuò)展函數(shù)的名字). The return value is the address of the function, if it’s supported, and NULL otherwise(如果擴(kuò)展被支持,那么該函數(shù)返回一個(gè)函數(shù)地址,否則返回NULL). Even if OpenGL returns a valid function pointer for a function that’s part of the extension you want to use, that doesn’t mean the extension is present(即便OpenGL返回了一個(gè)合法的函數(shù)指針,那也只是一個(gè)擴(kuò)展,這并不意味著擴(kuò)展存在). Sometimes the same function is part of more than one extension, and sometimes vendors ship drivers with partial implementations of extensions present(有時(shí)候同樣的函數(shù)是多個(gè)擴(kuò)展的一部分,也有的時(shí)候廠商只實(shí)現(xiàn)了擴(kuò)展的一部分). Always check for support for extensions using the official mechanisms or the sb7IsExtensionSupported() function(請(qǐng)確保使用擴(kuò)展之前來(lái)檢查擴(kuò)展是否被支持).
本日的翻譯就到這里,明天見(jiàn),拜拜~~
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
名稱欄目:UsingExtensionsinOpenGL(使用OpenGL擴(kuò)展)-創(chuàng)新互聯(lián)
文章鏈接:http://chinadenli.net/article8/cojsop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開(kāi)發(fā)、商城網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、定制網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)站營(yíng)銷(xiāo)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容