溫馨提示×

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

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Framebuffer Operations(幀緩沖區(qū)的操作)

發(fā)布時(shí)間:2020-07-15 07:32:47 來(lái)源:網(wǎng)絡(luò) 閱讀:482 作者:萌谷王 欄目:游戲開(kāi)發(fā)

周一到周五,每天一篇,北京時(shí)間早上7點(diǎn)準(zhǔn)時(shí)更新~,中英文對(duì)照,一邊學(xué)編程一邊彈吉他,做一個(gè)奇葩碼農(nóng)!

The framebuffer is the last stage of the OpenGL graphics pipeline(幀緩沖區(qū)是OpenGL圖形管線(xiàn)的最后一個(gè)階段). It can represent the visible content of the screen and a number of additional regions of memory that are used to store per-pixel values other than color(它可以表示屏幕可見(jiàn)區(qū)域的部分自己一些存儲(chǔ)里與這些像素有關(guān)的其他非顏色信息的內(nèi)存塊). On most platforms, this means the window you see on your desktop(在大多數(shù)平臺(tái)上,幀緩沖區(qū)指代的是窗口) (or possibly the whole screen if your application covers it), which is owned by the operating system (這個(gè)操作系統(tǒng)所管理的)(or windowing system to be more precise). The framebuffer provided by the windowing system is known as the default framebuffer, but it is possible to provide your own if you wish to do things like render into off-screen areas(操作系統(tǒng)所管理的幀緩沖區(qū)我們稱(chēng)之為默認(rèn)的緩沖區(qū),你也可以創(chuàng)建你自己的緩沖區(qū)用于離線(xiàn)渲染). The state held by the framebuffer includes information such as where the data produced by your fragment shader should be written, (幀緩沖區(qū)擁有的信息包括由你的fragment shader產(chǎn)生的數(shù)據(jù)應(yīng)該寫(xiě)到哪里去)what the format of that data should be, and so on(被寫(xiě)入的數(shù)據(jù)應(yīng)該是什么等等這類(lèi)的信息). This state is stored in a framebuffer object(這些信息都存儲(chǔ)在幀緩沖區(qū)里). Also considered part of the framebuffer, but not stored per framebuffer object, is the pixel operation state(像素操作階段,幀緩沖區(qū)可能只有部分進(jìn)行這個(gè)操作,而不是整個(gè)幀緩沖區(qū))

Pixel Operations(像素操作)

After the fragment shader has produced an output(在fragment shader產(chǎn)生了輸出之后), several things may happen to the fragment before it is written to the window(在像素被寫(xiě)到窗口上之前,會(huì)發(fā)生很多個(gè)操作), such as a determination of whether it even belongs in the window(比如判斷該像素是否屬于這個(gè)窗口的問(wèn)題). Each of these things may be turned on or off by your application(每一個(gè)操作都可以被你開(kāi)啟和關(guān)閉). The first thing that could happen is the scissor test, which tests your fragment against a rectangle that you can define(第一個(gè)事情就是scissor測(cè)試,你可以定義一個(gè)矩形來(lái)測(cè)試的你像素). If it’s inside the rectangle, then it will be processed further; if it’s outside, it will be thrown away(如果這個(gè)像素在矩形里面,那么這個(gè)矩形就會(huì)被傳輸給下一個(gè)階段進(jìn)行處理,否則會(huì)被丟棄)

Next comes the stencil test. This compares a reference value provided by your application with the contents of the stencil buffer, which stores a single4 value per pixel(下一個(gè)階段就是蒙版測(cè)試,它會(huì)根據(jù)你蒙版緩沖區(qū)里的值來(lái)進(jìn)行處理). The content of the stencil buffer has no particular semantic meaning and can be used for any purpose(蒙版測(cè)試是一個(gè)通用的操作,可以被用于任何事情)

After the stencil test has been performed, the depth test is performed. The depth test is an operation that compares the fragment’s z coordinate against the contents of the depth buffer(蒙版測(cè)試之后就輪到深度測(cè)試了,深度測(cè)試測(cè)試的是你當(dāng)前繪制的像素是否被遮擋的問(wèn)題). The depth buffer is a region of memory that, like the stencil buffer, is part of the framebuffer with enough space for a single value for each pixel; it contains the depth (which is related to distance from the viewer) of each pixel(深度緩沖器存儲(chǔ)著每個(gè)像素對(duì)應(yīng)的深度信息)

Normally, the values in the depth buffer range from 0 to 1, with 0 being the closest possible point in the depth buffer and 1 being the furthest possible point in the depth buffer(一般來(lái)說(shuō),深度的信息范圍是0~1,0表示離你最近的深度,1表示離你最遠(yuǎn)的深度). To determine whether a fragment is closer than other fragments that have already been rendered in the same place(為了判斷某一個(gè)像素比同一個(gè)位置的其他像素離你是否更近), OpenGL can compare the z component of the fragment’s window-space coordinate against the value already in the depth buffer(OpenGL會(huì)拿當(dāng)前像素的z的值與深度緩沖區(qū)上的z的值進(jìn)行比較). If this value is less than what’s already there, then the fragment is visible. The sense of this test can also be changed(如果當(dāng)前像素的深度值比深度緩沖區(qū)上的z的值小,則該像素可見(jiàn),否則不可見(jiàn)). For example, you can ask OpenGL to let fragments through that have a z coordinate that is greater than, equal to, or not equal to the content of the depth buffer(比如你當(dāng)前渲染的像素的z的值比深度緩沖區(qū)里的對(duì)應(yīng)的z的值大,那么當(dāng)前像素則不會(huì)被寫(xiě)入當(dāng)前的顏色緩沖區(qū)里去). The result of the depth test also affects what OpenGL does to the stencil buffer(深度測(cè)試的結(jié)果也會(huì)影響到蒙版緩沖區(qū)里的內(nèi)容).

Next, the fragment’s color is sent to either the blending or logical operation stage(接下來(lái)像素顏色被發(fā)送給混合或者是alpha邏輯操作的階段), depending on whether the framebuffer is considered to store floating-point, normalized, or integer values(這取決于幀緩沖區(qū)里存儲(chǔ)的數(shù)據(jù)是浮點(diǎn)數(shù)據(jù)還是單位化的數(shù)據(jù)還是整數(shù)). If the content of the framebuffer is either floating-point or normalized integer values, then blending is applied(如果幀緩沖區(qū)的數(shù)據(jù)格式是浮點(diǎn)數(shù)或者是單位化的整數(shù),那么下一個(gè)階段就是混合了). Blending is a highly configurable stage in OpenGL and will be covered in detail in its own section.(混合是一個(gè)非常具備可操作性的階段,所以我們將在它自己的章節(jié)詳細(xì)展開(kāi)講解)

In short, OpenGL is capable of using a wide range of functions that take components of the output of your fragment shader and of the current content of the framebuffer and calculate new values that are written back to the framebuffer(簡(jiǎn)單來(lái)說(shuō),OpenGL可以通過(guò)一大堆函數(shù)來(lái)操作你fragment shader輸出的內(nèi)容與幀緩沖區(qū)的內(nèi)容,并且計(jì)算出新的數(shù)據(jù)最終寫(xiě)回幀緩沖區(qū)). If the framebuffer contains unnormalized integer values(如果幀緩沖區(qū)里是沒(méi)有單位化的整型數(shù)據(jù)), then logical operations such as logical AND, OR, and XOR can be applied to the output of your shader and the value currently in the framebuffer to produce a new value that will be written back into the framebuffer(那么下一個(gè)處理階段就是邏輯操作了,使用and、or、XOR來(lái)操作當(dāng)前像素與幀緩沖區(qū)里的數(shù)據(jù),并最終將結(jié)果寫(xiě)回幀緩沖區(qū))

本日的翻譯就到這里,明天見(jiàn),拜拜~~

第一時(shí)間獲取最新橋段,請(qǐng)關(guān)注東漢書(shū)院以及圖形之心公眾號(hào)

東漢書(shū)院,等你來(lái)玩哦

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI