Skip to content

Commit aea7680

Browse files
authored
Merge pull request #4205 from Tyriar/triangle_strip
Draw quads with triangle strip
2 parents 1e6dfec + fb4a4e6 commit aea7680

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

addons/xterm-addon-webgl/src/GlyphRenderer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ export class GlyphRenderer extends Disposable {
127127
gl.vertexAttribPointer(VertexAttribLocations.UNIT_QUAD, 2, this._gl.FLOAT, false, 0, 0);
128128

129129
// Setup the unit quad element array buffer, this points to indices in
130-
// unitQuadVertices to allow is to draw 2 triangles from the vertices
131-
const unitQuadElementIndices = new Uint8Array([0, 1, 3, 0, 2, 3]);
130+
// unitQuadVertices to allow is to draw 2 triangles from the vertices via a
131+
// triangle strip
132+
const unitQuadElementIndices = new Uint8Array([0, 1, 2, 3]);
132133
const elementIndicesBuffer = gl.createBuffer();
133134
this.register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
134135
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementIndicesBuffer);
@@ -317,7 +318,7 @@ export class GlyphRenderer extends Disposable {
317318
gl.uniform2f(this._resolutionLocation, gl.canvas.width, gl.canvas.height);
318319

319320
// Draw the viewport
320-
gl.drawElementsInstanced(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0, bufferLength / INDICES_PER_CELL);
321+
gl.drawElementsInstanced(gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_BYTE, 0, bufferLength / INDICES_PER_CELL);
321322
}
322323

323324
public setAtlas(atlas: ITextureAtlas): void {

addons/xterm-addon-webgl/src/RectangleRenderer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ export class RectangleRenderer extends Disposable {
113113
gl.vertexAttribPointer(VertexAttribLocations.UNIT_QUAD, 2, this._gl.FLOAT, false, 0, 0);
114114

115115
// Setup the unit quad element array buffer, this points to indices in
116-
// unitQuadVertices to allow is to draw 2 triangles from the vertices
117-
const unitQuadElementIndices = new Uint8Array([0, 1, 3, 0, 2, 3]);
116+
// unitQuadVertices to allow is to draw 2 triangles from the vertices via a
117+
// triangle strip
118+
const unitQuadElementIndices = new Uint8Array([0, 1, 2, 3]);
118119
const elementIndicesBuffer = gl.createBuffer();
119120
this.register(toDisposable(() => gl.deleteBuffer(elementIndicesBuffer)));
120121
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elementIndicesBuffer);
@@ -153,7 +154,7 @@ export class RectangleRenderer extends Disposable {
153154
// Bind attributes buffer and draw
154155
gl.bindBuffer(gl.ARRAY_BUFFER, this._attributesBuffer);
155156
gl.bufferData(gl.ARRAY_BUFFER, this._vertices.attributes, gl.DYNAMIC_DRAW);
156-
gl.drawElementsInstanced(this._gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0, this._vertices.count);
157+
gl.drawElementsInstanced(this._gl.TRIANGLE_STRIP, 4, gl.UNSIGNED_BYTE, 0, this._vertices.count);
157158
}
158159

159160
public handleResize(): void {

0 commit comments

Comments
 (0)