91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Using Extensions in OpenGL(使用OpenGL擴展)

發布時間:2020-07-22 22:54:00 來源:網絡 閱讀:556 作者:萌谷王 欄目:游戲開發

周一到周五,每天一篇,北京時間早上7點準時更新~

All of the examples shown in this book so far have relied on the core functionality of OpenGL(到目前為止的案例都是基于OpenGL的核心標準的). 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(然而還有一些擴展的API是某部分廠商的硬件獨特的特性,可能是在標準API里是沒有的). Extensions can have many different effects on OpenGL functionality(這些擴展的特性可能會帶來很不一樣的影響)

An extension is any addition to a core version of OpenGL(擴展是指對核心版本API的額外補充). Extensions are listed in the OpenGL extension registry on the OpenGL Web site(擴展列表在OpenGL的網站上有展示). 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(這些擴展的實現與某個特定版本的OpenGL標準可能不一致,你需要注意擴展是哪個版本的OpenGL擴展). That means the text of the extensions describes how the core OpenGL specification must be changed if the extension is supported(也就是說,擴展描述了如果你啟動了擴展,OpenGL的實現會變成什么樣子). However, popular and generally useful extensions are normally “promoted” into the core versions of OpenGL(不過,很多有用的擴展一般都會最終被納入核心標準中去); 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(也就是說,每次OpenGL更新到最新版本的時候,以前那些擴展可能就不存在了,而是被納入了新版本OpenGL的標準里). 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.”(一個完整的擴展列表以及他們的其他相關信息在附錄C里)

There are three major classifications of extensions: vendor, EXT, and ARB(主要有三種擴展:廠商、EXT、ARB). Vendor extensions are written and implemented on one vendor’s hardware(廠商的擴展是在廠商自己的硬件上實現的). Initials representing the specific vendor are usually part of the extension name—“AMD” for Advanced Micro Devices or “NV” for NVIDIA, for example(通常實現的表述包含了廠商的名字,比如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(也可能存在多個廠商實現同一個廠商的擴展的情況,特別是如果那個擴展被廣泛接受的時候). EXT extensions are written together by two or more vendors(EXT擴展是被兩個以上的廠商實現的擴展). 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(一般情況下,可能起初只有一個廠商的擴展,后來又有其他廠商對此感興趣,且想對其進行細微調整,所以他們就聯合起來搞了,搞出來的擴展就是EXT擴展). ARB extensions are an official part of OpenGL because they are approved by the OpenGL governing body, the Architecture Review Board (ARB)(ARB擴展是OpenGL的官方Architecture Review Board所推動的擴展). These extensions are often supported by most or all major hardware vendors and may also have started out as vendor or EXT extensions(ARB擴展經常被大部分或者全部硬件廠商所支持,它們也可能源自廠商的擴展或者是EXT擴展)

This extension process may sound confusing at first(剛開始聽到擴展的推動過程的時候可能會感到疑惑). Hundreds of extensions currently are available!(上百個擴展現在是可以被使用的) But new versions of OpenGL are often constructed from extensions programmers have found useful(新的OpenGL版本往往是從有用的擴展進行構建的). In this way each extension gets its time in the sun(這樣一來,每一個擴展都有見到陽光的那一天). The ones that shine can be promoted to core(那些很屌的擴展則會被放到核心OpenGL標準里去); the ones that are less useful are not considered(那些不怎么實用的則不會被考慮). This “natural selection” process helps to ensure only the most useful and important new features make it into a core version of OpenGL(自然選擇能幫助來篩選出那些最有用和最重要的新特性)

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)(一個可以探測你電腦所支持的擴展的工具叫Realtech VR’s OpenGL Extensions Viewer,如圖3.6所示,它是免費的)
Using Extensions in OpenGL(使用OpenGL擴展)

Enhancing OpenGL with Extensions(使用擴展增強OpenGL)

Before using any extensions, you must make sure that they’re supported by the OpenGL implementation that your application is running on(在使用擴展之前,你需要確定,這個擴展在你當前運行的的設備上是被支持的). 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(你可以通過glGetIntegerv(GL_NUM_EXTENSIONS,*)來獲取當前環境支持的擴展的個數). Next, you can find out the name of each of the supported extensions by calling(然后你可以通過下面的API獲取每個擴展的名字)

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(第一個參數要傳GL_EXTENSIONS,第二個參數是第幾個擴展,這個值要小于上一步獲得的擴展個數). The function returns the name of the extension as a string(這個函數返回一個擴展的名字). 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(為了知道一個擴展是否被支持,你可以先拿到所有擴展的名字,然后在名字里找找看,是否存在你想查詢的那個). The book’s source code comes with a simple function that does this for you(在本課程中,我們就封裝了這樣一個方法). sb7IsExtensionSupported() has the prototype(它的名字叫sb7IsExtensionSupported,函數定義如下)

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(這個函數申明在sb7ext.h中,如果被查詢的擴展被支持,則返回非0,否則返回0). Your application should always check for support for extensions you wish to use before using them(你的程序要在使用擴展前檢查擴展是否被支持)

Extensions generally add to OpenGL in some combination of four different ways(擴展通常由四種方式的某種組合添加到OpenGL中):

They can make things legal that weren’t before, by simply removing restrictions from the OpenGL specification.(他們可以通過移除一些OpenGL的限制使得以前不合法的事情合法)
They can add tokens or extend the range of values that can be passed as parameters to existing functions.(他們相對于現存的函數,可以接受范圍更廣的參數或者token)
They can extend GLSL to add functionality, built-in functions, variables, or data types.(他們可以通過添加功能,內置變量或者什么數據類型來增強GLSL)
They can add entirely new functions to OpenGL itself(他們為OpenGL增加了的嶄新的函數)
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)(第一種情況下,以前被認為是錯誤的調用會變得正確,除了使用新被允許的行為,你不需要修改你的程序). Likewise, for the second case, you can just start using the new token values in the relevant functions, presuming that you have their values(同樣,對于第二種情況,如果你有這些參數的話,你可以開始在相關的API中使用新的參數). 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.(如果你在系統的頭文件里找不到的話,這些參數在擴展的文檔里)

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里的擴展,你需要在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擴展,你需要在你的shader里寫上下面這句話):

#extension GL_ABC_foobar_feature : enable

This tells the compiler that you intend to use the extension in your shader(這句話告訴編譯器,你要在shader里使用這個特性). If the compiler knows about the extension, it will let you compile the shader, even if the underlying hardware doesn’t support the feature(如果編譯器知道這個特性,即便底層硬件不支持,編譯器也可以編譯出正確的GPU程序). If this is the case, the compiler should issue a warning if it sees that the extension is actually being used(如果是這種情況的話,如果這個特性確實被shader使用了,編譯器應該發出警告). Typically, extensions to GLSL will add preprocessor tokens to indicate their presence(通常來講,GLSL的擴展會被進行預處理,從而確定他們的表現). 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(這句話就表明,你可以寫如下的代碼)

#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的實現不支持GL_ABC_foobar_feature擴展,編譯shader時將會失敗,并報出錯誤在哪里). In effect, GLSL extensions are opt-in features, and applications must tell compilers up front which extensions they intend to use(實際上GLSL擴展是具有選擇性特性的,應用程序應該告訴編譯器他們想使用什么樣的擴展)

Next we come to extensions that introduce new functions to OpenGL(接下來,我們看看那些為OpenGL添加了新函數的擴展). 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(在大多數平臺上,你無法直接訪問OpenGL的驅動,擴展函數不會那么神奇的直接就可以被你的程序訪問). Rather, you must ask the OpenGL driver for a function pointer that represents the function you want to call(更多的是,你需要找OpenGL的驅動要到你想要訪問的函數的指針). Function pointers are generally declared in two parts;(函數指針通常被定義成兩個部分) the first is the definition ofthe function pointer type, and the second is the function pointer variable itself.(第一個部分是函數的指針類型,第二個部分是函數指針本身) 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類型的函數指針,且這個函數接受一個GLenum和GLuint的參數). Next, it declares the glDrawTransformFeedback variable as an instance of this type(然后,它定義了該函數指針類型的實際的變量). In fact, on many platforms, the declaration of the glDrawTransformFeedback() function is actually just like this(實際上,在很多平臺上,就如同剛才展示的這樣,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(這看上去非常的復雜,但是幸運的是,下面的這個頭文件定義了所有的函數類型,函數指針的類型以及那些參數):

#include
#include
#include
These files can be found at the OpenGL extension registry Web site(這些可以在OpenGL擴展的網站上找到). The glext.h header contains both standard OpenGL extensions and many vendor-specific OpenGL extensions(glext.h包含了標準的OpenGL擴展和很多廠商的擴展), the wglext.h header contains a number of extensions that are Windows specific(wglext.h包含的是Windows上支持的擴展), and the glxext.h header contains definitions that are X specific (glxext.h包含的是X擴展,X指代的是Linux或者是Unix系的窗口系統)(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(查詢擴展函數的訪問地址會因平臺而異). The book’s application framework wraps up these intricacies into a handy function that is declared in the header file(本書的框架把這些方法打包進了sb7ext.h的一個函數里去了). The function sb7GetProcAddress() has this prototype(這個函數叫sb7GetProcAddress,它的定義如下):

void sb7GetProcAddress(const char funcname);
Here, funcname is the name of the extension function that you wish to use(這里funcname是擴展函數的名字). The return value is the address of the function, if it’s supported, and NULL otherwise(如果擴展被支持,那么該函數返回一個函數地址,否則返回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返回了一個合法的函數指針,那也只是一個擴展,這并不意味著擴展存在). Sometimes the same function is part of more than one extension, and sometimes vendors ship drivers with partial implementations of extensions present(有時候同樣的函數是多個擴展的一部分,也有的時候廠商只實現了擴展的一部分). Always check for support for extensions using the official mechanisms or the sb7IsExtensionSupported() function(請確保使用擴展之前來檢查擴展是否被支持).

本日的翻譯就到這里,明天見,拜拜~~

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

呼玛县| 吴桥县| 哈尔滨市| 永城市| 陇川县| 长武县| 古交市| 浏阳市| 阿拉善右旗| 安平县| 蕲春县| 金堂县| 高阳县| 新巴尔虎左旗| 鄯善县| 富裕县| 霍山县| 隆子县| 新竹市| 灌云县| 宜兴市| 安达市| 通化市| 绥中县| 新疆| 舟山市| 新密市| 柳河县| 通州区| 麻栗坡县| 蒲江县| 万安县| 屏边| 正阳县| 清水河县| 高清| 安丘市| 宜城市| 志丹县| 镇江市| 南城县|