WebGL.是否在GPU中创建缓冲区? [英] WebGL. Is it creating a buffer in GPU?

查看:211
本文介绍了WebGL.是否在GPU中创建缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找有关实时绘制相当大的数据流的决定.我想通过GPU处理它,以减少内存成本.

Looking for a decision about a realtime plotting of rather a large data stream. I would like to process it via a GPU to reduce memory costs.

我找到了一个WebGL示例:

I have found a WebGL example:

// Fill the buffer with the values that define a triangle.
function setGeometry(gl) {
  gl.bufferData(
      gl.ARRAY_BUFFER,
      new Float32Array([
             0, -100,
           150,  125,
          -175,  100]),
      gl.STATIC_DRAW);
}

并想澄清一些事情:

  • gl.ARRAY_BUFFER是否在GPU内而不是RAM内创建缓冲区?

  • Does gl.ARRAY_BUFFER create a buffer inside a GPU, not inside a RAM?

WebGL在Linux上稳定吗?

Is WebGL stable on linux?

更新: 也想弄清楚,是否有可能仅通过索引更新gl缓冲区的一部分.

UPDATE: also would like to clarify, if it is possible to update only a part of the gl buffer by index.

推荐答案

gl.createBuffergl.bufferData为WebGL创建缓冲区.它们是否在GPU上取决于平台和浏览器. AFAIK所有Intel GPU将顶点数据与其他CPU数据存储在同一内存中.另外,某些WebGL实现也可能在CPU ram中存储缓冲区的副本,因此实际上没有办法知道.

gl.createBuffer and gl.bufferData create buffers for WebGL. Whether those are on the GPU or not is up to the platform and browser. AFAIK All Intel GPUs store vertex data in the same memory as other CPU data. Also some WebGL implementations might store copies of buffers in CPU ram as well so there's really no way to know.

gl.bufferData设置缓冲区的大小并将数据放入其中.

gl.bufferData sets the size of a buffer and puts data in it.

// create buffer
const buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);

// set it's size to size of data and copy data into it
const data = new Uint8Array([1, 2, 3, 4, 5]);
gl.bufferData(g.ARRAY_BUFFER, data, gl.STATIC_DATA);

您不希望将数据放入其中,而是使用大小而不是TypedArray

You don't want to put data in it pass in a size instead of an TypedArray

// create buffer
const buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);

// set it's size to 1024 bytes
gl.bufferData(g.ARRAY_BUFFER, 1024, gl.STATIC_DATA);

之后,您可以使用gl.bufferSubData一次一次将数据放入其中.例子

After that you can put data in it a little at a time with gl.bufferSubData. Example

const offset = 100;
gl.bufferSubData(gl.ARRAY_BUFFER, offset, someTypedArray);

someTypedArray就是 TypedArray 喜欢

const someTypedArray = new Uint8Array(45);

在这种情况下,缓冲区中的字节100到144将使用someTypedArray

In which case the buffer would have bytes 100 to 144 get updated with the contents of someTypedArray

或者,如果您想使用TypedArray的一部分,则可以创建视图

Or if you want to use a part of an TypedArray then you can make view

const someTypedArray = new Uint8Array(1024);

...

const bufferOffset = 200;
cconstonst bufferLength = 50;
var someOtherTypedArray = new Uint8Array(
       someTypedArray.buffer, 
       someTypedArray.byteOffset + bufferOffset,
       bufferLength);

这使someOtherTypedArray成为someTypedArray的视图,该视图从200个字节开始到someTypedArray,长度为50个字节.

That makes someOtherTypedArray a view into someTypedArray that starts 200 bytes into someTypedArray and is 50 bytes long.

这篇关于WebGL.是否在GPU中创建缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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