diff options
author | karroffel <therzog@mail.de> | 2017-12-04 13:41:34 +0100 |
---|---|---|
committer | karroffel <therzog@mail.de> | 2018-03-01 15:12:30 +0100 |
commit | eac4c984dfe5eebb73b094aaf2ed5ab37b6e8fdf (patch) | |
tree | bdd2fc1a9a678422b37513a83f9bd842de532145 /drivers/gles2/shaders/canvas.glsl | |
parent | 7f3024d343aa1b14641ad5a7b56efaa1501550cf (diff) |
add GLES 2 renderer for 2D
This commit adds a new rendering backend, GLES2, and adds a
project setting to enable it.
Currently this backend can only be used on the X11 platform,
but integrating into other platforms is planned.
Diffstat (limited to 'drivers/gles2/shaders/canvas.glsl')
-rw-r--r-- | drivers/gles2/shaders/canvas.glsl | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl new file mode 100644 index 0000000000..11c6ab9b76 --- /dev/null +++ b/drivers/gles2/shaders/canvas.glsl @@ -0,0 +1,141 @@ +[vertex] + +#ifdef USE_GLES_OVER_GL +#define mediump +#define highp +#else +precision mediump float; +precision mediump int; +#endif + +uniform highp mat4 projection_matrix; +uniform highp mat4 modelview_matrix; +uniform highp mat4 extra_matrix; +attribute highp vec2 vertex; // attrib:0 +attribute vec4 color_attrib; // attrib:3 +attribute vec2 uv_attrib; // attrib:4 + +varying vec2 uv_interp; +varying vec4 color_interp; + +uniform highp vec2 color_texpixel_size; + +#ifdef USE_TEXTURE_RECT + +uniform vec4 dst_rect; +uniform vec4 src_rect; + +#endif + +uniform bool blit_pass; + +VERTEX_SHADER_GLOBALS + +vec2 select(vec2 a, vec2 b, bvec2 c) { + vec2 ret; + + ret.x = c.x ? b.x : a.x; + ret.y = c.y ? b.y : a.y; + + return ret; +} + +void main() { + + vec4 color = color_attrib; + +#ifdef USE_TEXTURE_RECT + + if (dst_rect.z < 0.0) { // Transpose is encoded as negative dst_rect.z + uv_interp = src_rect.xy + abs(src_rect.zw) * vertex.yx; + } else { + uv_interp = src_rect.xy + abs(src_rect.zw) * vertex; + } + + vec4 outvec = vec4(0.0, 0.0, 0.0, 1.0); + + // This is what is done in the GLES 3 bindings and should + // take care of flipped rects. + // + // But it doesn't. + // I don't know why, will need to investigate further. + + outvec.xy = dst_rect.xy + abs(dst_rect.zw) * select(vertex, vec2(1.0, 1.0) - vertex, lessThan(src_rect.zw, vec2(0.0, 0.0))); + + // outvec.xy = dst_rect.xy + abs(dst_rect.zw) * vertex; +#else + vec4 outvec = vec4(vertex.xy, 0.0, 1.0); + +#ifdef USE_UV_ATTRIBUTE + uv_interp = uv_attrib; +#else + uv_interp = vertex.xy; +#endif + +#endif + +{ + vec2 src_vtx=outvec.xy; +VERTEX_SHADER_CODE + +} + + color_interp = color; + + gl_Position = projection_matrix * modelview_matrix * outvec; + +} + +[fragment] + +#ifdef USE_GLES_OVER_GL +#define mediump +#define highp +#else +precision mediump float; +precision mediump int; +#endif + +uniform sampler2D color_texture; // texunit:0 +uniform highp vec2 color_texpixel_size; +uniform mediump sampler2D normal_texture; // texunit:1 + +varying mediump vec2 uv_interp; +varying mediump vec4 color_interp; + +uniform bool blit_pass; + +uniform vec4 final_modulate; + +#ifdef SCREEN_TEXTURE_USED + +uniform sampler2D screen_texture; // texunit:2 + +#endif + +#ifdef SCREEN_UV_USED + +uniform vec2 screen_pixel_size; + +#endif + +FRAGMENT_SHADER_GLOBALS + + +void main() { + + vec4 color = color_interp; + + color *= texture2D(color_texture, uv_interp); +{ + +FRAGMENT_SHADER_CODE + + +} + + color *= final_modulate; + + gl_FragColor = color; + +} |