Permalink
Browse files

remove old source files that were accidentally committed

  • Loading branch information...
1 parent 3f74660 commit 086d47258a6072f51f6544898eda58bcd4b8eac8 @sinisterchipmunk committed May 24, 2012
@@ -1,13 +0,0 @@
-Jax.Shader.Delegator = (function() {
- return Jax.Class.create({
- initialize: function(context, program, variables) {
- this.context = context;
- this.program = program;
- this.variables = variables;
- },
-
- doesExist: function(key) {
- return this.variables[key] != undefined;
- }
- });
-})();
@@ -1,53 +0,0 @@
-//= require "../delegator"
-
-Jax.Shader.AttributeDelegator = (function() {
- return Jax.Class.create(Jax.Shader.Delegator, {
- initialize: function($super, context, program) {
- var numAttributes = context.gl.getProgramParameter(program, GL_ACTIVE_ATTRIBUTES);
- var attributes = {};
- for (var i = 0; i < numAttributes; i++)
- {
- var attrib = context.gl.getActiveAttrib(program, i);
- attributes[attrib.name] = {
- length:attrib.length,
- size:attrib.size,
- type:attrib.type,
- type_str:Jax.Util.enumName(attrib.type),
- location: context.gl.getAttribLocation(program, attrib.name)
- };
- }
- $super(context, program, attributes);
- },
-
- set: function(name, value) {
- var v, c = this.context, i, variables = this.variables;
-
- function _set(name, value) {
- if (value == undefined) return;
-// if (value == undefined) throw new Error("Value is undefined for shader attribute "+JSON.stringify(name));
-
- if (v = variables[name]) {
- value.bind(c);
- c.gl.enableVertexAttribArray(v.location);
- c.gl.vertexAttribPointer(v.location, value.itemSize, value.dataType || GL_FLOAT, false, 0, 0);
-// } else {
-// console.warn("skipping assignment of attribute %s (variables: %s)", name, JSON.stringify(variables));
- }
- }
-
- if (arguments.length == 1 && typeof(arguments[0]) == "object")
- for (i in arguments[0])
- _set(i, arguments[0][i]);
- else
- for (i = 0; i < arguments.length; i += 2)
- _set(arguments[i], arguments[i+1]);
- },
-
- disableAll: function() {
- for (var v in this.variables) {
- v = this.variables[v];
- this.context.gl.disableVertexAttribArray(v.location);
- }
- }
- });
-})();
@@ -1,71 +0,0 @@
-//= require "../delegator"
-
-Jax.Shader.UniformDelegator = (function() {
- return Jax.Class.create(Jax.Shader.Delegator, {
- initialize: function($super, context, program) {
- var numUniforms = context.gl.getProgramParameter(program, GL_ACTIVE_UNIFORMS);
- var uniforms = {};
- for (var i = 0; i < numUniforms; i++)
- {
- var unif = context.gl.getActiveUniform(program, i);
- uniforms[unif.name] = {
- length:unif.length,
- size:unif.size,
- type:unif.type,
- type_str:Jax.Util.enumName(unif.type),
- location: context.gl.getUniformLocation(program, unif.name)
- };
- }
- $super(context, program, uniforms);
- },
-
- set: function(name, value) {
- var self = this;
- var variables = this.variables, v, c = this.context, i;
-
- function _set(name, value) {
- if (value == undefined) throw new Error("Value is undefined for shader uniform "+JSON.stringify(name));
-
- if (v = variables[name]) {
- try {
- switch(v.type) {
- case GL_FLOAT:
- value.length != undefined ? c.gl.uniform1fv(v.location, value) : c.gl.uniform1f(v.location, value);
- break;
- case GL_BOOL: // same as int
- case GL_INT:
- value.length != undefined ? c.gl.uniform1iv(v.location, value) : c.gl.uniform1i(v.location, value);
- break;
- case GL_FLOAT_VEC2: c.gl.uniform2fv(v.location, value); break;
- case GL_FLOAT_VEC3: c.gl.uniform3fv(v.location, value); break;
- case GL_FLOAT_VEC4: c.gl.uniform4fv(v.location, value); break;
- case GL_FLOAT_MAT2: c.gl.uniformMatrix2fv(v.location, false, value); break;
- case GL_FLOAT_MAT3: c.gl.uniformMatrix3fv(v.location, false, value); break;
- case GL_FLOAT_MAT4: c.gl.uniformMatrix4fv(v.location, false, value); break;
- case GL_BOOL_VEC2: // same as int
- case GL_INT_VEC2: c.gl.uniform2iv(v.location, value); break;
- case GL_BOOL_VEC3: // same as int
- case GL_INT_VEC3: c.gl.uniform3iv(v.location, value); break;
- case GL_BOOL_VEC4: // same as int
- case GL_INT_VEC4: c.gl.uniform4iv(v.location, value); break;
- case GL_SAMPLER_2D: c.gl.uniform1i(v.location, value); break;
- case GL_SAMPLER_CUBE: c.gl.uniform1i(v.location, value); break;
- default:
- throw new Error("Unexpected attribute type: "+v.type+" ("+JSON.stringify(v)+")");
- }
- } catch(e) {
- var error = new Error("Failed to set uniform for "+name+' ('+value+") in shader program:\n\n"+e);
- Jax.reraise(e, error);
- }
- }
- }
-
- if (arguments.length == 1 && typeof(arguments[0]) == "object")
- for (i in arguments[0])
- _set(i, arguments[0][i]);
- else
- for (i = 0; i < arguments.length; i += 2)
- _set(arguments[i], arguments[i+1]);
- }
- });
-})();
@@ -1,70 +0,0 @@
-/**
- * class Jax.Shader.Manifest
- *
- * Used to track variable assignments. After all assignments have been made just prior to committing a render phase,
- * the manifest will be used to actually pass variable values into the shader. This keeps from specifying shader
- * values more than once. Manifest can also be used to cache values between render passes, because its values are
- * never reset.
- **/
-Jax.Shader.Manifest = Jax.Class.create({
- initialize: function(existing) {
- this.values = {};
- this.texture_tracker = 0;
- this.variable_prefix = "";
- this.existing = existing || [];
- },
-
- set: function(name, value) {
- var i;
- if (value === undefined)
- if (typeof(name) == "object")
- for (i in name)
- this.set(i, name[i]);
- else throw new Error("Invalid argument (or the value given is undefined): "+
- JSON.stringify(name)+"\n\n"+new Error().stack);
- else
- for (i = 0; i < arguments.length; i += 2) {
- if (this.existing.indexOf(arguments[i]) != -1)
- this.values[arguments[i]] = arguments[i+1];
- else
- this.values[this.variable_prefix+arguments[i]] = arguments[i+1];
- }
- },
-
- getValue: function(name) {
- if (this.existing.indexOf(name) != -1)
- return this.values[name];
- else return this.values[this.variable_prefix+name];
- },
-
- texture: function(name, tex, context) {
- if (!context) throw new Error("Can't bind texture without a context");
- // if (this.texture_tracker == GL_MAX_ACTIVE_TEXTURES-1) {
- /* FIXME add a callback for Materials to enter compatibility mode and recompile their shaders
- before throwing a hard error. Until this is implemented, the hard error itself is disabled
- because it causes unnecessary barfing on machines that are otherwise capable of running the
- scene. Using too many textures doesn't seem to have any catastrophic results on tested
- hardware, except some visual anomolies, so there's no reason to crash out catastrophically.
- */
-// throw new Error("Maximum number of textures ("+GL_MAX_ACTIVE_TEXTURES+") has been reached!");
- // }
-
- if (typeof(this.getValue(name)) != "number")
- this.set(name, this.texture_tracker++);
-
- if (tex && tex.loaded) {
- context.gl.activeTexture(context.gl['TEXTURE'+this.getValue(name)]);
- tex.bind(context, this.getValue(name));
- }
- },
-
- apply: function(uniforms, attributes) {
- attributes.disableAll();
- for (var name in this.values) {
- if (uniforms.doesExist(name))
- uniforms.set(name, this.values[name]);
- else if (attributes.doesExist(name))
- attributes.set(name, this.values[name]);
- }
- }
-});
@@ -1,137 +0,0 @@
-//= require "jax/webgl/shader/delegator/attribute"
-//= require "jax/webgl/shader/delegator/uniform"
-//= require "jax/webgl/shader/manifest"
-
-Jax.Shader.Program = (function() {
- function buildShaderSources(self, context, material) {
- for (var i = 0; i < self.shaders.length; i++) {
- self.shaders[i].build(context, material);
- }
- }
-
- function getShaderProgram(self, context) {
- if (self.programs[context.id]) return self.programs[context.id];
- return self.programs[context.id] = context.gl.createProgram();
- }
-
- function addToVariableList(self, delegator) {
- for (var name in delegator.variables) {
- self.variable_names.push(name);
- }
- }
-
- function updateVariableList(self, context) {
- while (self.variable_names.length > 0) self.variable_names.pop();
- addToVariableList(self, self.getAttributeDelegator(context));
- addToVariableList(self, self.getUniformDelegator(context));
- }
-
- function linkProgram(self, context, material, program) {
- /* really attach those shaders that we've pretended to have attached already */
- for (var i = 0; i < self.shaders.length; i++) {
- var shader = self.shaders[i];
- var vert = shader.getVertexShader(context),
- frag = shader.getFragmentShader(context);
-
- if (vert) {
- program.vertex = vert;
- program.vertex_shader = vert;
- context.gl.attachShader(program, vert);
- }
- if (frag) {
- program.fragment = true;
- program.fragment_shader = frag;
- context.gl.attachShader(program, frag);
- }
- }
-
- if (!program.vertex || !program.fragment)
- throw new Error("Attempted to link program missing either a vertex or fragment shader! " +
- "(WebGL requires at least 1 of each.)");
-
- buildShaderSources(self, context, material);
- context.gl.linkProgram(program);
-
- if (!context.gl.getProgramParameter(program, GL_LINK_STATUS))
- throw new Error("Could not initialize shader!\n\n"+context.gl.getProgramInfoLog(program));
- else program.linked = true;
-
- context.gl.useProgram(program);
-
- self.attribute_delegator[context.id] = new Jax.Shader.AttributeDelegator(context, program);
- self.uniform_delegator[context.id] = new Jax.Shader.UniformDelegator(context, program);
- }
-
- return Jax.Class.create({
- initialize: function() {
- this.shaders = [];
- this.programs = {};
- this.attribute_delegator = {};
- this.uniform_delegator = {};
- this.variable_names = [];
- this.manifest = new Jax.Shader.Manifest(this.variable_names);
- },
-
- attach: function(shaderName, context) {
- if (!context) throw new Error("No context!");
- var shader = Jax.shaders[shaderName];
- if (!shader)
- throw new Error("Could not find shader named '"+shaderName+"'! " +
- "Does it exist in Jax.shaders?");
- this.shaders.push(shader);
- },
-
- invalidate: function() {
- for (var i in this.programs)
- this.programs[i].linked = false;
- },
-
- link: function(context, material) {
- var program = this.getGLProgram(context);
-
- if (!program.linked)
- linkProgram(this, context, material, program);
-
- // update list of variable names
- updateVariableList(this, context);
-
- return program;
- },
-
- setShaderVariables: function(context, mesh, material, model) {
- material.setShaderVariables(context, mesh, model, this.manifest);
- this.manifest.apply(this.getUniformDelegator(context), this.getAttributeDelegator(context));
- },
-
- render: function(context, mesh, material, model) {
- var program = this.link(context, material);
- context.gl.useProgram(program);
-
- this.setShaderVariables(context, mesh, material, model);
-
- try {
- var buffer;
- if ((buffer = mesh.getIndexBuffer()) && buffer.length > 0) {
- buffer.bind(context);
- context.gl.drawElements(mesh.draw_mode, buffer.length, buffer.dataType, 0);
- }
- else if ((buffer = mesh.getVertexBuffer()) && buffer.length > 0) {
- context.gl.drawArrays(mesh.draw_mode, 0, buffer.length);
- }
- } catch(e) {
- var error = new Error("Fatal error encountered while drawing mesh:\n\n"+e+"\n\nShaders: "+this.getShaderNames());
- Jax.reraise(e, error);
- }
- },
-
- getShaderNames: function() {
- var shaderNames = [];
- for (var i = 0; i < this.shaders.length; i++) shaderNames[i] = this.shaders[i].getName();
- return shaderNames;
- },
-
- getGLProgram: function(context) { return getShaderProgram(this, context); },
- getAttributeDelegator: function(context) { return this.attribute_delegator[context.id]; },
- getUniformDelegator: function(context) { return this.uniform_delegator[context.id]; }
- });
-})();

0 comments on commit 086d472

Please sign in to comment.