bufferData - 使用参数差异 [英] bufferData - usage parameter differences

查看:13
本文介绍了bufferData - 使用参数差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Khronos 阅读规范时,我发现:

bufferData(ulong target, Object data, ulong用法)

'usage' 参数可以是:STREAM_DRAW、STATIC_DRAW 或 DYNAMIC_DRAW

我的问题是,我应该使用哪一种?有什么优点,有什么区别?为什么我会选择使用其他的 STATIC_DRAW 来代替?

谢谢.

解决方案

对于桌面"OpenGL,这里有一个很好的解释:

http://www.opengl.org/wiki/Buffer_Object

基本上,使用参数是向 OpenGL/WebGL 提示您打算如何使用缓冲区的提示.然后 OpenGL/WebGL 可以根据您的提示优化缓冲区.

OpenGL ES docs 写了以下内容,与 OpenGL 不完全相同(请记住,WebGL 继承自 OpenGL ES):

  • 数据存储内容将被修改一次,最多使用几次.

静态

  • 数据存储内容将被修改一次并多次使用.

动态

  • 数据存储内容将被反复修改和多次使用.

访问的性质必须是:

绘图

  • 数据存储内容由应用程序修改,并用作 GL 绘图和图像规范命令的来源.

最常见的用法是 STATIC_DRAW(用于静态几何体),但我最近创建了一个小粒子系统,其中 DYNAMIC_DRAW 更有意义(粒子存储在单个缓冲区中,当粒子发射时,缓冲区的部分内容会更新).

http://jsfiddle.net/mortennobel/YHMQZ/

代码片段:

function createVertexBufferObject(){粒子缓冲区 = gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER,particleBuffer);var vertices = new Float32Array(vertexBufferSize *particleSize);gl.bufferData(gl.ARRAY_BUFFER,顶点,gl.DYNAMIC_DRAW);绑定属性();}函数发射粒子(x,y,velocityX,velocityY){gl.bindBuffer(gl.ARRAY_BUFFER,particleBuffer);//...gl.bufferSubData(gl.ARRAY_BUFFER,particleId*particleSize*sizeOfFloat,data);particleId = (particleId +1)%vertexBufferSize;}

While reading specification at Khronos, I found:

bufferData(ulong target, Object data, ulong usage) 

'usage' parameter can be: STREAM_DRAW, STATIC_DRAW or DYNAMIC_DRAW

My question is, which one should I use? What are the advantages, what are the differences? Why would I choose to use some other instead STATIC_DRAW?

Thanks.

解决方案

For 'desktop' OpenGL, there is a good explanation here:

http://www.opengl.org/wiki/Buffer_Object

Basically, usage parameter is a hint to OpenGL/WebGL on how you intend to use the buffer. The OpenGL/WebGL can then optimize the buffer depending on your hint.

The OpenGL ES docs writes the following, which is not exactly the same as for OpenGL (remember that WebGL is inherited from OpenGL ES):

STREAM

  • The data store contents will be modified once and used at most a few times.

STATIC

  • The data store contents will be modified once and used many times.

DYNAMIC

  • The data store contents will be modified repeatedly and used many times.

The nature of access must be:

DRAW

  • The data store contents are modified by the application, and used as the source for GL drawing and image specification commands.

The most common usage is STATIC_DRAW (for static geometry), but I have recently created a small particle system where DYNAMIC_DRAW makes more sense (the particles are stored in a single buffer, where parts of the buffer is updated when particles are emitted).

http://jsfiddle.net/mortennobel/YHMQZ/

Code snippet:

function createVertexBufferObject(){
    particleBuffer = gl.createBuffer();
    gl.bindBuffer(gl.ARRAY_BUFFER, particleBuffer);
    var vertices = new Float32Array(vertexBufferSize * particleSize);
    gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.DYNAMIC_DRAW);
    bindAttributes();
}

function emitParticle(x,y,velocityX, velocityY){
    gl.bindBuffer(gl.ARRAY_BUFFER, particleBuffer);
    // ...
    gl.bufferSubData(gl.ARRAY_BUFFER, particleId*particleSize*sizeOfFloat, data);
    particleId = (particleId +1 )%vertexBufferSize;
}

这篇关于bufferData - 使用参数差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆