<p>GLSL does not support C++ style namespaces. You might want to do some regex magic before parsing the shader, replacing '::' with '_' or something. You might want to have a preprocessor of sorts - or just forget about it entirely. </p>

CC BY-SA 4.0
2020-05-16T20:58:18.597Z
2020-05-16T20:58:18.597Z
Stephanus Tavilrond
<p>I have different functions for example normalmapping which I use all the time...
Now I thought about making a small glsl library.</p>

<p>My problem:
I don't want to have all functions within the same "namespace".</p>

<p>I would like to have it like:</p>

<pre><code>vec4 lighting::Phong(vec3 normal, vec3 color, vec3 lightPositionRelative)
</code></pre>

<p>The thing is, that I have tons of functions and sometimes multiple functions are related to the same thing, for example: A HashTable, AddKey, GetKey, HasKey...</p>

<p>So some kind of namespace or even better a class like structure.
What are the options I have?
How are you guys handle this?</p>

<glsl><data-structure>
Creating glsl library
Thomas
# Creating glsl library

(Asked by: username_0 on 2020-05-16)

I have different functions for example normalmapping which I use all the time...
Now I thought about making a small glsl library.

My problem:
I don't want to have all functions within the same "namespace".

I would like to have it like:

```
vec4 lighting::Phong(vec3 normal, vec3 color, vec3 lightPositionRelative)

```

The thing is, that I have tons of functions and sometimes multiple functions are related to the same thing, for example: A HashTable, AddKey, GetKey, HasKey...

So some kind of namespace or even better a class like structure.
What are the options I have?
How are you guys handle this?

**Tags:** glsl, data-structure


---

## 1 answers

### Answer by username_1 on 2020-05-16. Score: 3 | Accepted answer

GLSL does not support C++ style namespaces. You might want to do some regex magic before parsing the shader, replacing '::' with '\_' or something. You might want to have a preprocessor of sorts - or just forget about it entirely.


---

