简体   繁体   English

OpenGL 3.3:如何在传递到顶点和片段着色器之前实现解压缩纹理数据

[英]OpenGL 3.3: How implement uncompressing texture data before passing to vertex and fragment shader

I am pulling 12 bit data from a camera which is packed, so that 3 bytes define 2 consecutive pixels.我从打包的相机中提取 12 位数据,因此 3 个字节定义了 2 个连续像素。

Is there a way to decompress these into two 16 bit values before passing the data to the vertex shader for further processing?在将数据传递给顶点着色器进行进一步处理之前,有没有办法将它们解压缩为两个 16 位值?

This is the idea:这是这样的想法:

  1. Copy texture to PBO (Pixel Buffer Object):将纹理复制到 PBO(像素缓冲区对象):

  2. Now this PBO can be used by compute shader, where decompression can be performed.现在这个 PBO 可以被计算着色器使用,在那里可以执行解压缩。

  3. The result PBO can be copied back to texture.结果 PBO 可以复制回纹理。

To make this on gpu you need direct access to buffers elements, which opengl 3.3 doesn't have.要在 gpu 上进行此操作,您需要直接访问缓冲区元素,而 opengl 3.3 没有。 So you can do that only with 310es, 430 versions or vulkan.所以你只能用 310es、430 版本或 vulkan 来做到这一点。

Also it is possible to decompress image with cuda or OpenCL.也可以使用 cuda 或 OpenCL 解压缩图像。 In this case step 2 should be replaced by cuda or OpenCL routine.在这种情况下,步骤 2 应替换为 cuda 或 OpenCL 例程。

The other idea:另一个想法:

You can load texture as one component texture, and in fragment shader use texelFetch.您可以将纹理加载为一个组件纹理,并在片段着色器中使用 texelFetch。 In this case you will get the direct access to bytes of texture buffer.在这种情况下,您将直接访问纹理缓冲区的字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM