• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 14804036802

02 May 2025 09:58PM UTC coverage: 5.927% (-83.4%) from 89.28%
14804036802

Pull #3404

github

web-flow
Merge 5c103d7f8 into 0f2ccaeb2
Pull Request #3404: feat: added Graph module to Math

234 of 8383 branches covered (2.79%)

229 of 246 new or added lines in 1 file covered. (93.09%)

13145 existing lines in 208 files now uncovered.

934 of 15759 relevant lines covered (5.93%)

4.72 hits per line

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

0.0
/src/engine/Graphics/Context/vertex-buffer.ts
1
export interface VertexBufferOptions {
2
  /**
3
   * WebGL2RenderingContext this layout will be attached to, these cannot be reused across contexts.
4
   */
5
  gl: WebGL2RenderingContext;
6
  /**
7
   * Size in number of floats, so [4.2, 4.0, 2.1] is size = 3
8
   *
9
   * Ignored if data is passed directly
10
   */
11
  size?: number;
12
  /**
13
   * If the vertices never change switching 'static' can be more efficient on the gpu
14
   *
15
   * Default is 'dynamic'
16
   */
17
  type?: 'static' | 'dynamic';
18

19
  /**
20
   * Optionally pass pre-seeded data, size parameter is ignored
21
   */
22
  data?: Float32Array;
23
}
24

25
/**
26
 * Helper around vertex buffer to simplify creating and uploading geometry
27
 *
28
 * Under the hood uses Float32Array
29
 */
30
export class VertexBuffer {
31
  private _gl: WebGL2RenderingContext;
32

33
  /**
34
   * Access to the webgl buffer handle
35
   */
36
  public readonly buffer: WebGLBuffer;
37
  /**
38
   * Access to the raw data of the vertex buffer
39
   */
40
  public readonly bufferData: Float32Array;
41

42
  /**
43
   * If the vertices never change switching 'static' can be more efficient on the gpu
44
   *
45
   * Default is 'dynamic'
46
   */
UNCOV
47
  public type: 'static' | 'dynamic' = 'dynamic';
×
48

49
  constructor(options: VertexBufferOptions) {
UNCOV
50
    const { gl, size, type, data } = options;
×
UNCOV
51
    this._gl = gl;
×
UNCOV
52
    this.buffer = this._gl.createBuffer()!;
×
UNCOV
53
    if (!data && !size) {
×
54
      throw Error('Must either provide data or a size to the VertexBuffer');
×
55
    }
56

UNCOV
57
    if (!data) {
×
UNCOV
58
      this.bufferData = new Float32Array(size!);
×
59
    } else {
UNCOV
60
      this.bufferData = data;
×
61
    }
UNCOV
62
    this.type = type ?? this.type;
×
63
    // Allocate buffer
UNCOV
64
    gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
×
UNCOV
65
    gl.bufferData(gl.ARRAY_BUFFER, this.bufferData, this.type === 'static' ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW);
×
66
  }
67

68
  /**
69
   * Bind this vertex buffer
70
   */
71
  bind() {
UNCOV
72
    const gl = this._gl;
×
UNCOV
73
    gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
×
74
  }
75

76
  unbind() {
UNCOV
77
    const gl = this._gl;
×
UNCOV
78
    gl.bindBuffer(gl.ARRAY_BUFFER, null);
×
79
  }
80

81
  /**
82
   * Upload vertex buffer geometry to the GPU
83
   */
84
  upload(count?: number) {
UNCOV
85
    const gl = this._gl;
×
UNCOV
86
    gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
×
UNCOV
87
    if (count) {
×
UNCOV
88
      gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.bufferData, 0, count);
×
89
    } else {
90
      // TODO always use bufferSubData? need to perf test it
UNCOV
91
      gl.bufferData(gl.ARRAY_BUFFER, this.bufferData, this.type === 'static' ? gl.STATIC_DRAW : gl.DYNAMIC_DRAW);
×
92
    }
93
  }
94

95
  dispose() {
UNCOV
96
    const gl = this._gl;
×
UNCOV
97
    gl.deleteBuffer(this.buffer);
×
UNCOV
98
    this._gl = null as any;
×
99
  }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc