Skip to content

Commit

Permalink
Always call vertexAttribDivisor
Browse files Browse the repository at this point in the history
Previously, if the divisor property was absent, the
gl.vertexAttribDivisor call would be omitted, which
caused the divisor value to be inherited from the
previous program.

With this change, an absent divisor causes an explicit
call to gl.vertexAttribDivisor with parameter zero.

Note this is a breaking change if people have been
deliberately or accidentally carrying divisor values
forward from one program to the next.
  • Loading branch information
Dominic Prior authored and greggman committed Sep 11, 2022
1 parent 38b4137 commit 3d94eaf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function makeTypedArray(array, name) {
* @property {boolean} [normalize] whether or not to normalize the data. Default = false
* @property {number} [offset] offset into buffer in bytes. Default = 0
* @property {number} [stride] the stride in bytes per element. Default = 0
* @property {number} [divisor] the divisor in instances. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
* @property {number} [divisor] the divisor in instances. Default = 0
* where as anything else = do call it with this value
* @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
* @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
Expand All @@ -221,7 +221,7 @@ function makeTypedArray(array, name) {
* @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
* @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
* @property {number} [offset] offset for `vertexAttribPointer`. Default = 0
* @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
* @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = 0
* where as anything else = do call it with this value
* @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.
* @property {string} [name] synonym for `attrib`.
Expand Down
16 changes: 4 additions & 12 deletions src/programs.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,7 @@ function floatAttribSetter(gl, index) {
gl.enableVertexAttribArray(index);
gl.vertexAttribPointer(
index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);
if (b.divisor !== undefined) {
gl.vertexAttribDivisor(index, b.divisor);
}
gl.vertexAttribDivisor(index, b.divisor || 0);
}
};
}
Expand All @@ -416,9 +414,7 @@ function intAttribSetter(gl, index) {
gl.enableVertexAttribArray(index);
gl.vertexAttribIPointer(
index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);
if (b.divisor !== undefined) {
gl.vertexAttribDivisor(index, b.divisor);
}
gl.vertexAttribDivisor(index, b.divisor || 0);
}
};
}
Expand All @@ -437,9 +433,7 @@ function uintAttribSetter(gl, index) {
gl.enableVertexAttribArray(index);
gl.vertexAttribIPointer(
index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);
if (b.divisor !== undefined) {
gl.vertexAttribDivisor(index, b.divisor);
}
gl.vertexAttribDivisor(index, b.divisor || 0);
}
};
}
Expand All @@ -462,9 +456,7 @@ function matAttribSetter(gl, index, typeInfo) {
gl.enableVertexAttribArray(index + i);
gl.vertexAttribPointer(
index + i, size, type, normalize, stride, offset + rowOffset * i);
if (b.divisor !== undefined) {
gl.vertexAttribDivisor(index + i, b.divisor);
}
gl.vertexAttribDivisor(index + i, b.divisor || 0);
}
};
}
Expand Down

0 comments on commit 3d94eaf

Please sign in to comment.