diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/run_state.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/run_state.js | 711 |
1 files changed, 308 insertions, 403 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/run_state.js b/js/helper-classes/RDGE/src/core/script/run_state.js index acdb6797..7f08bd6c 100755 --- a/js/helper-classes/RDGE/src/core/script/run_state.js +++ b/js/helper-classes/RDGE/src/core/script/run_state.js | |||
@@ -4,461 +4,366 @@ 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 | var RDGE = RDGE || {}; | ||
8 | |||
9 | RDGE.RunState = function (userRunState, context) { | ||
10 | this.name = "RunState"; | ||
11 | this.userRunState = userRunState != undefined ? userRunState : new RDGE.core.RDGEState; | ||
12 | this.hasUserState = userRunState != undefined ? true : false; | ||
13 | this.renderer = context.renderer; | ||
14 | this.initialized = false; | ||
15 | }; | ||
16 | |||
17 | RDGE.RunState.prototype.Init = function () { | ||
18 | this.initialized = true; | ||
19 | var width = this.renderer.vpWidth; | ||
20 | var height = this.renderer.vpHeight; | ||
21 | var cam = new RDGE.camera(); | ||
22 | cam.setPerspective(45.0, width / height, 1.0, 100.0); | ||
23 | cam.setLookAt([0, 0, 20], [0, 0, 0], RDGE.vec3.up()); | ||
24 | |||
25 | this.renderer.cameraManager().setActiveCamera(cam); | ||
26 | |||
27 | if (this.hasUserState && this.userRunState.init != undefined) { | ||
28 | this.userRunState.init(); | ||
29 | } | ||
30 | |||
31 | if (this.hasUserState && this.userRunState && this.userRunState.onRunState) | ||
32 | this.userRunState.onRunState(); | ||
33 | |||
34 | |||
35 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
36 | |||
37 | // if(theScene=="Robots_rt") { | ||
38 | // g_enableShadowMapping=false; | ||
39 | // g_showSSAO=false; | ||
40 | // RDGE.globals.engine.defaultContext.uniforms[1]={ 'name': "u_lightAmb",'value': [0.5,0.5,0.5,1.0] }; | ||
41 | // RDGE.globals.engine.defaultContext.uniforms[7]={ 'name': "u_matAmbient",'value': [0.8,0.8,0.8,1] }; | ||
42 | // } | ||
43 | |||
44 | |||
45 | // g_hrDepthMapGenShader=createShader(this.renderer.ctx,'depthMap_vshader','depthMap_fshader',["vert","normal"]); | ||
46 | // g_depthMapGenShader=createShader(this.renderer.ctx,'norm_depth_vshader','norm_depth_fshader',["vert","normal"]); | ||
47 | |||
48 | // // shadow light | ||
49 | // g_mainLight=new RDGE.camera(); // camera to represent our light's point of view | ||
50 | // g_mainLight.setPerspective(45.0,width/height,1.0,200.0); | ||
51 | // g_mainLight.setLookAt([-60,17,-15],[-5,-5,15],RDGE.vec3.up()); // lights position and point of view | ||
52 | // g_mainLight.mvMatrix=RDGE.mat4.copy(g_mainLight.view); // hold model view transform | ||
53 | // g_mainLight.invViewMatrix=RDGE.mat4.inverse(g_mainLight.view); | ||
54 | // g_mainLight.mvpMatrix=RDGE.mat4.identity(); | ||
55 | // g_mainLight.shadowMatrix=RDGE.mat4.identity(); // shadow matrix creates shadow bias | ||
56 | // g_mainLight.shadowMatrix=RDGE.mat4.scale(g_mainLight.shadowMatrix,[0.5,0.5,0.5]); | ||
57 | // g_mainLight.shadowMatrix=RDGE.mat4.translate(g_mainLight.shadowMatrix,[0.5,0.5,0.5]); | ||
58 | // //g_cameraManager.setActiveCamera( g_mainLight ); | ||
59 | // | ||
60 | // uniformEnableGlow = this.renderer.ctx.getUniformLocation(RDGE.globals.engine.defaultContext.shaderProg, "u_renderGlow"); | ||
61 | // | ||
62 | // depthRTT=createRenderTargetTexture(1024,1024); | ||
63 | // glowRTT=createRenderTargetTexture(512,512); | ||
64 | // blurFX=new RDGE.fx.fxBlur([256,128,64],true); | ||
65 | // mainRTT=createRenderTargetTexture(1024,1024); | ||
66 | // ssaoFX=new RDGE.fx.fxSSAO(true); | ||
67 | // ssaoRTT=createRenderTargetTexture(1024,1024); | ||
68 | // depthRTT=createRenderTargetTexture(1024,1024); | ||
69 | // hrDepthRTT=createRenderTargetTexture(1024,1024); | ||
70 | // hrDepthRTTSSAO=createRenderTargetTexture(1024,1024); | ||
71 | // mainSceneQuad=new RDGE.ScreenQuad(mainRTT); | ||
72 | // mainSceneQuad.initialize(RDGE.renderInitScreenQuad); | ||
73 | |||
74 | // cubelight_Glow = this.renderer.createTexture("assets/images/cubelight_Glow.png"); | ||
75 | // lightRack_Glow = this.renderer.createTexture("assets/images/lightRack_Glow.png"); | ||
76 | // black = this.renderer.createTexture("assets/images/black.png"); | ||
77 | |||
78 | // renderGlow=false; | ||
79 | |||
80 | // // depth map and normal proc | ||
81 | // renderProcDepth=new GenerateDepthMap(); | ||
82 | // renderProcGlow=new GenerateGlowMap(); | ||
83 | // renderProc=new RDGE.SceneRender(); | ||
84 | // renderProcCreateShadowMap=new SceneCreateShadowMap(); | ||
85 | // renderProcHighResDepth=new GenerateHighResDepthMap(); | ||
86 | |||
87 | // RDGE.globals.engine.defaultContext.textureList.push({ 'handle': hrDepthRTT,'unit': 7,'type': RDGE.UNIFORMTYPE.TEXTURE2D }); | ||
88 | // RDGE.globals.engine.defaultContext.uniforms.push({ 'name': "depthMap",'value': [hrDepthRTT] }); | ||
7 | 89 | ||
8 | function RunState(userRunState, context) | ||
9 | { | ||
10 | this.name = "RunState"; | ||
11 | this.userRunState = userRunState != undefined ? userRunState : new RDGEState; | ||
12 | this.hasUserState = userRunState != undefined ? true : false; | ||
13 | this.renderer = context.renderer; | ||
14 | this.initialized = false; | ||
15 | } | ||
16 | |||
17 | RunState.prototype.Init = function() | ||
18 | { | ||
19 | this.initialized = true; | ||
20 | var width = this.renderer.vpWidth; | ||
21 | var height = this.renderer.vpHeight; | ||
22 | var cam = new camera(); | ||
23 | cam.setPerspective(45.0, width / height, 1.0, 100.0); | ||
24 | cam.setLookAt([0, 0, 20], [0, 0, 0], vec3.up()); | ||
25 | |||
26 | this.renderer.cameraManager().setActiveCamera( cam ); | ||
27 | |||
28 | if(this.hasUserState && this.userRunState.init != undefined) | ||
29 | { | ||
30 | this.userRunState.init(); | ||
31 | } | ||
32 | |||
33 | if (this.hasUserState && this.userRunState && this.userRunState.onRunState) | ||
34 | this.userRunState.onRunState(); | ||
35 | |||
36 | |||
37 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
38 | |||
39 | // if(theScene=="Robots_rt") { | ||
40 | // g_enableShadowMapping=false; | ||
41 | // g_showSSAO=false; | ||
42 | // g_Engine.defaultContext.uniforms[1]={ 'name': "u_lightAmb",'value': [0.5,0.5,0.5,1.0] }; | ||
43 | // g_Engine.defaultContext.uniforms[7]={ 'name': "u_matAmbient",'value': [0.8,0.8,0.8,1] }; | ||
44 | // } | ||
45 | |||
46 | |||
47 | // g_hrDepthMapGenShader=createShader(this.renderer.ctx,'depthMap_vshader','depthMap_fshader',["vert","normal"]); | ||
48 | // g_depthMapGenShader=createShader(this.renderer.ctx,'norm_depth_vshader','norm_depth_fshader',["vert","normal"]); | ||
49 | |||
50 | // // shadow light | ||
51 | // g_mainLight=new camera(); // camera to represent our light's point of view | ||
52 | // g_mainLight.setPerspective(45.0,width/height,1.0,200.0); | ||
53 | // g_mainLight.setLookAt([-60,17,-15],[-5,-5,15],vec3.up()); // lights position and point of view | ||
54 | // g_mainLight.mvMatrix=mat4.copy(g_mainLight.view); // hold model view transform | ||
55 | // g_mainLight.invViewMatrix=mat4.inverse(g_mainLight.view); | ||
56 | // g_mainLight.mvpMatrix=mat4.identity(); | ||
57 | // g_mainLight.shadowMatrix=mat4.identity(); // shadow matrix creates shadow bias | ||
58 | // g_mainLight.shadowMatrix=mat4.scale(g_mainLight.shadowMatrix,[0.5,0.5,0.5]); | ||
59 | // g_mainLight.shadowMatrix=mat4.translate(g_mainLight.shadowMatrix,[0.5,0.5,0.5]); | ||
60 | // //g_cameraManager.setActiveCamera( g_mainLight ); | ||
61 | // | ||
62 | // uniformEnableGlow = this.renderer.ctx.getUniformLocation(g_Engine.defaultContext.shaderProg, "u_renderGlow"); | ||
63 | // | ||
64 | // depthRTT=createRenderTargetTexture(1024,1024); | ||
65 | // glowRTT=createRenderTargetTexture(512,512); | ||
66 | // blurFX=new fxBlur([256,128,64],true); | ||
67 | // mainRTT=createRenderTargetTexture(1024,1024); | ||
68 | // ssaoFX=new fxSSAO(true); | ||
69 | // ssaoRTT=createRenderTargetTexture(1024,1024); | ||
70 | // depthRTT=createRenderTargetTexture(1024,1024); | ||
71 | // hrDepthRTT=createRenderTargetTexture(1024,1024); | ||
72 | // hrDepthRTTSSAO=createRenderTargetTexture(1024,1024); | ||
73 | // mainSceneQuad=new ScreenQuad(mainRTT); | ||
74 | // mainSceneQuad.initialize(renderInitScreenQuad); | ||
75 | |||
76 | // cubelight_Glow = this.renderer.createTexture("assets/images/cubelight_Glow.png"); | ||
77 | // lightRack_Glow = this.renderer.createTexture("assets/images/lightRack_Glow.png"); | ||
78 | // black = this.renderer.createTexture("assets/images/black.png"); | ||
79 | |||
80 | // renderGlow=false; | ||
81 | |||
82 | // // depth map and normal proc | ||
83 | // renderProcDepth=new GenerateDepthMap(); | ||
84 | // renderProcGlow=new GenerateGlowMap(); | ||
85 | // renderProc=new SceneRender(); | ||
86 | // renderProcCreateShadowMap=new SceneCreateShadowMap(); | ||
87 | // renderProcHighResDepth=new GenerateHighResDepthMap(); | ||
88 | |||
89 | // g_Engine.defaultContext.textureList.push({ 'handle': hrDepthRTT,'unit': 7,'type': UNIFORMTYPE.TEXTURE2D }); | ||
90 | // g_Engine.defaultContext.uniforms.push({ 'name': "depthMap",'value': [hrDepthRTT] }); | ||
91 | |||
92 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 90 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
93 | } | 91 | }; |
94 | 92 | ||
95 | RunState.prototype.ReInit = function() | 93 | RDGE.RunState.prototype.ReInit = function () { |
96 | { | 94 | if (!this.initialized) { |
97 | if(!this.initialized) | 95 | this.Init(); |
98 | { | 96 | } |
99 | this.Init(); | 97 | else { |
100 | } | 98 | if (this.hasUserState && this.userRunState && this.userRunState.onRunState) |
101 | else | 99 | this.userRunState.onRunState(); |
102 | { | 100 | } |
103 | if (this.hasUserState && this.userRunState && this.userRunState.onRunState) | 101 | }; |
104 | this.userRunState.onRunState(); | 102 | |
105 | } | 103 | RDGE.RunState.prototype.Update = function (dt) { |
106 | } | ||
107 | |||
108 | RunState.prototype.Update = function(dt) | ||
109 | { | ||
110 | this.userRunState.update(dt); | 104 | this.userRunState.update(dt); |
111 | } | 105 | }; |
112 | 106 | ||
113 | RunState.prototype.Resize = function() | 107 | RDGE.RunState.prototype.Resize = function () { |
114 | { | 108 | if (RDGE.globals.engine.lastWindowWidth == window.innerWidth && RDGE.globals.engine.lastWindowHeight == window.innerHeight) { |
115 | if(g_Eng |