Permalink
Browse files

code for caching variables

  • Loading branch information...
1 parent c06e731 commit b58de80e470b66192d9bc17e2bd5fbb65bbf65b0 Matt committed Mar 16, 2011

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -6,14 +6,13 @@
/*
*/
-c3dl.cartoon_callback = function (renderingObj)
+c3dl.cartoon_callback = function (renderingObj, scene)
{
var renderer = renderingObj.getRenderer();
var gl = renderingObj.getContext();
var geometry = renderingObj.getGeometry();
var effect = geometry.getEffect();
var programObjID = renderingObj.getProgramObjectID();
-
gl.useProgram(programObjID);
if (effect.getParameter("qMap") == null)
@@ -30,8 +29,8 @@ c3dl.cartoon_callback = function (renderingObj)
// create a ModelViewProjection matrix. By doing this, we can multiply
// 3 matrices together once per model instead of once per vertex
var modelViewProjMatrix = c3dl.multiplyMatrixByMatrix(projectionMatrix, modelViewMatrix);
- renderer.setUniformMatrix(programObjID, "modelViewMatrix", modelViewMatrix);
- renderer.setUniformMatrix(programObjID, "modelViewProjMatrix", modelViewProjMatrix);
+ renderer.setUniformMatrix(programObjID, "modelViewMatrix", modelViewMatrix, scene, "cartoon");
+ renderer.setUniformMatrix(programObjID, "modelViewProjMatrix", modelViewProjMatrix, scene, "cartoon");
// Commenting out until a fix is solved for the 2-object outline bug
// Only render the outline, which is a single pixel thick if the user
@@ -48,15 +47,15 @@ c3dl.cartoon_callback = function (renderingObj)
gl.enable(gl.CULL_FACE);
gl.cullFace(gl.FRONT);
gl.useProgram(outlineProgID);
- renderer.setUniformf(outlineProgID, "color", [0, 0, 0]);
+ renderer.setUniformf(outlineProgID, "color", [0, 0, 0], scene, "outlinecartoon");
var modelViewMatrix = c3dl.peekMatrix();
c3dl.matrixMode(c3dl.PROJECTION);
var projectionMatrix = c3dl.peekMatrix();
c3dl.matrixMode(c3dl.MODELVIEW);
var MVPMatrix = c3dl.multiplyMatrixByMatrix(projectionMatrix, modelViewMatrix);
- renderer.setUniformMatrix(outlineProgID, "modelViewProjMatrix", MVPMatrix);
+ renderer.setUniformMatrix(outlineProgID, "modelViewProjMatrix", MVPMatrix, scene, "outlinecartoon");
var contextWidth = renderer.getContextWidth();
var contextHeight = renderer.getContextHeight();
@@ -72,19 +71,20 @@ c3dl.cartoon_callback = function (renderingObj)
var normalAttribLoc = gl.getAttribLocation(outlineProgID, "Normal");
if (normalAttribLoc != -1 && currColl.getNormals())
{
- renderer.setVertexAttribArray(outlineProgID, "Normal", 3, currColl.getVBONormals());
+ renderer.setVertexAttribArray(outlineProgID, "Normal", 3, currColl.getVBONormals(), scene, "outlinecartoon"+primSet);
}
var texAttribLoc = gl.getAttribLocation(outlineProgID, "Texture");
+
if (texAttribLoc != -1 && currColl.getTexCoords())
{
- renderer.setVertexAttribArray(outlineProgID, "Texture", 2, currColl.getVBOTexCoords());
+ renderer.setVertexAttribArray(outlineProgID, "Texture", 2, currColl.getVBOTexCoords(), scene, "outlinecartoon"+primSet);
}
////////////////////////// End kludge
- renderer.setVertexAttribArray(outlineProgID, "Vertex", 3, currColl.getVBOVertices());
-
+ renderer.setVertexAttribArray(outlineProgID, "Vertex", 3, currColl.getVBOVertices(), scene, "outlinecartoon"+primSet);
+
gl.viewport(1, -1, contextWidth, contextHeight);
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
-
+
gl.viewport(-1, -1, contextWidth, contextHeight);
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
@@ -103,11 +103,12 @@ c3dl.cartoon_callback = function (renderingObj)
gl.useProgram(programObjID);
}
- renderer.setUniformi(programObjID, "lightingOn", true);
+ renderer.setUniformi(programObjID, "lightingOn", true, scene, "cartoon");
// render all the collation elements. Every collation element in an object will
// have the same tranformation
for (var coll = 0; coll < geometry.getPrimitiveSets().length; coll++)
{
+
var currColl = geometry.getPrimitiveSets()[coll];
var normalAttribLoc = gl.getAttribLocation(programObjID, "Normal");
@@ -118,14 +119,14 @@ c3dl.cartoon_callback = function (renderingObj)
// the top matrix is the modelview matrix.
var NormalMatrix = c3dl.inverseMatrix(modelViewMatrix);
NormalMatrix = c3dl.transposeMatrix(NormalMatrix);
- renderer.setUniformMatrix(programObjID, "normalMatrix", NormalMatrix);
- renderer.setVertexAttribArray(programObjID, "Normal", 3, currColl.getVBONormals());
+ renderer.setUniformMatrix(programObjID, "normalMatrix", NormalMatrix, scene, "cartoon"+coll);
+ renderer.setVertexAttribArray(programObjID, "Normal", 3, currColl.getVBONormals(), scene, "cartoon"+coll);
}
else
{
gl.disableVertexAttribArray(normalAttribLoc);
}
-
+
// TEXTURE
var texAttribLoc = gl.getAttribLocation(programObjID, "Texture");
var texID = renderer.getTextureID(currColl.getTexture());
@@ -145,14 +146,14 @@ c3dl.cartoon_callback = function (renderingObj)
// bind the collations texture object to texture unit 0 and make it active.
gl.bindTexture(gl.TEXTURE_2D, texID);
- renderer.setVertexAttribArray(programObjID, "Texture", 2, currColl.getVBOTexCoords());
- renderer.setUniformi(programObjID, "myTex", 0);
- renderer.setUniformi(programObjID, "usingTexture", true);
+ renderer.setVertexAttribArray(programObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "cartoon"+coll);
+ renderer.setUniformi(programObjID, "myTex", 0, scene, "cartoon"+coll);
+ renderer.setUniformi(programObjID, "usingTexture", true, scene, "cartoon"+coll);
}
else
{
gl.disableVertexAttribArray(texAttribLoc);
- renderer.setUniformi(programObjID, "usingTexture", false);
+ renderer.setUniformi(programObjID, "usingTexture", false, scene, "cartoon"+coll);
}
// Quantization Map
@@ -164,18 +165,20 @@ c3dl.cartoon_callback = function (renderingObj)
if (shadesTexID == -1)
{
renderer.addTexture(qMap);
+ //shadesTexID = renderer.texManager.getIDNumber(qMap)
}
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);
+ renderer.setUniformi(programObjID, "celShadeTex", 1, scene, "cartoon"+coll);
// VERTICES
- renderer.setVertexAttribArray(programObjID, "Vertex", 3, currColl.getVBOVertices());
+ renderer.setVertexAttribArray(programObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "cartoon"+coll);
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
}
}
@@ -6,7 +6,7 @@
/*
*/
-c3dl.gooch_callback = function (renderingObj)
+c3dl.gooch_callback = function (renderingObj, scene)
{
var renderer = renderingObj.getRenderer();
var gl = renderingObj.getContext();
@@ -22,8 +22,8 @@ c3dl.gooch_callback = function (renderingObj)
c3dl.matrixMode(c3dl.MODELVIEW);
var modelViewProjMatrix = c3dl.multiplyMatrixByMatrix(projectionMatrix, modelViewMatrix);
- renderer.setUniformMatrix(programObjID, "modelViewMatrix", modelViewMatrix);
- renderer.setUniformMatrix(programObjID, "modelViewProjMatrix", modelViewProjMatrix);
+ renderer.setUniformMatrix(programObjID, "modelViewMatrix", modelViewMatrix, scene, "gooch");
+ renderer.setUniformMatrix(programObjID, "modelViewProjMatrix", modelViewProjMatrix, scene, "gooch");
// Commenting out until a fix is solved for the 2-object outline bug
// Only render the outline, which is a single pixel thick if the user
@@ -40,15 +40,15 @@ c3dl.gooch_callback = function (renderingObj)
gl.enable(gl.CULL_FACE);
gl.cullFace(gl.FRONT);
gl.useProgram(outlineProgID);
- renderer.setUniformf(outlineProgID, "color", [0, 0, 0]);
+ renderer.setUniformf(outlineProgID, "color", [0, 0, 0], scene, "outlinegooch");
var modelViewMatrix = c3dl.peekMatrix();
c3dl.matrixMode(c3dl.PROJECTION);
var projectionMatrix = c3dl.peekMatrix();
c3dl.matrixMode(c3dl.MODELVIEW);
var MVPMatrix = c3dl.multiplyMatrixByMatrix(projectionMatrix, modelViewMatrix);
- renderer.setUniformMatrix(outlineProgID, "modelViewProjMatrix", MVPMatrix);
+ renderer.setUniformMatrix(outlineProgID, "modelViewProjMatrix", MVPMatrix, scene, "outlinegooch");
var contextWidth = renderer.getContextWidth();
var contextHeight = renderer.getContextHeight();
@@ -64,15 +64,15 @@ c3dl.gooch_callback = function (renderingObj)
var normalAttribLoc = gl.getAttribLocation(outlineProgID, "Normal");
if (normalAttribLoc != -1 && currColl.getNormals())
{
- renderer.setVertexAttribArray(outlineProgID, "Normal", 3, currColl.getVBONormals());
+ renderer.setVertexAttribArray(outlineProgID, "Normal", 3, currColl.getVBONormals(), scene, "outlinegooch"+primSet);
}
var texAttribLoc = gl.getAttribLocation(outlineProgID, "Texture");
if (texAttribLoc != -1 && currColl.getTexCoords())
{
- renderer.setVertexAttribArray(outlineProgID, "Texture", 2, currColl.getVBOTexCoords());
+ renderer.setVertexAttribArray(outlineProgID, "Texture", 2, currColl.getVBOTexCoords(), scene, "outlinegooch"+primSet);
}
////////////////////////// End kludge
- renderer.setVertexAttribArray(outlineProgID, "Vertex", 3, currColl.getVBOVertices());
+ renderer.setVertexAttribArray(outlineProgID, "Vertex", 3, currColl.getVBOVertices(), scene, "outlinegooch"+primSet);
gl.viewport(1, -1, contextWidth, contextHeight);
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
@@ -105,7 +105,7 @@ c3dl.gooch_callback = function (renderingObj)
var dummyAttribLoc = gl.getAttribLocation(programObjID, "dummyAttrib");
if (dummyAttribLoc !== -1 && currColl.getNormals())
{
- renderer.setVertexAttribArray(programObjID, "dummyAttrib", 3, currColl.getVBONormals());
+ renderer.setVertexAttribArray(programObjID, "dummyAttrib", 3, currColl.getVBONormals(), scene, "gooch");
}
var normalAttribLoc = gl.getAttribLocation(programObjID, "Normal");
@@ -117,19 +117,19 @@ c3dl.gooch_callback = function (renderingObj)
// the top matrix is the modelview matrix.
var NormalMatrix = c3dl.inverseMatrix(modelViewMatrix);
NormalMatrix = c3dl.transposeMatrix(NormalMatrix);
- renderer.setUniformMatrix(programObjID, "normalMatrix", NormalMatrix);
+ renderer.setUniformMatrix(programObjID, "normalMatrix", NormalMatrix, scene, "gooch");
- renderer.setVertexAttribArray(programObjID, "Normal", 3, currColl.getVBONormals());
+ renderer.setVertexAttribArray(programObjID, "Normal", 3, currColl.getVBONormals(), scene, "gooch");
}
else
{
gl.disableVertexAttribArray(normalAttribLoc);
}
- renderer.setUniformf(programObjID, "warmColor", effect.getParameter("warmColor"));
- renderer.setUniformf(programObjID, "coolColor", effect.getParameter("coolColor"));
- renderer.setUniformf(programObjID, "surfaceColor", effect.getParameter("surfaceColor"));
- renderer.setVertexAttribArray(programObjID, "Vertex", 3, currColl.getVBOVertices());
+ 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");
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
}
}
@@ -6,7 +6,7 @@
/**
@private
*/
-c3dl.greyscale_callback = function (renderingObj)
+c3dl.greyscale_callback = function (renderingObj, scene)
{
//
var progObjID = renderingObj.getProgramObjectID();
@@ -16,7 +16,7 @@ c3dl.greyscale_callback = function (renderingObj)
var effect = geometry.getEffect();
gl.useProgram(progObjID);
- renderer.setUniformf(progObjID, "color", effect.getParameter("color"));
+ renderer.setUniformf(progObjID, "color", effect.getParameter("color"), scene, "greyscale");
var modelViewMatrix = c3dl.peekMatrix();
c3dl.matrixMode(c3dl.PROJECTION);
@@ -26,8 +26,8 @@ c3dl.greyscale_callback = function (renderingObj)
// create a ModelViewProjection matrix. By doing this, we can multiply
// 3 matrices together once per model instead of once per vertex
var modelViewProjMatrix = c3dl.multiplyMatrixByMatrix(projectionMatrix, modelViewMatrix);
- renderer.setUniformMatrix(progObjID, "modelViewMatrix", modelViewMatrix);
- renderer.setUniformMatrix(progObjID, "modelViewProjMatrix", modelViewProjMatrix);
+ renderer.setUniformMatrix(progObjID, "modelViewMatrix", modelViewMatrix, scene, "greyscale");
+ renderer.setUniformMatrix(progObjID, "modelViewProjMatrix", modelViewProjMatrix, scene, "greyscale");
// render all the collation elements. Every collation element in an object will
// have the same tranformation
@@ -42,16 +42,16 @@ c3dl.greyscale_callback = function (renderingObj)
{
// every primitive collection can have a material associated with it.
// currColl.material.getEmission()
- renderer.setUniformf(progObjID, "material.emission", mat.getEmission());
- renderer.setUniformf(progObjID, "material.ambient", mat.getAmbient());
- renderer.setUniformf(progObjID, "material.diffuse", mat.getDiffuse());
- renderer.setUniformf(progObjID, "material.specular", mat.getSpecular());
- renderer.setUniformf(progObjID, "material.shininess", mat.getShininess());
- renderer.setUniformi(progObjID, "usingMaterial", true);
+ 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");
}
else
{
- renderer.setUniformi(progObjID, "usingMaterial", false);
+ renderer.setUniformi(progObjID, "usingMaterial", false, scene, "greyscale");
}
// NORMAL
@@ -64,8 +64,8 @@ c3dl.greyscale_callback = function (renderingObj)
// the top matrix is the modelview matrix.
var NormalMatrix = c3dl.inverseMatrix(modelViewMatrix);
NormalMatrix = c3dl.transposeMatrix(NormalMatrix);
- renderer.setUniformMatrix(progObjID, "normalMatrix", NormalMatrix);
- renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals());
+ renderer.setUniformMatrix(progObjID, "normalMatrix", NormalMatrix, scene, "greyscale");
+ renderer.setVertexAttribArray(progObjID, "Normal", 3, currColl.getVBONormals(), scene, "greyscale");
}
else
{
@@ -100,7 +100,7 @@ c3dl.greyscale_callback = function (renderingObj)
//gl.vertexAttribPointer(texAttribLoc, 2, gl.FLOAT, false, 0, currColl.getTexCoords());
//gl.enableVertexAttribArray(texAttribLoc);
- renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords());
+ renderer.setVertexAttribArray(progObjID, "Texture", 2, currColl.getVBOTexCoords(), scene, "greyscale");
usingTexture = true;
}
else
@@ -111,10 +111,10 @@ c3dl.greyscale_callback = function (renderingObj)
}
// tell the fragment shader if we are using textures or not
- renderer.setUniformi(progObjID, "usingTexture", usingTexture);
+ renderer.setUniformi(progObjID, "usingTexture", usingTexture, scene, "greyscale");
// Vertices
- renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices());
+ renderer.setVertexAttribArray(progObjID, "Vertex", 3, currColl.getVBOVertices(), scene, "greyscale");
gl.drawArrays(renderer.getFillMode(), 0, currColl.getVertices().length / 3);
}
}
Oops, something went wrong.

0 comments on commit b58de80

Please sign in to comment.