aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/ShaderManager.js
diff options
context:
space:
mode:
authorKruti Shah2012-07-17 12:40:00 -0700
committerKruti Shah2012-07-17 12:40:00 -0700
commitbf2d7bdb22c28089dc1067bc9094ebc590daac87 (patch)
tree2156d9920ea1b7db49ed6460545fea7cda121bae /js/helper-classes/RDGE/src/core/script/ShaderManager.js
parent7e2c2dbd040ed79a3f0678f91bd4b6db9cf69231 (diff)
parentb4b3e45d6684e77d361b4f8ca5be4889428320c5 (diff)
downloadninja-bf2d7bdb22c28089dc1067bc9094ebc590daac87.tar.gz
Merge branch 'refs/heads/TimelineUberJD' into Timeline-local-kruti
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/ShaderManager.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/ShaderManager.js221
1 files changed, 111 insertions, 110 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/ShaderManager.js b/js/helper-classes/RDGE/src/core/script/ShaderManager.js
index 06d44da5..061e9071 100755
--- a/js/helper-classes/RDGE/src/core/script/ShaderManager.js
+++ b/js/helper-classes/RDGE/src/core/script/ShaderManager.js
@@ -1,110 +1,111 @@
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 || {};
34RDGE.Shader = function (name, shaderHandle, renderProc, initRenderProc, envMap) { 34
35 this.name = name; 35RDGE.Shader = function (name, shaderHandle, renderProc, initRenderProc, envMap) {
36 this.shaderHandle = shaderHandle; 36 this.name = name;
37 this.initRenderProc = initRenderProc; 37 this.shaderHandle = shaderHandle;
38 this.renderProc = renderProc; 38 this.initRenderProc = initRenderProc;
39 this.postRenderProc = RDGE.postRenderProcDefault; 39 this.renderProc = renderProc;
40 this.envMap = envMap; 40 this.postRenderProc = RDGE.postRenderProcDefault;
41 this.envDiff = envMap; 41 this.envMap = envMap;
42}; 42 this.envDiff = envMap;
43 43};
44RDGE.ShaderManager = function () { 44
45 this.shaderMap = []; 45RDGE.ShaderManager = function () {
46}; 46 this.shaderMap = [];
47 47};
48RDGE.ShaderManager.prototype.addShader = function (name, vShader, fShader, attribs, renderProc, initRenderProc, envMapName, envDiffMapName) { 48
49 var shader = this.shaderMap[name]; 49RDGE.ShaderManager.prototype.addShader = function (name, vShader, fShader, attribs, renderProc, initRenderProc, envMapName, envDiffMapName) {
50 if (shader == undefined) { 50 var shader = this.shaderMap[name];
51 51 if (shader == undefined) {
52 var handle = RDGE.createShader(RDGE.globals.engine.getContext().renderer.ctx, vShader, fShader, attribs); 52
53 if (envMapName != undefined || envDiffMapName != undefined) { 53 var handle = RDGE.createShader(RDGE.globals.engine.getContext().renderer.ctx, vShader, fShader, attribs);
54 var envMap = g_texMan.loadMaterial(envMapName); 54 if (envMapName != undefined || envDiffMapName != undefined) {
55 var envDiff = g_texMan.loadMaterial(envDiffMapName); 55 var envMap = g_texMan.loadMaterial(envMapName);
56 this.shaderMap[name] = new RDGE.Shader(name, handle, renderProc, initRenderProc, envMap); 56 var envDiff = g_texMan.loadMaterial(envDiffMapName);
57 this.shaderMap[name].envDiff = envDiff; 57 this.shaderMap[name] = new RDGE.Shader(name, handle, renderProc, initRenderProc, envMap);
58 } 58 this.shaderMap[name].envDiff = envDiff;
59 else { 59 }
60 this.shaderMap[name] = new RDGE.Shader(name, handle, renderProc, initRenderProc, null); 60 else {
61 this.shaderMap[name].envDiff = null; 61 this.shaderMap[name] = new RDGE.Shader(name, handle, renderProc, initRenderProc, null);
62 } 62 this.shaderMap[name].envDiff = null;
63 63 }
64 this.shaderMap[name].name = name; 64
65 65 this.shaderMap[name].name = name;
66 return this.shaderMap[name]; 66
67 } 67 return this.shaderMap[name];
68 68 }
69 return shader; 69
70}; 70 return shader;
71 71};
72RDGE.ShaderManager.prototype.getShaderNames = function () { 72
73 var names = []; 73RDGE.ShaderManager.prototype.getShaderNames = function () {
74 for (var index in this.shaderMap) { 74 var names = [];
75 names.push(this.shaderMap[index].name); 75 for (var index in this.shaderMap) {
76 } 76 names.push(this.shaderMap[index].name);
77 77 }
78 return names; 78
79}; 79 return names;
80 80};
81RDGE.ShaderManager.prototype.getShaderByName = function (name) { 81
82 var shader = this.shaderMap[name]; 82RDGE.ShaderManager.prototype.getShaderByName = function (name) {
83 83 var shader = this.shaderMap[name];
84 if (shader != undefined && shader != null) 84
85 return shader; 85 if (shader != undefined && shader != null)
86 86 return shader;
87 return null; 87
88}; 88 return null;
89 89};
90 90
91/** 91
92* Setup shader names 92/**
93**/ 93* Setup shader names
94RDGE.ShaderManager.prototype.init = function () { 94**/
95 // create shaders for each look 95RDGE.ShaderManager.prototype.init = function () {
96 this.addShader("default", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_DullPlastic.png", "material_DullPlastic.png"); 96 // create shaders for each look
97 this.addShader("barlights", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_barlights.png", "material_barlightsDull.png"); 97 this.addShader("default", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_DullPlastic.png", "material_DullPlastic.png");
98 this.addShader("gloss", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_gloss.png", "material_glossDull.png"); 98 this.addShader("barlights", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_barlights.png", "material_barlightsDull.png");
99 this.addShader("inGlass", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_inGlass.png", "material_inGlassDull.png"); 99 this.addShader("gloss", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_gloss.png", "material_glossDull.png");
100 this.addShader("normals", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_normal.png", "material_normalDull.png"); 100 this.addShader("inGlass", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_inGlass.png", "material_inGlassDull.png");
101 this.addShader("paint", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_paint.png", "material_paintDull.png"); 101 this.addShader("normals", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_normal.png", "material_normalDull.png");
102 this.addShader("plastic", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_plastic.png", "material_plasticDull.png"); 102 this.addShader("paint", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_paint.png", "material_paintDull.png");
103 this.addShader("shadows", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_shadows.png", "material_shadowsDull.png"); 103 this.addShader("plastic", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_plastic.png", "material_plasticDull.png");
104 this.addShader("skin", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_skin.png", "material_skinDull.png"); 104 this.addShader("shadows", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_shadows.png", "material_shadowsDull.png");
105 this.addShader("wax", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_wax.png", "material_waxDull.png"); 105 this.addShader("skin", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_skin.png", "material_skinDull.png");
106 106 this.addShader("wax", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_wax.png", "material_waxDull.png");
107 // used by backdrop 107
108 this.addShader("shadowReceiver", shadow_vshader, shadow_fshader, ["vert", "normal", "texcoord"], RDGE.renderProcShadowReceiver, RDGE.renderInitShadowReceiver); 108 // used by backdrop
109 this.addShader("shadowProj", shadowProj_vshader, shadowProj_fshader, ["vert", "normal", "texcoord"], RDGE.renderProcShadowProjection, RDGE.renderInitShadowProjection); 109 this.addShader("shadowReceiver", shadow_vshader, shadow_fshader, ["vert", "normal", "texcoord"], RDGE.renderProcShadowReceiver, RDGE.renderInitShadowReceiver);
110}; 110 this.addShader("shadowProj", shadowProj_vshader, shadowProj_fshader, ["vert", "normal", "texcoord"], RDGE.renderProcShadowProjection, RDGE.renderInitShadowProjection);
111};