use glsl built-in ifdef directive for extensions

This commit is contained in:
2019-01-30 14:00:56 +01:00
parent c516e8ae78
commit 489036a40c

View File

@@ -85,27 +85,27 @@ void App::initShaders()
"}\n"; "}\n";
static const char* shader_blend_f = static const char* shader_blend_f =
SHADER_VERSION SHADER_VERSION
#ifdef __IOS__ "#if defined(GL_EXT_shader_framebuffer_fetch)\n"
"#extension GL_EXT_shader_framebuffer_fetch : enable\n" " #extension GL_EXT_shader_framebuffer_fetch : enable\n"
#endif "#endif\n"
"uniform sampler2D tex;\n" "uniform sampler2D tex;\n"
"uniform sampler2D tex_alpha;\n" "uniform sampler2D tex_alpha;\n"
"uniform sampler2D tex_bg;\n" "uniform sampler2D tex_bg;\n"
"uniform mediump float alpha;\n" "uniform mediump float alpha;\n"
"uniform int blend_mode;\n" "uniform int blend_mode;\n"
"in mediump vec2 uv;\n" "in mediump vec2 uv;\n"
#ifdef __IOS__ "#if defined(GL_EXT_shader_framebuffer_fetch)\n"
"inout highp vec4 frag;\n" " inout highp vec4 frag;\n"
#else "#else\n"
"out mediump vec4 frag;\n" " out mediump vec4 frag;\n"
#endif "#endif\n"
SHADER_FUNCTION_BLEND SHADER_FUNCTION_BLEND
"void main() {\n" "void main() {\n"
#ifdef __IOS__ "#if defined(GL_EXT_shader_framebuffer_fetch)\n"
" highp vec4 bg = frag;\n" " highp vec4 bg = frag;\n"
#else "#else\n"
" mediump vec4 bg = texture(tex_bg, uv);\n" " mediump vec4 bg = texture(tex_bg, uv);\n"
#endif "#endif\n"
" mediump vec4 fg = vec4(texture(tex, uv).rgb, texture(tex_alpha, uv).a);\n" " mediump vec4 fg = vec4(texture(tex, uv).rgb, texture(tex_alpha, uv).a);\n"
" if (fg.a == 0.0) { frag = bg; return; }\n" " if (fg.a == 0.0) { frag = bg; return; }\n"
" mediump float contribution = (1.0 - bg.a) * fg.a;\n" " mediump float contribution = (1.0 - bg.a) * fg.a;\n"
@@ -357,9 +357,9 @@ void App::initShaders()
"}\n"; "}\n";
static const char* shader_stroke_f = static const char* shader_stroke_f =
SHADER_VERSION SHADER_VERSION
#ifdef __IOS__ "#if defined(GL_EXT_shader_framebuffer_fetch)\n"
"#extension GL_EXT_shader_framebuffer_fetch : enable\n" " #extension GL_EXT_shader_framebuffer_fetch : enable\n"
#endif "#endif\n"
"uniform mediump sampler2D tex;\n" "uniform mediump sampler2D tex;\n"
"uniform mediump sampler2D tex_bg;\n" "uniform mediump sampler2D tex_bg;\n"
"uniform mediump sampler2D tex_stencil;\n" "uniform mediump sampler2D tex_stencil;\n"
@@ -375,22 +375,22 @@ void App::initShaders()
"in mediump vec2 uv;\n" "in mediump vec2 uv;\n"
"in mediump vec2 uv_2;\n" "in mediump vec2 uv_2;\n"
"in mediump float q;\n" "in mediump float q;\n"
#ifdef __IOS__ "#if defined(GL_EXT_shader_framebuffer_fetch)\n"
"inout mediump vec4 frag;\n" " inout mediump vec4 frag;\n"
#else "#else\n"
"out mediump vec4 frag;\n" " out mediump vec4 frag;\n"
#endif "#endif\n"
SHADER_FUNCTION_RAND SHADER_FUNCTION_RAND
"void main() {\n" "void main() {\n"
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n" " mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
" mediump float stencil = 1.0 - (texture(tex_stencil, (uv2+stencil_offset) * 5.0).r) * stencil_alpha;\n" " mediump float stencil = 1.0 - (texture(tex_stencil, (uv2+stencil_offset) * 5.0).r) * stencil_alpha;\n"
" mediump float brush_alpha = ( 1.0 - texture(tex, uv/q).r ) * alpha;\n" " mediump float brush_alpha = ( 1.0 - texture(tex, uv/q).r ) * alpha;\n"
" mediump vec4 fg = vec4(col.rgb, brush_alpha * stencil);\n" " mediump vec4 fg = vec4(col.rgb, brush_alpha * stencil);\n"
#ifdef __IOS__ "#if defined(GL_EXT_shader_framebuffer_fetch)\n"
" mediump vec4 bg = frag;\n" " mediump vec4 bg = frag;\n"
#else "#else\n"
" mediump vec4 bg = texture(tex_bg, uv2);\n" " mediump vec4 bg = texture(tex_bg, uv2);\n"
#endif "#endif\n"
" fg.a *= 1.0-rand(uv2+uv)*noise;\n" " fg.a *= 1.0-rand(uv2+uv)*noise;\n"
" if (fg.a == 0.0) discard;\n" " if (fg.a == 0.0) discard;\n"
" if (mix_alpha > 0.0){\n" " if (mix_alpha > 0.0){\n"