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