GFX: make OS X work with OpenGL 2.1 shaders

This commit is contained in:
Pawel Kolodziejski 2015-02-21 13:43:30 +01:00
parent f7407f35f2
commit c3da0c33a4
3 changed files with 41 additions and 13 deletions

View file

@ -28,7 +28,6 @@ namespace Graphics {
namespace BuiltinShaders { namespace BuiltinShaders {
const char *boxVertex = const char *boxVertex =
"#version 100\n"
"attribute vec2 position;\n" "attribute vec2 position;\n"
"attribute vec2 texcoord;\n" "attribute vec2 texcoord;\n"
"uniform vec2 offsetXY;\n" "uniform vec2 offsetXY;\n"
@ -47,11 +46,12 @@ const char *boxVertex =
"}\n"; "}\n";
const char *boxFragment = const char *boxFragment =
"#version 100\n" "#ifdef GL_ES\n"
"#ifdef GL_FRAGMENT_PRECISION_HIGH\n" "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
"precision highp float;\n" "precision highp float;\n"
"#else\n" "#else\n"
"precision mediump float;\n" "precision mediump float;\n"
"#endif\n"
"#endif\n" "#endif\n"
"varying vec2 Texcoord;\n" "varying vec2 Texcoord;\n"
"uniform sampler2D tex;\n" "uniform sampler2D tex;\n"

View file

@ -28,15 +28,37 @@ namespace Graphics {
namespace BuiltinShaders { namespace BuiltinShaders {
const char *compatVertex = const char *compatVertex =
#if defined(USE_OPENGL_SHADERS)
"#if __VERSION__ < 130\n"
"float round(in float x) {\n"
"return sign(x) * floor(abs(x) + .5);\n"
"}\n"
"#define highp\n"
"#define in attribute\n"
"#define out varying\n"
"#endif\n"
#else
"#ifdef GL_ES\n" "#ifdef GL_ES\n"
"mediump float round(in mediump float x) {\n" "mediump float round(in mediump float x) {\n"
" return sign(x) * floor(abs(x) + .5);\n" "return sign(x) * floor(abs(x) + .5);\n"
"}\n" "}\n"
"#define in attribute\n" "#define in attribute\n"
"#define out varying\n" "#define out varying\n"
"#endif\n"; "#endif\n"
#endif
;
const char *compatFragment = const char *compatFragment =
#if defined(USE_OPENGL_SHADERS)
"#if __VERSION__ < 130\n"
"#define in varying\n"
"#define OUTPUT\n"
"#define outColor gl_FragColor\n"
"#define texture texture2D\n"
"#else\n"
"#define OUTPUT out vec4 outColor;\n"
"#endif\n"
#else
"#ifdef GL_ES\n" "#ifdef GL_ES\n"
"#define in varying\n" "#define in varying\n"
"#ifdef GL_FRAGMENT_PRECISION_HIGH\n" "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
@ -49,7 +71,9 @@ const char *compatFragment =
"#define texture texture2D\n" "#define texture texture2D\n"
"#else\n" "#else\n"
"#define OUTPUT out vec4 outColor;\n" "#define OUTPUT out vec4 outColor;\n"
"#endif\n"; "#endif\n"
#endif
;
} }
} }

View file

@ -74,7 +74,11 @@ static GLuint createCompatShader(const char *shaderSource, GLenum shaderType, co
#ifdef USE_GLES2 #ifdef USE_GLES2
"#version 100\n", "#version 100\n",
#else #else
#ifdef MACOSX
"#version 120\n",
#else
"#version 130\n", "#version 130\n",
#endif
#endif #endif
compatSource, compatSource,
shaderSource shaderSource