1

我听说顶点着色器使用 OpenGL 3.x(使用 TexelFetch 方法)访问用户自己的缓冲区数据(纹理缓冲区对象)

所以最近我尝试在 IOS7 的 OpenglES 3.0 顶点着色器上应用 TPB 技术,但我无法使用 TBO bcz OpenGLES 3.0 无法提供它。

我的顶点着色器必须访问 TBO 并使用它的数据,例如速度、位置和力。

我想在 OpenglES 3.0 上使用类似的 TBO techinc。

如果我使用像素缓冲区对象,我可以在着色器上使用“texelFetch()”方法访问它们吗?

我怎样才能弄清楚我的工作?有人知道什么好方法吗?

4

1 回答 1

0

I don't believe you can sample directly from a Pixel Buffer Object.

One obvious option is to use a regular texture instead of a Texture Buffer Object. The maximum texture size of ES 3.0 compatible iOS devices is 4096 (source: https://developer.apple.com/library/iOS/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/OpenGLESPlatforms/OpenGLESPlatforms.html). There are a few sub-cases depending on how big your data is. With n being the number of texels:

  • If n is at most 4096, you can store it in a 2D texture that has size n x 1.
  • If n is more than 4096, you can store it in a 2D texture of size 4096 x ((n + 4095) / 4096).

In both cases, you can still use texelFetch() to get the data from the texture. In the first case, you sample (i, 0) to get value i. In the second case, you sample (i % 4096, i / 4096).

If you already have the data in a buffer, you can store it the texture by binding the buffer as GL_PIXEL_UNPACK_BUFFER before calling glTexImage2D(), which will then source the data from the buffer.

Another option to consider are Uniform Buffer Objects. This allows you to bind the content of a buffer to a uniform block, which then gives you access to the values in the shader. Look up glBindBuffer(), glBindBufferBase(), glBindBufferRange() with the GL_UNIFORM_BUFFER target for details. The maximum size of a uniform block in bytes is given by GL_MAX_UNIFORM_BLOCK_SIZE, and is 16,384 on iOS/A7 devices.

于 2014-09-17T08:06:22.713 回答