diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/run_state.js')
-rw-r--r-- | js/helper-classes/RDGE/src/core/script/run_state.js | 456 |
1 files changed, 456 insertions, 0 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 new file mode 100644 index 00000000..ad56d9ea --- /dev/null +++ b/js/helper-classes/RDGE/src/core/script/run_state.js | |||
@@ -0,0 +1,456 @@ | |||
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 | |||
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 | |||
34 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
35 | |||
36 | // if(theScene=="Robots_rt") { | ||
37 | // g_enableShadowMapping=false; | ||
38 | // g_showSSAO=false; | ||
39 | // g_Engine.defaultContext.uniforms[1]={ 'name': "u_lightAmb",'value': [0.5,0.5,0.5,1.0] }; | ||
40 | // g_Engine.defaultContext.uniforms[7]={ 'name': "u_matAmbient",'value': [0.8,0.8,0.8,1] }; | ||
41 | // } | ||
42 | |||
43 | |||
44 | // g_hrDepthMapGenShader=createShader(this.renderer.ctx,'depthMap_vshader','depthMap_fshader',["vert","normal"]); | ||
45 | // g_depthMapGenShader=createShader(this.renderer.ctx,'norm_depth_vshader','norm_depth_fshader',["vert","normal"]); | ||
46 | |||
47 | // // shadow light | ||
48 | // g_mainLight=new camera(); // camera to represent our light's point of view | ||
49 | // g_mainLight.setPerspective(45.0,width/height,1.0,200.0); | ||
50 | // g_mainLight.setLookAt([-60,17,-15],[-5,-5,15],vec3.up()); // lights position and point of view | ||
51 | // g_mainLight.mvMatrix=mat4.copy(g_mainLight.view); // hold model view transform | ||
52 | // g_mainLight.invViewMatrix=mat4.inverse(g_mainLight.view); | ||
53 | // g_mainLight.mvpMatrix=mat4.identity(); | ||
54 | // g_mainLight.shadowMatrix=mat4.identity(); // shadow matrix creates shadow bias | ||
55 | // g_mainLight.shadowMatrix=mat4.scale(g_mainLight.shadowMatrix,[0.5,0.5,0.5]); | ||
56 | // g_mainLight.shadowMatrix=mat4.translate(g_mainLight.shadowMatrix,[0.5,0.5,0.5]); | ||
57 | // //g_cameraManager.setActiveCamera( g_mainLight ); | ||
58 | // | ||
59 | // uniformEnableGlow = this.renderer.ctx.getUniformLocation(g_Engine.defaultContext.shaderProg, "u_renderGlow"); | ||
60 | // | ||
61 | // depthRTT=createRenderTargetTexture(1024,1024); | ||
62 | // glowRTT=createRenderTargetTexture(512,512); | ||
63 | // blurFX=new fxBlur([256,128,64],true); | ||
64 | // mainRTT=createRenderTargetTexture(1024,1024); | ||
65 | // ssaoFX=new fxSSAO(true); | ||
66 | // ssaoRTT=createRenderTargetTexture(1024,1024); | ||
67 | // depthRTT=createRenderTargetTexture(1024,1024); | ||
68 | // hrDepthRTT=createRenderTargetTexture(1024,1024); | ||
69 | // hrDepthRTTSSAO=createRenderTargetTexture(1024,1024); | ||
70 | // mainSceneQuad=new ScreenQuad(mainRTT); | ||
71 | // mainSceneQuad.initialize(renderInitScreenQuad); | ||
72 | |||
73 | // cubelight_Glow = this.renderer.createTexture("assets/images/cubelight_Glow.png"); | ||
74 | // lightRack_Glow = this.renderer.createTexture("assets/images/lightRack_Glow.png"); | ||
75 | // black = this.renderer.createTexture("assets/images/black.png"); | ||
76 | |||
77 | // renderGlow=false; | ||
78 | |||
79 | // // depth map and normal proc | ||
80 | // renderProcDepth=new GenerateDepthMap(); | ||
81 | // renderProcGlow=new GenerateGlowMap(); | ||
82 | // renderProc=new SceneRender(); | ||
83 | // renderProcCreateShadowMap=new SceneCreateShadowMap(); | ||
84 | // renderProcHighResDepth=new GenerateHighResDepthMap(); | ||
85 | |||
86 | // g_Engine.defaultContext.textureList.push({ 'handle': hrDepthRTT,'unit': 7,'type': UNIFORMTYPE.TEXTURE2D }); | ||
87 | // g_Engine.defaultContext.uniforms.push({ 'name': "depthMap",'value': [hrDepthRTT] }); | ||
88 | |||
89 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
90 | } | ||
91 | |||
92 | RunState.prototype.ReInit = function() | ||
93 | { | ||
94 | if(!this.initialized) | ||
95 | { | ||
96 | this.Init(); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | RunState.prototype.Update = function(dt) | ||
101 | { | ||
102 | this.userRunState.update(dt); | ||
103 | } | ||
104 | |||
105 | RunState.prototype.Resize = function() | ||
106 | { | ||
107 | if(g_Engine.lastWindowWidth == window.innerWidth && g_Engine.lastWindowHeight == window.innerHeight) | ||
108 | { | ||
109 | this.userRunState.resize(); | ||
110 | g_Engine.lastWindowWidth = window.innerWidth; | ||
111 | g_Engine.lastWindowHeight = window.innerHeight; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | RunState.prototype.Draw = function () | ||
116 | { | ||
117 | var width = this.renderer.vpWidth; | ||
118 | var height = this.renderer.vpHeight; | ||
119 | |||
120 | this.renderer._clear(); | ||
121 | |||
122 | this.userRunState.draw(); | ||
123 | |||
124 | // ~~~~ removing post process till multi-context and post process system is in place | ||
125 | // if(this.currentScene==null) | ||
126 | // return; | ||
127 | |||
128 | // this.renderer.setClearColor([1.0,1.0,1.0,1.0]); | ||
129 | |||
130 | // // post process will eventually be wrapped in | ||
131 | // this.renderer.ctx.bindFramebuffer(renderer.ctx.FRAMEBUFFER, depthRTT.frameBuffer); | ||
132 | // this.renderer.setViewPort(0,0,1024,1024); | ||
133 | // this.renderer.clear(this.renderer.colorBuffer | this.renderer.depthBuffer); | ||
134 | // this.currentScene.render(renderProcDepth); | ||
135 | |||
136 | // this.renderer.ctx.bindFramebuffer(this.renderer.ctx.FRAMEBUFFER,hrDepthRTTSSAO.frameBuffer); | ||
137 | // this.renderer.setViewPort(0, 0, 1024, 1024); | ||
138 | // this.renderer.clear( this.renderer.colorBuffer | this.renderer.depthBuffer ); | ||
139 | // renderProcHighResDepth.cullFront=false; | ||
140 | // this.currentScene.render(renderProcHighResDepth); | ||
141 | |||
142 | // if(g_enableShadowMapping) | ||
143 | // { | ||
144 | // this.renderer.cameraManager().pushCamera(g_mainLight); | ||
145 | |||
146 | // this.renderer.ctx.bindFramebuffer( this.renderer.ctx.FRAMEBUFFER, hrDepthRTT.frameBuffer ); | ||
147 | // this.renderer.setViewPort(0, 0, 1024, 1024); | ||
148 | // this.renderer.clear( this.renderer.colorBuffer | this.renderer.depthBuffer ); | ||
149 | // renderProcHighResDepth.cullFront=true; | ||
150 | // this.currentScene.render(renderProcHighResDepth); | ||
151 | |||
152 | // this.renderer.cameraManager().popCamera(); | ||
153 | // } | ||
154 | |||
155 | // this.renderer.ctx.bindFramebuffer(this.renderer.ctx.FRAMEBUFFER, mainRTT.frameBuffer); | ||
156 | // this.renderer.setViewPort(0,0,1024,1024); | ||
157 | |||
158 | // if(g_showScene) | ||
159 | // { | ||
160 | // this.renderer.clear( this.renderer.colorBuffer | this.renderer.depthBuffer ); | ||
161 | // this.currentScene.render(renderProc); | ||
162 | // } else | ||
163 | // { | ||
164 | // this.renderer.clear( this.renderer.ctx.colorBuffer | this.renderer.ctx.depthBuffer ); | ||
165 | // } | ||
166 | |||
167 | // if(g_showSSAO) | ||
168 | // { | ||
169 | // ssaoFX.doSSAO(mainRTT, depthRTT, hrDepthRTTSSAO, ssaoRTT, g_sampleRadius, g_intensity, g_distScale, g_bias); | ||
170 | // } | ||
171 | |||
172 | // if(g_showBloom) { | ||
173 | // // render glow map | ||
174 | // this.renderer.ctx.bindFramebuffer(this.renderer.ctx.FRAMEBUFFER,glowRTT.frameBuffer); | ||
175 | // this.renderer.setViewPort(0,0,512,512); | ||
176 | // this.renderer.clear( this.renderer.colorBuffer | this.renderer.depthBuffer ); | ||
177 | // this.currentScene.render(renderProcGlow); | ||
178 | |||
179 | // // Combine | ||
180 | // blurFX.doBlur(glowRTT,null,[g_bloomIntensity1,g_bloomIntensity2,g_bloomIntensity3,g_bloomIntensity4],g_showSSAO?ssaoRTT:mainRTT); | ||
181 | // } | ||
182 | // else if(g_showScene||g_showSSAO) | ||
183 | // { | ||
184 | // this.renderer.bindFramebuffer(this.renderer.ctx.FRAMEBUFFER,null); | ||
185 | // this.renderer.setViewPort(0, 0, width, height); | ||
186 | // this.renderer.clear( this.renderer.colorBuffer | this.renderer.depthBuffer ); | ||
187 | |||
188 | // mainSceneQuad.texture=g_showSSAO?ssaoRTT:mainRTT; | ||
189 | // renderProcScreenQuad(mainSceneQuad); | ||
190 | // } | ||
191 | // else | ||
192 | // { | ||
193 | // this.renderer.clear( this.renderer.colorBuffer | this.renderer.depthBuffer ); | ||
194 | // } | ||
195 | |||
196 | |||
197 | } | ||
198 | |||
199 | RunState.prototype.Shutdown = function() | ||
200 | { | ||
201 | if(this.userRunState.shutdown != undefined) | ||
202 | { | ||
203 | this.userRunState.shutdown(); | ||
204 | } | ||
205 | } | ||
206 | |||
207 | RunState.prototype.LeaveState = function() | ||
208 | { | ||
209 | if(this.userRunState.onComplete != undefined) | ||
< |