diff options
author | Molly Lloyd <molly@mapbox.com> | 2016-04-20 15:21:44 -0700 |
---|---|---|
committer | Molly Lloyd <molly@mapbox.com> | 2016-04-28 17:13:20 -0700 |
commit | c86f558e9d608ac19ca5b26ea8f72e2dc43c07c0 (patch) | |
tree | c398f14a1cdc646119fac4ac8c0d557ca970e29d /src/mbgl/shader | |
parent | da78422c5c37b2150eefeb399658903e45bf05d9 (diff) | |
download | qtlocation-mapboxgl-c86f558e9d608ac19ca5b26ea8f72e2dc43c07c0.tar.gz |
[core] port outlinepattern for fill-pattern anti-aliasing from gl-js to native
add outlinepattern shader class to relevant files
add outlinepattern code to painter_fill.cpp
add outlinepattern code to fill_bucket
refactor painter_fill, fix tests
fix merge conflicts and setDepthSublayer
update render test to no antialiasing so travis will be happy
Diffstat (limited to 'src/mbgl/shader')
-rw-r--r-- | src/mbgl/shader/outlinepattern.fragment.glsl | 30 | ||||
-rw-r--r-- | src/mbgl/shader/outlinepattern.vertex.glsl | 21 | ||||
-rw-r--r-- | src/mbgl/shader/outlinepattern_shader.cpp | 21 | ||||
-rw-r--r-- | src/mbgl/shader/outlinepattern_shader.hpp | 32 |
4 files changed, 104 insertions, 0 deletions
diff --git a/src/mbgl/shader/outlinepattern.fragment.glsl b/src/mbgl/shader/outlinepattern.fragment.glsl new file mode 100644 index 0000000000..dd1efd63e6 --- /dev/null +++ b/src/mbgl/shader/outlinepattern.fragment.glsl @@ -0,0 +1,30 @@ +uniform float u_opacity; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; +uniform float u_mix; + +uniform sampler2D u_image; + +varying vec2 v_pos_a; +varying vec2 v_pos_b; +varying vec2 v_pos; + +void main() { + vec2 imagecoord = mod(v_pos_a, 1.0); + vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); + vec4 color1 = texture2D(u_image, pos); + + vec2 imagecoord_b = mod(v_pos_b, 1.0); + vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); + vec4 color2 = texture2D(u_image, pos2); + + // find distance to outline for alpha interpolation + + float dist = length(v_pos - gl_FragCoord.xy); + float alpha = smoothstep(1.0, 0.0, dist); + + + gl_FragColor = mix(color1, color2, u_mix) * alpha * u_opacity; +}
\ No newline at end of file diff --git a/src/mbgl/shader/outlinepattern.vertex.glsl b/src/mbgl/shader/outlinepattern.vertex.glsl new file mode 100644 index 0000000000..e31b77b560 --- /dev/null +++ b/src/mbgl/shader/outlinepattern.vertex.glsl @@ -0,0 +1,21 @@ +uniform vec2 u_patternscale_a; +uniform vec2 u_patternscale_b; +uniform vec2 u_offset_a; +uniform vec2 u_offset_b; + +attribute vec2 a_pos; + +uniform mat4 u_matrix; +uniform vec2 u_world; + +varying vec2 v_pos_a; +varying vec2 v_pos_b; +varying vec2 v_pos; + + +void main() { + gl_Position = u_matrix * vec4(a_pos, 0, 1); + v_pos_a = u_patternscale_a * a_pos + u_offset_a; + v_pos_b = u_patternscale_b * a_pos + u_offset_b; + v_pos = (gl_Position.xy/gl_Position.w + 1.0) / 2.0 * u_world; +} diff --git a/src/mbgl/shader/outlinepattern_shader.cpp b/src/mbgl/shader/outlinepattern_shader.cpp new file mode 100644 index 0000000000..44b76b74c0 --- /dev/null +++ b/src/mbgl/shader/outlinepattern_shader.cpp @@ -0,0 +1,21 @@ +#include <mbgl/shader/outlinepattern_shader.hpp> +#include <mbgl/shader/outlinepattern.vertex.hpp> +#include <mbgl/shader/outlinepattern.fragment.hpp> +#include <mbgl/gl/gl.hpp> + +#include <cstdio> + +using namespace mbgl; + +OutlinePatternShader::OutlinePatternShader(gl::GLObjectStore& glObjectStore) + : Shader( + "outlinepattern", + shaders::outlinepattern::vertex, shaders::outlinepattern::fragment, + glObjectStore + ) { +} + +void OutlinePatternShader::bind(GLbyte *offset) { + MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_pos)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 0, offset)); +} diff --git a/src/mbgl/shader/outlinepattern_shader.hpp b/src/mbgl/shader/outlinepattern_shader.hpp new file mode 100644 index 0000000000..eed3839fd3 --- /dev/null +++ b/src/mbgl/shader/outlinepattern_shader.hpp @@ -0,0 +1,32 @@ +#ifndef MBGL_SHADER_SHADER_OUTLINEPATTERN +#define MBGL_SHADER_SHADER_OUTLINEPATTERN + +#include <mbgl/shader/shader.hpp> +#include <mbgl/shader/uniform.hpp> + +namespace mbgl { + +class OutlinePatternShader : public Shader { +public: + OutlinePatternShader(gl::GLObjectStore&); + + void bind(GLbyte *offset) final; + + UniformMatrix<4> u_matrix = {"u_matrix", *this}; + Uniform<std::array<GLfloat, 2>> u_pattern_tl_a = {"u_pattern_tl_a", *this}; + Uniform<std::array<GLfloat, 2>> u_pattern_br_a = {"u_pattern_br_a", *this}; + Uniform<std::array<GLfloat, 2>> u_pattern_tl_b = {"u_pattern_tl_b", *this}; + Uniform<std::array<GLfloat, 2>> u_pattern_br_b = {"u_pattern_br_b", *this}; + Uniform<GLfloat> u_opacity = {"u_opacity", *this}; + Uniform<GLfloat> u_mix = {"u_mix", *this}; + Uniform<GLint> u_image = {"u_image", *this}; + Uniform<std::array<GLfloat, 2>> u_patternscale_a = {"u_patternscale_a", *this}; + Uniform<std::array<GLfloat, 2>> u_patternscale_b = {"u_patternscale_b", *this}; + Uniform<std::array<GLfloat, 2>> u_offset_a = {"u_offset_a", *this}; + Uniform<std::array<GLfloat, 2>> u_offset_b = {"u_offset_b", *this}; + Uniform<std::array<GLfloat, 2>> u_world = {"u_world", *this}; +}; + +} // namespace mbgl + +#endif
\ No newline at end of file |