diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/helper-classes/RDGE/src/core/script/renderer.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-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/renderer.js')
-rw-r--r-- | js/helper-classes/RDGE/src/core/script/renderer.js | 1696 |
1 files changed, 1696 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/renderer.js b/js/helper-classes/RDGE/src/core/script/renderer.js new file mode 100644 index 00000000..0c51d2cb --- /dev/null +++ b/js/helper-classes/RDGE/src/core/script/renderer.js | |||
@@ -0,0 +1,1696 @@ | |||
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 | g_renderStats = {}; | ||
8 | g_renderStats.numDrawCalls = new stat("rendering", "numDrawCalls", 0, null, false); | ||
9 | g_renderStats.numTriangles = new stat("rendering", "numTriangles", 0, null, false); | ||
10 | g_renderStats.numVerts = new stat("rendering", "numVerts", 0, null, false); | ||
11 | g_renderStats.numPasses = new stat("rendering", "numPasses", 0, null, false); | ||
12 | g_renderStats.reset = function() { | ||
13 | g_renderStats.numTriangles.value = 0; | ||
14 | g_renderStats.numDrawCalls.value = 0; | ||
15 | g_renderStats.numVerts.value = 0; | ||
16 | g_renderStats.numPasses.value = 0; | ||
17 | }; | ||
18 | |||
19 | rdgeConstants = {}; | ||
20 | |||
21 | /* | ||
22 | * clear flags | ||
23 | */ | ||
24 | rdgeConstants.colorBuffer = 0x00004000; | ||
25 | rdgeConstants.depthBuffer = 0x00000100; | ||
26 | rdgeConstants.stencilBuffer = 0x00000400; | ||
27 | |||
28 | /* | ||
29 | * buffer types | ||
30 | */ | ||
31 | rdgeConstants.BUFFER_STATIC = 0; | ||
32 | rdgeConstants.BUFFER_DYNAMIC = 1; | ||
33 | rdgeConstants.BUFFER_STREAM = 2; | ||
34 | |||
35 | /* | ||
36 | * primitive types | ||
37 | */ | ||
38 | rdgeConstants.POINTS = 0; | ||
39 | rdgeConstants.LINES = 1; | ||
40 | rdgeConstants.LINE_LOOP = 2; | ||
41 | rdgeConstants.LINE_STRIP = 3; | ||
42 | rdgeConstants.TRIANGLES = 4; | ||
43 | rdgeConstants.TRIANGLE_STRIP = 5; | ||
44 | rdgeConstants.TRIANGLE_FAN = 6; | ||
45 | |||
46 | /* | ||
47 | * primitive data types | ||
48 | */ | ||
49 | rdgeConstants.BYTE = 0x1400; | ||
50 | rdgeConstants.UNSIGNED_BYTE = 0x1401; | ||
51 | rdgeConstants.SHORT = 0x1402; | ||
52 | rdgeConstants.UNSIGNED_SHORT = 0x1403; | ||
53 | rdgeConstants.INT = 0x1404; | ||
54 | rdgeConstants.UNSIGNED_INT = 0x1405; | ||
55 | rdgeConstants.FLOAT = 0x1406; | ||
56 | |||
57 | /* | ||
58 | * pre-defined vertex element type | ||
59 | */ | ||
60 | rdgeConstants.VS_ELEMENT_FLOAT4 = 4; | ||
61 | rdgeConstants.VS_ELEMENT_POS = 3; | ||
62 | rdgeConstants.VS_ELEMENT_NORM = 3; | ||
63 | rdgeConstants.VS_ELEMENT_FLOAT3 = 3; | ||
64 | rdgeConstants.VS_ELEMENT_FLOAT2 = 2; | ||
65 | rdgeConstants.VS_ELEMENT_UV = 2; | ||
66 | rdgeConstants.VS_ELEMENT_FLOAT = 1; | ||
67 | rdgeConstants.MAX_ELEM_TYPES = 7; | ||
68 | |||
69 | // GL Definition of buffer types | ||
70 | rdgeConstants.BUFFER_STATIC = 0x88E0; | ||
71 | rdgeConstants.BUFFER_DYNAMIC = 0x88E4; | ||
72 | rdgeConstants.BUFFER_STREAM = 0x88E8; | ||
73 | |||
74 | // render constants | ||
75 | rdgeConstants.MAX_MATERIAL_LIGHTS = 4; | ||
76 | |||
77 | /* | ||
78 | * Material categories determine sorting | ||
79 | * materials support the following categories | ||
80 | */ | ||
81 | rdgeConstants.categoryEnumeration = | ||
82 | { | ||
83 | 'BACKGROUND' : 0, | ||
84 | 'OPAQUE' : 1, | ||
85 | 'TRANSPARENT' : 2, | ||
86 | 'ADDITIVE' : 3, | ||
87 | 'TRANSLUCENT' : 4, | ||
88 | 'FOREGROUND' : 5, | ||
89 | 'MAX_CAT' : 6 | ||
90 | }; | ||
91 | |||
92 | /* | ||
93 | * Node types supported by the scene graph | ||
94 | */ | ||
95 | rdgeConstants.nodeType = | ||
96 | { | ||
97 | 'TRNODE' : 0, | ||
98 | 'MESHNODE' : 1, | ||
99 | 'MATNODE' : 2, | ||
100 | 'LIGHTNODE' : 3 | ||
101 | }; | ||
102 | |||
103 | // generate an id for the renderer to map a render buffer to primitive | ||
104 | rdgeId = 0; | ||
105 | function getBufferID() | ||
106 | { | ||
107 | return rdgeId++; | ||
108 | } | ||
109 | |||
110 | |||
111 | _renderer = function(canvas) { | ||
112 | |||
113 | /* | ||
114 | * Initialize the context associated with this canvas | ||
115 | */ | ||
116 | this.ctx; | ||
117 | |||
118 | try { | ||
119 | this.ctx = canvas.getContext("experimental-webgl", { preserveDrawingBuffer: true }); // true, true, false, true, true); | ||
120 | |||
121 | if (!this.ctx) this.ctx = canvas.getContext("webgl", { preserveDrawingBuffer: true }); | ||
122 | if (!this.ctx) this.ctx = canvas.getContext("webkit-3d", { preserveDrawingBuffer: true }); | ||
123 | if (!this.ctx) this.ctx = canvas.getContext("moz-webgl", { preserveDrawingBuffer: true }); | ||
124 | } | ||
125 | catch (err) { } | ||
126 | if (!this.ctx) { | ||
127 | window.console.log("Could not create GL context"); | ||
128 | return null; | ||
129 | } | ||
130 | |||
131 | // set viewport for the first time | ||
132 | this.ctx.viewport(0, 0, canvas.width, canvas.height); | ||
133 | |||
134 | // Add a console output to the renderer | ||
135 | this.console = ("console" in window) ? window.console : { log: function() { } }; | ||
136 | |||
137 | /* | ||
138 | * Set the default clear color | ||
139 | */ | ||
140 | this.ctx.clearColor(1, 0, 0, 1); | ||
141 | |||
142 | /* | ||
143 | * the clear color of this renderer | ||
144 | */ | ||
145 | this.clearColor = [1, 0, 0, 1]; | ||
146 | |||
147 | /* | ||
148 | * The clear flags clear color and depth buffers by default | ||
149 | */ | ||
150 | this.clearFlags = this.ctx.COLOR_BUFFER_BIT | this.ctx.DEPTH_BUFFER_BIT | ||
151 | |||
152 | /* | ||
153 | * clear flags | ||
154 | */ | ||
155 | this.colorBuffer = this.ctx.COLOR_BUFFER_BIT; | ||
156 | this.depthBuffer = this.ctx.DEPTH_BUFFER_BIT; | ||
157 | this.stencilBuffer = this.ctx.STENCIL_BUFFER_BIT; | ||
158 | |||
159 | /* | ||
160 | * buffer types | ||
161 | */ | ||
162 | this.BUFFER_STATIC = 0; | ||
163 | this.BUFFER_DYNAMIC = 1; | ||
164 | this.BUFFER_STREAM = 2; | ||
165 | |||
166 | /* | ||
167 | * primitive types | ||
168 | */ | ||
169 | this.POINTS = 0; | ||
170 | this.LINES = 1; | ||
171 | this.LINE_LOOP = 2; | ||
172 | this.LINE_STRIP = 3; | ||
173 | this.TRIANGLES = 4; | ||
174 | this.TRIANGLE_STRIP = 5; | ||
175 | this.TRIANGLE_FAN = 6; | ||
176 | |||
177 | /* | ||
178 | * primitive data types | ||
179 | */ | ||
180 | this.BYTE = 0x1400; | ||
181 | this.UNSIGNED_BYTE = 0x1401; | ||
182 | this.SHORT = 0x1402; | ||
183 | this.UNSIGNED_SHORT = 0x1403; | ||
184 | this.INT = 0x1404; | ||
185 | this.UNSIGNED_INT = 0x1405; | ||
186 | this.FLOAT = 0x1406; | ||
187 | |||
188 | /* | ||
189 | * pre-defined vertex element type | ||
190 | */ | ||
191 | this.VS_ELEMENT_FLOAT4 = 4; | ||
192 | this.VS_ELEMENT_POS = 3; | ||
193 | this.VS_ELEMENT_NORM = 3; | ||
194 | this.VS_ELEMENT_FLOAT3 = 3; | ||
195 | this.VS_ELEMENT_FLOAT2 = 2; | ||
196 | this.VS_ELEMENT_UV = 2; | ||
197 | this.VS_ELEMENT_FLOAT = 1; | ||
198 | this.MAX_ELEM_TYPES = 7; | ||
199 | |||
200 | // GL Definition of buffer types | ||
201 | this.BUFFER_STATIC = 0x88E0; | ||
202 | this.BUFFER_DYNAMIC = 0x88E4; | ||
203 | this.BUFFER_STREAM = 0x88E8; | ||
204 | |||
205 | // render constants | ||
206 | this.MAX_MATERIAL_LIGHTS = 4; | ||
207 | |||
208 | // max system textures | ||
209 | this.usedTextureUnits = 5; | ||
210 | |||
211 | /* | ||
212 | * the renderers current viewport | ||
213 | */ | ||
214 | this.vpX = 0; | ||
215 | this.vpY = 0; | ||
216 | this.vpWidth = canvas.width; | ||
217 | this.vpHeight = canvas.height; | ||
218 | |||
219 | /* | ||
220 | * the camera manager - contains the camera stack for this render context | ||