[core] pack extrude and line distance into unsigned byte
instead of a signed byte. It's a bit easier to understand.
6c29251b35
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user