Changeset 19745
- Timestamp:
- 11/17/15 17:02:22 (9 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/plot_unit.js
r19741 r19745 20 20 //}}} 21 21 22 //load the shaders:23 loadShaders(gl);24 25 22 //Initialize the buffer structure: 26 23 node = Node(gl,options); -
issm/trunk-jpl/src/m/plot/webgl.js
r19741 r19745 1 1 /*This is where we have all our webgl relevant functionality for the plotting routines: */ 2 var shaders = {};3 2 //{{{ GL Initialization 4 3 function initWebGL(canvas,options) { //{{{ … … 27 26 gl.enableVertexAttribArray(0); 28 27 gl.enableVertexAttribArray(1); 28 29 // Load shaders and store them in gl object 30 gl.shaders = loadShaders(gl); 29 31 30 32 // Add context state variables … … 68 70 69 71 node= {buffers:[], 70 shader: shaders["colored"]["program"],72 shader:gl.shaders["colored"]["program"], 71 73 draw:null, 72 74 hideOcean:false, … … 128 130 //{{{ Shader Loading 129 131 function loadShaders(gl) { //{{{ 130 var shader_name_array = ["colored"]; 131 //var shaders = {}; 132 for (var i = 0; i < shader_name_array.length; i++) { 133 loadShader(gl,shader_name_array[i]); 134 } 135 //return shaders; 136 } //}}} 137 function loadShader(gl,shaderName) { //{{{ 138 //var shader = {loaded:false, vsh:{}, fsh:{}}; 132 // TODO: Subsitute shaders["colored"] with shaderColored 133 shaderName = "colored"; 134 shaders = {}; 139 135 shaders[shaderName] = {loaded:false, vsh:{}, fsh:{}}; 140 $.ajax({ 141 url: "webgl/shaders/" + shaderName + ".vsh", 142 async: false, 143 dataType: "script" 144 }); 145 $.ajax({ 146 url: "webgl/shaders/" + shaderName + ".fsh", 147 async: false, 148 dataType: "script" 149 }); 136 shaders["colored"]["vsh"]["string"] = ` 137 attribute vec3 aVertexPosition; 138 attribute vec4 aVertexColor; 139 140 uniform mat4 uMVPMatrix; 141 uniform float uAlpha; 142 143 varying vec4 vColor; 144 145 void main(void) { 146 gl_Position = uMVPMatrix * vec4(aVertexPosition.xyz, 1.0); 147 vColor = vec4(aVertexColor.xyz, uAlpha); 148 } 149 `; 150 shaders["colored"]["fsh"]["string"] = ` 151 precision mediump float; 152 153 varying vec4 vColor; 154 155 void main(void) { 156 gl_FragColor = vColor; 157 } 158 `; 150 159 151 160 shaders[shaderName]["vsh"]["shader"] = getShaderByString(gl, shaders[shaderName]["vsh"]["string"], "vsh"); … … 190 199 } 191 200 shaders[shaderName]["loaded"] = true; 192 //return shader;201 return shaders; 193 202 } //}}} 194 203 function getShaderByString(gl,str,type) { //{{{ … … 213 222 214 223 return shader; 215 } //}}}216 function functionToString(functionVariable) { //{{{217 //Workaround for loading text files - store as multiline comment in function, then strip string from function once loaded218 return functionVariable.toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');219 224 } //}}} 220 225 function nameFromLine(line) { //{{{
Note:
See TracChangeset
for help on using the changeset viewer.