Move shader support code into ol.webgl

This commit is contained in:
Tom Payne
2013-03-23 18:29:26 +01:00
parent 4ec8bf2360
commit 731fcd3d17
9 changed files with 111 additions and 112 deletions

81
src/ol/webgl/shader.js Normal file
View File

@@ -0,0 +1,81 @@
goog.provide('ol.webgl.FragmentShader');
goog.provide('ol.webgl.VertexShader');
goog.require('goog.functions');
goog.require('goog.webgl');
/**
* @constructor
* @param {string} source Source.
*/
ol.webgl.Shader = function(source) {
/**
* @private
* @type {string}
*/
this.source_ = source;
};
/**
* @return {number} Type.
*/
ol.webgl.Shader.prototype.getType = goog.abstractMethod;
/**
* @return {string} Source.
*/
ol.webgl.Shader.prototype.getSource = function() {
return this.source_;
};
/**
* @return {boolean} Is animated?
*/
ol.webgl.Shader.prototype.isAnimated = goog.functions.FALSE;
/**
* @constructor
* @extends {ol.webgl.Shader}
* @param {string} source Source.
*/
ol.webgl.FragmentShader = function(source) {
goog.base(this, source);
};
goog.inherits(ol.webgl.FragmentShader, ol.webgl.Shader);
/**
* @inheritDoc
*/
ol.webgl.FragmentShader.prototype.getType = function() {
return goog.webgl.FRAGMENT_SHADER;
};
/**
* @constructor
* @extends {ol.webgl.Shader}
* @param {string} source Source.
*/
ol.webgl.VertexShader = function(source) {
goog.base(this, source);
};
goog.inherits(ol.webgl.VertexShader, ol.webgl.Shader);
/**
* @inheritDoc
*/
ol.webgl.VertexShader.prototype.getType = function() {
return goog.webgl.VERTEX_SHADER;
};

View File

@@ -0,0 +1,106 @@
goog.provide('{{namespace}}.shader');
goog.require('ol.webgl.FragmentShader');
goog.require('ol.webgl.VertexShader');
/**
* @constructor
* @extends {ol.webgl.FragmentShader}
*/
{{namespace}}.shader.Fragment = function() {
goog.base(this, {{namespace}}.shader.Fragment.SOURCE);
};
goog.inherits({{namespace}}.shader.Fragment, ol.webgl.FragmentShader);
goog.addSingletonGetter({{namespace}}.shader.Fragment);
/**
* @const
* @type {string}
*/
{{namespace}}.shader.Fragment.DEBUG_SOURCE = 'precision mediump float;\n{{getOriginalFragmentSource}}';
/**
* @const
* @type {string}
*/
{{namespace}}.shader.Fragment.OPTIMIZED_SOURCE = 'precision mediump float;{{getFragmentSource}}';
/**
* @const
* @type {string}
*/
{{namespace}}.shader.Fragment.SOURCE = goog.DEBUG ?
{{namespace}}.shader.Fragment.DEBUG_SOURCE :
{{namespace}}.shader.Fragment.OPTIMIZED_SOURCE;
/**
* @constructor
* @extends {ol.webgl.VertexShader}
*/
{{namespace}}.shader.Vertex = function() {
goog.base(this, {{namespace}}.shader.Vertex.SOURCE);
};
goog.inherits({{namespace}}.shader.Vertex, ol.webgl.VertexShader);
goog.addSingletonGetter({{namespace}}.shader.Vertex);
/**
* @const
* @type {string}
*/
{{namespace}}.shader.Vertex.DEBUG_SOURCE = '{{getOriginalVertexSource}}';
/**
* @const
* @type {string}
*/
{{namespace}}.shader.Vertex.OPTIMIZED_SOURCE = '{{getVertexSource}}';
/**
* @const
* @type {string}
*/
{{namespace}}.shader.Vertex.SOURCE = goog.DEBUG ?
{{namespace}}.shader.Vertex.DEBUG_SOURCE :
{{namespace}}.shader.Vertex.OPTIMIZED_SOURCE;
/**
* @constructor
*/
{{namespace}}.shader.uniform = function() {};
{{#getUniforms}}
/**
* @const
* @type {string}
*/
{{namespace}}.shader.uniform.{{originalName}} =
goog.DEBUG ? '{{originalName}}' : '{{shortName}}';
{{/getUniforms}}
/**
* @constructor
*/
{{namespace}}.shader.attribute = function() {};
{{#getAttributes}}
/**
* @const
* @type {string}
*/
{{namespace}}.shader.attribute.{{originalName}} =
goog.DEBUG ? '{{originalName}}' : '{{shortName}}';
{{/getAttributes}}