diff options
author | Ansis Brammanis <brammanis@gmail.com> | 2016-03-28 16:58:54 -0700 |
---|---|---|
committer | Ansis Brammanis <brammanis@gmail.com> | 2016-03-28 17:44:42 -0700 |
commit | 3cc55a9dacf2c0984ca277500b334c3f44fa60c0 (patch) | |
tree | fdfdcbcffa0b4926e2f91178019956d889c22437 /src | |
parent | 196b7903d17f365b40e88624d6b1de2782ce2b2e (diff) | |
download | qtlocation-mapboxgl-3cc55a9dacf2c0984ca277500b334c3f44fa60c0.tar.gz |
[core] pack extrude and line distance into unsigned byte
instead of a signed byte. It's a bit easier to understand.
https://github.com/mapbox/mapbox-gl-js/commit/6c29251b3572ce9f2afae8182b56da6c1b9838b4
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/geometry/line_buffer.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/shader/line.vertex.glsl | 4 | ||||
-rw-r--r-- | src/mbgl/shader/line_shader.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/shader/linepattern.vertex.glsl | 6 | ||||
-rw-r--r-- | src/mbgl/shader/linepattern_shader.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/shader/linesdf.vertex.glsl | 6 | ||||
-rw-r--r-- | src/mbgl/shader/linesdf_shader.cpp | 2 |
7 files changed, 24 insertions, 16 deletions
diff --git a/src/mbgl/geometry/line_buffer.cpp b/src/mbgl/geometry/line_buffer.cpp index 75b9af7e20..3d979a2a45 100644 --- a/src/mbgl/geometry/line_buffer.cpp +++ b/src/mbgl/geometry/line_buffer.cpp @@ -13,16 +13,24 @@ GLsizei LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey, coords[0] = (x * 2) | tx; coords[1] = (y * 2) | ty; - int8_t *extrude = static_cast<int8_t *>(data); - extrude[4] = ::round(extrudeScale * ex); - extrude[5] = ::round(extrudeScale * ey); + uint8_t *ubytes = static_cast<uint8_t *>(data); + // add 128 to store an byte in an unsigned byte + ubytes[4] = ::round(extrudeScale * ex) + 128; + ubytes[5] = ::round(extrudeScale * ey) + 128; + + // Encode the -1/0/1 direction value into the first two bits of .z of a_data. + // Combine it with the lower 6 bits of `linesofar` (shifted by 2 bites to make + // room for the direction value). The upper 8 bits of `linesofar` are placed in + // the `w` component. `linesofar` is scaled down by `LINE_DISTANCE_SCALE` so that + // we can store longer distances while sacrificing precision. // Encode the -1/0/1 direction value into .zw coordinates of a_data, which is normally covered // by linesofar, so we need to merge them. // The z component's first bit, as well as the sign bit is reserved for the direction, // so we need to shift the linesofar. - extrude[6] = ((dir < 0) ? -1 : 1) * ((dir ? 1 : 0) | static_cast<int8_t>((linesofar << 1) & 0x7F)); - extrude[7] = ((linesofar >> 6) & 0xFF) - 128; + + ubytes[6] = ((dir == 0 ? 0 : (dir < 0 ? -1 : 1 )) + 1) | ((linesofar & 0x3F) << 2); + ubytes[7] = linesofar >> 6; return idx; } diff --git a/src/mbgl/shader/line.vertex.glsl b/src/mbgl/shader/line.vertex.glsl index 1bd7f5ef5f..973e92a17d 100644 --- a/src/mbgl/shader/line.vertex.glsl +++ b/src/mbgl/shader/line.vertex.glsl @@ -23,8 +23,8 @@ varying vec2 v_normal; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/src/mbgl/shader/line_shader.cpp b/src/mbgl/shader/line_shader.cpp index e4df0531d8..c54b3312d8 100644 --- a/src/mbgl/shader/line_shader.cpp +++ b/src/mbgl/shader/line_shader.cpp @@ -17,5 +17,5 @@ void LineShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); } diff --git a/src/mbgl/shader/linepattern.vertex.glsl b/src/mbgl/shader/linepattern.vertex.glsl index 6fa499106c..5cceb64038 100644 --- a/src/mbgl/shader/linepattern.vertex.glsl +++ b/src/mbgl/shader/linepattern.vertex.glsl @@ -32,9 +32,9 @@ varying float v_linesofar; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; + float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/src/mbgl/shader/linepattern_shader.cpp b/src/mbgl/shader/linepattern_shader.cpp index 7acd42f727..40f64ed139 100644 --- a/src/mbgl/shader/linepattern_shader.cpp +++ b/src/mbgl/shader/linepattern_shader.cpp @@ -17,5 +17,5 @@ void LinepatternShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); } diff --git a/src/mbgl/shader/linesdf.vertex.glsl b/src/mbgl/shader/linesdf.vertex.glsl index f24d8399b8..9174e4d987 100644 --- a/src/mbgl/shader/linesdf.vertex.glsl +++ b/src/mbgl/shader/linesdf.vertex.glsl @@ -36,9 +36,9 @@ varying vec2 v_tex_b; varying float v_gamma_scale; void main() { - vec2 a_extrude = a_data.xy; - float a_direction = sign(a_data.z) * mod(a_data.z, 2.0); - float a_linesofar = (abs(floor(a_data.z / 2.0)) + (a_data.w + 128.0) * 64.0) * LINE_DISTANCE_SCALE; + vec2 a_extrude = a_data.xy - 128.0; + float a_direction = mod(a_data.z, 4.0) - 1.0; + float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; // We store the texture normals in the most insignificant bit // transform y so that 0 => -1 and 1 => 1 diff --git a/src/mbgl/shader/linesdf_shader.cpp b/src/mbgl/shader/linesdf_shader.cpp index 00adaf0c86..1358127925 100644 --- a/src/mbgl/shader/linesdf_shader.cpp +++ b/src/mbgl/shader/linesdf_shader.cpp @@ -17,5 +17,5 @@ void LineSDFShader::bind(GLbyte* offset) { MBGL_CHECK_ERROR(glVertexAttribPointer(a_pos, 2, GL_SHORT, false, 8, offset + 0)); MBGL_CHECK_ERROR(glEnableVertexAttribArray(a_data)); - MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_BYTE, false, 8, offset + 4)); + MBGL_CHECK_ERROR(glVertexAttribPointer(a_data, 4, GL_UNSIGNED_BYTE, false, 8, offset + 4)); } |