【问题标题】:Macros when compiling shader for webgl为 webgl 编译着色器时的宏
【发布时间】:2012-08-08 03:21:29
【问题描述】:

在 OpenGL ES 2 中,您可以将字符串数组设置为着色器源

void ShaderSource( uint shader, sizei count, const char **string, const int *length );

可用于将宏“注入”到着色器源中。 WebGL 中的相应函数看起来只需要一个字符串。

void shaderSource(WebGLShader shader, DOMString source)

是否只有使用宏手动将它们插入源字符串的可能性?

【问题讨论】:

    标签: macros shader webgl


    【解决方案1】:

    我不确定你所说的inject macros是什么意思

    const char* str1 = "foo";
    const char* str2 = "bar";
    const char* strings[] = { str1, str2, }
    
    glShaderSource(shader, 2, strings, NULL);
    

    在功能上等同于

    var str1 = "foo";
    var str2 = "bar";
    var strings = [str1, str2];
    gl.shaderSource(shader, strings.join(""));
    

    所以,回答你的问题。如果您想插入宏,请将它们添加到您提供给 gl.shaderSource 的字符串中。宏和它们来自哪个字符串没有什么特别之处。就 GL 而言,它只是一个大字符串。

    【讨论】:

    • 功能等效,是的。我最终将字符串连接起来,但我认为将其交给实现这些功能的任何东西可能会更有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 2017-07-03
    相关资源
    最近更新 更多