我在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上它返回不完整的附件
OpenGL ES(无扩展)要求纹理在宽度和高度上是2的幂。检查在调用glTexImage2D()之后是否得到GL_INVALID_VALUE错误。如果你得到一个错误,那么你可能会考虑调整你的纹理大小。