Merge pull request #6979 from JohanAR/shaderpp_concat

Add concatenation to shader preprocessor
This commit is contained in:
Rémi Verschelde
2023-09-27 10:51:36 +02:00
committed by GitHub

View File

@@ -47,8 +47,8 @@ General syntax
Defines the identifier after that directive as a macro, and replaces all
successive occurrences of it with the replacement code given in the shader.
Replacement is performed on a "whole words" basis, which means no replacement is
performed if the string is part of another string (without any spaces separating
it).
performed if the string is part of another string (without any spaces or
operators separating it).
Defines with replacements may also have one or more *arguments*, which can then
be passed when referencing the define (similar to a function call).
@@ -56,6 +56,21 @@ be passed when referencing the define (similar to a function call).
If the replacement code is not defined, the identifier may only be used with
``#ifdef`` or ``#ifndef`` directives.
If the *concatenation* symbol (``##``) is present in the replacement code then
it will be removed upon macro insertion, together with any space surrounding
it, and join the surrounding words and arguments into a new token.
.. code-block:: glsl
uniform sampler2D material0;
#define SAMPLE(N) vec4 tex##N = texture(material##N, UV)
void fragment() {
SAMPLE(0);
ALBEDO = tex0.rgb;
}
Compared to constants (``const CONSTANT = value;``), ``#define`` can be used
anywhere within the shader (including in uniform hints).
``#define`` can also be used to insert arbitrary shader code at any location,