Changeset 19864 for issm/trunk-jpl/src/m/plot/webgl.js
- Timestamp:
- 12/07/15 23:23:47 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/webgl.js
r19853 r19864 22 22 // Clear the color as well as the depth buffer. 23 23 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 24 // Enable color blending/overlay 25 gl.enable(gl.BLEND); 24 26 25 27 // Allocate arrays equal to maximium number of attributes used by any one shader … … 99 101 } //}}} 100 102 function Node(gl,options) { //{{{ 101 102 var node; 103 104 node= {buffers:[], 103 //Returns a Node object that contains default display states for webgl object 104 return {buffers:[], 105 105 shader:gl.shaders["unlit_textured"]["program"], 106 106 draw:null, … … 109 109 useIndexBuffer:true, 110 110 useOrthographic:false, 111 transparency:1.0,111 alpha:1.0, 112 112 disableDepthTest:false, 113 113 enableCullFace:false, … … 120 120 modelMatrix:mat4.create(), 121 121 shaderName:"unlit_textured", 122 overlay:false, 122 123 }; 123 124 return node;125 126 124 } //}}} 127 125 function recalculateModelMatrix(node) { //{{{ … … 210 208 '', 211 209 'uniform sampler2D uColorSampler;', 210 'uniform float uAlpha;', 212 211 '', 213 212 'void main(void) {', 214 ' gl_FragColor = texture2D(uColorSampler, vec2(vTextureCoord.s, vTextureCoord.t));',213 ' gl_FragColor = vec4(texture2D(uColorSampler, vec2(vTextureCoord.s, vTextureCoord.t)).rgb, uAlpha);', 215 214 '}'].join('\n'); 216 215 shaderNames.forEach(function(shaderName){ … … 323 322 } 324 323 gl.uniformMatrix4fv(node["shader"]["uMVPMatrix"], false, mvpMatrix); 325 gl.uniform1f(node["shader"]["uAlpha"], node[" transparency"]);324 gl.uniform1f(node["shader"]["uAlpha"], node["alpha"]); 326 325 if (node["texture"]) { 327 326 gl.activeTexture(gl.TEXTURE0); … … 329 328 gl.uniform1i(node["shader"]["uColorSampler"], 0); 330 329 } 331 if (node["useIndexBuffer"]) { 330 if (node["overlay"] == true) { 331 gl.blendFunc(gl.SRC_ALPHA, gl.ONE); 332 } 333 else { 334 gl.blendFunc (gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); 335 } 336 if (node["useIndexBuffer"] == true) { 332 337 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, node["buffers"][node["buffers"].length - 1]); 333 338 gl.drawElements(node["drawMode"], node["buffers"][node["buffers"].length - 1].numItems, gl.UNSIGNED_SHORT, 0); … … 350 355 } 351 356 } //}}} 352 function draw(gl,options,canvas,node ) { //{{{357 function draw(gl,options,canvas,nodes) { //{{{ 353 358 354 359 // Set clear color to black, fully opaque … … 358 363 } 359 364 else throw Error(sprintf("s%s%s\n","initWebGL error message: cound not find out background color for curent canvas ",canvas)); 360 365 361 366 // Clear the color as well as the depth buffer. 362 367 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 363 368 364 window.requestAnimationFrame(function(time) {draw(gl,options,canvas,node )});369 window.requestAnimationFrame(function(time) {draw(gl,options,canvas,nodes)}); 365 370 updateCameraMatrix(canvas); 366 367 drawSceneGraphNode(gl, canvas, node); 371 for (var node in nodes) { 372 drawSceneGraphNode(gl, canvas, nodes[node]); 373 } 368 374 } //}}} 369 375 //}}}
Note:
See TracChangeset
for help on using the changeset viewer.