glGenFramebuffers或glGenFramebuffersEXT? [英] glGenFramebuffers or glGenFramebuffersEXT?

查看:314
本文介绍了glGenFramebuffers或glGenFramebuffersEXT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm confused. To use the Framebuffer Object extension (FBO) in OpenGL 1.x on Windows, which of these do I use?:

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

据我从具有不同硬件的用户的报告中可以看出,某些驱动程序既不支持,也不支持两者之一或全部支持所有组合.

As far as I can tell from reports from users with different hardware, some drivers support all combinations of neither, one of the two, or both.

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

Which is the right one to use? Do some drivers really support one but not the other? Is it correct to try to fall back from one to the other if not found?

编辑:ATI Radeon卡及其相关代码仍然存在严重问题.我们刚刚使用此代码启动了商业编辑器(www.scirra.com).似乎无论我使用哪种代码组合来使用FBO,用户的某种不同组合都报告他们根本看不到任何东西(即,什么也没有渲染).

I'm still having serious problems with ATI Radeon cards and the code around this. We just launched a commercial editor using this code (www.scirra.com). It seems no matter what combination of code I use to use FBOs, some different combination of users reports they cannot see anything at all (i.e. nothing renders).

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

Here's the code where I detect whether to use the ARB functions (no suffix) or the EXT-suffixed functions. This runs on startup:

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,以预期将其渲染到纹理:

Then later on during startup it creates a FBO in anticipation of rendering to texture:

// 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卡似乎特别有问题.我不确定是否涉及驱动程序错误,但我想我的上述代码很可能在做出错误的假设.

I have been through many variations of this code, and I simply cannot get it to work for everyone. There is always a group of users who report nothing renders at all. ATI Radeon HD cards seem to be particularly problematic. I'm not sure if there's a driver bug involved, but I guess it's more likely my above code is making an incorrect assumption.

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

500 rep bounty and I'll send a free Business license to anyone who knows what's wrong! (Worth £99)

更多细节.这是已知会失败的卡的列表:

Edit 2: some more details. Here is a list of cards that this is known to fail on:

ATI Mobility Radeon HD 5650

ATI Mobility Radeon HD 5650

ATI Radeon X1600 Pro

ATI Radeon X1600 Pro

ATI Mobility Radeon HD 4200

ATI Mobility Radeon HD 4200

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

No rendering to texture is actually done. It appears the glGenFramebuffers call alone stops rendering completely on these cards. I could defer creation of the FBO to the first time render-to-texture is actually done, but then presumably it will just stop rendering again.

我可以使用GLEW,但是我的代码不能执行什么操作?我查看了源代码,似乎使用了类似的wglGetProcAddress列表.在我的情况下,将返回方法,否则glGenFramebuffers将为NULL并崩溃.有什么想法...吗?

I could use GLEW, but what does it do that my code doesn't? I had a look through the source and it seems to use a similar list of wglGetProcAddress. Methods are being returned in my case, else glGenFramebuffers would be NULL and crash. Any ideas...?

推荐答案

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

If the extension GL_EXT_framebuffer_object is present, then you can use wglGetProcAddress("glGenFramebuffersEXT");.

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

If the OpenGL version is >= 3.0 (in this version the FBO extension was added to the core), then you can use wglGetProcAddress("glGenFramebuffers");.

这篇关于glGenFramebuffers或glGenFramebuffersEXT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆