有没有办法检查程序使用的OpenGL / GLSL扩展?

时间:2015-01-01 17:36:00

标签: opengl opengl-es glsl glsles

我想知道是否有一些工具可以检查您在程序或着色器中使用的扩展程序(或者您必须检查的最小化GL版本)。

类似于:'checkGL directory'来获取程序在目录中使用的扩展名列表。

输出类似于:

GL_MIRRORED_REPEAT        - GL_VERSION_1_4 - GL_OES_texture_mirrored_repeat
glUseProgram              - GL_VERSION_2_0 - GL_ES_VERSION_2_0
glEnableVertexAttribArray - GL_VERSION_2_0 - GL_ES_VERSION_2_0

1 个答案:

答案 0 :(得分:2)

我从来没有以编程方式完成此操作,但如果您依赖于编译器错误并且具有解析XML文件的经验,那么它应该是直截了当的。代替现有的实际工具(我不知道),这就是你自己实现它的方法。

按照正常情况构建程序,但注释掉与GL相关的所有包含(例如 #include <GL/gl.h>#include <GL/glew.h>),然后将编译器错误日志保存到文件中。给定此错误日志,您可以通过解析OpenGL XML registry来跟踪缺少的函数和常量所需的GL扩展和/或核心版本。

我建议解析GL常量,类型和函数的编译器错误日志而不是源代码,因为编译器将通过预处理器运行它,这将消除大量的误报。您可以自己轻松解析项目目录中的每个.c.cpp.h等文件,并查找以gl*或{{1}开头的所有内容但是,这将天真地包括非活动代码分支,注释等。


XML注册表是Khronos用于在其网站上生成标题的内容,如果您知道如何解析它,它会为每个API函数,enumerant,typedef和扩展提供非常详细的信息。

根据您的示例,您将找到:

GL_*

这意味着在“gl”(桌面GL)中,<feature api="gl" name="GL_VERSION_1_4" number="1.4"> <require> ... <enum name="GL_MIRRORED_REPEAT"/> ... </require> </feature> ... <feature api="gles2" name="GL_ES_VERSION_2_0" number="2.0"> <require> ... <enum name="GL_MIRRORED_REPEAT"/> ... </require> </feature> 是版本1.4的核心,而“gles2”(OpenGL ES 2.0+)则是版本2.0的核心。

小心不要过多地阅读标签“gles2”(这是一个包含ES 2.0或更新版本的OpenGL ES的分支,解析实际的GL_MIRRORED_REPEATname找出版本要求)。

如果您知道核心常量number的枚举值,那么您可以查找具有相同值的所有其他枚举,并将它们追溯到已提升为核心的相应扩展名。

交叉引用提供GL_MIRRORED_REPEAT(0x8370)的所有扩展名:

GL_MIRRORED_REPEAT

在这种情况下,<enums namespace="GL" start="0x8370" end="0x837F" vendor="HP"> <!-- NOTE: IBM is using values in this range, because of a bobble when an employee left DEC for IBM at the same time as they were assigned the range. their registry became inconsistent. It's unknown whether HP has any conflicts. They have never reported using any values in this range. Lesson: assigned ranges belong to vendors, not engineers! --> <enum value="0x8370" name="GL_MIRRORED_REPEAT"/> <enum value="0x8370" name="GL_MIRRORED_REPEAT_ARB"/> <enum value="0x8370" name="GL_MIRRORED_REPEAT_IBM"/> <enum value="0x8370" name="GL_MIRRORED_REPEAT_OES"/> <unused start="0x8371" end="0x837F" vendor="HP"/> </enums> ... <extension name="GL_ARB_texture_mirrored_repeat" supported="gl"> <require> <enum name="GL_MIRRORED_REPEAT_ARB"/> </require> </extension> <extension name="GL_IBM_texture_mirrored_repeat" supported="gl"> <require> <enum name="GL_MIRRORED_REPEAT_IBM"/> </require> </extension> <extension name="GL_OES_texture_mirrored_repeat" supported="gles1"> <require> <enum name="GL_MIRRORED_REPEAT_OES"/> </require> </extension> 由GL中的GL_MIRRORED_REPEATGL_ARB_texture_mirrored_repeat以及GLES 1.x中的GL_IBM_texture_mirrored_repeat提供GL_OES_texture_mirrored_repeat


关于确定GLSL着色器的最小版本号,没有可以在那里解析的XML文件。唯一真正的优点是,如果将#version ...指令设置得太低,大多数GLSL编译器会在着色器信息日志中的错误/警告中包含所需的版本和/或扩展名。

您最好的选择是使用GLslangOpenGL Reference Compiler)以强制版 110 (桌面GL)和 100 <来验证着色器/ strong>(OpenGL ES)。它不像供应商GLSL编译器那么完整,但无论你使用什么GPU,它的输出总是一致的,你应该能够为它编写解析器。


UPDATE:

我在几个小时内将一个项目整合在一起,大概是你想要的,这是一些示例输出:

Enter OpenGL name to search for: GL_MIRRORED_REPEAT
--------------------------------
 >> Enum:   GL_MIRRORED_REPEAT is 0x8370

  * Core in                   GL_VERSION_1_4    (   gl 1.4)
  * Core in                GL_ES_VERSION_2_0    (gles2 2.0)

 >> Enum Alias: GL_MIRRORED_REPEAT_ARB <<
  * Provided by GL_ARB_texture_mirrored_repeat (gl)

 >> Enum Alias: GL_MIRRORED_REPEAT_IBM <<
  * Provided by GL_IBM_texture_mirrored_repeat (gl)

 >> Enum Alias: GL_MIRRORED_REPEAT_OES <<
  * Provided by GL_OES_texture_mirrored_repeat (gles1)


Enter OpenGL name to search for: glEnableVertexAttribArray
--------------------------------
 >> Command:  void glEnableVertexAttribArray (GLuint index)

  * Core in                   GL_VERSION_2_0    (   gl 2.0)
  * Core in                GL_ES_VERSION_2_0    (gles2 2.0)

 >> Command Alias: glEnableVertexAttribArrayARB <<
  * Provided by GL_ARB_vertex_program (gl)

此项目的源代码可在GitHub here上找到。