This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Molly Lloyd
committed
Apr 26, 2016
1 parent
bf013e5
commit 097cf73
Showing
10 changed files
with
164 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |