OpenGL and GLSL on macOS Catalina - macos

It's quite a few years now that I develop and maintain an OpenGL app on macOS. Even on Catalina it runs beautifully and fast. Now I need to add a particles feature and use glDrawElementsInstancedARB. The extensions GL_ARB_draw_instanced and GL_ARB_instanced_arrays are present.
As I have read on the web, this command has to be used together with a GLSL shader, so I tried to develop a GLSL shader too. The problem: the shader won't compile. I get an error on the first line
layout (location=0) in vec3 position;
also, the max version allowed is
#version 130
while the GLView app (freely available on the MAS) tells me
CORE: OpenGL version 4.1 ATI-3.10.18
COMPATIBILITY: OpenGL version 2.1 ATI-3.10.18
and glGetString(GL_SHADING_LANGUAGE_VERSION) returns
GLSL Version: 1.20
I know that Apple has just deprecated OpenGL.
Anyway, do you think is a way to compile my shader?
Should I need to install something extra? If so, should my users install something extra too?

Related

How to enable OpenGL 3.X in Mac OS?

Previously I'm using OpenGL on Mac via glew 2.1.0 and JUCE5, but it can only access OpenGL 2.1 APIs. I can't believe that my Macbook Air (Intel Graphics) bought on 2018 can only provide this, and I'm tired to maintain two sets of API calls and shaders for 2.1 and 3.X separately. Then I tried to replace all #include <GL/glew.h> with #include <OpenGL/gl3.h>, then link with OpenGL framework directly. However, the program still failed to compile a #version 130 shader (it claims not supported).
Here I want to know that:
Does all recent Apple devices (after 2010) capable for OpenGL 3.0?
How to turn on OpenGL 3.0 support on MacOS?
Finally I found the way: I have to enable it on JUCE side. When JUCE's OpenGL context is created, I must explicitly set expected OpenGL version by setOpenGLVersionRequired( juce::OpenGLContext::openGL3_2 ) before using it.
IMPORTANT: this would still lead failure to a compile to #version 130 shader, as Apple would strictly deprecate all old features prior to specified API version. A simple workaround is to dynamically prepend a version declaration according to system type, as GLSL 1.3.0 features is mostly included by GLSL 1.5.0.

cannot use GLSL 330 on mac mavericks

I'm trying to learn OpenGL and the material is using #version 330 in shaders. I can compile it successfully, but when I try to run it, it complains Version 330 is not supported.
In my source code, I use free glut and OpenGL framework in Xcode. If I also include these two lines of code
glutInitContextVersion(3,1);
glutInitContextFlags(GLUT_CORE_PROFILE);
it cannot be compiled.
My mac is MacBook Pro Mid 2012. It should support OpenGL4.1 according to apply.
So how can I compile version 330 shaders?
OS X requires that you request a 3.2 core profile in order to receive a 3.3 or later context. This is because 3.2 finally removed the functionally that was deprecated in 3.0.
So if you want to use a #version 330 shader then your code should look like this:
glutInitContextVersion(3,2);
glutInitContextFlags(GLUT_CORE_PROFILE);
EDIT Apparently X11 doesn't support OpenGL higher than 2.1 on OS X. As such, I suggest you switch to GLFW.

What does Chromium/Firefox use instead of Angle on MacOSX?

Since both Chromium and Firefox are using Angle as their OpenGL ES 2.0 compat layer in Windows, I am wondering, what they are using on MacOSX, since all that is available there is OpenGL 3.2 (which is not compatible with OpenGL ES 2.0).
Are both crafting their own layer and how do they work?
Both use their own layer.
Both use ANGLE on all platforms as a shader validator (to validate the shader meets all the rules of WebGL) and as a shader translator (to translate the shader from WebGL GLSL to OpenGL GLSL)
Both also take various other steps to emulate OpenGL ES 2.0 on top of OpenGL like enforcing npot restrictions, limiting access to non WebGL features, etc...

Using OpenGL ES on the Mac

Is it possible and not too complicated to use OpenGL ES for OS X development. I have been writing Mac applications for three years now and I am ready to start learning about OpenGL, but I want use OpenGL ES because there is a lot of information about using it with Xcode and Objective-C and from some of the code samples I found it seems easier to learn than the full OpenGL.
Thanks!
OpenGL-ES 1.1 is a true subset of OpenGL-2, ES-2 is a subset of OpenGL-3, the main difference is, how the context is created and managed. However context creation and management happen outside of OpenGL actually. So as long as you stick to OpenGL-ES, minus extensions specific to ES (i.e. OES extensions) you can do with an ordinary OpenGL context of the right version.
There are OpenGL-ES compatibility profiles, but those just disable functionality, don't add new one.

free software for debugging shaders

Are there any free software tools to debug GLSL shaders?
Try glslDevil
Just adding this answer for future readers:
On OS X, if you have the Developer Tools installed (a free download for the most current OS version), one of the many tools aside from Xcode is the OpenGL Shader Builder which :
[...] is a tool for developing and debugging programs for the graphics processing unit (GPU). It can help you visualize and preview shader objects without the complexity of surrounding code.
[...] You can use the shader builder with programs written with OpenGL Shading Language or with older-style ARB vertex and fragment programs. OpenGL Shader Builder also supports geometry shaders, a recent addition to the OpenGL specification.
Emphasis added

Resources