无法在Android SDK模拟器设备上初始化FBO

时间:2013-02-18 14:42:48

标签: android android-emulator android-ndk opengl-es-2.0

这就是FBO的初始化方式:

/**
 * Initializes Renderbuffer.
 */
static GLuint init_renderbuffer(GLuint width, GLuint height, GLenum format) {
    GLuint renderbuffer;

    glGenRenderbuffers(1, &renderbuffer);
    checkGlError("init_renderbuffer: glGenRenderbuffers");

    glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
    checkGlError("init_renderbuffer: glBindRenderbuffer");

    glRenderbufferStorage(GL_RENDERBUFFER, format, width, height);
    checkGlError("init_renderbuffer: glRenderbufferStorage");

    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    checkGlError("init_renderbuffer: glBindRenderbuffer");

    return renderbuffer;
}

/**
 * Initializes FBO.
 */
static void engine_init_fbo(struct engine* engine, GLuint width, GLuint height) {
    // create renderable texture
    glGenTextures(1, &engine->renderableTexture);
    checkGlError("engine_init_fbo: glGenTextures");

    glBindTexture(GL_TEXTURE_2D, engine->renderableTexture);
    checkGlError("engine_init_fbo: glBindTexture");

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0);
    checkGlError("engine_init_fbo: glTexImage2D");

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    checkGlError("engine_init_fbo: glTexParameteri");

    // create render buffers
    engine->depthRenderBuffer   = init_renderbuffer(width, height, GL_DEPTH_COMPONENT16);
    engine->stencilRenderBuffer = init_renderbuffer(width, height, GL_STENCIL_INDEX8);

    LOGI("****************************** FBO: T: %d, D: %d, S: %d", engine->renderableTexture,
         engine->depthRenderBuffer, engine->stencilRenderBuffer);

    // create framebuffer object
    glGenFramebuffers(1, &engine->framebufferObject);
    checkGlError("engine_init_fbo: glGenFramebuffers");

    glBindFramebuffer(GL_FRAMEBUFFER, engine->framebufferObject);
    checkGlError("engine_init_fbo: glBindFramebuffer");

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, engine->renderableTexture, 0);
    checkGlError("engine_init_fbo: glFramebufferTexture2D");

    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, engine->depthRenderBuffer);
    checkGlError("engine_init_fbo: glFramebufferRenderbuffer");

    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, engine->stencilRenderBuffer);
    checkGlError("engine_init_fbo: glFramebufferRenderbuffer");

    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    checkGlError("engine_init_fbo: glCheckFramebufferStatus");

    if(status != GL_FRAMEBUFFER_COMPLETE) {
        switch(status) {
            case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
                LOGI("****************************** engine_init_fbo: FBO error: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
                break;

            case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
                LOGI("****************************** engine_init_fbo: FBO error: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
                break;

            case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
                LOGI("****************************** engine_init_fbo: FBO error: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
                break;

            case GL_FRAMEBUFFER_UNSUPPORTED:
                LOGI("****************************** engine_init_fbo: FBO error: FRAMEBUFFER_UNSUPPORTED");
                break;

            default:
                LOGI("****************************** engine_init_fbo: Unknown FBO error");
        }
    }
    else {
        LOGI("****************************** engine_init_fbo: FBO has been successfully initialized");
    }

    glBindTexture(GL_TEXTURE_2D, 0);
    checkGlError("engine_init_fbo: glBindTexture");

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    checkGlError("engine_init_fbo: glBindFramebuffer");
}

正如您所看到的,这里的所有内容都是根据OpenGL ES标准完成的:使用RGB565内部格式的2D纹理作为颜色; 2个渲染缓冲区用作深度和模板表面;尺寸为32x32。

它在真实设备上工作正常(Alcatel OT 918D,在adb logcat中打印“FBO已成功初始化”),但在虚拟设备上失败并显示FRAMEBUFFER_UNSUPPORTED。

我的虚拟设备的CPU是原子,启用了GPU仿真,OpenGL ES 2.0工作正常 - 使用其他应用程序(不使用FBO)进行检查。

整个项目(基于来自NDK的本机活动样本),可以使用ndk-build编译,在这里: https://docs.google.com/file/d/0Byy41LxMuTKUZVJxSUtBZDVDXzA/edit?usp=sharing

我的问题是:这是android-sdk模拟器中的错误吗?因为一切似乎都符合OpenGL ES 2.0实现的最低要求。

谢谢!

编辑: 找到了解决方案。看来,AVD不支持附加对象的这种配置。我不得不删除模板附件以使其工作。

EDIT2: 它似乎是上下文创建问题。我不需要模板位,所以可能AVD创建了没有模板支持的上下文,以及阿尔卡特手机 - 带有模板。

无论如何,这不是一个错误,而是我的错误。

0 个答案:

没有答案