Skip to content

Commit

Permalink
Fix instancing may cause other attribute divisor wrong bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Feb 25, 2019
1 parent e9ffa4c commit f798784
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,10 @@ var Renderer = Base.extend(function () {

if (isInstanced) {
for (var i = 0; i < instancedAttrLocations.length; i++) {
_gl.disableVertexAttribArray(instancedAttrLocations[i]);
if (!instancedAttrLocations[i].enabled) {
_gl.disableVertexAttribArray(instancedAttrLocations[i].location);
}
ext.vertexAttribDivisorANGLE(instancedAttrLocations[i].location, 0);
}
}
},
Expand All @@ -905,12 +908,17 @@ var Renderer = Base.extend(function () {
}

var glType = attributeBufferTypeMap[bufferObj.type] || _gl.FLOAT;;
_gl.enableVertexAttribArray(location); // TODO
var isEnabled = program.isAttribEnabled(this, location);
if (!program.isAttribEnabled(this, location)) {
_gl.enableVertexAttribArray(location);
}
locations.push({
location: location,
enabled: isEnabled
});
_gl.bindBuffer(_gl.ARRAY_BUFFER, bufferObj.buffer);
_gl.vertexAttribPointer(location, bufferObj.size, glType, false, 0, 0);
ext.vertexAttribDivisorANGLE(location, bufferObj.divisor);

locations.push(location);
}

return locations;
Expand Down
10 changes: 9 additions & 1 deletion src/gpu/GLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ var GLProgram = Base.extend({
}

for (var i = 0; i < enabledAttributeListInContext.length; i++) {
switch(enabledAttributeListInContext[i]){
switch (enabledAttributeListInContext[i]){
case SHADER_STATE_TO_ENABLE:
_gl.enableVertexAttribArray(i);
enabledAttributeListInContext[i] = SHADER_STATE_PENDING;
Expand Down Expand Up @@ -279,6 +279,14 @@ var GLProgram = Base.extend({
return location;
},

isAttribEnabled: function (renderer, location) {
var enabledAttributeListInContext
= enabledAttributeList[renderer.__uid__]
|| [];

return !!enabledAttributeListInContext[location];
},

buildProgram: function (_gl, shader, vertexShaderCode, fragmentShaderCode) {
var vertexShader = _gl.createShader(_gl.VERTEX_SHADER);
var program = _gl.createProgram();
Expand Down

0 comments on commit f798784

Please sign in to comment.