aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/jshader.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/jshader.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/jshader.js1528
1 files changed, 764 insertions, 764 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/jshader.js b/js/helper-classes/RDGE/src/core/script/jshader.js
index b9170857..559380e3 100755
--- a/js/helper-classes/RDGE/src/core/script/jshader.js
+++ b/js/helper-classes/RDGE/src/core/script/jshader.js
@@ -1,764 +1,764 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility, Inc
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4BSD License.
5 5
6Redistribution and use in source and binary forms, with or without 6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 7modification, are permitted provided that the following conditions are met:
8 8
9 - Redistributions of source code must retain the above copyright notice, 9 - Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 10 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the 12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution. 13 documentation and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors 14 - Neither the name of Motorola Mobility nor the names of its contributors
15 may be used to endorse or promote products derived from this software 15 may be used to endorse or promote products derived from this software
16 without specific prior written permission. 16 without specific prior written permission.
17 17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE. 28POSSIBILITY OF SUCH DAMAGE.
29</copyright> */ 29</copyright> */
30 30
31// RDGE namespaces 31// RDGE namespaces
32var RDGE = RDGE || {}; 32var RDGE = RDGE || {};
33 33
34/* 34/*
35this API should be familiar to anyone who has worked with HLSL effect files. 35this API should be familiar to anyone who has worked with HLSL effect files.
36*/ 36*/
37 37
38/* 38/*
39 * A map of types to uniform 'binding' functions 39 * A map of types to uniform 'binding' functions
40 */ 40 */
41RDGE.bindMap={}; 41RDGE.bindMap={};
42RDGE.bindMap['int'] = function(ctx, a,b) { ctx.uniform1iv(a,b); }; 42RDGE.bindMap['int'] = function(ctx, a,b) { ctx.uniform1iv(a,b); };
43RDGE.bindMap['float'] = function(ctx, a,b) { ctx.uniform1fv(a,b); }; 43RDGE.bindMap['float'] = function(ctx, a,b) { ctx.uniform1fv(a,b); };
44RDGE.bindMap['vec2'] = function(ctx, a,b) { ctx.uniform2fv(a,b); }; 44RDGE.bindMap['vec2'] = function(ctx, a,b) { ctx.uniform2fv(a,b); };
45RDGE.bindMap['vec3'] = function(ctx, a,b) { ctx.uniform3fv(a,b); }; 45RDGE.bindMap['vec3'] = function(ctx, a,b) { ctx.uniform3fv(a,b); };
46RDGE.bindMap['vec4'] = function(ctx, a,b) { ctx.uniform4fv(a,b); }; 46RDGE.bindMap['vec4'] = function(ctx, a,b) { ctx.uniform4fv(a,b); };
47RDGE.bindMap['mat3'] = function(ctx, a,b) { ctx.uniformMatrix3fv(a,false,b); }; 47RDGE.bindMap['mat3'] = function(ctx, a,b) { ctx.uniformMatrix3fv(a,false,b); };
48RDGE.bindMap['mat4'] = function(ctx, a,b) 48RDGE.bindMap['mat4'] = function(ctx, a,b)
49{ 49{
50 ctx.uniformMatrix4fv(a,false,b); 50 ctx.uniformMatrix4fv(a,false,b);
51 RDGE.globals.engine.getContext().debug.mat4CallCount++; 51 RDGE.globals.engine.getContext().debug.mat4CallCount++;
52}; 52};
53 53
54RDGE.bindMap['tex2d'] = function(ctx, a,b) 54RDGE.bindMap['tex2d'] = function(ctx, a,b)
55{ 55{
56 ctx.activeTexture(ctx.TEXTURE0+b[0]); 56 ctx.activeTexture(ctx.TEXTURE0+b[0]);
57 ctx.bindTexture(ctx.TEXTURE_2D, b[1]); 57 ctx.bindTexture(ctx.TEXTURE_2D, b[1]);
58 ctx.uniform1iv(a,[b[0]]); 58 ctx.uniform1iv(a,[b[0]]);
59}; 59};
60 60
61RDGE.bindMap['texCube']=function(ctx, a,b) 61RDGE.bindMap['texCube']=function(ctx, a,b)
62{ 62{
63 ctx.activeTexture(ctx.TEXTURE0+b[0]); 63 ctx.activeTexture(ctx.TEXTURE0+b[0]);
64 ctx.bindTexture(ctx.TEXTURE_CUBE_MAP, b[1]); 64 ctx.bindTexture(ctx.TEXTURE_CUBE_MAP, b[1]);
65 ctx.uniform1iv(a,[b[0]]); 65 ctx.uniform1iv(a,[b[0]]);
66}; 66};
67 67
68RDGE.lightDataMap = 68RDGE.lightDataMap =
69[ 69[
70 function(ctx, loc, lightNode) { ctx.uniform3fv(loc, lightNode.position); }, 70 function(ctx, loc, lightNode) { ctx.uniform3fv(loc, lightNode.position); },
71 function(ctx, loc, lightNode) { ctx.uniform4fv(loc, lightNode.lightDiffuse); }, 71 function(ctx, loc, lightNode) { ctx.uniform4fv(loc, lightNode.lightDiffuse); },
72 function(ctx, loc, lightNode) { ctx.uniform4fv(loc, lightNode.lightAmbient); }, 72 function(ctx, loc, lightNode) { ctx.uniform4fv(loc, lightNode.lightAmbient); },
73 function(ctx, loc, lightNode) { ctx.uniform4fv(loc, lightNode.lightSpecular); } 73 function(ctx, loc, lightNode) { ctx.uniform4fv(loc, lightNode.lightSpecular); }
74]; 74];
75 75
76RDGE.paramTypeNameMapping = null; 76RDGE.paramTypeNameMapping = null;
77 77
78RDGE.jshader = function (addr) { 78RDGE.jshader = function (addr) {
79 this.name = addr; 79 this.name = addr;
80 this.def = null; 80 this.def = null;
81 this.technique = {}; 81 this.technique = {};
82 this.params = {}; 82 this.params = {};
83 this.compiledShaders = {}; 83 this.compiledShaders = {};
84 this.resetRS = false; 84 this.resetRS = false;
85 this.currentPass = 0; 85 this.currentPass = 0;
86 this.type_jshader = {}; 86 this.type_jshader = {};
87 this.global = {}; 87 this.global = {};
88 this.renderer = RDGE.globals.engine.getContext().renderer; 88 this.renderer = RDGE.globals.engine.getContext().renderer;
89 this.ctx = this.renderer.ctx; 89 this.ctx = this.renderer.ctx;
90 90
91 // load jshader definition at addr (if provided) 91 // load jshader definition at addr (if provided)
92 if (addr != undefined && addr != null) { 92 if (addr != undefined && addr != null) {
93 // a synchronous ajax request 93 // a synchronous ajax request
94 request = new XMLHttpRequest(); 94 request = new XMLHttpRequest();
95 request.open("GET", addr, false); 95 request.open("GET", addr, false);
96 request.send(null); 96 request.send(null);
97 this.def = JSON.parse(request.responseText); 97 this.def = JSON.parse(request.responseText);
98 } 98 }
99 99
100 if (!RDGE.paramTypeNameMapping) { 100 if (!RDGE.paramTypeNameMapping) {
101 var gl = this.ctx; 101 var gl = this.ctx;
102 RDGE.paramTypeNameMapping = {}; 102 RDGE.paramTypeNameMapping = {};
103 RDGE.paramTypeNameMapping[gl.BOOL] = "bool"; 103 RDGE.paramTypeNameMapping[gl.BOOL] = "bool";
104 RDGE.paramTypeNameMapping[gl.INT] = "int"; 104 RDGE.paramTypeNameMapping[gl.INT] = "int";
105 RDGE.paramTypeNameMapping[gl.FLOAT] = "float"; 105 RDGE.paramTypeNameMapping[gl.FLOAT] = "float";
106 RDGE.paramTypeNameMapping[gl.FLOAT_VEC2] = "vec2"; 106 RDGE.paramTypeNameMapping[gl.FLOAT_VEC2] = "vec2";
107 RDGE.paramTypeNameMapping[gl.FLOAT_VEC3] = "vec3"; 107 RDGE.paramTypeNameMapping[gl.FLOAT_VEC3] = "vec3";
108 RDGE.paramTypeNameMapping[gl.FLOAT_VEC4] = "vec4"; 108 RDGE.paramTypeNameMapping[gl.FLOAT_VEC4] = "vec4";
109 RDGE.paramTypeNameMapping[gl.INT_VEC2] = "vec2"; 109 RDGE.paramTypeNameMapping[gl.INT_VEC2] = "vec2";
110 RDGE.paramTypeNameMapping[gl.INT_VEC3] = "vec3"; 110 RDGE.paramTypeNameMapping[gl.INT_VEC3] = "vec3";
111 RDGE.paramTypeNameMapping[gl.INT_VEC4] = "vec4"; 111 RDGE.paramTypeNameMapping[gl.INT_VEC4] = "vec4";
112 RDGE.paramTypeNameMapping[gl.BOOL_VEC2] = "vec2"; 112 RDGE.paramTypeNameMapping[gl.BOOL_VEC2] = "vec2";
113 RDGE.paramTypeNameMapping[gl.BOOL_VEC3] = "vec3"; 113 RDGE.paramTypeNameMapping[gl.BOOL_VEC3] = "vec3";
114 RDGE.paramTypeNameMapping[gl.BOOL_VEC4] = "vec4"; 114 RDGE.paramTypeNameMapping[gl.BOOL_VEC4] = "vec4";
115 RDGE.paramTypeNameMapping[gl.FLOAT_MAT2] = "mat2"; 115 RDGE.paramTypeNameMapping[gl.FLOAT_MAT2] = "mat2";
116 RDGE.paramTypeNameMapping[gl.FLOAT_MAT3] = "mat3"; 116 RDGE.paramTypeNameMapping[gl.FLOAT_MAT3] = "mat3";
117 RDGE.paramTypeNameMapping[gl.FLOAT_MAT4] = "mat4"; 117 RDGE.paramTypeNameMapping[gl.FLOAT_MAT4] = "mat4";
118 RDGE.paramTypeNameMapping[gl.SAMPLER_2D] = "tex2d"; 118 RDGE.paramTypeNameMapping[gl.SAMPLER_2D] = "tex2d";
119 RDGE.paramTypeNameMapping[gl.SAMPLER_CUBE] = "texCube"; 119 RDGE.paramTypeNameMapping[gl.SAMPLER_CUBE] = "texCube";
120 } 120 }
121 121
122 /* 122 /*
123 * private helper functions 123 * private helper functions
124 */ 124 */
125 this.bindParameters = function (pass) { 125 this.bindParameters = function (pass) {
126 var params = pass.defParamsList; // global parameters to start with 126 var params = pass.defParamsList; // global parameters to start with