[Opengeoscience-developers] OpenGeoscience branch, enhance_map_api, updated. 47c6fdc45819e689355385a5b95d15500fe6b333

Aashish Chaudhary aashish.chaudhary at kitware.com
Fri Mar 1 11:52:00 EST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenGeoscience".

The branch, enhance_map_api has been updated
       via  47c6fdc45819e689355385a5b95d15500fe6b333 (commit)
       via  d5d02452db746b4dccf15838bfdea8b5c95bb406 (commit)
      from  2a9f3465e2f164b9e7cb848947d40e45fcd11a2b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://public.kitware.com/gitweb?p=OpenGeoscience/opengeoscience.git;a=commitdiff;h=47c6fdc45819e689355385a5b95d15500fe6b333
commit 47c6fdc45819e689355385a5b95d15500fe6b333
Author:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
AuthorDate: Fri Mar 1 11:51:37 2013 -0500
Commit:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
CommitDate: Fri Mar 1 11:51:37 2013 -0500

    Improving vgl code

diff --git a/web/lib/vgl/blend.js b/web/lib/vgl/blend.js
index 6be84b8..4b20dca 100644
--- a/web/lib/vgl/blend.js
+++ b/web/lib/vgl/blend.js
@@ -30,7 +30,7 @@ vglModule.blendFunction = function(source, destination) {
 
   /// Private variables
   var m_source = source;
-  var m_desination = destination;
+  var m_destination = destination;
 
   /**
    * Apply blend function to the current state
@@ -38,7 +38,7 @@ vglModule.blendFunction = function(source, destination) {
    */
   this.apply = function(renderState) {
     gl.blendFunc(m_source, m_destination);
-  }
+  };
 
   return this;
 }
@@ -54,12 +54,10 @@ vglModule.blend = function() {
   if (!(this instanceof vglModule.blend)) {
     return new vglModule.blend();
   }
-  vglModule.materialAttribute.call(this);
-
-  this.m_type = materialAttributeType.Blend;
+  vglModule.materialAttribute.call(this, materialAttributeType.Blend);
 
   /// Private member variables
-  var m_wasEnabled;
+  var m_wasEnabled  = false;
   var m_blendFunction =
     vglModule.blendFunction(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
 
@@ -68,12 +66,11 @@ vglModule.blend = function() {
    *
    */
   this.bind  = function(renderState) {
+    m_wasEnabled = gl.isEnabled(gl.BLEND);
 
-    this.m_wasEnabled = gl.IsEnabled(gl.BLEND);
-
-    if (this.m_enabled) {
-      gl.enable(GL_BLEND);
-      this.m_blendFunction.apply(renderState);
+    if (this.enabled()) {
+      gl.enable(gl.BLEND);
+      m_blendFunction.apply(renderState);
     } else {
       gl.disable(gl.BLEND);
     }
@@ -86,15 +83,11 @@ vglModule.blend = function() {
    *
    */
   this.undoBind = function(renderState) {
-
-    if (this.m_wasEnabled) {
-      gl.enable(GL_BLEND);
+    if (m_wasEnabled) {
+      gl.enable(gl.BLEND);
     } else {
-      gl.disable(GL_BLEND);
+      gl.disable(gl.BLEND);
     }
-
-    this.setDirtyStateOff();
-
     return true;
   };
 
diff --git a/web/lib/vgl/materialAttribute.js b/web/lib/vgl/materialAttribute.js
index e4a60c5..77f63b9 100644
--- a/web/lib/vgl/materialAttribute.js
+++ b/web/lib/vgl/materialAttribute.js
@@ -30,43 +30,54 @@ materialAttributeType =   {
     "Depth" : 0x4
   };
 
-vglModule.materialAttribute = function() {
+vglModule.materialAttribute = function(type) {
+
+  if (!(this instanceof vglModule.materialAttribute)) {
+    return new vglModule.materialAttribute();
+  }
   vglModule.object.call(this);
-  this.m_type = materialAttributeType.Undefined;
-  this.m_enabled = true;
-};
 
-inherit(vglModule.materialAttribute, vglModule.object);
+  /// Private member variables
+  var m_type = type;
+  var m_enabled = true;
 
+  /// Public member methods
+  this.type = function() {
+    return m_type;
+  };
 
-vglModule.materialAttribute.prototype.type = function() {
-  return this.m_type;
-};
+  this.enabled = function() {
+    return m_enabled;
+  }
 
+  this.setup = function(renderState) {
+    return false;
+  };
 
-vglModule.materialAttribute.prototype.setup = function(renderState) {
-  return false;
-};
 
+  this.bind  = function(renderState) {
+    return false;
+  };
 
-vglModule.materialAttribute.prototype.bind  = function(renderState) {
-  return false;
-};
+  this.undoBind = function(renderState) {
+    return false;
+  };
 
-vglModule.materialAttribute.prototype.undoBind = function(renderState) {
-  return false;
-};
 
+  this.setupVertexData = function(renderState, key) {
+    return false;
+  };
 
-vglModule.materialAttribute.prototype.setupVertexData = function(renderState, key) {
-  return false;
-};
 
+  this.bindVertexData = function(renderState, key) {
+    return false;
+  };
+
+  this.undoBindVertexData = function(renderState, key) {
+    return false;
+  };
 
-vglModule.materialAttribute.prototype.bindVertexData = function(renderState, key) {
-  return false;
+  return this;
 };
 
-vglModule.materialAttribute.prototype.undoBindVertexData = function(renderState, key) {
-  return false;
-};
\ No newline at end of file
+inherit(vglModule.materialAttribute, vglModule.object);
diff --git a/web/lib/vgl/shaderProgram.js b/web/lib/vgl/shaderProgram.js
index e6f5a05..c00329e 100644
--- a/web/lib/vgl/shaderProgram.js
+++ b/web/lib/vgl/shaderProgram.js
@@ -23,9 +23,13 @@
 //////////////////////////////////////////////////////////////////////////////
 
 vglModule.shaderProgram = function() {
-  vglModule.materialAttribute.call(this);
 
-  this.m_type = materialAttributeType.ShaderProgram;
+  if (!(this instanceof vglModule.shaderProgram)) {
+    return new vglModule.shaderProgram();
+  }
+  vglModule.materialAttribute.call(this, materialAttributeType.ShaderProgram);
+
+  /// Private member variables
   this.m_programHandle = 0;
   this.m_shaders = [];
   this.m_uniforms = [];
@@ -33,198 +37,198 @@ vglModule.shaderProgram = function() {
 
   this.m_uniformNameToLocation = {};
   this.m_vertexAttributeNameToLocation = {};
-};
 
-inherit(vglModule.shaderProgram, vglModule.materialAttribute);
+  /// Public member methods
+  this.queryUniformLocation = function(name) {
+    return gl.getUniformLocation(this.m_programHandle, name);
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.queryUniformLocation = function(name) {
-  return gl.getUniformLocation(this.m_programHandle, name);
-};
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.queryAttributeLocation = function(name) {
-  return gl.getAttribLocation(this.m_programHandle, name);
-};
+  this.queryAttributeLocation = function(name) {
+    return gl.getAttribLocation(this.m_programHandle, name);
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.addShader = function(shader) {
-  if (this.m_shaders.indexOf(shader) > -1)   {
-    return false;
-  }
 
-  for (var i = 0; i < this.m_shaders.length; ++i) {
-    if (this.m_shaders[i].shaderType() === shader.shaderType()) {
-      this.m_shaders.splice(this.m_shaders.indexOf(shader), 1);
+  this.addShader = function(shader) {
+    if (this.m_shaders.indexOf(shader) > -1)   {
+      return false;
     }
-  }
 
-  this.m_shaders.push(shader);
+    for (var i = 0; i < this.m_shaders.length; ++i) {
+      if (this.m_shaders[i].shaderType() === shader.shaderType()) {
+        this.m_shaders.splice(this.m_shaders.indexOf(shader), 1);
+      }
+    }
 
-  this.setModified();
+    this.m_shaders.push(shader);
 
-  return true;
-};
+    this.setModified();
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.addUniform = function(uniform) {
-  if (this.m_uniforms.indexOf(uniform) > -1) {
-    return false;
-  }
+    return true;
+  };
 
-  this.m_uniforms.push(uniform);
 
-  this.setModified();
-};
+  this.addUniform = function(uniform) {
+    if (this.m_uniforms.indexOf(uniform) > -1) {
+      return false;
+    }
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.addVertexAttribute = function(attr, key) {
-  this.m_vertexAttributes[key] = attr;
+    this.m_uniforms.push(uniform);
 
-  this.setModified();
-};
+    this.setModified();
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.uniformLocation = function(name) {
-  return this.m_uniformNameToLocation[name];
-};
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.attributeLocation = function(name) {
-  return this.m_vertexAttributeNameToLocation[name];
-};
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.uniformExist = function() {
-  // TODO
-};
+  this.addVertexAttribute = function(attr, key) {
+    this.m_vertexAttributes[key] = attr;
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.updateUniforms = function() {
-  for (var i = 0; i < this.m_uniforms.length; ++i) {
-    this.m_uniforms[i].callGL(
-      this.m_uniformNameToLocation[this.m_uniforms[i].name()]);
-  }
-};
+    this.setModified();
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.link = function() {
-  gl.linkProgram(this.m_programHandle);
 
-  // If creating the shader program failed, alert
-  if (!gl.getProgramParameter(this.m_programHandle, gl.LINK_STATUS)) {
-    console.log("[ERROR] Unable to initialize the shader program.");
-    return false;
-  }
+  this.uniformLocation = function(name) {
+    return this.m_uniformNameToLocation[name];
+  };
 
-  return true;
-};
+  this.attributeLocation = function(name) {
+    return this.m_vertexAttributeNameToLocation[name];
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.validate = function() {
-  // TODO
-};
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.use = function() {
-  gl.useProgram(this.m_programHandle);
-};
+  this.uniformExist = function() {
+    // TODO
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.cleanUp = function() {
-  this.deleteVertexAndFragment();
-  this.deleteProgram();
-};
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.deleteProgram = function() {
-  gl.deleteProgram(this.m_programHandle);
-};
-
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.deleteVertexAndFragment = function() {
-  for (var i = 0; i < this.m_shaders.length; ++i) {
-    gl.deleteShader(this.m_shaders[i].shaderHandle());
-  }
-};
+  this.updateUniforms = function() {
+    for (var i = 0; i < this.m_uniforms.length; ++i) {
+      this.m_uniforms[i].callGL(
+        this.m_uniformNameToLocation[this.m_uniforms[i].name()]);
+    }
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.bind = function(renderState) {
-  var i = 0;
 
-  if (this.m_programHandle === 0 || this.modified()) {
-    this.m_programHandle = gl.createProgram();
+  this.link = function() {
+    gl.linkProgram(this.m_programHandle);
 
-    if (this.m_programHandle === 0) {
-      console.log("[ERROR] Cannot create Program Object");
+    // If creating the shader program failed, alert
+    if (!gl.getProgramParameter(this.m_programHandle, gl.LINK_STATUS)) {
+      console.log("[ERROR] Unable to initialize the shader program.");
       return false;
     }
 
-    // Compile shaders
-    for (i = 0; i < this.m_shaders.length; ++i) {
-      this.m_shaders[i].compile();
-      this.m_shaders[i].attachShader(this.m_programHandle);
+    return true;
+  };
+
+
+  this.validate = function() {
+    // TODO
+  };
+
+
+  this.use = function() {
+    gl.useProgram(this.m_programHandle);
+  };
+
+
+  this.cleanUp = function() {
+    this.deleteVertexAndFragment();
+    this.deleteProgram();
+  };
+
+
+  this.deleteProgram = function() {
+    gl.deleteProgram(this.m_programHandle);
+  };
+
+
+  this.deleteVertexAndFragment = function() {
+    for (var i = 0; i < this.m_shaders.length; ++i) {
+      gl.deleteShader(this.m_shaders[i].shaderHandle());
     }
+  };
+
+
+  this.bind = function(renderState) {
+    var i = 0;
+
+    if (this.m_programHandle === 0 || this.modified()) {
+      this.m_programHandle = gl.createProgram();
 
-    this.bindAttributes();
+      if (this.m_programHandle === 0) {
+        console.log("[ERROR] Cannot create Program Object");
+        return false;
+      }
 
-    // link program
-    if (!this.link()) {
-      console.log("[ERROR] Failed to link Program");
-      this.cleanUp();
+      // Compile shaders
+      for (i = 0; i < this.m_shaders.length; ++i) {
+        this.m_shaders[i].compile();
+        this.m_shaders[i].attachShader(this.m_programHandle);
+      }
+
+      this.bindAttributes();
+
+      // link program
+      if (!this.link()) {
+        console.log("[ERROR] Failed to link Program");
+        this.cleanUp();
+      }
+
+      this.use();
+
+      this.bindUniforms();
+
+      this.setModified(false);
+    }
+    else {
+      this.use();
     }
 
-    this.use();
+    // Call update callback.
+    for (i = 0; i < this.m_uniforms.length; ++i) {
+      this.m_uniforms[i].update(renderState, this);
+    }
 
-    this.bindUniforms();
+    // Now update values to GL.
+    this.updateUniforms();
+  };
 
-    this.setModified(false);
-  }
-  else {
-    this.use();
-  }
+  this.undoBind = function(renderState) {
+    // Do nothing
+  };
 
-  // Call update callback.
-  for (i = 0; i < this.m_uniforms.length; ++i) {
-    this.m_uniforms[i].update(renderState, this);
-  }
 
-  // Now update values to GL.
-  this.updateUniforms();
-};
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.undoBind = function(renderState) {
-  // Do nothing
-};
+  this.bindVertexData = function(renderState, key) {
+    if (this.m_vertexAttributes.hasOwnProperty(key)) {
+      this.m_vertexAttributes[key].bindVertexData(renderState, key);
+    }
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.bindVertexData = function(renderState, key) {
-  if (this.m_vertexAttributes.hasOwnProperty(key)) {
-    this.m_vertexAttributes[key].bindVertexData(renderState, key);
-  }
-};
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.undoBindVertexData = function(renderState, key) {
-  if (this.m_vertexAttributes.hasOwnProperty(key)) {
-    this.m_vertexAttributes[key].undoBindVertexData(renderState, key);
-  }
-};
+  this.undoBindVertexData = function(renderState, key) {
+    if (this.m_vertexAttributes.hasOwnProperty(key)) {
+      this.m_vertexAttributes[key].undoBindVertexData(renderState, key);
+    }
+  };
 
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.bindUniforms = function() {
-  for (var i = 0; i < this.m_uniforms.length; ++i) {
-    this.m_uniformNameToLocation[this.m_uniforms[i].name()] =
-      this.queryUniformLocation(this.m_uniforms[i].name());
 
-    console.log(this.m_uniforms[i].name());
-    console.log(this.queryUniformLocation(this.m_uniforms[i].name()));
-  }
-};
-///---------------------------------------------------------------------------
-vglModule.shaderProgram.prototype.bindAttributes = function() {
-  var index = 0;
-  for (var i in this.m_vertexAttributes) {
-    var name = this.m_vertexAttributes[i].name();
-    gl.bindAttribLocation(this.m_programHandle, index, name);
-    this.m_vertexAttributeNameToLocation[name] = index++;
-  }
+  this.bindUniforms = function() {
+    for (var i = 0; i < this.m_uniforms.length; ++i) {
+      this.m_uniformNameToLocation[this.m_uniforms[i].name()] =
+        this.queryUniformLocation(this.m_uniforms[i].name());
+
+      console.log(this.m_uniforms[i].name());
+      console.log(this.queryUniformLocation(this.m_uniforms[i].name()));
+    }
+  };
+
+  this.bindAttributes = function() {
+    var index = 0;
+    for (var i in this.m_vertexAttributes) {
+      var name = this.m_vertexAttributes[i].name();
+      gl.bindAttribLocation(this.m_programHandle, index, name);
+      this.m_vertexAttributeNameToLocation[name] = index++;
+    }
+  };
 };
+
+inherit(vglModule.shaderProgram, vglModule.materialAttribute);
diff --git a/web/lib/vgl/texture.js b/web/lib/vgl/texture.js
index 9005202..b5159d2 100644
--- a/web/lib/vgl/texture.js
+++ b/web/lib/vgl/texture.js
@@ -23,10 +23,13 @@
 //////////////////////////////////////////////////////////////////////////////
 
 vglModule.texture = function() {
-  vglModule.materialAttribute.call(this);
 
-  this.m_type = materialAttributeType.Texture;
+  if (!(this instanceof vglModule.texture)) {
+    return new vglModule.texture();
+  }
+  vglModule.materialAttribute.call(this, materialAttributeType.Texture);
 
+  /// Private member variables
   this.m_width = 0;
   this.m_height = 0;
   this.m_depth = 0;
@@ -40,215 +43,217 @@ vglModule.texture = function() {
   this.m_internalFormat = null;
 
   this.m_image = null;
-};
-
-inherit(vglModule.texture, vglModule.materialAttribute);
-
-
-vglModule.texture.prototype.setup = function(renderState) {
-  if (this.modified()) {
-    gl.deleteTexture(this.m_textureHandle);
-    this.m_textureHandle = gl.createTexture();
-    gl.bindTexture(gl.TEXTURE_2D, this.m_textureHandle);
-    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
-    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
-    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
-    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
-    gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
-    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
-
-    if (this.m_image !== null) {
-      this.updateDimensions();
-      this.computeInternalFormatUsingImage();
-
-      //console.log("m_internalFormat " + this.m_internalFormat);
-      //console.log("m_pixelFormat " + this.m_pixelFormat);
-      //console.log("m_pixelDataType " + this.m_pixelDataType);
 
-      // FOR now support only 2D textures
-      gl.texImage2D(gl.TEXTURE_2D, 0, this.m_internalFormat,
-                    this.m_pixelFormat, this.m_pixelDataType, this.m_image);
+  /// Public member methods
+  this.setup = function(renderState) {
+    if (this.modified()) {
+      gl.deleteTexture(this.m_textureHandle);
+      this.m_textureHandle = gl.createTexture();
+      gl.bindTexture(gl.TEXTURE_2D, this.m_textureHandle);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+      gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
+      gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
+
+      if (this.m_image !== null) {
+        this.updateDimensions();
+        this.computeInternalFormatUsingImage();
+
+        //console.log("m_internalFormat " + this.m_internalFormat);
+        //console.log("m_pixelFormat " + this.m_pixelFormat);
+        //console.log("m_pixelDataType " + this.m_pixelDataType);
+
+        // FOR now support only 2D textures
+        gl.texImage2D(gl.TEXTURE_2D, 0, this.m_internalFormat,
+                      this.m_pixelFormat, this.m_pixelDataType, this.m_image);
+      }
+      else {
+        gl.texImage2D(gl.TEXTURE_2D, 0, this.m_internalFormat,
+                      this.m_pixelFormat, this.m_pixelDataType, null);
+      }
+
+      gl.bindTexture(gl.TEXTURE_2D, null);
+      this.setModified(false);
     }
-    else {
-      gl.texImage2D(gl.TEXTURE_2D, 0, this.m_internalFormat,
-                    this.m_pixelFormat, this.m_pixelDataType, null);
-    }
-
-    gl.bindTexture(gl.TEXTURE_2D, null);
-    this.setModified(false);
-  }
-};
+  };
 
 
-vglModule.texture.prototype.bind = function(renderState) {
-  // TODO Call setup via material setup
-  if (this.modified()) {
-    this.setup(renderState);
-  }
-
-  gl.activeTexture(gl.TEXTURE0);
-  gl.bindTexture(gl.TEXTURE_2D, this.m_textureHandle);
-};
-
-vglModule.texture.prototype.undoBind = function(renderState) {
-  gl.bindTexture(gl.TEXTURE_2D, null);
-};
-
+  this.bind = function(renderState) {
+    // TODO Call setup via material setup
+    if (this.modified()) {
+      this.setup(renderState);
+    }
 
-vglModule.texture.prototype.handleTextureLoaded = function(image) {
-  this.m_image = image;
-  this.updateDimensions();
-  this.setModified(true);
-};
+    gl.activeTexture(gl.TEXTURE0);
+    gl.bindTexture(gl.TEXTURE_2D, this.m_textureHandle);
+  };
 
+  this.undoBind = function(renderState) {
+    gl.bindTexture(gl.TEXTURE_2D, null);
+  };
 
-vglModule.texture.prototype.image = function() {
-  return this.m_image;
-};
 
-vglModule.texture.prototype.setImage = function(image) {
-  if (image !== null) {
-    image.onload = this.handleTextureLoaded(image);
-    return true;
-  }
+  this.handleTextureLoaded = function(image) {
+    this.m_image = image;
+    this.updateDimensions();
+    this.setModified(true);
+  };
 
-  return false;
-};
 
+  this.image = function() {
+    return this.m_image;
+  };
 
-vglModule.texture.prototype.textureUnit = function() {
-  return this.m_textureUnit;
-};
+  this.setImage = function(image) {
+    if (image !== null) {
+      image.onload = this.handleTextureLoaded(image);
+      return true;
+    }
 
-vglModule.texture.prototype.setTextureUnit = function(unit) {
-  if (this.m_textureUnit === unit) {
     return false;
-  }
+  };
 
-  this.m_textureUnit = unit;
-  this.setModified(true);
-  return true;
-};
 
+  this.textureUnit = function() {
+    return this.m_textureUnit;
+  };
 
-vglModule.texture.prototype.width = function() {
-  return this.m_width;
-};
+  this.setTextureUnit = function(unit) {
+    if (this.m_textureUnit === unit) {
+      return false;
+    }
 
-vglModule.texture.prototype.setWidth = function(width) {
-  if (this.m_image === null) {
-    return false;
-  }
+    this.m_textureUnit = unit;
+    this.setModified(true);
+    return true;
+  };
 
-  this.m_width = width;
-  this.setModified(true);
 
-  return true;
-};
+  this.width = function() {
+    return this.m_width;
+  };
 
+  this.setWidth = function(width) {
+    if (this.m_image === null) {
+      return false;
+    }
 
-vglModule.texture.prototype.depth = function() {
-  return this.m_depth;
-};
+    this.m_width = width;
+    this.setModified(true);
 
-vglModule.texture.prototype.setDepth = function(depth) {
-  if (this.m_image === null) {
-    return false;
-  }
+    return true;
+  };
 
-  this.m_depth = depth;
-  this.setModified(true);
 
-  return true;
-};
+  this.depth = function() {
+    return this.m_depth;
+  };
 
+  this.setDepth = function(depth) {
+    if (this.m_image === null) {
+      return false;
+    }
 
-vglModule.texture.prototype.textureHandle = function() {
-  return this.m_textureHandle;
-};
+    this.m_depth = depth;
+    this.setModified(true);
 
+    return true;
+  };
 
-vglModule.texture.prototype.internalFormat = function() {
-  return this.m_internalFormat;
-};
 
-vglModule.texture.prototype.setInternalFormat = function(internalFormat) {
-  if (this.m_internalFormat !== internalFormat) {
-    this.m_internalFormat = internalFormat;
-    this.setModified(true);
+  this.textureHandle = function() {
+    return this.m_textureHandle;
+  };
 
-    return true;
-  }
 
-  return false;
-};
+  this.internalFormat = function() {
+    return this.m_internalFormat;
+  };
 
+  this.setInternalFormat = function(internalFormat) {
+    if (this.m_internalFormat !== internalFormat) {
+      this.m_internalFormat = internalFormat;
+      this.setModified(true);
 
-vglModule.texture.prototype.pixelFormat = function() {
-  return this.m_pixelFormat;
-};
+      return true;
+    }
 
-vglModule.texture.prototype.setPixelFormat = function(pixelFormat) {
-  if (this.m_image === null) {
     return false;
-  }
+  };
 
-  this.m_pixelFormat = pixelFormat;
-  this.setModified(true);
-  return true;
-};
 
+  this.pixelFormat = function() {
+    return this.m_pixelFormat;
+  };
 
-vglModule.texture.prototype.pixelDataType = function() {
-  return this.m_pixelDataType;
-};
+  this.setPixelFormat = function(pixelFormat) {
+    if (this.m_image === null) {
+      return false;
+    }
 
-vglModule.texture.prototype.setPixelDataType = function(pixelDataType) {
-  if (this.m_image === null) {
-    return false;
-  }
+    this.m_pixelFormat = pixelFormat;
+    this.setModified(true);
+    return true;
+  };
 
-  this.m_pixelDataTYpe = pixelDataType;
 
-  this.setModified(true);
+  this.pixelDataType = function() {
+    return this.m_pixelDataType;
+  };
 
-  return true;
-};
+  this.setPixelDataType = function(pixelDataType) {
+    if (this.m_image === null) {
+      return false;
+    }
 
+    this.m_pixelDataTYpe = pixelDataType;
 
-vglModule.texture.prototype.computeInternalFormatUsingImage = function() {
-  // Currently image does not define internal format
-  // and hence it's pixel format is the only way to query
-  // information on how color has been stored.
-//  switch (this.m_image.pixelFormat()) {
-//  case gl.RGB:
-//    this.m_internalFormat = gl.RGB;
-//    break;
-//  case gl.RGBA:
-//    this.m_internalFormat = gl.RGBA;
-//    break;
-//  case gl.Luminance:
-//    this.m_internalFormat = gl.Luminance;
-//    break;
-//  case gl.LuminanceAlpha:
-//    this.m_internalFormat = gl.LuminanceAlpha;
-//    break;
-//  // Do nothing when image pixel format is none or undefined.
-//  default:
-//    break;
-//  };
-
-  // TODO Fix this
-  this.m_internalFormat = gl.RGBA;
-  this.m_pixelFormat = gl.RGBA;
-  this.m_pixelDataType = gl.UNSIGNED_BYTE;
-};
+    this.setModified(true);
 
+    return true;
+  };
+
+
+  this.computeInternalFormatUsingImage = function() {
+    // Currently image does not define internal format
+    // and hence it's pixel format is the only way to query
+    // information on how color has been stored.
+//    switch (this.m_image.pixelFormat()) {
+//    case gl.RGB:
+//      this.m_internalFormat = gl.RGB;
+//      break;
+//    case gl.RGBA:
+//      this.m_internalFormat = gl.RGBA;
+//      break;
+//    case gl.Luminance:
+//      this.m_internalFormat = gl.Luminance;
+//      break;
+//    case gl.LuminanceAlpha:
+//      this.m_internalFormat = gl.LuminanceAlpha;
+//      break;
+//    // Do nothing when image pixel format is none or undefined.
+//    default:
+//      break;
+//    };
+
+    // TODO Fix this
+    this.m_internalFormat = gl.RGBA;
+    this.m_pixelFormat = gl.RGBA;
+    this.m_pixelDataType = gl.UNSIGNED_BYTE;
+  };
+
+
+  this.updateDimensions = function() {
+    if (this.m_image !== null) {
+      this.m_width = this.m_image.width;
+      this.m_height = this.m_image.height;
+      this.m_depth = 0; // Only 2D images are supported now
+    }
+  };
 
-vglModule.texture.prototype.updateDimensions = function() {
-  if (this.m_image !== null) {
-    this.m_width = this.m_image.width;
-    this.m_height = this.m_image.height;
-    this.m_depth = 0; // Only 2D images are supported now
-  }
+  return;
 };
+
+inherit(vglModule.texture, vglModule.materialAttribute);
diff --git a/web/lib/vgl/utils.js b/web/lib/vgl/utils.js
index ac0aac3..289fbcc 100644
--- a/web/lib/vgl/utils.js
+++ b/web/lib/vgl/utils.js
@@ -152,6 +152,7 @@ vglModule.utils.createPlane = function(originX, originY, originZ,
   mapper.setGeometryData(planeSource.create());
 
   var mat = new vglModule.material();
+  var blend = new vglModule.blend();
   var prog = new vglModule.shaderProgram();
   var vertexShader = vglModule.utils.createVertexShader(gl);
   var fragmentShader = vglModule.utils.createFragmentShader(gl);
@@ -175,6 +176,7 @@ vglModule.utils.createPlane = function(originX, originY, originZ,
   prog.addShader(fragmentShader);
   prog.addShader(vertexShader);
   mat.addAttribute(prog);
+  mat.addAttribute(blend);
 
   var actor = new vglModule.actor();
   console.log(actor);
@@ -205,6 +207,7 @@ vglModule.utils.createTexturePlane = function(originX, originY, originZ,
   mapper.setGeometryData(planeSource.create());
 
   var mat = new vglModule.material();
+  var blend = new vglModule.blend();
   var prog = new vglModule.shaderProgram();
   var vertexShader = vglModule.utils.createTextureVertexShader(gl);
   var fragmentShader = vglModule.utils.createTextureFragmentShader(gl);
@@ -226,7 +229,9 @@ vglModule.utils.createTexturePlane = function(originX, originY, originZ,
   prog.addUniform(samplerUniform);
   prog.addShader(fragmentShader);
   prog.addShader(vertexShader);
+
   mat.addAttribute(prog);
+  mat.addAttribute(blend);
 
   var actor = new vglModule.actor();
   console.log(actor);

http://public.kitware.com/gitweb?p=OpenGeoscience/opengeoscience.git;a=commitdiff;h=d5d02452db746b4dccf15838bfdea8b5c95bb406
commit d5d02452db746b4dccf15838bfdea8b5c95bb406
Author:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
AuthorDate: Fri Mar 1 11:23:17 2013 -0500
Commit:     Aashish Chaudhary <aashish.chaudhary at kitware.com>
CommitDate: Fri Mar 1 11:23:17 2013 -0500

    Adding blend attribute

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 88ef489..c9929fb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,6 +53,7 @@ set(JS_LINT_FILES
     ${CMAKE_SOURCE_DIR}/web/lib/vgl/init.js
     ${CMAKE_SOURCE_DIR}/web/lib/vgl/mapper.js
     ${CMAKE_SOURCE_DIR}/web/lib/vgl/materialAttribute.js
+    ${CMAKE_SOURCE_DIR}/web/lib/vgl/blend.js
     ${CMAKE_SOURCE_DIR}/web/lib/vgl/material.js
     ${CMAKE_SOURCE_DIR}/web/lib/vgl/modelViewMatrixStack.js
     ${CMAKE_SOURCE_DIR}/web/lib/vgl/node.js
@@ -85,6 +86,7 @@ set(JS_UGLIFY_FILES
   ${CMAKE_SOURCE_DIR}/web/lib/vgl/geomData.js
   ${CMAKE_SOURCE_DIR}/web/lib/vgl/mapper.js
   ${CMAKE_SOURCE_DIR}/web/lib/vgl/materialAttribute.js
+  ${CMAKE_SOURCE_DIR}/web/lib/vgl/blend.js
   ${CMAKE_SOURCE_DIR}/web/lib/vgl/material.js
   ${CMAKE_SOURCE_DIR}/web/lib/vgl/renderer.js
   ${CMAKE_SOURCE_DIR}/web/lib/vgl/shader.js
diff --git a/web/lib/vgl/blend.js b/web/lib/vgl/blend.js
new file mode 100644
index 0000000..6be84b8
--- /dev/null
+++ b/web/lib/vgl/blend.js
@@ -0,0 +1,104 @@
+/*========================================================================
+  VGL --- VTK WebGL Rendering Toolkit
+
+  Copyright 2013 Kitware, Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ ========================================================================*/
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// blendFunction class
+//
+//////////////////////////////////////////////////////////////////////////////
+
+vglModule.blendFunction = function(source, destination) {
+
+  if (!(this instanceof vglModule.blendFunction)) {
+    return new vglModule.blendFunction(source, destination);
+  }
+
+  /// Private variables
+  var m_source = source;
+  var m_desination = destination;
+
+  /**
+   * Apply blend function to the current state
+   *
+   */
+  this.apply = function(renderState) {
+    gl.blendFunc(m_source, m_destination);
+  }
+
+  return this;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// blend class
+//
+//////////////////////////////////////////////////////////////////////////////
+
+vglModule.blend = function() {
+
+  if (!(this instanceof vglModule.blend)) {
+    return new vglModule.blend();
+  }
+  vglModule.materialAttribute.call(this);
+
+  this.m_type = materialAttributeType.Blend;
+
+  /// Private member variables
+  var m_wasEnabled;
+  var m_blendFunction =
+    vglModule.blendFunction(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
+
+  /**
+   * Bind blend attribute
+   *
+   */
+  this.bind  = function(renderState) {
+
+    this.m_wasEnabled = gl.IsEnabled(gl.BLEND);
+
+    if (this.m_enabled) {
+      gl.enable(GL_BLEND);
+      this.m_blendFunction.apply(renderState);
+    } else {
+      gl.disable(gl.BLEND);
+    }
+
+    return true;
+  };
+
+  /**
+   * Undo blend attribute
+   *
+   */
+  this.undoBind = function(renderState) {
+
+    if (this.m_wasEnabled) {
+      gl.enable(GL_BLEND);
+    } else {
+      gl.disable(GL_BLEND);
+    }
+
+    this.setDirtyStateOff();
+
+    return true;
+  };
+
+  return this;
+};
+
+inherit(vglModule.blend, vglModule.materialAttribute);
diff --git a/web/lib/vgl/materialAttribute.js b/web/lib/vgl/materialAttribute.js
index df6d5ba..e4a60c5 100644
--- a/web/lib/vgl/materialAttribute.js
+++ b/web/lib/vgl/materialAttribute.js
@@ -38,35 +38,35 @@ vglModule.materialAttribute = function() {
 
 inherit(vglModule.materialAttribute, vglModule.object);
 
-///---------------------------------------------------------------------------
+
 vglModule.materialAttribute.prototype.type = function() {
   return this.m_type;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.materialAttribute.prototype.setup = function(renderState) {
   return false;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.materialAttribute.prototype.bind  = function(renderState) {
   return false;
 };
-///---------------------------------------------------------------------------
+
 vglModule.materialAttribute.prototype.undoBind = function(renderState) {
   return false;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.materialAttribute.prototype.setupVertexData = function(renderState, key) {
   return false;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.materialAttribute.prototype.bindVertexData = function(renderState, key) {
   return false;
 };
-///---------------------------------------------------------------------------
+
 vglModule.materialAttribute.prototype.undoBindVertexData = function(renderState, key) {
   return false;
 };
\ No newline at end of file
diff --git a/web/lib/vgl/texture.js b/web/lib/vgl/texture.js
index 13afc70..9005202 100644
--- a/web/lib/vgl/texture.js
+++ b/web/lib/vgl/texture.js
@@ -22,7 +22,6 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
-///---------------------------------------------------------------------------
 vglModule.texture = function() {
   vglModule.materialAttribute.call(this);
 
@@ -45,7 +44,7 @@ vglModule.texture = function() {
 
 inherit(vglModule.texture, vglModule.materialAttribute);
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.setup = function(renderState) {
   if (this.modified()) {
     gl.deleteTexture(this.m_textureHandle);
@@ -80,7 +79,7 @@ vglModule.texture.prototype.setup = function(renderState) {
   }
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.bind = function(renderState) {
   // TODO Call setup via material setup
   if (this.modified()) {
@@ -90,23 +89,23 @@ vglModule.texture.prototype.bind = function(renderState) {
   gl.activeTexture(gl.TEXTURE0);
   gl.bindTexture(gl.TEXTURE_2D, this.m_textureHandle);
 };
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.undoBind = function(renderState) {
   gl.bindTexture(gl.TEXTURE_2D, null);
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.handleTextureLoaded = function(image) {
   this.m_image = image;
   this.updateDimensions();
   this.setModified(true);
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.image = function() {
   return this.m_image;
 };
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.setImage = function(image) {
   if (image !== null) {
     image.onload = this.handleTextureLoaded(image);
@@ -116,11 +115,11 @@ vglModule.texture.prototype.setImage = function(image) {
   return false;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.textureUnit = function() {
   return this.m_textureUnit;
 };
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.setTextureUnit = function(unit) {
   if (this.m_textureUnit === unit) {
     return false;
@@ -131,11 +130,11 @@ vglModule.texture.prototype.setTextureUnit = function(unit) {
   return true;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.width = function() {
   return this.m_width;
 };
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.setWidth = function(width) {
   if (this.m_image === null) {
     return false;
@@ -147,11 +146,11 @@ vglModule.texture.prototype.setWidth = function(width) {
   return true;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.depth = function() {
   return this.m_depth;
 };
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.setDepth = function(depth) {
   if (this.m_image === null) {
     return false;
@@ -163,16 +162,16 @@ vglModule.texture.prototype.setDepth = function(depth) {
   return true;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.textureHandle = function() {
   return this.m_textureHandle;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.internalFormat = function() {
   return this.m_internalFormat;
 };
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.setInternalFormat = function(internalFormat) {
   if (this.m_internalFormat !== internalFormat) {
     this.m_internalFormat = internalFormat;
@@ -184,11 +183,11 @@ vglModule.texture.prototype.setInternalFormat = function(internalFormat) {
   return false;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.pixelFormat = function() {
   return this.m_pixelFormat;
 };
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.setPixelFormat = function(pixelFormat) {
   if (this.m_image === null) {
     return false;
@@ -199,11 +198,11 @@ vglModule.texture.prototype.setPixelFormat = function(pixelFormat) {
   return true;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.pixelDataType = function() {
   return this.m_pixelDataType;
 };
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.setPixelDataType = function(pixelDataType) {
   if (this.m_image === null) {
     return false;
@@ -216,7 +215,7 @@ vglModule.texture.prototype.setPixelDataType = function(pixelDataType) {
   return true;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.computeInternalFormatUsingImage = function() {
   // Currently image does not define internal format
   // and hence it's pixel format is the only way to query
@@ -245,7 +244,7 @@ vglModule.texture.prototype.computeInternalFormatUsingImage = function() {
   this.m_pixelDataType = gl.UNSIGNED_BYTE;
 };
 
-///---------------------------------------------------------------------------
+
 vglModule.texture.prototype.updateDimensions = function() {
   if (this.m_image !== null) {
     this.m_width = this.m_image.width;

-----------------------------------------------------------------------

Summary of changes:
 CMakeLists.txt                   |    2 +
 web/lib/vgl/blend.js             |   97 ++++++++++
 web/lib/vgl/materialAttribute.js |   75 +++++----
 web/lib/vgl/shaderProgram.js     |  312 +++++++++++++++++----------------
 web/lib/vgl/texture.js           |  360 +++++++++++++++++++-------------------
 web/lib/vgl/utils.js             |    5 +
 6 files changed, 487 insertions(+), 364 deletions(-)
 create mode 100644 web/lib/vgl/blend.js


hooks/post-receive
-- 
OpenGeoscience



More information about the Opengeoscience-developers mailing list