Skip to content

Commit 575e23b

Browse files
authored
fixed ordered attributes (#636)
Attributes have to be bound by order 0, 1, 2, 3, etc. If it comes in mixed order f.e; 0, 3, 4, 2, 1 it can cause problems on devices.
2 parents 8a05977 + 2993273 commit 575e23b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/core/lib/WebGlContextWrapper.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,16 +716,17 @@ export class WebGlContextWrapper {
716716
* @param program
717717
* @returns object with numbers
718718
*/
719-
getAttributeLocations(program: WebGLProgram): Record<string, number> {
719+
getAttributeLocations(program: WebGLProgram): string[] {
720720
const gl = this.gl;
721721
const length = gl.getProgramParameter(
722722
program,
723723
gl.ACTIVE_ATTRIBUTES,
724724
) as number;
725-
const result = {} as Record<string, number>;
725+
726+
const result: string[] = [];
726727
for (let i = 0; i < length; i++) {
727728
const { name } = gl.getActiveAttrib(program, i) as WebGLActiveInfo;
728-
result[name] = gl.getAttribLocation(program, name);
729+
result[gl.getAttribLocation(program, name)] = name;
729730
}
730731
return result;
731732
}

src/core/renderers/webgl/WebGlShaderProgram.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
4545
protected vao: WebGLVertexArrayObject | undefined;
4646
protected renderer: WebGlRenderer;
4747
protected glw: WebGlContextWrapper;
48-
protected attributeLocations: Record<string, number>;
48+
protected attributeLocations: string[];
4949
protected uniformLocations: Record<string, WebGLUniformLocation> | null;
5050
protected lifecycle: Pick<WebGlShaderType, 'update' | 'canBatch'>;
5151
protected useSystemAlpha = false;
@@ -135,8 +135,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
135135

136136
disableAttributes() {
137137
const glw = this.glw;
138-
const attribs = Object.keys(this.attributeLocations);
139-
const attribLen = attribs.length;
138+
const attribLen = this.attributeLocations.length;
140139
for (let i = 0; i < attribLen; i++) {
141140
glw.disableVertexAttribArray(i);
142141
}
@@ -278,7 +277,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
278277

279278
bindBufferCollection(buffer: BufferCollection) {
280279
const { glw } = this;
281-
const attribs = Object.keys(this.attributeLocations);
280+
const attribs = this.attributeLocations;
282281
const attribLen = attribs.length;
283282

284283
for (let i = 0; i < attribLen; i++) {
@@ -332,8 +331,8 @@ export class WebGlShaderProgram implements CoreShaderProgram {
332331
this.program = null;
333332
this.uniformLocations = null;
334333

335-
const attribs = Object.keys(this.attributeLocations);
336-
const attribLen = attribs.length;
334+
const attribs = this.attributeLocations;
335+
const attribLen = this.attributeLocations.length;
337336
for (let i = 0; i < attribLen; i++) {
338337
this.glw.deleteBuffer(attribs[i]!);
339338
}

0 commit comments

Comments
 (0)