我如何支持不同的OpenGL版本? [英] How do I support different OpenGL versions?

查看:160
本文介绍了我如何支持不同的OpenGL版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的系统,一个是OpenGL 1.4,另一个是3.我的程序使用的着色器是OpenGL 3的一部分,在1.4实现中仅作为ARB扩展受支持.

由于我无法在OpenGL 1.4中使用OpenGL 3功能,是否有一种方法可以同时支持两个OpenGL版本而无需两次编写相同的OpenGL代码(ARB/EXT和v3)?

解决方案

除非出于某种原因您真的必须支持10年之久的图形卡,否则我强烈建议将OpenGL 2.0而不是1.4作为目标(事实上,我什至愿意直至定位到2.1版.

由于使用"3.0核心着色器"必然意味着图形卡必须至少具有某些GLSL版本,因此排除了至少不能提供至少GLSL版本的硬件. OpenGL 2.0.这意味着,如果具有OpenGL 1.4 的人可以运行您的着色器,则说明他使用的是8-10岁的驱动程序.除了支持梦night,没有什么收获.

以OpenGL 2.1为目标是合理的,如今几乎没有任何系统不支持OpenGL(即使假设至少使用OpenGL 3.2也是完全合理的选择).

大约两年前,入门级OpenGL 3.3兼容卡的处理能力约为高端OpenGL 1.4卡的1000倍,其市场价格约为25美元.如果您打算出售您的应用程序,则必须问自己是否有能力负担不起(或不愿负担得起)这笔费用,这将是您合理地期望为您的软件付款的人.

话虽如此,但同时支持OpenGL 2.x和OpenGL> 3.1实在是一场噩梦,因为着色语言发生了一些重要变化,这些变化远远超出了#define in varying范围,并且会经常咬你. /p>

因此,我选择个人不再使用实例数组和着色器对象再次定位低于3.2版的对象.这适用于所有可以合理预期具有运行现代应用程序处理能力的硬件,并且其中包括那些懒得将驱动程序升级到3.3的用户,它们在单个代码路径中提供了相同的功能.可以加载OpenGL 4.x功能作为扩展,如果可以的话.
但是,当然,每个人都必须自己决定哪种鞋最合适.

够了,回到实际的问题:
关于不为扩展名/内核复制代码,在许多情况下,您可以使用相同的名称,函数指针和常量.但是,请注意:作为一揽子声明,这是非法的,不确定的且危险的.
实际上,大多数(不是全部!)扩展都与各自的核心功能相同,并且工作原理相同.但是如何知道哪些可以使用,哪些会吃掉猫呢?看 gl.spec -一个具有alias条目的函数是与其别名完全相同且无法区分.您可以安全互换使用它们.
有问题的扩展程序通常也会在某处添加解释性注释(例如这不是PrimitiveRestartIndexNV的别名,因为它设置了服务器而不是客户端状态." ),但并不依赖于这些,依靠alias字段.

I have two different systems one with OpenGL 1.4 and one with 3. My program uses Shaders which are part of OpenGL 3 and are only supported as ARB extension in the 1.4 implementation.

Since I cant use the OpenGL 3 functions with OpenGL 1.4 is there a way to support both OpenGL versions without writing the same OpenGL code twice (ARB/EXT and v3)?

解决方案

Unless you really have to support 10 year old graphics cards for some reason, I strongly recommend targetting OpenGL 2.0 instead of 1.4 (in fact, I'd even go as far as targetting version 2.1).

Since using "shaders that are core in 3.0" necessarily means that the graphics card must be capable of at least some version of GLSL, this rules out any hardware that is not capable of providing at least OpenGL 2.0. Which means that if someone has OpenGL 1.4 and can run your shaders, he is using 8-10 year old drivers. There is little to gain (apart from a support nightmare) from that.

Targetting OpenGL 2.1 is reasonable, there are hardly any systems nowadays which don't support that (even assuming a minimum of OpenGL 3.2 may be an entirely reasonable choice).

The market price for an entry level OpenGL 3.3 compatible card with roughly 1000x the processing power of a high end OpenGL 1.4 card was around $25 some two years ago. If you ever intend to sell your application, you have to ask yourself whether someone who cannot afford (or does not want to afford) this would be someone you'd reasonably expect to pay for your software.

Having said that, supporting OpenGL 2.x and OpenGL >3.1 at the same time is a nightmare, because there are non-trivial changes in the shading language which go far beyond #define in varying and which will bite you regularly.

Therefore, I have personally chosen to never again target anything lower than version 3.2 with instanced arrays and shader objects. This works with all hardware that can be reasonably expected having the processing power to run a modern application, and it includes the users who were too lazy to upgrade their driver to 3.3, providing the same features in a single code path. OpenGL 4.x features are loadable as extension if available, which is fine.
But, of course, everybody has to decide for himself/herself which shoe fits best.

Enough of my blah blah, back to the actual question:
About not duplicating code for extensions/core, you can in many cases use the same names, function pointers, and constants. However, be warned: As a blanket statement, this is illegal, undefined, and dangerous.
In practice, most (not all!) extensions are identical to the respective core functionality, and work just the same. But how to know which ones you can use and which ones will eat your cat? Look at gl.spec -- a function which has an alias entry is identical and indistinguishable from its alias. You can safely use these interchangeably.
Extensions which are problematic often have an explanatory comment somewhere as well (such as "This is not an alias of PrimitiveRestartIndexNV, since it sets server instead of client state."), but do not rely on these, rely on the alias field.

这篇关于我如何支持不同的OpenGL版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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