# Shader version error on mac

**URL:** <https://discourse.processing.org/t/shader-version-error-on-mac/6155>\
**Category:** Processing\
**Created:** [December 1, 2018, 9:11pm UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155 "2018-12-01T21:11:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)\
**Post date:** [December 1, 2018, 9:11pm UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/1 "2018-12-01T21:11:43Z")

</div>

Hi!

What glsl version should I use on a shader for mac?

I am working on a library thats uses a shader, works ok on Windows, but has compile errors on mac(tried El Capitan and High Sierra). A #version directive is required, nothing below 150 is supported, but 150 onwards you cant use “texture2D” as it should be changed to just “texture”. After changing it, any texture fetch throws an “unknown error” when compiling.

Maybe Processing is adding “uniform sampler2D texture” to the shader?

Thanks

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [December 2, 2018, 12:48am UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/2 "2018-12-02T00:48:50Z")

</div>

Generally if you don’t require a specific version you can leave it out entirely and the shader preprocessor will add it in and rewrite keywords and functions. Although AFAIK it should work with a version in place - maybe you’ve found a bug.

---

<div class="post-metadata">

**Author:** ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)\
**Post date:** [December 2, 2018, 10:29am UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/3 "2018-12-02T10:29:57Z")

</div>

Thanks Neil. If I dont´t define the version I get an error requiring it (only on OSX). I was using some modern syntaxis, so I tried moving back to atributes and varyings, but seems like OSX does not support anything older than 150.

Shaders included in examples work without the version directive, maybe its related to using some fancy functions like texture2Dlod…

I´ve also tried defining one of Processing´s own shader type, like PROCESSING\_TEXLIGHT\_SHADER, but it does not change anything.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [December 2, 2018, 10:59am UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/4 "2018-12-02T10:59:27Z")

</div>

Without a version directive Processing will attempt to rewrite the shader code to suit the GL version (eg. attributes/varyings to in/out) It shouldn’t touch the source with a version in place.

Check out [https://github.com/processing/processing/blob/master/core/src/processing/opengl/PGL.java#L1948](https://github.com/processing/processing/blob/master/core/src/processing/opengl/PGL.java#L1948) It might give you a hint to why yours is failing.

---

<div class="post-metadata">

**Author:** ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)\
**Post date:** [December 2, 2018, 1:08pm UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/5 "2018-12-02T13:08:29Z")

</div>

Interesting, will look into it. Thanks!

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [December 2, 2018, 2:42pm UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/6 "2018-12-02T14:42:09Z")

</div>

One bug that I found on Mac was if I tried to declare and initialize an array outside of any function. This works on Linux, but apparently not on Mac. I had to populate the array inside `main` like this:

```auto
vec2 dirs[4];
void main()
{
    dirs[0] = vec2(0.0, 1.0);
    dirs[1] = vec2(0.0, -1.0);
    dirs[2] = vec2(1.0, 0.0);
    dirs[3] = vec2(-1.0, 0.0);

```

---

<div class="post-metadata">

**Author:** ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)\
**Post date:** [December 3, 2018, 11:45am UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/7 "2018-12-03T11:45:44Z")

</div>

Thanks hamoid, just checked and I’m not declaring arrays beyond the standard Processing lighting arrays. I guess something similar might be happening.

Since I don’t usually use Macs, I will put it on Github in case someone find it useful and wants to fix it.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [December 7, 2018, 12:11am UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/8 "2018-12-07T00:11:07Z")

</div>

> [@hamoid](#):
>
> One bug that I found on Mac was if I tried to declare and initialize an array outside of any function.

@hamoid – I’m curious – is this filed as a bug somewhere?

---

<div class="post-metadata">

**Author:** ![kosowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kosowski/32/550_2.png) [@kosowski](https://discourse.processing.org/u/kosowski)\
**Post date:** [December 7, 2018, 8:39am UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/9 "2018-12-07T08:39:46Z")

</div>

Do shader compilation bugs come from the shader compiler provided by specific graphics driver or are they related to Processing?

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [December 7, 2018, 9:03am UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/10 "2018-12-07T09:03:49Z")

</div>

The graphics driver. One thing I’ve also noticed is some drivers (Intel!) being stricter about the spec where other vendors will let you get away with mixing things from different versions. Mind you, I think the graphics driver on Apple is part of the OS? Apple also definitely stricter.

GLSL is like Java - write once, test everywhere 😄

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [December 7, 2018, 9:32am UTC](https://discourse.processing.org/t/shader-version-error-on-mac/6155/11 "2018-12-07T09:32:32Z")

</div>

I’ve been reading and it [might not be an actual bug](https://stackoverflow.com/questions/10467110/how-to-define-constant-array-in-glsl-opengl-es-2-0), but something supported on certain version of GLSL and not supported on others.

My approach was to try things out and if they work, they are good. But I have discovered what @neilcsmith mentions above: “write once, test everywhere”. The fact that it works on my system doesn’t mean it will work on others, or that it is even correct. Maybe my driver is more tolerant, or includes features it shouldn’t.
