Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between GLSL and GLSL ES 2

Two questions really...

  1. Is GLSL ES 2 a totally separate language, or a special version of GLSL?
  2. What are the differences between them, in terms of "standard library" functions, syntax and capabilities?

I am writing shaders for an application targeted at Windows, Mac and iPad and I would prefer not to have to add more versions of each shader - well simpler shaders anyway.

like image 295
Mr. Boy Avatar asked Apr 30 '12 11:04

Mr. Boy


People also ask

What is the difference between OpenGL es and OpenGL?

The main difference between the two is that OpenGL ES is made for embedded systems like smartphones, while OpenGL is the one on desktops. On the coding level, OpenGL ES does not support fixed-function functions like glBegin/glEnd etc... OpenGL can support fixed-function pipeline (using a compatibility profile).

What GLSL version should I use?

You pick the GLSL version for the version of OpenGL that is your minimum supported version. If your minimum supported GL version is 2.1, then your GLSL version should be 1.10. If your minimum supported version is GL 4.1, then your GLSL version should be 4.10.

What is the difference between OpenGL and GLSL?

The short version is: OpenGL is an API for rendering graphics, while GLSL (which stands for GL shading language) is a language that gives programmers the ability to modify pipeline shaders. To put it another way, GLSL is a (small) part of the overall OpenGL framework.

What is GLSL used for?

About GLSL These shading languages are used to program shaders (i.e. more or less small programs) that are executed on a GPU (graphics processing unit), i.e. the processor of the graphics system of a computer – as opposed to the CPU (central processing unit) of a computer.


1 Answers

Is GLSL ES 2 a totally separate language, or a special version of GLSL?

Every version of GLSL is ultimately a "totally separate language;" some aren't even backwards compatible with previous versions. However, the ES variation of GLSL is even moreso.

Think of it as a fork of desktop GLSL. A fork of GLSL from six versions ago, mind you.

What are the differences between them, in terms of "standard library" functions, syntax and capabilities?

Between which versions?

The only possible reason you could have to try to share shaders between these platforms is if you're trying to share OpenGL code between them. So you'd have to be limiting yourself to desktop OpenGL 2.1 functionality.

That means you'd be using desktop GLSL version 1.20. This is similar to GLSL ES version 1.00 (the version of GLSL is not given the same number as the matching GL version. Well, until desktop GL 3.3/4.0 and GLSL 3.30/4.00), but still different. In ES, you have a lot of precision qualifiers that desktop GLSL 1.20 doesn't handle.

The best way to handle that is to use a "preamble" shader string. See, glShaderSource takes multiple shader strings, which it slaps together and compiles as one. You can take your main shader string (main and its various code, attribute definitions, uniforms, etc) and stick a "preamble" shader string in front of that. The preamble would be different depending on what you're compiling for.

Your ES GLSL 1.00 preamble would look like this:

#version 100  //Must start with a version specifier. 

Your desktop GLSL 1.20 preamble would look like this:

#version 120 #define lowp #define mediump #define highp 

And maybe a few other judicious #defines. This way, your shader can have those precision qualifiers set, and they'll just be #defined away when using desktop GLSL.

This is a lot like platform-neutral coding in C/C++, where you often have some platform-specific header that changes the definition and/or has #defines that you can condition code based on.

like image 129
Nicol Bolas Avatar answered Oct 19 '22 01:10

Nicol Bolas