GLSL:检查是否支持扩展 [英] GLSL: check if an extension is supported

查看:97
本文介绍了GLSL:检查是否支持扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您不能使用不受支持的扩展,驱动程序将返回编译错误.但是,您可以直接从GLSL代码检查某些扩展程序的可用性吗?有这样的东西吗?

You can't use an unsupported extension, driver will return compilation error. But can you check availability of some extension directly from GLSL code? Is there something like this?

#version XXX core
#if supported(EXT_some_extension)
#extension EXT_some_extension: enable
#endif

...

更新:根据 Nicol Bolas 答案.是的,这也出现在我的脑海中,但是由于某种原因,它不起作用

UPDATE: According to Nicol's Bolas answer. Yes, that appeared in my mind too, but for some reason, it is not working

#version 150 core
#extension ARB_explicit_attrib_location : enable
#ifdef ARB_explicit_attrib_location
#define useLayout layout(location = 2)
#else
#define useLayout  //thats an empty space
#endif

in vec2 in_Position;
useLayout in vec2 in_TextureCoord;
...

宏"useLayout"始终设置为空白,但是如果我只留下#enable指令而没有条件,它将使用它(我的驱动程序支持它).好像没有定义扩展名,这是其他东西(可能是吗?)(#if defined(ARB_explicit_attrib_location)也不起作用)

Macro "useLayout" is always set to empty space, but if I left only #enable directive without conditions it will use it (my driver supports it). Looks like extensions do not being defined, it is something else (probably?) (#if defined(ARB_explicit_attrib_location) does not work too)

推荐答案

#if supported(EXT_some_extension)
#extension GL_EXT_some_extension: enable
#endif

您正在尝试编写有条件地使用特定扩展名的着色器.做您想做的正确方法是:

You are trying to write a shader that conditionally uses a certain extension. The correct way to do what you're trying to do is this:

#extension EXT_some_extension: enable

#ifdef GL_EXT_some_extension
//Code that uses the extension.
#endif //GL_EXT_some_extension

每个具有GLSL功能的OpenGL扩展都将具有特定的#define.并且enable标志只会在扩展名不在时发出警告.如果未激活,则不会触发#ifdef.

Every OpenGL extension that has GLSL features will have a specific #define for it. And the enable flag will only emit a warning if the extension isn't around. If it's not active, the #ifdef won't trigger.

这篇关于GLSL:检查是否支持扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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