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