Skip to content
Browse files

caching for speed

  • Loading branch information...
1 parent b58de80 commit 65c67e88912a206349e4075b3339f19935dc7738 Matt committed Mar 16, 2011
View
56 c3dl/renderer/rendererwebgl.js
@@ -283,18 +283,18 @@ c3dl.WebGL = c3dl.inherit(c3dl.Renderer, function () {
// base string to shorten code below.
var base = "lights[" + lightID + "].";
glCanvas3D.useProgram(PID);
- this.setUniformf(PID, base + "position", [0, 0, 0], scene, "light"+i);
- this.setUniformf(PID, base + "ambient", [0, 0, 0], scene, "light"+i);
- this.setUniformf(PID, base + "diffuse", [0, 0, 0], scene, "light"+i);
+ this.setUniformf(PID, base + "position", [0, 0, 0], scene, "light"+i+lightID);
+ this.setUniformf(PID, base + "ambient", [0, 0, 0], scene, "light"+i+lightID);
+ this.setUniformf(PID, base + "diffuse", [0, 0, 0], scene, "light"+i+lightID);
this.setUniformf(PID, base + "specular", [0, 0, 0], scene, "light"+i);
- this.setUniformf(PID, base + "spotDirection", [0, 0, -1], scene, "light"+i);
- this.setUniformf(PID, base + "spotCutoff", 180, scene, "light"+i);
- this.setUniformf(PID, base + "spotExponent", 0, scene, "light"+i);
- this.setUniformf(PID, base + "attenuation1", 1, scene, "light"+i);
- this.setUniformf(PID, base + "attenuation2", 0, scene, "light"+i);
- this.setUniformf(PID, base + "attenuation3", 0, scene, "light"+i);
- this.setUniformi(PID, base + "type", 0, scene, "light"+i);
- this.setUniformi(PID, base + "isOn", 0, scene, "light"+i);
+ this.setUniformf(PID, base + "spotDirection", [0, 0, -1], scene, "light"+i+lightID);
+ this.setUniformf(PID, base + "spotCutoff", 180, scene, "light"+i+lightID);
+ this.setUniformf(PID, base + "spotExponent", 0, scene, "light"+i+lightID);
+ this.setUniformf(PID, base + "attenuation1", 1, scene, "light"+i+lightID);
+ this.setUniformf(PID, base + "attenuation2", 0, scene, "light"+i+lightID);
+ this.setUniformf(PID, base + "attenuation3", 0, scene, "light"+i+lightID);
+ this.setUniformi(PID, base + "type", 0, scene, "light"+i+lightID);
+ this.setUniformi(PID, base + "isOn", 0, scene, "light"+i+lightID);
}
}
}
@@ -315,8 +315,8 @@ c3dl.WebGL = c3dl.inherit(c3dl.Renderer, function () {
for (var i = 0, len = this.programsWithLights.length; i < len; i++)
{
glCanvas3D.useProgram(this.programsWithLights[i]);
- this.setUniformf(this.programsWithLights[i], "ambientLightColor", ambientLight, scene, "light"+i);
- this.setUniformi(this.programsWithLights[i], "lightingOn", this.getLighting(), scene, "light"+i);
+ this.setUniformf(this.programsWithLights[i], "ambientLightColor", ambientLight, scene, "ambientLight");
+ this.setUniformi(this.programsWithLights[i], "lightingOn", this.getLighting(), scene, "ambientLight"+i);
}
// turn it back on if it was on before.
@@ -354,7 +354,7 @@ c3dl.WebGL = c3dl.inherit(c3dl.Renderer, function () {
// if the light is off, that's the only uniform var that needs to be set.
if (lightList[i].isOn() == false)
{
- this.setUniformi(shader, base + "isOn", lightList[i].isOn(), scene, "light"+i);
+ this.setUniformi(shader, base + "isOn", lightList[i].isOn(), scene, "light"+progObjIter+i);
}
else
{
@@ -365,10 +365,10 @@ c3dl.WebGL = c3dl.inherit(c3dl.Renderer, function () {
var dir = c3dl.multiplyMatrixByDirection(c3dl.peekMatrix(), lightList[i].getDirection());
dir =c3dl.addVectorComponent(dir,0);
- this.setUniformf(shader, base + "position", dir, scene, "light"+i);
+ this.setUniformf(shader, base + "position", dir, scene, "light"+progObjIter+i);
// this is used to distinguish a directional light from a spotlight.
- this.setUniformf(shader, base + "spotCutoff", 180, scene, "light"+i);
+ this.setUniformf(shader, base + "spotCutoff", 180, scene, "light"+progObjIter+i);
}
// check if its a spotlight first before positional light!
@@ -383,8 +383,8 @@ c3dl.WebGL = c3dl.inherit(c3dl.Renderer, function () {
this.setUniformf(shader, base + "position", pos, scene, "light"+i);
this.setUniformf(shader, base + "spotDirection", dir, scene, "light"+i);
- this.setUniformf(shader, base + "spotCutoff", lightList[i].getCutoff(), scene, "light"+i);
- this.setUniformf(shader, base + "spotExponent", lightList[i].getExponent(), scene, "light"+i);
+ this.setUniformf(shader, base + "spotCutoff", lightList[i].getCutoff(), scene, "light"+progObjIter+i);
+ this.setUniformf(shader, base + "spotExponent", lightList[i].getExponent(), scene, "light"+progObjIter+i);
}
else if (lightList[i] instanceof c3dl.PositionalLight)
@@ -394,23 +394,23 @@ c3dl.WebGL = c3dl.inherit(c3dl.Renderer, function () {
pos = c3dl.multiplyMatrixByVector(c3dl.peekMatrix(), pos);
pos = c3dl.addVectorComponent(pos,1);
- this.setUniformf(shader, base + "position", pos, scene, "light"+i);
- this.setUniformf(shader, base + "spotCutoff", 180.0, scene, "light"+i);
+ this.setUniformf(shader, base + "position", pos, scene, "light"+progObjIter+i);
+ this.setUniformf(shader, base + "spotCutoff", 180.0, scene, "light"+progObjIter+i);
}
- this.setUniformi(shader, base + "type", lightList[i].getType(), scene, "light"+i);
- this.setUniformi(shader, base + "isOn", lightList[i].isOn(), scene, "light"+i);
- this.setUniformf(shader, base + "ambient", lightList[i].getAmbient(), scene, "light"+i);
- this.setUniformf(shader, base + "diffuse", lightList[i].getDiffuse(), scene, "light"+i);
- this.setUniformf(shader, base + "specular", lightList[i].getSpecular(), scene, "light"+i);
+ this.setUniformi(shader, base + "type", lightList[i].getType(), scene, "light"+progObjIter+i);
+ this.setUniformi(shader, base + "isOn", lightList[i].isOn(), scene, "light"+progObjIter+i);
+ this.setUniformf(shader, base + "ambient", lightList[i].getAmbient(), scene, "light"+progObjIter+i);
+ this.setUniformf(shader, base + "diffuse", lightList[i].getDiffuse(), scene, "light"+progObjIter+i);
+ this.setUniformf(shader, base + "specular", lightList[i].getSpecular(), scene, "light"+progObjIter+i);
// lights are attenuated as long as they are not directional lights
if (!(lightList[i] instanceof c3dl.DirectionalLight))
{
var attn = lightList[i].getAttenuation();
- this.setUniformf(shader, base + "attenuation1", attn[0], scene, "light"+i);
- this.setUniformf(shader, base + "attenuation2", attn[1], scene, "light"+i);
- this.setUniformf(shader, base + "attenuation3", attn[2], scene, "light"+i);
+ this.setUniformf(shader, base + "attenuation1", attn[0], scene, "light"+progObjIter+i);
+ this.setUniformf(shader, base + "attenuation2", attn[1], scene, "light"+progObjIter+i);
+ this.setUniformf(shader, base + "attenuation3", attn[2], scene, "light"+progObjIter+i);
}
}
}
View
9 c3dl/scene.js
@@ -58,6 +58,7 @@ c3dl.Scene = function ()
var updateHandler = null;
// Performance variables
+ var timerID = 0;
var lastTimeTaken = Date.now();
var numFramesSinceSceneStart = 0;
@@ -973,6 +974,7 @@ c3dl.Scene = function ()
// If a user wants to stop rendering, this is where it happens
if (exitRender)
{
+ timerID = clearInterval(timerID);
if (c3dl.debug.SHARK === true)
{
stopShark();
@@ -1033,7 +1035,7 @@ c3dl.Scene = function ()
this.refresh = function() {
thisScn.render();
- requestAnimFrame(thisScn.refresh);
+
}
/**
@@ -1062,9 +1064,8 @@ c3dl.Scene = function ()
// Benchmark hook:
if (typeof(benchmarkSetupDone) == "function") benchmarkSetupDone();
-
- this.refresh();
-
+ timerID = setInterval(this.render, 5);
+ //this.refresh();
this.setAmbientLight([ambientLight[0], ambientLight[1], ambientLight[2]]);
}
View
34 c3dl/shaders/model/cartoon/cartoon_callback.js
@@ -14,7 +14,6 @@ c3dl.cartoon_callback = function (renderingObj, scene)
var effect = geometry.getEffect();
var programObjID = renderingObj.getProgramObjectID();
gl.useProgram(programObjID);
-
if (effect.getParameter("qMap") == null)
{
c3dl.debug.logWarning('"qMap" is a required parameter for c3dl.effects.CARTOON');
@@ -68,12 +67,23 @@ c3dl.cartoon_callback = function (renderingObj, scene)
// before trying to set it.
// This is a kludge for Safari and Chrome since they want these attributes
////////////////////////////
- var normalAttribLoc = gl.getAttribLocation(outlineProgID, "Normal");
+
+ var normalAttribLoc = scene.curContextCache.attributes["outlinecartoon"+primSet+"Normal"];
+ if(normalAttribLoc ==undefined ) {
+ normalAttribLoc = gl.getAttribLocation(outlineProgID, "Normal");
+ scene.curContextCache.attributes["outlinecartoon"+primSet+"Normal"] = normalAttribLoc;
+ }
+
if (normalAttribLoc != -1 && currColl.getNormals())
{
renderer.setVertexAttribArray(outlineProgID, "Normal", 3, currColl.getVBONormals(), scene, "outlinecartoon"+primSet);
}
- var texAttribLoc = gl.getAttribLocation(outlineProgID, "Texture");
+
+ var texAttribLoc = scene.curContextCache.attributes["outlinecartoon"+primSet+"Texture"];
+ if(texAttribLoc ==undefined ) {
+ texAttribLoc = gl.getAttribLocation(outlineProgID, "Texture");
+ scene.curContextCache.attributes["outlinecartoon"+primSet+"Texture"] = texAttribLoc;
+ }
if (texAttribLoc != -1 && currColl.getTexCoords())
{
@@ -110,8 +120,13 @@ c3dl.cartoon_callback = function (renderingObj, scene)
{
var currColl = geometry.getPrimitiveSets()[coll];
- var normalAttribLoc = gl.getAttribLocation(programObjID, "Normal");
-
+
+ var normalAttribLoc = scene.curContextCache.attributes["cartoon"+coll+"Normal"];
+ if(normalAttribLoc ==undefined ) {
+ normalAttribLoc = gl.getAttribLocation(programObjID, "Normal");
+ scene.curContextCache.attributes["cartoon"+coll+"Normal"] = normalAttribLoc;
+ }
+
// if the object acutally has normals and the normal attribute was found
// NORMALS
if (currColl.getNormals())
@@ -128,7 +143,12 @@ c3dl.cartoon_callback = function (renderingObj, scene)
}
// TEXTURE
- var texAttribLoc = gl.getAttribLocation(programObjID, "Texture");
+ var texAttribLoc = scene.curContextCache.attributes["cartoon"+coll+"Texture"];
+ if(texAttribLoc ==undefined ) {
+ texAttribLoc = gl.getAttribLocation(programObjID, "Texture");
+ scene.curContextCache.attributes["cartoon"+coll+"Texture"] = texAttribLoc;
+ }
+
var texID = renderer.getTextureID(currColl.getTexture());
// if the texture isn't loaded, but this collation element has one,
@@ -171,8 +191,8 @@ c3dl.cartoon_callback = function (renderingObj, scene)
gl.activeTexture(gl.TEXTURE1);
// Minefield is throwing an exception here, but still running?
+
gl.bindTexture(gl.TEXTURE_2D, shadesTexID);
- alert("")
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
renderer.setUniformi(programObjID, "celShadeTex", 1, scene, "cartoon"+coll);
View
43 c3dl/shaders/model/gooch/gooch_callback.js
@@ -61,12 +61,22 @@ c3dl.gooch_callback = function (renderingObj, scene)
// before trying to set it.
// This is a kludge for Safari and Chrome since they want these attributes
////////////////////////////
- var normalAttribLoc = gl.getAttribLocation(outlineProgID, "Normal");
+ var normalAttribLoc = scene.curContextCache.attributes["outlinegooch"+primSet+"Normal"];
+ if(normalAttribLoc ==undefined ) {
+ normalAttribLoc = gl.getAttribLocation(outlineProgID, "Normal");
+ scene.curContextCache.attributes["outlinegooch"+primSet+"Normal"] = normalAttribLoc;
+ }
+
if (normalAttribLoc != -1 && currColl.getNormals())
{
renderer.setVertexAttribArray(outlineProgID, "Normal", 3, currColl.getVBONormals(), scene, "outlinegooch"+primSet);
}
- var texAttribLoc = gl.getAttribLocation(outlineProgID, "Texture");
+ var texAttribLoc = scene.curContextCache.attributes["outlinegooch"+primSet+"Texture"];
+ if(texAttribLoc ==undefined ) {
+ texAttribLoc = gl.getAttribLocation(outlineProgID, "Texture");
+ scene.curContextCache.attributes["outlinegooch"+primSet+"Texture"] = texAttribLoc;
+ }
+
if (texAttribLoc != -1 && currColl.getTexCoords())
{
renderer.setVertexAttribArray(outlineProgID, "Texture", 2, currColl.getVBOTexCoords(), scene, "outlinegooch"+primSet);
@@ -102,34 +112,43 @@ c3dl.gooch_callback = function (renderingObj, scene)
{
var currColl = geometry.getPrimitiveSets()[coll];
- var dummyAttribLoc = gl.getAttribLocation(programObjID, "dummyAttrib");
+ var dummyAttribLoc = scene.curContextCache.attributes["gooch"+coll+"dummyAttrib"];
+ if(dummyAttribLoc ==undefined ) {
+ dummyAttribLoc = gl.getAttribLocation(programObjID, "dummyAttrib");
+ scene.curContextCache.attributes["gooch"+coll+"dummyAttrib"] = dummyAttribLoc;
+ }
+
if (dummyAttribLoc !== -1 && currColl.getNormals())
{
- renderer.setVertexAttribArray(programObjID, "dummyAttrib", 3, currColl.getVBONormals(), scene, "gooch");
+ renderer.setVertexAttribArray(programObjID, "dummyAttrib", 3, currColl.getVBONormals(), scene, "gooch"+coll);
}
- var normalAttribLoc = gl.getAttribLocation(programObjID, "Normal");
-
+ var normalAttribLoc = scene.curContextCache.attributes["gooch"+coll+"Normal"];
+ if(normalAttribLoc ==undefined ) {
+ normalAttribLoc = gl.getAttribLocation(programObjID, "Normal");
+ scene.curContextCache.attributes["gooch"+coll+"Normal"] = normalAttribLoc;
+ }
+
// if the object acutally has normals and the normal attribute was found
//
if (normalAttribLoc !== -1 && currColl.getNormals())
{
// the top matrix is the modelview matrix.
var NormalMatrix = c3dl.inverseMatrix(modelViewMatrix);
NormalMatrix = c3dl.transposeMatrix(NormalMatrix);
- renderer.setUniformMatrix(programObjID, "normalMatrix", NormalMatrix, scene, "gooch");
+ renderer.setUniformMatrix(programObjID, "normalMatrix", NormalMatrix, scene, "gooch"+coll);
- renderer.setVertexAttribArray(programObjID, "Normal", 3, currColl.getVBONormals(), scene, "gooch");
+ renderer.setVertexAttribArray(programObjID, "Normal", 3, currColl.getVBONormals(), scene, "gooch"+coll);
}
else
{
gl.disableVertexAttribArray(normalAttribLoc);
}
- renderer.setUniformf(programObjID, "warmColor", effect.getParameter("warmColor"), scene, "gooch");
- renderer.setUniformf(programObjID, "coolColor", effect.getParameter("coolColor"), scene, "gooch");
- renderer.setUniformf(programObjID, "surfaceColor", effect.getParameter("surfaceColor"), scene, "gooch");
- renderer.setVertexAttribArray(programObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "gooch");
+ renderer.setUniformf(programObjID, "warmColor", effect.getParameter("warmColor"), scene, "gooch"+coll);
+ renderer.setUniformf(programObjID, "coolColor", effect.getParameter("coolColor"), scene, "gooch"+coll);
+ renderer.setUniformf(programObjID, "surfaceColor", effect.getParameter("surfaceColor"), scene, "gooch"+coll);
+ renderer.setVertexAttribArray(programObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "gooch"+coll);
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
}
}
View
40 c3dl/shaders/model/greyscale/greyscale_callback.js
@@ -42,30 +42,34 @@ c3dl.greyscale_callback = function (renderingObj, scene)
{
// every primitive collection can have a material associated with it.
// currColl.material.getEmission()
- renderer.setUniformf(progObjID, "material.emission", mat.getEmission(), scene, "greyscale");
- renderer.setUniformf(progObjID, "material.ambient", mat.getAmbient(), scene, "greyscale");
- renderer.setUniformf(progObjID, "material.diffuse", mat.getDiffuse(), scene, "greyscale");
- renderer.setUniformf(progObjID, "material.specular", mat.getSpecular(), scene, "greyscale");
- renderer.setUniformf(progObjID, "material.shininess", mat.getShininess(), scene, "greyscale");
- renderer.setUniformi(progObjID, "usingMaterial", true, scene, "greyscale");
+ renderer.setUniformf(progObjID, "material.emission", mat.getEmission(), scene, "greyscale"+coll);
+ renderer.setUniformf(progObjID, "material.ambient", mat.getAmbient(), scene, "greyscale"+coll);
+ renderer.setUniformf(progObjID, "material.diffuse", mat.getDiffuse(), scene, "greyscale"+coll);
+ renderer.setUniformf(progObjID, "material.specular", mat.getSpecular(), scene, "greyscale"+coll);
+ renderer.setUniformf(progObjID, "material.shininess", mat.getShininess(), scene, "greyscale"+coll);
+ renderer.setUniformi(progObjID, "usingMaterial", true, scene, "greyscale"+coll);
}
else
{
- renderer.setUniformi(progObjID, "usingMaterial", false, scene, "greyscale");
+ renderer.setUniformi(progObjID, "usingMaterial", false, scene, "greyscale"+coll);
}
// NORMAL
- var normalAttribLoc = gl.getAttribLocation(progObjID, "Normal");
-
+ var normalAttribLoc = scene.curContextCache.attributes["greyscale"+coll+"Normal"];
+ if (normalAttribLoc == undefined) {
+ normalAttribLoc = gl.getAttribLocation(progObjID, "Normal");
+ scene.curContextCache.attributes["greyscale"+coll+"Normal"] = normalAttribLoc;
+ }
+
// if the object acutally has normals and the normal attribute was found
//
if (currColl.getNormals())
{
// the top matrix is the modelview matrix.
var NormalMatrix = c3dl.inverseMatrix(modelViewMatrix);
NormalMatrix = c3dl.transposeMatrix(NormalMatrix);
- renderer.setUniformMatrix(progObjID, "normalMatrix", NormalMatrix, scene, "greyscale");
- renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "greyscale");
+ renderer.setUniformMatrix(progObjID, "normalMatrix", NormalMatrix, scene, "greyscale"+coll);
+ renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "greyscale"+coll);
}
else
{
@@ -75,8 +79,12 @@ c3dl.greyscale_callback = function (renderingObj, scene)
// TEXTURE
var usingTexture = false;
- var texAttribLoc = gl.getAttribLocation(progObjID, "Texture");
-
+ var texAttribLoc = scene.curContextCache.attributes["greyscale"+coll+"Texture"];
+ if (texAttribLoc == undefined) {
+ texAttribLoc = gl.getAttribLocation(progObjID, "Texture");
+ scene.curContextCache.attributes["greyscale"+coll+"Texture"] = texAttribLoc;
+ }
+
//
var texID = renderer.getTextureID(currColl.getTexture());
@@ -100,7 +108,7 @@ c3dl.greyscale_callback = function (renderingObj, scene)
//gl.vertexAttribPointer(texAttribLoc, 2, gl.FLOAT, false, 0, currColl.getTexCoords());
//gl.enableVertexAttribArray(texAttribLoc);
- renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "greyscale");
+ renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "greyscale"+coll);
usingTexture = true;
}
else
@@ -111,10 +119,10 @@ c3dl.greyscale_callback = function (renderingObj, scene)
}
// tell the fragment shader if we are using textures or not
- renderer.setUniformi(progObjID, "usingTexture", usingTexture, scene, "greyscale");
+ renderer.setUniformi(progObjID, "usingTexture", usingTexture, scene, "greyscale"+coll);
// Vertices
- renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "greyscale");
+ renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "greyscale"+coll);
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
}
}
View
30 c3dl/shaders/model/sepia/sepia_callback.js
@@ -42,25 +42,29 @@ c3dl.sepia_callback = function (renderingObj, scene)
// every primitive collection can have a material associated with it.
// currColl.material.getEmission()
- renderer.setUniformi(progObjID, "usingMaterial", false, scene, "sepia");
+ renderer.setUniformi(progObjID, "usingMaterial", false, scene, "sepia"+coll);
}
else
{
- renderer.setUniformi(progObjID, "usingMaterial", false, scene, "sepia");
+ renderer.setUniformi(progObjID, "usingMaterial", false, scene, "sepia"+coll);
}
// NORMAL
- var normalAttribLoc = gl.getAttribLocation(progObjID, "Normal");
-
+ var normalAttribLoc = scene.curContextCache.attributes["sepia"+coll+"Normal"];
+ if (normalAttribLoc == undefined) {
+ normalAttribLoc = gl.getAttribLocation(progObjID, "Normal");
+ scene.curContextCache.attributes["sepia"+coll+"Normal"] = normalAttribLoc;
+ }
+
// if the object acutally has normals and the normal attribute was found
//
if (currColl.getNormals())
{
// the top matrix is the modelview matrix.
var NormalMatrix = c3dl.inverseMatrix(modelViewMatrix);
NormalMatrix = c3dl.transposeMatrix(NormalMatrix);
- renderer.setUniformMatrix(progObjID, "normalMatrix", NormalMatrix, scene, "sepia");
- renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "sepia");
+ renderer.setUniformMatrix(progObjID, "normalMatrix", NormalMatrix, scene, "sepia"+coll);
+ renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "sepia"+coll);
}
else
{
@@ -70,10 +74,14 @@ c3dl.sepia_callback = function (renderingObj, scene)
// TEXTURE
var usingTexture = false;
- var texAttribLoc = gl.getAttribLocation(progObjID, "Texture");
-
+ var texAttribLoc = scene.curContextCache.attributes["sepia"+coll+"Texture"];
+ if (texAttribLoc == undefined) {
+ texAttribLoc = gl.getAttribLocation(progObjID, "Texture");
+ scene.curContextCache.attributes["sepia"+coll+"Texture"] = texAttribLoc;
+ }
+
//
- var texID = renderer.getTextureID(currColl.getTexture(), scene, "sepia");
+ var texID = renderer.getTextureID(currColl.getTexture(), scene, "sepia"+coll);
// if the texture isn't loaded, but this collation element has one,
// queue one up
@@ -92,7 +100,7 @@ c3dl.sepia_callback = function (renderingObj, scene)
{
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texID);
- renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "sepia");
+ renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "sepia"+coll);
usingTexture = true;
}
else
@@ -106,7 +114,7 @@ c3dl.sepia_callback = function (renderingObj, scene)
renderer.setUniformi(progObjID, "usingTexture", usingTexture, scene, "sepia");
// Vertices
- renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "sepia");
+ renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "sepia"+coll);
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
}
}
View
18 c3dl/shaders/model/solid_color/solid_color_callback.js
@@ -37,20 +37,28 @@ c3dl.solid_color_callback = function (renderingObj, scene)
// before trying to set it.
// This is a kludge for Safari and Chrome since they want these attributes
////////////////////////////
- var normalAttribLoc = glCanvas3D.getAttribLocation(progObjID, "Normal");
+ var normalAttribLoc = scene.curContextCache.attributes["solidcolor"+coll+"Normal"];
+ if (normalAttribLoc == undefined) {
+ normalAttribLoc = glCanvas3D.getAttribLocation(progObjID, "Normal");
+ scene.curContextCache.attributes["solidcolor"+coll+"Normal"] = normalAttribLoc;
+ }
if (normalAttribLoc != -1 && currColl.getNormals())
{
- renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "solidcolor");
+ renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "solidcolor"+coll);
+ }
+ var texAttribLoc = scene.curContextCache.attributes["solidcolor"+coll+"Texture"];
+ if (texAttribLoc == undefined) {
+ texAttribLoc = glCanvas3D.getAttribLocation(progObjID, "Texture");
+ scene.curContextCache.attributes["solidcolor"+coll+"Texture"] = texAttribLoc;
}
- var texAttribLoc = glCanvas3D.getAttribLocation(progObjID, "Texture");
if (texAttribLoc != -1 && currColl.getTexCoords())
{
- renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "solidcolor");
+ renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "solidcolor"+coll);
}
////////////////////////// End kludge
// VERTICES
- renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "solidcolor");
+ renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "solidcolor"+coll);
glCanvas3D.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
}
}
View
38 c3dl/shaders/model/standard/std_callback.js
@@ -24,8 +24,8 @@ c3dl.std_callback = function (renderingObj, scene)
// 3 matrices together once per model instead of once per vertex
var modelViewProjMatrix = c3dl.multiplyMatrixByMatrix(projectionMatrix, modelViewMatrix, c3dl.mat1);
- renderer.setUniformMatrix(progObjID, "modelViewMatrix", modelViewMatrix, scene, "std_callback");
- renderer.setUniformMatrix(progObjID, "modelViewProjMatrix", modelViewProjMatrix, scene, "std_callback");
+ renderer.setUniformMatrix(progObjID, "modelViewMatrix", modelViewMatrix, scene, "std");
+ renderer.setUniformMatrix(progObjID, "modelViewProjMatrix", modelViewProjMatrix, scene, "std");
// render all the collation elements. Every collation element in an object will
// have the same tranformation
@@ -40,23 +40,23 @@ c3dl.std_callback = function (renderingObj, scene)
{
// every primitive collection can have a material associated with it.
// currColl.material.getEmission()
- renderer.setUniformf(progObjID, "material.emission", mat.emission, scene, "std_callback");
- renderer.setUniformf(progObjID, "material.ambient", mat.ambient, scene, "std_callback");
- renderer.setUniformf(progObjID, "material.diffuse", mat.diffuse, scene, "std_callback");
- renderer.setUniformf(progObjID, "material.specular", mat.specular, scene, "std_callback");
- renderer.setUniformf(progObjID, "material.shininess", mat.shininess, scene, "std_callback");
- renderer.setUniformi(progObjID, "usingMaterial", true, scene, "std_callback");
+ renderer.setUniformf(progObjID, "material.emission", mat.emission, scene, "std");
+ renderer.setUniformf(progObjID, "material.ambient", mat.ambient, scene, "std");
+ renderer.setUniformf(progObjID, "material.diffuse", mat.diffuse, scene, "std");
+ renderer.setUniformf(progObjID, "material.specular", mat.specular, scene, "std");
+ renderer.setUniformf(progObjID, "material.shininess", mat.shininess, scene, "std");
+ renderer.setUniformi(progObjID, "usingMaterial", true, scene, "std");
}
else
{
- renderer.setUniformi(progObjID, "usingMaterial", false, scene, "std_callback");
+ renderer.setUniformi(progObjID, "usingMaterial", false, scene, "std");
}
// NORMAL
- var normalAttribLoc = scene.curContextCache.attributes["std_callback"+"Normal"];
+ var normalAttribLoc = scene.curContextCache.attributes["std"+"Normal"];
if(normalAttribLoc ==undefined ) {
normalAttribLoc = glCanvas3D.getAttribLocation(progObjID, "Normal");
- scene.curContextCache.attributes["std_callback"+"Normal"] = normalAttribLoc;
+ scene.curContextCache.attributes["std"+"Normal"] = normalAttribLoc;
}
// if the object acutally has normals and the normal attribute was found
//
@@ -65,8 +65,8 @@ c3dl.std_callback = function (renderingObj, scene)
// the top matrix is the modelview matrix.
var NormalMatrix = c3dl.inverseMatrix(modelViewMatrix);
c3dl.transposeMatrix(NormalMatrix, NormalMatrix);
- renderer.setUniformMatrix(progObjID, "normalMatrix", NormalMatrix, scene, "std_callback");
- renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "std_callback");
+ renderer.setUniformMatrix(progObjID, "normalMatrix", NormalMatrix, scene, "std");
+ renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "std");
}
else
{
@@ -75,10 +75,10 @@ c3dl.std_callback = function (renderingObj, scene)
// TEXTURE
var usingTexture = false;
- var texAttribLoc = scene.curContextCache.attributes["std_callback"+"Texture"];
+ var texAttribLoc = scene.curContextCache.attributes["std"+"Texture"];
if(texAttribLoc ==undefined) {
texAttribLoc = glCanvas3D.getAttribLocation(progObjID, "Texture");
- scene.curContextCache.attributes["std_callback"+"Texture"] = texAttribLoc;
+ scene.curContextCache.attributes["std"+"Texture"] = texAttribLoc;
}
var texID = renderer.texManager.getID(currColl.getTexture());
@@ -105,7 +105,7 @@ c3dl.std_callback = function (renderingObj, scene)
{
glCanvas3D.activeTexture(glCanvas3D.TEXTURE0);
glCanvas3D.bindTexture(glCanvas3D.TEXTURE_2D, texID);
- renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "std_callback");
+ renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "std");
usingTexture = true;
}
else
@@ -116,11 +116,11 @@ c3dl.std_callback = function (renderingObj, scene)
}
// tell the fragment shader if we are using textures or not
- renderer.setUniformi(progObjID, "usingTexture", usingTexture, scene, "std_callback");
- renderer.setUniformi(progObjID, "lightingOn", true, scene, "std_callback");
+ renderer.setUniformi(progObjID, "usingTexture", usingTexture, scene, "std");
+ renderer.setUniformi(progObjID, "lightingOn", true, scene, "std");
// VERTICES
- renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "std_callback");
+ renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "std");
if (renderer.getFillMode() === c3dl.FILL) {
if (currColl.fillType === "TRIANGLE_STRIP") {
glCanvas3D.drawArrays(glCanvas3D.TRIANGLE_STRIP, 0, currColl.getVertices().length / 3);

0 comments on commit 65c67e8

Please sign in to comment.
Something went wrong with that request. Please try again.