周一到周五,每天一篇,北京時間早上7點準(zhǔn)時更新~
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供襄城網(wǎng)站建設(shè)、襄城做網(wǎng)站、襄城網(wǎng)站設(shè)計、襄城網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、襄城企業(yè)網(wǎng)站模板建站服務(wù),十年襄城做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。After allocating storage space for your buffer object using glBufferStorage(), one possible next step is to fill the buffer with known data. Whether you use the initial data parameter of glBufferStorage(), use glBufferSubData() to put the initial data in the buffer, or use glMapBufferRange() to obtain a pointer to the buffer’s data store and fill it with your application, you will need to get the buffer into a known state before you can use it productively. If the data you want to put into a buffer is a constant value, it is probably much more efficient to call glClearBufferSubData() or glClearNamedBufferSubData(), whose prototypes are
在緩沖區(qū)對象分配好了內(nèi)存后,下一步可能就輪到給給內(nèi)存填充數(shù)據(jù)了。你可以在分配內(nèi)存的同時為緩沖區(qū)填充數(shù)據(jù),也可以使用glBufferSubData或者glMapBufferRange在緩沖區(qū)內(nèi)存分配好之后 為緩沖區(qū)填充數(shù)據(jù)。在你使用buffer之前,你需要把buffer置于一個已知的狀態(tài)。如果你想往緩沖區(qū)里刷入常數(shù),那么你可以使用glClearBufferSubData或者glClearNamedBufferSubData來高效的做這事。
void glClearBufferSubData(GLenum target,
GLenum internalformat,
GLintptr offset,
GLsizeiptr size,
GLenum format,
GLenum type,
const void data);
void glClearNamedBuffeSubData(GLuint buffer,
GLenum internalformat,
GLintptr offset,
GLsizeiptr size,
GLenum format,
GLenum type,
const void data);
These functions take a pointer to a variable containing the values that you want to clear the buffer object to and, after converting it to the format specified in internalformat, replicate the data across the range of the buffer’s data store specified by offset and size, both of which are measured in bytes. format and type tell OpenGL about the data pointed to by data. The format can be one of GL_RED, GL_RG, GL_RGB, or GL_RGBA to specify one-, two-, three-, or four-channel data, for example. Meanwhile, type should represent the data type of the components. For instance, it could be GL_UNSIGNED_BYTE or GL_FLOAT to specify unsigned bytes or floating-point data, respectively. The most common types supported by OpenGL and their corresponding C data types are listed in Table 5.3.
這些函數(shù)使用data指針指向位置的數(shù)據(jù)去刷新緩沖區(qū)的內(nèi)存,數(shù)據(jù)會被轉(zhuǎn)化成internalformat的格式,數(shù)據(jù)刷新的多少由offset和size指定,數(shù)據(jù)大小的單位為字節(jié)。 format和type告訴OpenGL,data指針指向的數(shù)據(jù)的格式,format的值可以是GGL_RED, GL_RG, GL_RGB,或者 GL_RGBA,用來標(biāo)記數(shù)據(jù)是1、2、3、4通道的數(shù)據(jù)。type這里指定的是每個通道是什么格式。 比如,它可能是GL_UNSIGNED_BYTE或者GL_FLOAT。比較常見的類型在表5.3里展示出來了
Once your data has been sent to the GPU, it’s entirely possible you may want to share that data between buffers or copy the results from one buffer into another. OpenGL provides an easy-to-use way of doing that. glCopyBufferSubData() and glCopyNamedBufferSubData() let you specify which buffers are involved as well as the size and offsets to use.
當(dāng)你把數(shù)據(jù)發(fā)送給GPU后,你可能希望與其他buffer共享數(shù)據(jù)或者是從一個buffer拷貝數(shù)據(jù)到另一個buffer。OpenGL提供的對應(yīng)的API是 glCopyBufferSubData和glCopyNamedBufferSubData,他們的定義如下
void glCopyBufferSubData(GLenum readtarget,
GLenum writetarget,
GLintptr readoffset,
GLintptr writeoffset,
GLsizeiptr size);
void glCopyNamedBufferSubData(GLuint readBuffer,
GLuint writeBuffer,
GLintptr readOffset,
GLintptr writeOffset,
GLsizeiptr size);
For glCopyBufferSubData(), the readtarget and writetarget are the targets where the two buffers you want to copy data between are bound. They can be buffers bound to any of the available buffer binding points. However, since buffer binding points can have only one buffer bound at a time, you couldn’t copy between two buffers that are both bound to the GL_ARRAY_BUFFER target, for example. Thus, when you perform the copy, you need to pick two targets to bind the buffers to, which will disturb the OpenGL state.
glCopyBufferSubData的數(shù)據(jù)讀取地址和數(shù)據(jù)寫入地址只某個綁定的節(jié)點而不是buffer對象本身的標(biāo)記。然而每個特定的綁定節(jié)點只能綁定一個buffer,所以你無法將兩個都綁定在GL_ARRAY_BUFFER 上的buffer進行數(shù)據(jù)拷貝。所以,在你要拷貝的時候,你需要將buffer綁定到兩個綁定節(jié)點上去,然后執(zhí)行拷貝操作,這實際上會擾亂OpenGL狀態(tài)機
To resolve this, OpenGL provides the GL_COPY_READ_BUFFER and GL_COPY_WRITE_BUFFER targets. These targets were added specifically to allow you to copy data from one buffer to another without any unintended side effects. Because they are not used for anything else in OpenGL, you can bind your read and write buffers to these binding points without affecting any other buffer target.
為了實現(xiàn)這一目標(biāo),OpenGL提供兩個專門的綁定節(jié)點,GL_COPY_READ_BUFFER和GL_COPY_WRITE_BUFFER,這倆節(jié)點能執(zhí)行buffer間的數(shù)據(jù)拷貝,并且沒有什么副作用。 因為這倆貨除了具備拷貝功能以外不會有其他功能,所以你執(zhí)行buffer間拷貝的時候,改變這倆個節(jié)點的狀態(tài)不會影響到其他的OpenGL的邏輯。
Alternatively, you can use the glCopyNamedBufferSubData() form, which takes the names of the two buffers directly. Of course, you can specify the same buffer for both readBuffer and writeBuffer to copy a region of data between two offsets in the same buffer object. Be careful that the regions to be copied don’t overlap, though, as in this case the results of the copy are undefined. You can consider glCopyNamedBufferSubData() as a form of the C function memcpy for buffer objects.
同樣的,你可以使用第二個glCopyNamedBufferSubData,直接傳入寫數(shù)據(jù)的地址和讀數(shù)據(jù)的地址。你同樣可以指定寫入和讀取的是同一個buffer,并在buffer內(nèi)的不同區(qū)域內(nèi)進行數(shù)據(jù)的拷貝。你可以把這個函數(shù)想象成為memcpy
The readoffset and writeoffset parameters tell OpenGL where in the source and destination buffers to read or write the data, and the size parameter tells it how big the copy should be. Be sure that the ranges you are reading from and writing to remain within the bounds of the buffers; otherwise, your copy will fail. You may notice the types of readoffset, writeoffset, and size, which are GLintptr and GLsizeiptr. These types are special definitions of integer types that are at least wide enough to hold a pointer variable
readoffset和writeoffset告訴OpenGL讀地址和寫地址的數(shù)據(jù)偏移位置。size告訴OpenGL拷貝數(shù)據(jù)的大小。你必須保證別越界了,否則你的拷貝會失敗。 你可能注意到了GLintptr和GLsizeiptr,這些數(shù)據(jù)都是整型的數(shù)據(jù),它們對于標(biāo)記指針的地址來說已經(jīng)足夠大了。
本日的翻譯就到這里,明天見,拜拜~~
第一時間獲取最新橋段,請關(guān)注東漢書院以及圖形之心公眾號
東漢書院,等你來玩哦
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)站標(biāo)題:FillingandCopyingDatainBuffers-創(chuàng)新互聯(lián)
文章URL:http://m.newbst.com/article32/dshppc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、企業(yè)網(wǎng)站制作、移動網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、微信小程序、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容