OpenGL 显示列表(已弃用但受支持)如何判断是否受支持?

OpenGL display lists (deprecated but supported) how to tell if supported?

我了解到在 OpenGL v3 中显示列表已被弃用,但一些制造商会在可预见的未来支持它们。

是否有 OpenGL get... 函数明确告诉我我正在询问的驱动程序是否支持显示列表?

调用 glGetString with GL_VERSION. If the version is equal or lower than 2.1, display lists are surely supported. In the case the version is greater, it depends if you have requested an OpenGL CORE profile or an OpenGL COMPATIBILITY 配置文件。

为简化起见,如果您使用 wglCreateContext (or equalivalent on other platforms), you are creating a compatibility profile. You should also check support for GL_ARB_compatibility calling glGetStringGL_EXTENSIONS 创建上下文。

如果您至少使用 OpenGL 3.0,则可以使用 glGetIntegerv() 查询所有详细信息。如果您处理更旧的版本,则必须先检查 glGetString(GL_VERSION)。如果低于 3.0,您就完成了(支持显示列表)。否则,请继续进行以下检查。

在 3.0 及更高版本中,您还可以通过以下方式获取当前版本:

GLint majVers = 0, minVers = 0;
glGetIntegerv(GL_MAJOR_VERSION, &majVers);
glGetIntegerv(GL_MINOR_VERSION, &minVers);

虽然核心配置文件仅在 3.2 中引入,但显示列表已在 3.0 中标记为已弃用。当时引入了 "forward compatible" 标志。所以理论上,您可以在不支持显示列表的情况下实现 3.0。然后,从3.2开始,任何使用核心配置文件的东西显然都没有显示列表。

这是未经测试的,但我相信正确的测试逻辑应该是这样的:

bool hasDisplayLists = true;
if (strcmp(glGetString(GL_VERSION), "3") > 0) {
    // Check for forward-compatible flag in 3.0 and higher.
    GLint ctxFlags = 0;
    glGetIntegerv(GL_CONTEXT_FLAGS, &ctxFlags);
    if (ctxFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) {
        hasDisplayLists = false;
    } else {
        GLint majVers = 0, minVers = 0;
        glGetIntegerv(GL_MAJOR_VERSION, &majVers);
        glGetIntegerv(GL_MINOR_VERSION, &minVers);
        // Check for core profile in 3.2 and higher.
        if (majVers > 3 || minVers >= 2) {
            GLint profMask = 0;
            glGetIntegerv(GL_CONTEXT_PROFILE_MASK, profMask);
            if (profMask & GL_CONTEXT_CORE_PROFILE_BIT) {
                hasDisplayLists = false;
            }
        }
    }
}