OpenGL ES and OpenGL-compatible shaders

I want to have the same shader source for OpenGL ES and OpenGL (Windows). For this, I want to define custom data types and use only the OpenGL ES features.

One approach is to determine:

#define highp
#define mediump
#define lowp

for the Windows shader and burn the shader, as for OpenGL ES.

Another approach is to define custom data types like this for OpenGL ES:

#define hvec2 highp vec2

and how is it for windows

#define hvec2 vec2

What do you think is better? Do you have other solutions to this problem?

+5
source share
3 answers

My solution was to write shader code compatible with both APIs, and then when loading the source code for the shader fragment in OpenGL ES, just add the following line:

precision mediump float;

. OpenGL ES , , , . lowp highp, .

. 4.5.3 Shading Language OpenGL ES: http://www.khronos.org/files/opengles_shading_language.pdf

#define, .

+4

http://www.opengl.org/registry/specs/ARB/ES2_compatibility.txt

OpenGL ES 2.0, OpenGL 3.x. OpenGL ES 2.0 OpenGL.

+4

I did this by simply specifying the following at the beginning of each shader when the shader runs in windows:

#define lowp
#define mediump
#define highp

Additionally, I give the shader information that plattform uses (WINDOWS, MOBILE, IOS), which can be used as follows:

#ifdef WINDOWS
precision mediump float;
#endif
+1
source

All Articles