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 | 124 |
1 files changed, 57 insertions, 67 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/ShaderManager.js b/js/helper-classes/RDGE/src/core/script/ShaderManager.js index f253d3c7..c5ee0c3f 100755 --- a/js/helper-classes/RDGE/src/core/script/ShaderManager.js +++ b/js/helper-classes/RDGE/src/core/script/ShaderManager.js | |||
@@ -4,93 +4,83 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | function Shader(name, shaderHandle, renderProc, initRenderProc, envMap) | 7 | // RDGE namespaces |
8 | { | 8 | var RDGE = RDGE || {}; |
9 | this.name = name; | 9 | |
10 | this.shaderHandle = shaderHandle; | 10 | RDGE.Shader = function (name, shaderHandle, renderProc, initRenderProc, envMap) { |
11 | this.name = name; | ||
12 | this.shaderHandle = shaderHandle; | ||
11 | this.initRenderProc = initRenderProc; | 13 | this.initRenderProc = initRenderProc; |
12 | this.renderProc = renderProc; | 14 | this.renderProc = renderProc; |
13 | this.postRenderProc = postRenderProcDefault; | 15 | this.postRenderProc = RDGE.postRenderProcDefault; |
14 | this.envMap = envMap; | 16 | this.envMap = envMap; |
15 | this.envDiff = envMap; | 17 | this.envDiff = envMap; |
16 | } | 18 | }; |
17 | 19 | ||
18 | function ShaderManager() | 20 | RDGE.ShaderManager = function () { |
19 | { | ||
20 | this.shaderMap = []; | 21 | this.shaderMap = []; |
21 | } | 22 | }; |
22 | 23 | ||
23 | ShaderManager.prototype.addShader = function(name, vShader, fShader, attribs, renderProc, initRenderProc, envMapName, envDiffMapName) | 24 | RDGE.ShaderManager.prototype.addShader = function (name, vShader, fShader, attribs, renderProc, initRenderProc, envMapName, envDiffMapName) { |
24 | { | ||
25 | var shader = this.shaderMap[name]; | 25 | var shader = this.shaderMap[name]; |
26 | if(shader == undefined) | 26 | if (shader == undefined) { |
27 | { | 27 | |
28 | 28 | var handle = RDGE.createShader(RDGE.globals.engine.getContext().renderer.ctx, vShader, fShader, attribs); | |
29 | var handle = createShader(g_Engine.getContext().renderer.ctx, vShader, fShader, attribs); | 29 | if (envMapName != undefined || envDiffMapName != undefined) { |
30 | if (envMapName != undefined || envDiffMapName != undefined) | 30 | var envMap = g_texMan.loadMaterial(envMapName); |
31 | { | 31 | var envDiff = g_texMan.loadMaterial(envDiffMapName); |
32 | var envMap = g_texMan.loadMaterial(envMapName); | 32 | this.shaderMap[name] = new RDGE.Shader(name, handle, renderProc, initRenderProc, envMap); |
33 | var envDiff = g_texMan.loadMaterial(envDiffMapName); | 33 | this.shaderMap[name].envDiff = envDiff; |
34 | this.shaderMap[name] = new Shader(name, handle, renderProc, initRenderProc, envMap); | 34 | } |
35 | this.shaderMap[name].envDiff = envDiff; | 35 | else { |
36 | } | 36 | this.shaderMap[name] = new RDGE.Shader(name, handle, renderProc, initRenderProc, null); |
37 | else | 37 | this.shaderMap[name].envDiff = null; |
38 | { | 38 | } |
39 | this.shaderMap[name] = new Shader(name, handle, renderProc, initRenderProc, null); | 39 | |
40 | this.shaderMap[name].envDiff = null; | 40 | this.shaderMap[name].name = name; |
41 | } | 41 | |
42 | |||
43 | this.shaderMap[name].name = name; | ||
44 | |||
45 | return this.shaderMap[name]; | 42 | return this.shaderMap[name]; |
46 | } | 43 | } |
47 | 44 | ||
48 | return shader; | 45 | return shader; |
49 | } | 46 | }; |
50 | 47 | ||
51 | ShaderManager.prototype.getShaderNames = function() | 48 | RDGE.ShaderManager.prototype.getShaderNames = function () { |
52 | { | ||
53 | var names = []; | 49 | var names = []; |
54 | for(var index in this.shaderMap) | 50 | for (var index in this.shaderMap) { |
55 | { | ||
56 | names.push(this.shaderMap[index].name); | 51 | names.push(this.shaderMap[index].name); |
57 | } | 52 | } |
58 | 53 | ||
59 | return names; | 54 | return names; |
60 | } | 55 | }; |
61 | 56 | ||
62 | ShaderManager.prototype.getShaderByName = function(name) | 57 | RDGE.ShaderManager.prototype.getShaderByName = function (name) { |
63 | { | ||
64 | var shader = this.shaderMap[name]; | 58 | var shader = this.shaderMap[name]; |
65 | 59 | ||
66 | if(shader != undefined && shader != null) | 60 | if (shader != undefined && shader != null) |
67 | return shader; | 61 | return shader; |
68 | 62 | ||
69 | // gl.console.log("No shader by the name of: \"" + name + "\""); | ||
70 | |||
71 | return null; | 63 | return null; |
72 | } | 64 | }; |
73 | 65 | ||
74 | 66 | ||
75 | /** | 67 | /** |
76 | * Setup shader names | 68 | * Setup shader names |
77 | **/ | 69 | **/ |
78 | ShaderManager.prototype.init = function() | 70 | RDGE.ShaderManager.prototype.init = function () { |
79 | { | ||
80 | // create shaders for each look | 71 | // create shaders for each look |
81 | this.addShader( "default", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_DullPlastic.png", "material_DullPlastic.png" ); | 72 | this.addShader("default", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_DullPlastic.png", "material_DullPlastic.png"); |
82 | this.addShader( "barlights",vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_barlights.png", "material_barlightsDull.png"); | 73 | this.addShader("barlights", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_barlights.png", "material_barlightsDull.png"); |
83 | this.addShader( "gloss", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_gloss.png", "material_glossDull.png" ); | 74 | this.addShader("gloss", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_gloss.png", "material_glossDull.png"); |
84 | this.addShader( "inGlass", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_inGlass.png", "material_inGlassDull.png"); | 75 | this.addShader("inGlass", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_inGlass.png", "material_inGlassDull.png"); |
85 | this.addShader( "normals", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_normal.png", "material_normalDull.png" ); | 76 | this.addShader("normals", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_normal.png", "material_normalDull.png"); |
86 | this.addShader( "paint", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_paint.png", "material_paintDull.png" ); | 77 | this.addShader("paint", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_paint.png", "material_paintDull.png"); |
87 | this.addShader( "plastic", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_plastic.png", "material_plasticDull.png" ); | 78 | this.addShader("plastic", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_plastic.png", "material_plasticDull.png"); |
88 | this.addShader( "shadows", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_shadows.png", "material_shadowsDull.png" ); | 79 | this.addShader("shadows", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_shadows.png", "material_shadowsDull.png"); |
89 | this.addShader( "skin", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_skin.png", "material_skinDull.png" ); | 80 | this.addShader("skin", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_skin.png", "material_skinDull.png"); |
90 | this.addShader( "wax", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], renderProcDefault, renderInitProcDefault, "material_wax.png", "material_waxDull.png" ); | 81 | this.addShader("wax", vortexVShader, vortexFShader, ["vert", "normal", "texcoord"], RDGE.renderProcDefault, RDGE.renderInitProcDefault, "material_wax.png", "material_waxDull.png"); |
91 | 82 | ||
92 | // used by backdrop | 83 | // used by backdrop |
93 | this.addShader("shadowReceiver",shadow_vshader, shadow_fshader, ["vert", "normal", "texcoord"], renderProcShadowReceiver, renderInitShadowReceiver); | 84 | this.addShader("shadowReceiver", shadow_vshader, shadow_fshader, ["vert", "normal", "texcoord"], RDGE.renderProcShadowReceiver, RDGE.renderInitShadowReceiver); |
94 | this.addShader("shadowProj", shadowProj_vshader, shadowProj_fshader, [ "vert", "normal", "texcoord"], renderProcShadowProjection, renderInitShadowProjection); | 85 | this.addShader("shadowProj", shadowProj_vshader, shadowProj_fshader, ["vert", "normal", "texcoord"], RDGE.renderProcShadowProjection, RDGE.renderInitShadowProjection); |
95 | 86 | }; | |
96 | } | ||