diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/ShaderManager.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/ShaderManager.js | 220 |
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> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | BSD License. |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 7 | modification, 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 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | 30 | ||
31 | // RDGE namespaces | 31 | // RDGE namespaces |
32 | var RDGE = RDGE || {}; | 32 | var RDGE = RDGE || {}; |
33 | 33 | ||
34 | RDGE.Shader = function (name, shaderHandle, renderProc, initRenderProc, envMap) { | 34 | RDGE.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 | ||
44 | RDGE.ShaderManager = function () { | 44 | RDGE.ShaderManager = function () { |
45 | this.shaderMap = []; | 45 | this.shaderMap = []; |
46 | }; | 46 | }; |
47 | 47 | ||
48 | RDGE.ShaderManager.prototype.addShader = function (name, vShader, fShader, attribs, renderProc, initRenderProc, envMapName, envDiffMapName) { | 48 | RDGE.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 | ||
72 | RDGE.ShaderManager.prototype.getShaderNames = function () { | 72 | RDGE.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 | ||
81 | RDGE.ShaderManager.prototype.getShaderByName = function (name) { | 81 | RDGE.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 | **/ |
94 | RDGE.ShaderManager.prototype.init = function () { | 94 | RDGE.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 | }; |