将纹理转换为GL_COMPRESSED_RGBA
Convert texture to GL_COMPRESSED_RGBA
我正在寻找如何将GL_RGBA帧缓冲纹理转换为GL_COMPRESSED_RGBA纹理,最好是在 GPU 上。帧缓冲显然不能具有GL_COMPRESSED_RGBA的内部格式,因此我需要一种转换方法。
请参阅此描述 OpenGL 纹理压缩的文档。步骤的顺序就像(这很笨拙 - 整个纹理的缓冲区对象会有所改善)
GLUint mytex, myrbo, myfbo;
glGenTextures(1, &mytex);
glBindTexture(GL_TEXTURE_2D, mytex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, 0 );
glGenRenderbuffers(1, &myrbo);
glBindRenderbuffer(GL_RENDERBUFFER, myrbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, width, height)
glGenFramebuffers(1, &myfbo);
glBindFramebuffer(GL_FRAMEBUFFER, myfbo);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, myrbo);
// If you need a Z Buffer:
// create a 2nd renderbuffer for the framebuffer GL_DEPTH_ATTACHMENT
// render (i.e. create the data for the texture)
// Now get the data out of the framebuffer by requesting a compressed read
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA,
0, 0, width, height, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glDeleteRenderbuffers(1, &myrbo);
glDeleteFramebuffers(1, &myfbo);
// Validate it's compressed / read back compressed data
GLInt format = 0, compressed_size = 0;
glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
char *data = malloc(compressed_size);
glGetCompressedTexImage(GL_TEXTURE_2D, 0, data);
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTexture(1, &mytex);
// data now contains the compressed thing
如果您使用PBO对象作为纹理,则可以在没有malloc()
的情况下逃脱。
如果您想在不
传输到 CPU 的情况下在 GPU 上执行压缩 - 这里有两个示例,您可以重新用于 OpenGL(它们基于 DX)
- GPU 加速纹理压缩
- GPU 加速纹理压缩 2
希望这有帮助!
相关文章:
- 如何对存储为"Compressed Sparse Row"的矩阵进行稀疏矩阵索引?
- 保存的 Gdiplus::位图始终具有 Alpha 通道 (RGBA/ARGB)
- libPNG 读取 X,Y 处的 RGBA 直接绕过缓冲区
- libtiff读写C 中的RGBA图像
- 在DXGI格式之间转换RGBA数据
- PCL:找不到字段'rgba'的匹配项
- 使用 cuda 将通道与 RGBA 图像分离(无法显示完整图像)
- 从前期浮动RGBA转换为8位RGBA的有效方法
- 使用无法获得适当的输出将RGBA转换为YUV422格式
- 我是否需要为我的 Windows 应用创建 RGBA 以外的图标
- 实现近乎实时的CPU功能,如glAlphaFunc(GL_GREATER),具有RGB源和RGBA覆盖
- OpenCV C++:将RGBA转换为HSL,然后拆分通道
- 如何将BGRA缓冲区转换为RGBA缓冲区格式
- 用C 和RGBA像素的向量重新尺寸
- 将双rgba颜色值转换为十六进制字符
- 使用RGBA值填充C++Cinder纹理
- 开源或低成本的跨平台视频编解码器库,可用于商业目的,并支持RGBA格式
- 使用 C++ 将 RGBA 值转换为 2D 数组
- 提取并以十进制形式返回 RGBA 颜色的各个组成部分
- OpenCV 2.3:将Mat 转换为 RGBA 像素数组