diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/renderer.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/renderer.js | 2299 |
1 files changed, 1121 insertions, 1178 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/renderer.js b/js/helper-classes/RDGE/src/core/script/renderer.js index a50b8a68..06e9885e 100755 --- a/js/helper-classes/RDGE/src/core/script/renderer.js +++ b/js/helper-classes/RDGE/src/core/script/renderer.js | |||
@@ -4,112 +4,81 @@ 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 | g_renderStats = {}; | 7 | var RDGE = RDGE || {}; |
8 | g_renderStats.numDrawCalls = new stat("rendering", "numDrawCalls", 0, null, false); | 8 | |
9 | g_renderStats.numTriangles = new stat("rendering", "numTriangles", 0, null, false); | 9 | // runtime globals |
10 | g_renderStats.numVerts = new stat("rendering", "numVerts", 0, null, false); | 10 | RDGE.rdgeConstants = (function () { |
11 | g_renderStats.numPasses = new stat("rendering", "numPasses", 0, null, false); | 11 | return { |
12 | g_renderStats.reset = function() { | 12 | // clear flags |
13 | g_renderStats.numTriangles.value = 0; | 13 | colorBuffer: 0x00004000, |
14 | g_renderStats.numDrawCalls.value = 0; | 14 | depthBuffer: 0x00000100, |
15 | g_renderStats.numVerts.value = 0; | 15 | stencilBuffer: 0x00000400, |
16 | g_renderStats.numPasses.value = 0; | 16 | |
17 | }; | 17 | // buffer types |
18 | 18 | BUFFER_STATIC: 0, | |
19 | rdgeConstants = {}; | 19 | BUFFER_DYNAMIC: 1, |
20 | 20 | BUFFER_STREAM: 2, | |
21 | /* | 21 | |
22 | * clear flags | 22 | // primitive types |
23 | */ | 23 | POINTS: 0, |
24 | rdgeConstants.colorBuffer = 0x00004000; | 24 | LINES: 1, |
25 | rdgeConstants.depthBuffer = 0x00000100; | 25 | LINE_LOOP: 2, |
26 | rdgeConstants.stencilBuffer = 0x00000400; | 26 | LINE_STRIP: 3, |
27 | 27 | TRIANGLES: 4, | |
28 | /* | 28 | TRIANGLE_STRIP: 5, |
29 | * buffer types | 29 | TRIANGLE_FAN: 6, |
30 | */ | 30 | |
31 | rdgeConstants.BUFFER_STATIC = 0; | 31 | // primitive data types |
32 | rdgeConstants.BUFFER_DYNAMIC = 1; | 32 | BYTE: 0x1400, |
33 | rdgeConstants.BUFFER_STREAM = 2; | 33 | UNSIGNED_BYTE: 0x1401, |
34 | 34 | SHORT: 0x1402, | |
35 | /* | 35 | UNSIGNED_SHORT: 0x1403, |
36 | * primitive types | 36 | INT: 0x1404, |
37 | */ | 37 | UNSIGNED_INT: 0x1405, |
38 | rdgeConstants.POINTS = 0; | 38 | FLOAT: 0x1406, |
39 | rdgeConstants.LINES = 1; | 39 | |
40 | rdgeConstants.LINE_LOOP = 2; | 40 | // pre-defined vertex element type |
41 | rdgeConstants.LINE_STRIP = 3; | 41 | VS_ELEMENT_FLOAT4: 4, |
42 | rdgeConstants.TRIANGLES = 4; | 42 | VS_ELEMENT_POS: 3, |
43 | rdgeConstants.TRIANGLE_STRIP = 5; | 43 | VS_ELEMENT_NORM: 3, |
44 | rdgeConstants.TRIANGLE_FAN = 6; | 44 | VS_ELEMENT_FLOAT3: 3, |
45 | 45 | VS_ELEMENT_FLOAT2: 2, | |
46 | /* | 46 | VS_ELEMENT_UV: 2, |
47 | * primitive data types | 47 | VS_ELEMENT_FLOAT: 1, |
48 | */ | 48 | MAX_ELEM_TYPES: 7, |
49 | rdgeConstants.BYTE = 0x1400; | 49 | |
50 | rdgeConstants.UNSIGNED_BYTE = 0x1401; | 50 | // GL Definition of buffer types |
51 | rdgeConstants.SHORT = 0x1402; | 51 | BUFFER_STATIC: 0x88E0, |
52 | rdgeConstants.UNSIGNED_SHORT = 0x1403; | 52 | BUFFER_DYNAMIC: 0x88E4, |
53 | rdgeConstants.INT = 0x1404; | 53 | BUFFER_STREAM: 0x88E8, |
54 | rdgeConstants.UNSIGNED_INT = 0x1405; | 54 | |
55 | rdgeConstants.FLOAT = 0x1406; | 55 | // render constants |
56 | 56 | MAX_MATERIAL_LIGHTS: 4, | |
57 | /* | 57 | |
58 | * pre-defined vertex element type | 58 | // Material categories determine sorting materials support the following categories |
59 | */ | 59 | categoryEnumeration: |
60 | rdgeConstants.VS_ELEMENT_FLOAT4 = 4; | 60 | { |
61 | rdgeConstants.VS_ELEMENT_POS = 3; | 61 | 'BACKGROUND': 0, |
62 | rdgeConstants.VS_ELEMENT_NORM = 3; | 62 | 'OPAQUE': 1, |
63 | rdgeConstants.VS_ELEMENT_FLOAT3 = 3; | 63 | 'TRANSPARENT': 2, |
64 | rdgeConstants.VS_ELEMENT_FLOAT2 = 2; | 64 | 'ADDITIVE': 3, |
65 | rdgeConstants.VS_ELEMENT_UV = 2; | 65 | 'TRANSLUCENT': 4, |
66 | rdgeConstants.VS_ELEMENT_FLOAT = 1; | 66 | 'FOREGROUND': 5, |
67 | rdgeConstants.MAX_ELEM_TYPES = 7; | 67 | 'MAX_CAT': 6 |
68 | 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 | 69 | ||
111 | _renderer = function(canvas) { | 70 | // Node types supported by the scene graph |
71 | nodeType: | ||
72 | { | ||
73 | 'TRNODE': 0, | ||
74 | 'MESHNODE': 1, | ||
75 | 'MATNODE': 2, | ||
76 | 'LIGHTNODE': 3 | ||
77 | } | ||
78 | }; | ||
79 | })(); | ||
112 | 80 | ||
81 | RDGE._renderer = function (canvas) { | ||
113 | /* | 82 | /* |
114 | * Initialize the context associated with this canvas | 83 | * Initialize the context associated with this canvas |
115 | */ | 84 | */ |
@@ -132,7 +101,7 @@ _renderer = function(canvas) { | |||
132 | this.ctx.viewport(0, 0, canvas.width, canvas.height); | 101 | this.ctx.viewport(0, 0, canvas.width, canvas.height); |
133 | 102 | ||
134 | // Add a console output to the renderer | 103 | // Add a console output to the renderer |
135 | this.console = ("console" in window) ? window.console : { log: function() { } }; | 104 | this.console = ("console" in window) ? window.console : { log: function () { } }; |
136 | 105 | ||
137 | /* | 106 | /* |
138 | * Set the default clear color | 107 | * Set the default clear color |
@@ -219,7 +188,7 @@ _renderer = function(canvas) { | |||
219 | /* | 188 | /* |
220 | * the camera manager - contains the camera stack for this render context | 189 | * the camera manager - contains the camera stack for this render context |
221 | */ | 190 | */ |
222 | this.cameraMan = new cameraManager(); | 191 | this.cameraMan = new RDGE.cameraManager(); |
223 | 192 | ||
224 | /* | 193 | /* |
225 | * a list of device buffers that are owned by this render context | 194 | * a list of device buffers that are owned by this render context |
@@ -230,88 +199,88 @@ _renderer = function(canvas) { | |||
230 | /* | 199 | /* |
231 | * State wrappers | 200 | * State wrappers |
232 | */ | 201 | */ |
233 | this.cullBackFace = function() { | 202 | this.cullBackFace = function () { |
234 | this.ctx.cullFace(this.ctx.Back); | 203 | this.ctx.cullFace(this.ctx.Back); |
235 | } | 204 | }; |
236 | 205 | ||
237 | this.cullFrontFace = function() { | 206 | this.cullFrontFace = function () { |
238 | this.ctx.cullFace(this.ctx.FRONT); | 207 | this.ctx.cullFace(this.ctx.FRONT); |
239 | } | 208 | }; |
240 | 209 | ||
241 | this.disableCulling = function() { | 210 | this.disableCulling = function () { |
242 | this.ctx.disable(this.ctx.CULL_FACE); | 211 | this.ctx.disable(this.ctx.CULL_FACE); |
243 | } | 212 | }; |
244 | 213 | ||
245 | this.enableCulling = function() { | 214 | this.enableCulling = function () { |
246 | this.ctx.enable(this.ctx.CULL_FACE); | 215 | this.ctx.enable(this.ctx.CULL_FACE); |
247 | } | 216 | }; |
248 | 217 | ||
249 | this.enablePolyOffsetFill = function() { | 218 | this.enablePolyOffsetFill = function () { |
250 | this.ctx.enable(this.ctx.POLYGON_OFFSET_FILL); | 219 | this.ctx.enable(this.ctx.POLYGON_OFFSET_FILL); |
251 | } | 220 | }; |
252 | 221 | ||
253 | this.disablePolyOffsetFill = function() { |