Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

uber / deck.gl / 13945

20 Sep 2019 - 0:32 coverage decreased (-2.9%) to 79.802%
13945

Pull #3655

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Update layer.md
Pull Request #3655: Update pydeck layer docs

3399 of 4611 branches covered (73.72%)

Branch coverage included in aggregate %.

7024 of 8450 relevant lines covered (83.12%)

5682.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.76
/modules/core/src/transitions/gpu-interpolation-transition.js
1
import GL from '@luma.gl/constants';
8×
2
import {Buffer, Transform} from '@luma.gl/core';
3
import Attribute from '../lib/attribute';
4
import {
5
  padBuffer,
6
  getAttributeTypeFromSize,
7
  getSourceBufferAttribute,
8
  getAttributeBufferLength,
9
  cycleBuffers
10
} from '../lib/attribute-transition-utils';
11
import Transition from './transition';
12

13
export default class GPUInterpolationTransition {
14
  constructor({gl, attribute, timeline}) {
UNCOV
15
    this.gl = gl;
!
UNCOV
16
    this.type = 'interpolation';
!
UNCOV
17
    this.transition = new Transition(timeline);
!
UNCOV
18
    this.attribute = attribute;
!
19
    // this is the attribute we return during the transition - note: if it is a constant
20
    // attribute, it will be converted and returned as a regular attribute
21
    // `attribute.userData` is the original options passed when constructing the attribute.
22
    // This ensures that we set the proper `doublePrecision` flag and shader attributes.
UNCOV
23
    this.attributeInTransition = new Attribute(gl, attribute.userData);
!
UNCOV
24
    this.currentBufferLayout = attribute.bufferLayout;
!
25
    // storing currentLength because this.buffer may be larger than the actual length we want to use
26
    // this is because we only reallocate buffers when they grow, not when they shrink,
27
    // due to performance costs
UNCOV
28
    this.currentLength = 0;
!
UNCOV
29
    this.transform = getTransform(gl, attribute);
!
UNCOV
30
    const bufferOpts = {
!
31
      byteLength: 0,
32
      usage: GL.DYNAMIC_COPY
33
    };
UNCOV
34
    this.buffers = [
!
35
      new Buffer(gl, bufferOpts), // from
36
      new Buffer(gl, bufferOpts) // current
37
    ];
38
  }
39

40
  get inProgress() {
UNCOV
41
    return this.transition.inProgress;
!
42
  }
43

44
  // this is called when an attribute's values have changed and
45
  // we need to start animating towards the new values
46
  // this also correctly resizes / pads the transform's buffers
47
  // in case the attribute's buffer has changed in length or in
48
  // bufferLayout
49
  start(transitionSettings, numInstances) {
UNCOV
50
    if (transitionSettings.duration <= 0) {
Branches [[0, 0], [0, 1]] missed. !
UNCOV
51
      this.transition.cancel();
!
UNCOV
52
      return;
!
53
    }
54

UNCOV
55
    const {gl, buffers, attribute} = this;
!
56
    // Alternate between two buffers when new transitions start.
57
    // Last destination buffer is used as an attribute (from state),
58
    // And the other buffer is now the current buffer.
UNCOV
59
    cycleBuffers(buffers);
!
60

UNCOV
61
    const padBufferOpts = {
!
62
      numInstances,
63
      attribute,
64
      fromLength: this.currentLength,
65
      fromBufferLayout: this.currentBufferLayout,
66
      getData: transitionSettings.enter
67
    };
68

UNCOV
69
    for (const buffer of buffers) {
!
UNCOV
70
      padBuffer({buffer, ...padBufferOpts});
!
71
    }
72

UNCOV
73
    this.currentBufferLayout = attribute.bufferLayout;
!
UNCOV
74
    this.currentLength = getAttributeBufferLength(attribute, numInstances);
!
75
    this.attributeInTransition.update({
!
76
      buffer: buffers[1],
77
      // Hack: Float64Array is required for double-precision attributes
78
      // to generate correct shader attributes
79
      value: attribute.value
80
    });
81

UNCOV
82
    this.transition.start(transitionSettings);
!
83

UNCOV
84
    this.transform.update({
!
85
      elementCount: Math.floor(this.currentLength / attribute.size),
86
      sourceBuffers: {
87
        aFrom: buffers[0],
88
        aTo: getSourceBufferAttribute(gl, attribute)
89
      },
90
      feedbackBuffers: {
91
        vCurrent: buffers[1]
92
      }
93
    });
94
  }
95

96
  update() {
UNCOV
97
    const updated = this.transition.update();
!
UNCOV
98
    if (updated) {
Branches [[1, 0], [1, 1]] missed. !
99
      const {
100
        time,
101
        settings: {duration, easing}
UNCOV
102
      } = this.transition;
!
UNCOV
103
      const t = easing(time / duration);
!
104
      this.transform.run({
!
105
        uniforms: {time: t}
106
      });
107
    }
UNCOV
108
    return updated;
!
109
  }
110

111
  cancel() {
UNCOV
112
    this.transition.cancel();
!
UNCOV
113
    this.transform.delete();
!
114
    while (this.buffers.length) {
!
115
      this.buffers.pop().delete();
!
116
    }
117
  }
118
}
119

120
const vs = `
1×
121
#define SHADER_NAME interpolation-transition-vertex-shader
122

123
uniform float time;
124
attribute ATTRIBUTE_TYPE aFrom;
125
attribute ATTRIBUTE_TYPE aTo;
126
varying ATTRIBUTE_TYPE vCurrent;
127

128
void main(void) {
129
  vCurrent = mix(aFrom, aTo, time);
130
  gl_Position = vec4(0.0);
131
}
132
`;
133

134
function getTransform(gl, attribute) {
UNCOV
135
  const attributeType = getAttributeTypeFromSize(attribute.size);
!
UNCOV
136
  return new Transform(gl, {
!
137
    vs,
138
    defines: {
139
      ATTRIBUTE_TYPE: attributeType
140
    },
141
    varyings: ['vCurrent']
142
  });
143
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC