aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/jpass.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/helper-classes/RDGE/src/core/script/jpass.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/jpass.js')
-rw-r--r--js/helper-classes/RDGE/src/core/script/jpass.js710
1 files changed, 710 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/jpass.js b/js/helper-classes/RDGE/src/core/script/jpass.js
new file mode 100644
index 00000000..326394dc
--- /dev/null
+++ b/js/helper-classes/RDGE/src/core/script/jpass.js
@@ -0,0 +1,710 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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 * jpass geometry set - determines the category(s) of geometry that a pass will render
9 * can be OR'ed together
10 */
11jpassGeoSet =
12{
13 'BACKGROUND' :1,
14 'OPAQUE' :2,
15 'TRANSPARENT' :4,
16 'ADDITIVE' :8,
17 'TRANSLUCENT' :16,
18 'FOREGROUND' :32,
19 'ALL' :127,
20 'SCREEN_QUAD' :128, // a screen aligned quad - for rendering a texture to screen
21 'SHADOW' :256, // the opaque geometry from shadow light's point of view
22 'MAXSETS' :9
23};
24
25
26/*
27 * The abstract base class that defines a jpass
28 * a jpass represents a single render pass of the scene graph
29 */
30_jpassBaseClass = function() {
31 this.context = g_Engine.getContext();
32 this.renderer = g_Engine.getContext().renderer;
33 this.sortCats = rdgeConstants.categoryEnumeration;
34 this.bucketCount = rdgeConstants.categoryEnumeration.MAX_CAT;
35
36 // render order
37 this.renderOrder = [];
38 this.renderOrder[this.sortCats.BACKGROUND] = 0;
39 this.renderOrder[this.sortCats.OPAQUE] = 1;
40 this.renderOrder[this.sortCats.TRANSPARENT] = 2;
41 this.renderOrder[this.sortCats.ADDITIVE] = 3
42 this.renderOrder[this.sortCats.TRANSLUCENT] = 4;
43 this.renderOrder[this.sortCats.FOREGROUND] = 5;
44
45 // the name of this pass
46 this.name = "renderPass_" + nodeIdGen.getId();
47
48 /*
49 * if 0 this pass and children are culled from rendering
50 */
51 this.visibility = 1;
52
53 /*
54 * called when the pass is hidden - override for customication
55 */
56 this.onHide = function() {
57
58 }
59
60 /*
61 * Called by the system to hide the pass and its children
62 */
63 this.hidePass = function() {
64 this.onHide();
65
66 for (var i = 0, len = this.children.length; i < len; ++i) {
67 this.children[i].hidePass();
68 }
69 }
70
71 /*
72 * the default output render targets that this pass will create
73 */
74 this.defaultTargetOut = {};
75
76 /*
77 * All the outputs required by the pass
78 */
79 this.outputs =
80 [
81 // example
82 // {'name':"u_mainRT", 'type':"target", 'width':1024, 'height':1024, 'mips':false}
83 ];
84
85 /*
86 * notifies the the renderer that the viewport was modified and needs to be reset
87 */
88 this.dirty = false;
89
90 /*
91 * Index of the currently selected output target
92 */
93 this.outputIndex = 0;
94
95 /*
96 * outputs from the previous pass are set as inputs for this pass
97 */
98 this.inputs =
99 [
100 ];
101
102 /*
103 * other textures requested for this pass
104 */
105 this.textures =
106 [
107
108 ];
109
110 /*
111 * the flags that control how the pass is rendered
112 */
113 this.frustum_culling = "enable"; // disable/enable frustum culling during the pass
114 this.clear = null; // flags to clear the output target with before rendering
115 this.clearColor = null;
116
117 /*
118 * Contains a list of geometry to be rendered, during a post process render pass this will usually by a screen quad
119 */
120 this.renderList =
121 [
122 // example
123 // { 'name':'opaqeobjects', 'geo'{ 'OPAQUE':[ new renderObject(meshNode, transformNode, RenderContext)]} }
124 ];
125
126 /*
127 * The passes that will render after this pass
128 */
129 this.children = [];
130
131 /*
132 * This shader will override all other shaders
133 */
134 this.shader = null;
135
136 /*
137 * Technique of from shader to use, if null currently set technique is used
138 */
139 this.technique = null;
140
141 /*
142 * determines the geometry that will be rendered during the pass
143 */
144 this.geometrySet = "SCREEN_QUAD";
145
146
147 /*
148 * A camera set here will override any camera active in the scene
149 */
150 this.camera = null;
151
152 /*
153 * Initialize the pass
154 */
155 this.init = function() {
156
157 }
158
159 /*
160 * inserts a node into the child map using the pass name as the key
161 */
162 this.insertChildPass = function(jpassObj) {
163 this.children[jpassObj.name] = jpassObj;
164 }
165
166 /*
167 * the scene-graph to process
168 */
169 this.process = function() {
170 // pre-defined local variables to prevent allocation
171 var context;
172 var shaderProg;
173 var listCount;
174 var len;
175 var passes;
176 var pass;
177 var node;
178 var mesh;
179 var meshCount;
180 var nodeIdx = 0;
181 var meshIdx = 0;
182 var paramIdx = 0;
183 var passIdx = 0;
184
185 var renderer = g_Engine.getContext().renderer;
186
187 //this.renderer = g_Engine.getContext().renderer;
188
189 // bind output target for rendering
190 this.bindOutput();
191
192 // call custom pre-render step
193 this.preRender();
194
195 var activeCam = renderer.cameraManager().getActiveCamera();
196
197 if (this.technique) {
198 this.shader.setTechnique(this.technique);
199 }
200
201 renderer.projectionMatrix = activeCam.proj;
202
203 // parameters that can be set once per pass
204 rdgeGlobalParameters.u_inv_viewport_width.set([1.0 / renderer.vpWidth]);
205 rdgeGlobalParameters.u_inv_viewport_height.set([1.0 / renderer.vpHeight]);
206 rdgeGlobalParameters.u_farZ.set([activeCam.zFar()]);
207 rdgeGlobalParameters.u_projMatrix.set(renderer.projectionMatrix);
208
209 for (var bucketIdx = 0, bckCnt = this.renderList.length; bucketIdx < bckCnt; ++bucketIdx) {
210 //var curList = this.renderList[bucketIdx];
211 listCount = this.renderList[bucketIdx].length;
212
213 for (nodeIdx = 0; nodeIdx < listCount; ++nodeIdx) {
214 node = this.renderList[bucketIdx][nodeIdx].node;
215
216 if (node.world) {
217 context = this.renderList[bucketIdx][nodeIdx].context;
218 shaderProg = this.shader ? this.shader : context.shaderProg;
219
220 renderer.mvMatrix = mat4.mul4x3(node.world, activeCam.view);