8

我很困惑。要在 Windows 上使用 OpenGL 1.x 中的帧缓冲区对象扩展 (FBO),我应该使用哪些?:

wglGetProcAddress("glGenFramebuffers");
// or
wglGetProcAddress("glGenFramebuffersEXT");

据我从使用不同硬件的用户的报告中可以看出,一些驱动程序不支持任何一种、两者之一或两者的所有组合。

哪个是正确的使用?某些驱动程序真的支持其中一个而不支持另一个吗?如果找不到,尝试从一个退回到另一个是否正确?


编辑: 我仍然对 ATI Radeon 卡和围绕此的代码有严重的问题。我们刚刚使用此代码 (www.scirra.com) 推出了一个商业编辑器。似乎无论我使用什么代码组合来使用 FBO,一些不同的用户组合都报告说他们根本看不到任何东西(即没有渲染)。

这是我检测是否使用 ARB 函数(无后缀)或 EXT 后缀函数的代码。这在启动时运行:

gl_extensions = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
gl_vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
gl_renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
gl_version = reinterpret_cast<const char*>(glGetString(GL_VERSION));
gl_shading_language = reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION));

// If OpenGL version >= 3, framebuffer objects are core - enable regardless of extension
// (the flags are initialised to false)
if (atof(gl_version) >= 3.0)
{
    support_framebuffer_object = true;
    support_framebuffer_via_ext = false;
}
else
{
    // Detect framebuffer object support via ARB (for OpenGL version < 3) - also uses non-EXT names
    if (strstr(gl_extensions, "ARB_framebuffer_object") != 0)
    {
        support_framebuffer_object = true;
        support_framebuffer_via_ext = false;
    }
    // Detect framebuffer object support via EXT (for OpenGL version < 3) - uses the EXT names
    else if (strstr(gl_extensions, "EXT_framebuffer_object") != 0)
    {
        support_framebuffer_object = true;
        support_framebuffer_via_ext = true;
    }
}

然后稍后在启动期间它会创建一个 FBO 以预期渲染到纹理:

// Render-to-texture support: create a frame buffer object (FBO)
if (support_framebuffer_object)
{
    // If support is via EXT (OpenGL version < 3), add the EXT suffix; otherwise functions are core (OpenGL version >= 3)
    // or ARB without the EXT suffix, so just get the functions on their own.
    std::string suffix = (support_framebuffer_via_ext ? "EXT" : "");

    glGenFramebuffers = (glGenFramebuffers_t)wglGetProcAddress((std::string("glGenFramebuffers") + suffix).c_str());
    glDeleteFramebuffers = (glDeleteFramebuffers_t)wglGetProcAddress((std::string("glDeleteFramebuffers") + suffix).c_str());
    glBindFramebuffer = (glBindFramebuffer_t)wglGetProcAddress((std::string("glBindFramebuffer") + suffix).c_str());
    glFramebufferTexture2D = (glFramebufferTexture2D_t)wglGetProcAddress((std::string("glFramebufferTexture2D") + suffix).c_str());
    glCheckFramebufferStatus = (glCheckFramebufferStatus_t)wglGetProcAddress((std::string("glCheckFramebufferStatus") + suffix).c_str());
    glGenerateMipmap = (glGenerateMipmap_t)wglGetProcAddress((std::string("glGenerateMipmap") + suffix).c_str());

    // Create a FBO in anticipation of render-to-texture
    glGenFramebuffers(1, &fbo);
}

我经历了这段代码的许多变体,我根本无法让它适用于所有人。总有一群用户报告根本没有渲染。ATI Radeon HD 卡似乎特别成问题。我不确定是否涉及驱动程序错误,但我想我上面的代码更有可能做出了不正确的假设。

500 代表赏金,​​我将向任何知道出了什么问题的人发送免费的营业执照!(价值 99 英镑)


编辑2:更多细节。以下是已知会失败的卡列表:

ATI 移动 Radeon HD 5650

ATI Radeon X1600 Pro

ATI 移动 Radeon HD 4200

实际上没有渲染到纹理。看来glGenFramebuffers仅调用就完全停止了在这些卡上的渲染。我可以将 FBO 的创建推迟到第一次实际完成渲染到纹理时,但随后大概它会再次停止渲染。

我可以使用 GLEW,但我的代码没有做什么?我查看了源代码,它似乎使用了类似的wglGetProcAddress. 在我的情况下,方法正在返回,否则glGenFramebuffers将为 NULL 并崩溃。有任何想法吗...?

4

2 回答 2

10

如果存在扩展名GL_EXT_framebuffer_object,那么您可以使用wglGetProcAddress("glGenFramebuffersEXT");.

如果 OpenGL 版本 >= 3.0(在此版本中,FBO 扩展已添加到核心),那么您可以使用wglGetProcAddress("glGenFramebuffers");.

于 2011-08-02T13:45:54.697 回答
4

您包含的代码不是问题。当然,绑定点应该和你已经做的一样。

在支持ARB_framebuffer_object的情况下,使用不带EXT后缀的入口点。在支持EXT_framebuffer_object的情况下,使用带有EXT后缀的入口点。如果两者都受支持,您可以通过获取正确的绑定点来选择实现。

我对这个问题非常感兴趣(因为我有类似的疑问,因为你)。

如果您将ARB规范与EXT规范进行比较,您会发现很多差异。

在这里,我将引用关于这个主题的最有趣的ARB规范段落。

规范很长,但ARB变体包含许多关于EXT兼容性问题的讨论。由于您正在运行应用程序,因此入口点可能是正确的,并且错误(如 Nicolas Bolas 所建议)可能在帧缓冲区完整性中。

介绍所有可能的检查,并仔细检查两次实施(一次考虑ARB规范,一次考虑EXT规范)。


此扩展在 EXT_framebuffer_object 上包含哪些附加功能?

   Currently we incorporate the following layered extensions:

     * EXT_framebuffer_multisample
     * EXT_framebuffer_blit
     * EXT_packed_depth_stencil

以及以下功能:

     * Permit attachments with different width and height (mixed
       dimensions)

     * Permit color attachments with different formats (mixed
       formats).

     * Render to 1 and 2 component R/RG formats that are provided
       via the ARB_texture_rg extension. L/A/LA/I will be
       left for a separate (trivial) extension.

     * Gen'ed names must be used for framebuffer objects and
       renderbuffers.

     * Added FramebufferTextureLayer.
  ...

与 EXT_framebuffer_object 的其他区别是什么?

     * Framebuffer completeness only considers the attachments named
       by DRAW_BUFFERi and READ_BUFFER.  Any other attachments do
       not affect framebuffer completeness.  (In
       EXT_framebuffer_object, all attachments affected framebuffer
       completeness, independent of the DRAW_BUFFERi and READ_BUFFER
       state.)
     * Added new queries for the sizes of the bit planes for color, 
       depth and stencil attachments at a framebuffer attachment point.
     * Added new queries for framebuffer attachment component type and
       color encoding.
     * Many other minor tweaks to synchronize with the GL3 framebuffer
       objects.
     * ARB FBOs are not shareable.

此扩展和 EXT_framebuffer_object 都具有“绑定帧缓冲区”功能(BindFramebuffer 和 BindFramebufferEXT)。这两个函数在功能上有什么区别吗?

    RESOLVED: Yes. Both extensions will create a new framebuffer object
    if called with an unused name. However, BindFramebuffer defined in
    this extension will generate an INVALID_OPERATION error if the name
    provided has not been generated by GenFramebuffer. That error did
    not exist in EXT_framebuffer_object, and this extension does not
    modify the behavior of BindFramebufferEXT. This difference also
    applies to BindRenderbuffer from this extension vs.
    BindRenderbufferEXT from EXT_framebuffer_object.
于 2011-08-26T09:15:37.020 回答