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?
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.
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.
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.
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:
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.
I’ve been reading and it might not be an actual bug, 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.