2

我的 Nexus 7 上的 OpenGL ES 1.0 渲染引擎出现问题 - 我正在尝试创建帧缓冲区,但它总是返回GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES,代码如下所示:

#ifdef __ANDROID__
glGenFramebuffersOES(1, &gameSurfaceFrameBuffer);   
#else
glGenFramebuffers(1, &gameSurfaceFrameBuffer);
#endif

#ifdef __ANDROID__
glBindFramebufferOES(GL_FRAMEBUFFER_OES, gameSurfaceFrameBuffer);
#else
glBindFramebuffer(GL_FRAMEBUFFER, gameSurfaceFrameBuffer);
#endif

glGenTextures(1, &gameSurfaceTexture);
glBindTexture(GL_TEXTURE_2D, gameSurfaceTexture);

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

glTexImage2D(GL_TEXTURE_2D, 0, 4, 48 * 14, 48 * 12, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

#ifdef __ANDROID__
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, gameSurfaceTexture, 0);
#else
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,    gameSurfaceTexture, 0);
#endif

#ifdef __ANDROID__
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
#else
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
#endif

#ifdef __ANDROID__
if(status != GL_FRAMEBUFFER_COMPLETE_OES){
#else
if(status != GL_FRAMEBUFFER_COMPLETE){
#endif
std::stringstream ss;
ss << "gameSurfaceFrameBuffer, status != GL_FRAMEBUFFER_COMPLETE ";
ss << "status = " << status;
throw ss.str();
}
}

如您所见,我有适用于 Android 和普通 OpenGL 的代码 - 该代码在 Windows 上运行良好,但在 Android 上它返回不完整的附件。

4

1 回答 1

0

OpenGL ES(没有扩展)要求纹理的宽度和高度是 2 的幂。检查 glTexImage2D() 调用后是否收到 GL_INVALID_VALUE 错误。如果您遇到错误,那么您可能会考虑调整纹理的大小。

于 2013-01-20T22:31:10.467 回答