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 | 2310 |
1 files changed, 1126 insertions, 1184 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/renderer.js b/js/helper-classes/RDGE/src/core/script/renderer.js index c01068a4..0b9185d0 100755 --- a/js/helper-classes/RDGE/src/core/script/renderer.js +++ b/js/helper-classes/RDGE/src/core/script/renderer.js | |||
@@ -4,123 +4,91 @@ 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 | // primitive types |
18 | 18 | POINTS: 0, | |
19 | rdgeConstants = {}; | 19 | LINES: 1, |
20 | 20 | LINE_LOOP: 2, | |
21 | /* | 21 | LINE_STRIP: 3, |
22 | * clear flags | 22 | TRIANGLES: 4, |
23 | */ | 23 | TRIANGLE_STRIP: 5, |
24 | rdgeConstants.colorBuffer = 0x00004000; | 24 | TRIANGLE_FAN: 6, |
25 | rdgeConstants.depthBuffer = 0x00000100; | 25 | |
26 | rdgeConstants.stencilBuffer = 0x00000400; | 26 | // primitive data types |
27 | 27 | BYTE: 0x1400, | |
28 | /* | 28 | UNSIGNED_BYTE: 0x1401, |
29 | * buffer types | 29 | SHORT: 0x1402, |
30 | */ | 30 | UNSIGNED_SHORT: 0x1403, |
31 | rdgeConstants.BUFFER_STATIC = 0; | 31 | INT: 0x1404, |
32 | rdgeConstants.BUFFER_DYNAMIC = 1; | 32 | UNSIGNED_INT: 0x1405, |
33 | rdgeConstants.BUFFER_STREAM = 2; | 33 | FLOAT: 0x1406, |
34 | 34 | ||
35 | /* | 35 | // pre-defined vertex element type |
36 | * primitive types | 36 | VS_ELEMENT_FLOAT4: 4, |
37 | */ | 37 | VS_ELEMENT_POS: 3, |
38 | rdgeConstants.POINTS = 0; | 38 | VS_ELEMENT_NORM: 3, |
39 | rdgeConstants.LINES = 1; | 39 | VS_ELEMENT_FLOAT3: 3, |
40 | rdgeConstants.LINE_LOOP = 2; | 40 | VS_ELEMENT_FLOAT2: 2, |
41 | rdgeConstants.LINE_STRIP = 3; | 41 | VS_ELEMENT_UV: 2, |
42 | rdgeConstants.TRIANGLES = 4; | 42 | VS_ELEMENT_FLOAT: 1, |
43 | rdgeConstants.TRIANGLE_STRIP = 5; | 43 | MAX_ELEM_TYPES: 7, |
44 | rdgeConstants.TRIANGLE_FAN = 6; | 44 | |
45 | 45 | // GL Definition of buffer types | |
46 | /* | 46 | BUFFER_STATIC: 0x88E0, |
47 | * primitive data types | 47 | BUFFER_DYNAMIC: 0x88E4, |
48 | */ | 48 | BUFFER_STREAM: 0x88E8, |
49 | rdgeConstants.BYTE = 0x1400; | 49 | |
50 | rdgeConstants.UNSIGNED_BYTE = 0x1401; | 50 | // render constants |
51 | rdgeConstants.SHORT = 0x1402; | 51 | MAX_MATERIAL_LIGHTS: 4, |
52 | rdgeConstants.UNSIGNED_SHORT = 0x1403; | 52 | |
53 | rdgeConstants.INT = 0x1404; | 53 | // Material categories determine sorting materials support the following categories |
54 | rdgeConstants.UNSIGNED_INT = 0x1405; | 54 | categoryEnumeration: |
55 | rdgeConstants.FLOAT = 0x1406; | 55 | { |
56 | 56 | 'BACKGROUND': 0, | |
57 | /* | 57 | 'OPAQUE': 1, |
58 | * pre-defined vertex element type | 58 | 'TRANSPARENT': 2, |
59 | */ | 59 | 'ADDITIVE': 3, |
60 | rdgeConstants.VS_ELEMENT_FLOAT4 = 4; | 60 | 'TRANSLUCENT': 4, |
61 | rdgeConstants.VS_ELEMENT_POS = 3; | 61 | 'FOREGROUND': 5, |
62 | rdgeConstants.VS_ELEMENT_NORM = 3; | 62 | 'MAX_CAT': 6 |
63 | rdgeConstants.VS_ELEMENT_FLOAT3 = 3; | 63 | }, |
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 | 64 | ||
111 | _renderer = function(canvas) { | 65 | // Node types supported by the scene graph |
66 | nodeType: | ||
67 | { | ||
68 | 'TRNODE': 0, | ||
69 | 'MESHNODE': 1, | ||
70 | 'MATNODE': 2, | ||
71 | 'LIGHTNODE': 3 | ||
72 | } | ||
73 | }; | ||
74 | })(); | ||
112 | 75 | ||
76 | RDGE._renderer = function (canvas) { | ||
113 | /* | 77 | /* |
114 | * Initialize the context associated with this canvas | 78 | * Initialize the context associated with this canvas |
115 | */ | 79 | */ |
116 | this.ctx; | ||
117 | |||
118 | try { | 80 | try { |
119 | this.ctx = canvas.getContext("experimental-webgl", { preserveDrawingBuffer: true }); // true, true, false, true, true); | 81 | this.ctx = canvas.getContext("experimental-webgl", { preserveDrawingBuffer: true }); // true, true, false, true, true); |
120 | 82 | ||
121 | if (!this.ctx) this.ctx = canvas.getContext("webgl", { preserveDrawingBuffer: true }); | 83 | if (!this.ctx) { |
122 | if (!this.ctx) this.ctx = canvas.getContext("webkit-3d", { preserveDrawingBuffer: true }); | 84 | this.ctx = canvas.getContext("webgl", { preserveDrawingBuffer: true }); |
123 | if (!this.ctx) this.ctx = canvas.getContext("moz-webgl", { preserveDrawingBuffer: true }); | 85 | } |
86 | if (!this.ctx) { | ||
87 | this.ctx = canvas.getContext("webkit-3d", { preserveDrawingBuffer: true }); | ||
88 | } | ||
89 | if (!this.ctx) { | ||
90 | this.ctx = canvas.getContext("moz-webgl", { preserveDrawingBuffer: true }); | ||
91 | } | ||
124 | } | 92 | } |
125 | catch (err) { } | 93 | catch (err) { } |
126 | if (!this.ctx) { | 94 | if (!this.ctx) { |
@@ -132,7 +100,7 @@ _renderer = function(canvas) { | |||
132 | this.ctx.viewport(0, 0, canvas.width, canvas.height); | 100 | this.ctx.viewport(0, 0, canvas.width, canvas.height); |
133 | 101 | ||
134 | // Add a console output to the renderer | 102 | // Add a console output to the renderer |
135 | this.console = ("console" in window) ? window.console : { log: function() { } }; | 103 | this.console = ("console" in window) ? window.console : { log: function () { } }; |
136 | 104 | ||
137 | /* | 105 | /* |
138 | * Set the default clear color | 106 | * Set the default clear color |
@@ -219,7 +187,7 @@ _renderer = function(canvas) { | |||
219 | /* | 187 | /* |
220 | * the camera manager - contains the camera stack for this render context | 188 | * the camera manager - contains the camera stack for this render context |
221 | */ | 189 | */ |
222 | this.cameraMan = new cameraManager(); | 190 | this.cameraMan = new RDGE.cameraManager(); |
223 | 191 | ||
224 | /* | 192 | /* |
225 | * a list of device buffers that are owned by this render context | 193 | * a list of device buffers that are owned by this render context |
@@ -230,88 +198,88 @@ _renderer = function(canvas) { | |||
230 | /* | 198 | /* |
231 | * State wrappers | 199 | * State wrappers |
232 | */ | 200 | */ |
233 | this.cullBackFace = function() { | 201 | this.cullBackFace = function () { |
234 | this.ctx.cullFace(this.ctx.Back); | 202 | this.ctx.cullFace(this.ctx.Back); |
235 | } | 203 | }; |
236 | 204 | ||
237 | this.cullFrontFace = function() { | 205 | this.cullFrontFace = function () { |
238 | this.ctx.cullFace(this.ctx.FRONT); | 206 | this.ctx.cullFace(this.ctx.FRONT); |
239 | } | 207 | }; |
240 |