在GLSL中从外部定义预处理器宏 [英] Externally Define Preprocessor Macros in GLSL

查看:537
本文介绍了在GLSL中从外部定义预处理器宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GLSL具有完整的C样式预处理器.唯一不起作用的是#include.很棒的功能之一是,您可以使用#ifdef注释掉功能,从而创建一个着色器,如果不使用某些功能,则可以将其稀疏.

GLSL has a full C-style preprocessor. The only thing that does not work is #include. One of the great features is that that you can used #ifdef to comment out functions and thus create one shader that can be thinned out if certain features are not used.

我的问题是:

是否可以通过C代码定义宏?

使用openGL界面似乎无法做到这一点.快速的技巧是在代码加载表单文件之前在#define FOO之前添加几行.但这似乎有些倒退.

There seems no way to do that with the openGL interface. The quick hack is to prepend a few lines with #define FOO before the code loaded form file. But it seems kind of backwards.

推荐答案

您实际上并不需要在加载的代码之前添加它.这就是为什么glShaderSourceARB API中有多个字符串.

You don't really need to prepend it to the code you loaded. That's why there are multiple strings in the glShaderSourceARB API.

您想要的东西如下所示:

Something like the following does what you are looking for:

char *sources[2] = { "#define FOO\n", sourceFromFile };
glShaderSourceARB(shader, 2, sources, NULL);

这篇关于在GLSL中从外部定义预处理器宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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