简体   繁体   English

如何检查OpenGL版本的一致性?

[英]How to check for OpenGL version conformance?

I want to make sure that my application conforms to OpenGL 2.1. 我想确保我的应用程序符合OpenGL 2.1。 How can I check this? 我怎么检查这个?

Because my computer supports GL4.4, even if I use, for example, glGenVertexArrays() , it will work successfully. 因为我的计算机支持GL4.4,即使我使用glGenVertexArrays() ,它也能成功运行。 But glGenVertexArrays() is only available with GL3+. glGenVertexArrays()仅适用于GL3 +。

So, I want to verify that my app only uses GL2.1 functionality. 所以,我想验证我的应用程序仅使用GL2.1功能。 One way is to run it on my old PC that support only GL2.1, but I'm looking for an easier way. 一种方法是在我只支持GL2.1的旧PC上运行它,但我正在寻找一种更简单的方法。

If you find an extension loader that supports generating version specific headers, as described by @datenwolf, that's probably your easiest solution. 如果您找到支持生成版本特定标头的扩展加载器,如@datenwolf所述,这可能是您最简单的解决方案。 There's another options you can try if necessary. 如有必要,您可以尝试其他选项。

The official OpenGL headers you can find at https://www.opengl.org/registry contain the definitions grouped by version, and enclosed in preprocessor conditions. 您可以在https://www.opengl.org/registry上找到的官方OpenGL标题包含按版本分组的定义,并包含在预处理器条件中。 The layout looks like this: 布局如下所示:

...
#ifndef GL_VERSION_2_1
#define GL_VERSION_2_1 1
// GL 2.1 definitions
#endif
#ifndef GL_VERSION_3_0
#define GL_VERSION_3_0 1
// GL 3.0 definitions
#endif
#ifndef GL_VERSION_3_1
#define GL_VERSION_3_1 1
// GL 3.1 definitions
#endif
...

You should be able to include the official header at least for a version test. 您应该能够至少在版本测试中包含官方标题。 If you disable the versions you do not want to use by defining the corresponding pre-processor symbol, you will get compile errors if you are trying to use features from those versions. 如果通过定义相应的预处理器符号来禁用您不想使用的版本,则在尝试使用这些版本的功能时,将出现编译错误。 For example for GL 2.1: 例如对于GL 2.1:

#define GL_VERSION_3_0 1
#define GL_VERSION_3_1 1
#define GL_VERSION_3_2 1
#define GL_VERSION_3_3 1
#define GL_VERSION_4_0 1
#define GL_VERSION_4_1 1
#define GL_VERSION_4_2 1
#define GL_VERSION_4_3 1
#define GL_VERSION_4_4 1
#define GL_VERSION_4_5 1
#include <GL/glext.h>

// your code

You can compile it in an environment in which only the OpenGL-2.1 symbols are available. 您可以在只有OpenGL-2.1符号可用的环境中编译它。 Depending on which extension wrapper / loader you use this can be easy or hard. 根据您使用的扩展包装器/装载器,这可能很容易或很难。

For example if you use the glloadgen OpenGL loader generator you can generate a header file and compilation unit that will cover only exactly the OpenGL-2.1 symbols and tokens. 例如,如果您使用glloadgen OpenGL加载器生成器,您可以生成一个头文件和编译单元,它将仅涵盖OpenGL-2.1符号和标记。 If you then compile your project using this, the compiler will error out on anything that's not covered. 如果您使用此编译项目,编译器将在未涵盖的任何内容上出错。

Try https://github.com/cginternals/glbinding . 试试https://github.com/cginternals/glbinding It's an OpenGL wrapper library which supports exactly what you ask for: 它是一个OpenGL包装程序库,它完全支持您的要求:

Feature-Centered Header Design 以功能为中心的标题设计

The OpenGL API is iteratively developed and released in versions, internally (for the API specification) named features . OpenGL API是在内部(对于API规范)命名的功能的版本中迭代开发和发布的。 The latest feature/version of OpenGL is 4.5. OpenGL的最新功能/版本是4.5。 The previous version are 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, and 4.4. 以前的版本是1.0,1.1,1.2,1.3,1.4,1.5,2.0,2.1,3.0,3.1,3.2,3.3,4.0,4.1,4.2,4.3和4.4。 OpenGL uses a deprecation model for removing outdated parts of its API which results in compatibility (with deprecated API) and core (without deprecated API) usage that is manifested in the targeted OpenGL context. OpenGL使用弃用模型来删除其API的过时部分,从而导致与目标OpenGL上下文中的兼容性(使用已弃用的API)和核心(没有弃用的API)使用。 On top of that, new API concepts are suggested as extensions (often vendor specific) that might be integrated into future versions. 最重要的是,新API概念被建议作为可能集成到未来版本中的扩展(通常是特定于供应商)。 All this results in many possible specific manifestations of the OpenGL API you can use in your program. 所有这些都会导致您可以在程序中使用的OpenGL API的许多可能的特定表现形式。

One tough task is to adhere to one agreed set of functions in your own OpenGL program (eg, OpenGL 3.2 Core if you want to develop for every Windows, macOS, and Linux released in the last 4 years). 一个艰巨的任务是在您自己的OpenGL程序中遵循一组商定的功能(例如,如果您想为过去4年发布的每个Windows,macOS和Linux进行开发,请使用OpenGL 3.2 Core)。 glbinding facilitates this by providing per-feature headers by means of well-defined/generated subsets of the OpenGL API. glbinding通过OpenGL API的明确定义/生成的子集提供每个功能头来促进这一点。

All-Features OpenGL Headers 全功能OpenGL标头

If you do not use per-feature headers the OpenGL program can look like this: 如果您不使用每个功能标头,OpenGL程序可能如下所示:

 #include <glbinding/gl/gl.h> // draw code gl::glClear(gl::GL_COLOR_BUFFER_BIT | gl::GL_DEPTH_BUFFER_BIT); gl::glUniform1i(u_numcubes, m_numcubes); gl::glDrawElementsInstanced(gl::GL_TRIANGLES, 18, gl::GL_UNSIGNED_BYTE, 0, m_numcubes * m_numcubes); 

Single-Feature OpenGL Headers 单功能OpenGL标头

When developing your code on Windows with latest drivers installed, the code above is likely to compile and run. 在安装了最新驱动程序的Windows上开发代码时,上面的代码可能会编译并运行。 But if you want to port it to systems with less mature driver support (eg, macOS or Linux using open source drivers), you may wonder if glDrawElementsInstanced is available. 但是如果你想将它移植到不太成熟的驱动程序支持的系统(例如,使用开源驱动程序的macOS或Linux),你可能想知道glDrawElementsInstanced是否可用。 In this case, just switch to per-feature headers of glbinding and choose the OpenGL 3.2 Core headers (as you know that at least this version is available on all target platforms): 在这种情况下,只需切换到glbinding的每个功能标头,然后选择OpenGL 3.2 Core标头(如您所知,至少此版本在所有目标平台上都可用):

 #include <glbinding/gl32core/gl.h> // draw code gl32core::glClear(gl32core::GL_COLOR_BUFFER_BIT | gl32core::GL_DEPTH_BUFFER_BIT); gl32core::glUniform1i(u_numcubes, m_numcubes); gl32core::glDrawElementsInstanced(gl32core::GL_TRIANGLES, 18, gl32core::GL_UNSIGNED_BYTE, 0, m_numcubes * m_numcubes); 

If the code compiles than you can be sure it is OpenGL 3.2 Core compliant. 如果代码编译比您可以确定它符合OpenGL 3.2 Core。 Using functions that are not yet available or relying on deprecated functionality is prevented. 使用尚不可用的功能或依赖于已弃用的功能将被阻止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM