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