Skip to content

Commit

Permalink
Merge pull request #5004 from AnalyticalGraphicsInc/safer-attribute-c…
Browse files Browse the repository at this point in the history
…hecking

Safer model attribute checking
  • Loading branch information
pjcozzi authored Feb 15, 2017
2 parents ae147ce + 12efaec commit 0d5f969
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ define([
// the normal attribute.
for (i = 1; i < length; ++i) {
var attribute = attributes[i];
if (/position/i.test(attribute)) {
if (/pos/i.test(attribute)) {
attributes[i] = attributes[0];
attributes[0] = attribute;
break;
Expand Down Expand Up @@ -2332,6 +2332,7 @@ define([
// Retrieve the compiled shader program to as#dex values to attributes
var attributeLocations = {};

var location;
var index;
var technique = techniques[materials[primitive.material].technique];
var parameters = technique.parameters;
Expand All @@ -2340,23 +2341,27 @@ define([
var programVertexAttributes = program.vertexAttributes;
var programAttributeLocations = program._attributeLocations;

// Note: WebGL shader compiler may have optimized and removed some attributes from programAttributeLocations
for (var location in programAttributeLocations){
if (programAttributeLocations.hasOwnProperty(location)) {
// Note: WebGL shader compiler may have optimized and removed some attributes from programVertexAttributes
for (location in programVertexAttributes){
if (programVertexAttributes.hasOwnProperty(location)) {
var attribute = attributes[location];
index = programVertexAttributes[location].index;
if (defined(attribute)) {
var vertexAttribute = programVertexAttributes[location];
if (defined(vertexAttribute)) {
index = vertexAttribute.index;
var parameter = parameters[attribute];
attributeLocations[parameter.semantic] = index;
}
} else {
// Pre-created attributes.
// Some pre-created attributes, like per-instance pickIds, may be compiled out of the draw program
// but should be included in the list of attribute locations for the pick program.
// This is safe to do since programVertexAttributes and programAttributeLocations are equivalent except
// that programVertexAttributes optimizes out unused attributes.
var parameter = parameters[attribute];
attributeLocations[parameter.semantic] = index;
}
}
}

// Always add pre-created attributes.
// Some pre-created attributes, like per-instance pickIds, may be compiled out of the draw program
// but should be included in the list of attribute locations for the pick program.
// This is safe to do since programVertexAttributes and programAttributeLocations are equivalent except
// that programVertexAttributes optimizes out unused attributes.
var precreatedAttributes = model._precreatedAttributes;
if (defined(precreatedAttributes)) {
for (location in precreatedAttributes) {
if (precreatedAttributes.hasOwnProperty(location)) {
index = programAttributeLocations[location];
attributeLocations[location] = index;
}
Expand Down

0 comments on commit 0d5f969

Please # to comment.