gl-shader
Advanced tools
Comparing version 4.2.0 to 4.2.1
34
index.js
@@ -13,2 +13,3 @@ 'use strict' | ||
this.gl = gl | ||
this.gl.lastAttribCount = 0 // fixme where else should we store info, safe but not nice on the gl object | ||
@@ -33,2 +34,20 @@ //Default initialize these to null | ||
} | ||
// ensuring that we have the right number of enabled vertex attributes | ||
var i | ||
var newAttribCount = this.gl.getProgramParameter(this.program, this.gl.ACTIVE_ATTRIBUTES) // more robust approach | ||
//var newAttribCount = Object.keys(this.attributes).length // avoids the probably immaterial introspection slowdown | ||
var oldAttribCount = this.gl.lastAttribCount | ||
if(newAttribCount > oldAttribCount) { | ||
for(i = oldAttribCount; i < newAttribCount; i++) { | ||
this.gl.enableVertexAttribArray(i) | ||
} | ||
} else if(oldAttribCount > newAttribCount) { | ||
for(i = newAttribCount; i < oldAttribCount; i++) { | ||
this.gl.disableVertexAttribArray(i) | ||
} | ||
} | ||
this.gl.lastAttribCount = newAttribCount | ||
this.gl.useProgram(this.program) | ||
@@ -38,2 +57,12 @@ } | ||
proto.dispose = function() { | ||
// disabling vertex attributes so new shader starts with zero | ||
// and it's also useful if all shaders are disposed but the | ||
// gl context is reused for subsequent replotting | ||
var oldAttribCount = this.gl.lastAttribCount | ||
for (var i = 0; i < oldAttribCount; i++) { | ||
this.gl.disableVertexAttribArray(i) | ||
} | ||
this.gl.lastAttribCount = 0 | ||
if(this._fref) { | ||
@@ -125,3 +154,4 @@ this._fref.dispose() | ||
var attributeLocations = [] | ||
for(var i=0; i<attributes.length; ++i) { | ||
var i | ||
for(i=0; i<attributes.length; ++i) { | ||
var attr = attributes[i] | ||
@@ -166,3 +196,3 @@ if(attr.type.indexOf('mat') >= 0) { | ||
var curLocation = 0 | ||
for(var i=0; i<attributeLocations.length; ++i) { | ||
for(i=0; i<attributeLocations.length; ++i) { | ||
if(attributeLocations[i] < 0) { | ||
@@ -169,0 +199,0 @@ while(attributeLocations.indexOf(curLocation) >= 0) { |
{ | ||
"name": "gl-shader", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "WebGL shader wrapper", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -97,3 +97,3 @@ gl-shader | ||
], | ||
attribuets: [ | ||
attributes: [ | ||
{ type: 'vec3', name: 'position' } | ||
@@ -100,0 +100,0 @@ ] |
36404
904