问题描述
OpenGL 有许多直接接受指针的函数.其中一些从这些指针读取数据,其他将数据写入这些指针.
OpenGL has a number of functions that directly take pointers. Some of them read data from those pointers, others write data to those pointers.
然而,OpenGL 函数通常不会立即执行.通常,当您绘制某些东西时,绘制需要一段时间才能完成.
However, OpenGL functions often don't execute immediately. Usually, when you draw something, it takes a while for the drawing to finish.
那么我怎么知道 OpenGL 何时完成了我给它的指针?
So how do I know when OpenGL is finished with a pointer I give it?
推荐答案
所有 OpenGL 函数,除了下面提到的例外,都将使用您在该函数返回时提供的任何指针来完成.所以 glReadPixels
返回时将完成所有像素读取和格式转换.这就是异步像素传输对于读取操作如此重要的原因.它允许 OpenGL 不这样做,不与 GPU 同步.
All OpenGL functions, with the exception noted below, will be finished with any pointer you give it upon that function's return. So glReadPixels
will have finished all pixel reading and format conversion upon its return. This is why asynchronous pixel transfer is so important for reading operations. It allows OpenGL to not do that, to not synchronize with the GPU.
此规则的唯一例外是每个以指针"一词结尾的函数.诸如 glVertexAttribPointer
、glTexCoordPointer
之类的东西.当您将客户端内存与这些函数(在核心配置文件 OpenGL 3.2+ 中不再合法)一起使用时,这些函数会存储一个指向该内存的指针.因此,只要您打算使用这些顶点属性进行渲染,就必须确保该指针有效.
The only exception to this rule is every function that ends in the word "Pointer". Things like glVertexAttribPointer
, glTexCoordPointer
, and the like. When you use client-side memory with these functions (no longer legal in core profile OpenGL 3.2+), these functions store a pointer to that memory. Therefore, you must ensure that this pointer is valid for as long as you intend to render with those vertex attributes.
在使用客户端内存的每次渲染调用之后,OpenGL 要求实现在渲染函数返回时完成从客户端内存的读取.所以你可以调用glDrawArrays
,然后删除有问题的指针.只要您在更改这些指针之前不进行另一个绘制调用,就可以了.这意味着 OpenGL 必须在渲染调用返回时复制出所有相关的顶点数据(使用缓冲区对象更快的原因之一).
After each rendering call using client-memory, OpenGL requires that the implementation have finished reading from client memory by the time the rendering function returns. So you can call glDrawArrays
, then delete the pointers in question. And as long as you don't make another draw call until you've changed those pointers, you're fine. This means OpenGL has to have copied out all relevant vertex data by the time the rendering call returns (one of the reasons why using buffer objects is faster).
这篇关于OpenGL 什么时候完成函数中的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!