GLSL version 120 on MacOS

I would like to use GLSL version 120 with OpenGL 2.1 on MacOS 10.12.6 to get a (kind of) ES2 compatible environment. I’ve tried configuring Cinder like this:

CINDER_APP( ShaderRendererApp, RendererGl( RendererGl::Options().version( 2, 1 ) ), prepareSettings )

but I always get an error compiling the version 120 shader: VERTEX: ERROR: 0:1: '' : version '120' is not supported.

Any ideas on how to get GL 2.1 running on MacOS? Alternatively, maybe there’s some way to emulate iOS and run under true ES2? Or use Docker to run Linux with ES2?

EDIT:

So it appears OpenGL is running version 4.1 despite asking for version 2.1. Any idea why RendererGl wouldn’t provide a 2.1 context, even when explicitly turning off core profile?

I remember trying to set up a similar environment in a project until I realized that my Macbook had no problem running ES2 (#version 100) shaders.

I’m not exactly sure about the reason, but if you just want shader compatibility maybe you can get away with that.

Yeah, that’s not working for me. I think I tracked it down to the fact that RendererImplGlMac always uses NSOpenGLProfileVersion3_2Core, regardless of the GL version you ask for. Which makes sense because Cinder is using a lot of more modern GL features.

I ended up solving this by just injecting a lot of #define statements into my shader to make it compatible with GLSL 150. Stuff like:

out vec4 oColor;
#define gl_FragColor oColor
#define varying in

It probably wouldn’t work for a more complex shader, but in my case it did.

Another option I almost got working was using Docker and the thewtex/docker-opengl image to compile Cinder with CINDER_TARGET_GL=es2 and then run my app in that. I think it could work, I just bailed because it would be too much work for others to run. But it could be useful in another situation. I’m curious if anyone has done anything like that successfully?

You could potential use preprocessor to do this job instead of editing every of your shaders manually.

p.s. I’ve tried the docker path before but probably work - basically because inside docker the OpenGL environment is emulated and not utilising hardware - because mac has Apple’s own driver that doesn’t map 1 on 1 to any linux drivers.

Yeah, I just used the preprocessor. Interesting to know about docker. That’s what I was afraid of.