OpenGL 何时完成函数中的指针?

When does OpenGL get finished with pointers in functions?(OpenGL 何时完成函数中的指针?)

本文介绍了OpenGL 何时完成函数中的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

此规则的唯一例外是每个以单词Pointer"结尾的函数.glVertexAttribPointerglTexCoordPointer 之类的东西.当您将客户端内存与这些函数一起使用时(在核心配置文件 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 何时完成函数中的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:OpenGL 何时完成函数中的指针?

基础教程推荐