opengl es 2.0 c++ 中的 glDrawBuffers
glDrawBuffers in opengl es 2.0 c++
我正在将代码从 Windows 移植到 Android,Opengl ES 2.0 中不存在一些 GL 方法。
目的是将所有渲染到将使用特定着色器渲染的纹理。
第一行:
Windows版本
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);
ES 2.0版本?我不确定
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0, 0);
第二行:
windows版本
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);
而不是 OpenGL ES 2.0 中的 glFramebufferTexture
in (desktop) OpenGL, it can be used glFramebufferTexture2D
。
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 版本相似。
进一步注意,为了满足帧缓冲区完整性的规则,附加图像的内部格式必须是 Color-renderable 格式。
有关详细信息,请参阅 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.
我正在将代码从 Windows 移植到 Android,Opengl ES 2.0 中不存在一些 GL 方法。
目的是将所有渲染到将使用特定着色器渲染的纹理。
第一行:
Windows版本
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);
ES 2.0版本?我不确定
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0, 0);
第二行:
windows版本
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);
而不是 OpenGL ES 2.0 中的 glFramebufferTexture
in (desktop) OpenGL, it can be used glFramebufferTexture2D
。
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 版本相似。
进一步注意,为了满足帧缓冲区完整性的规则,附加图像的内部格式必须是 Color-renderable 格式。
有关详细信息,请参阅 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.