c++ - opengl es 2.0 c++ 中的 glDrawBuffers

标签 c++ opengl-es

我正在将代码从 Windows 移植到 Android,但 Opengl ES 2.0 中不存在一些 GL 方法。

目的是将所有渲染到将使用特定着色器渲染的纹理。

第一行:

window 版本

glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);

ES 2.0 版本?我不确定

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0, 0);

第二行:

window 版

GLenum DrawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, DrawBuffers);

ES 2.0 版本 ?

缺失

代码:

glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);

glGenTextures(1, &renderedTexture);

glBindTexture(GL_TEXTURE_2D, renderedTexture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 768, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);

GLenum DrawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, DrawBuffers);

编辑:

调整后,应用程序运行但崩溃,logcat 显示:

D/libGLESv2: DTS_GLAPI : DTS is not allowed for Package : xxx.xxx 

和声明:

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)

是真的

当前代码是:

glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);

glGenTextures(1, &renderedTexture);

glBindTexture(GL_TEXTURE_2D, renderedTexture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 768, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0, 0);

最佳答案

而不是 glFramebufferTexture在(桌面)OpenGL 中,可以使用 glFramebufferTexture2D在 OpenGL ES 2.0 中。
glFramebufferTexture2D 的第三个参数是纹理目标,在您的例子中是 GL_TEXTURE_2D:

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0, 0);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 
                       GL_TEXTURE_2D, renderedTexture, 0); 


将调用转移到 glDrawBuffers没有必要,因为在初始状态下,片段颜色零的绘制缓冲区是 COLOR_ATTACHMENT0,而在 OpenGL ES 2.0 中,唯一可能的颜色附件是 COLOR_ATTACHMENT0
在 OpenGL ES 3.0 中,此行为发生变化,并且与您正在使用的(桌面)OpenGL 版本相似。


进一步注意,为了满足帧缓冲区完整性的规则,附加图像的内部格式必须是可渲染格式。

有关详细信息,请参阅 OpenGL ES 2.0 Full Specification - 4.4.5 帧缓冲区完整性(第 117/118 页)。

The framebuffer object target is said to be framebuffer complete if it is the window-system-provided framebuffer, or if all the following conditons are true:

[...]

  • The combination of internal formats of the attached images does not violate an implementation-dependent set of restrictions.

关于c++ - opengl es 2.0 c++ 中的 glDrawBuffers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54826074/

相关文章:

iphone - 我应该为 OpenGL ES 中的纹理坐标使用什么数据类型?

ios - opengles在iphone中显示人脸

c++ - 如何在 beast 1.7 中打印 http 消息

c++ - 使用 MATlab 访问投影仪

c++ - 通过电线登录?

c++ - 在 VS2015 中使用平台工具设置 "Microsoft CodeGen v140_clang_c2"进行编译时,包括 <functional> 和 <memory> header 会导致错误

c++ - 30fps 的大型点云数据渲染查看器

opengl-es - opengl 1.1 渲染缓冲区生成只有 960px 而不是 1136px 宽度

java - 在 GLSL 片段着色器中将 YUV (yCbCr420p) 转换为 RGB?

android - OpenGL es,在生成和渲染 MIP 贴图时控制 VM 使用