diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/rendercontext.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/rendercontext.js | 454 |
1 files changed, 227 insertions, 227 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/rendercontext.js b/js/helper-classes/RDGE/src/core/script/rendercontext.js index 6bc8665b..83c64473 100755 --- a/js/helper-classes/RDGE/src/core/script/rendercontext.js +++ b/js/helper-classes/RDGE/src/core/script/rendercontext.js | |||
@@ -4,265 +4,265 @@ 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 | // render flags, handles, states | 7 | var RDGE = RDGE || {}; |
8 | |||
9 | var g_whiteTex = null; | ||
10 | var g_blackTex = null; | ||
11 | var g_blueTex = null; | ||
12 | 8 | ||
13 | function RDGEWebTexture() | 9 | // render flags, handles, states |
14 | { | 10 | RDGE.g_whiteTex = null; |
15 | this.handle; // gl handle | 11 | RDGE.g_blackTex = null; |
16 | this.unit; // the texture slot/unit | 12 | RDGE.g_blueTex = null; |
17 | this.type = UNIFORMTYPE.TEXTURE2D; | 13 | |
18 | } | 14 | /* These objects appear to be unused so they are currently commented out |
15 | RDGE.RDGEWebTexture = function () { | ||
16 | this.handle; // gl handle | ||
17 | this.unit; // the texture slot/unit | ||
18 | this.type = RDGE.UNIFORMTYPE.TEXTURE2D; | ||
19 | }; | ||
19 | 20 | ||
20 | function RDGEWebUniformPair(uniform, value, type) { | 21 | RDGE.RDGEWebUniformPair = function (uniform, value, type) { |
21 | this.uniform = uniform; | 22 | this.uniform = uniform; |
22 | this.value = value; | 23 | this.value = value; |
23 | this.type = type; | 24 | this.type = type; |
24 | } | 25 | }; |
25 | 26 | ||
26 | 27 | ||
27 | // pass a function that takes no parameters | 28 | // pass a function that takes no parameters |
28 | function defaultState() | 29 | RDGE.defaultState = function () { |
29 | { | 30 | return [function () { gl.disable(gl.CULL_FACE) }, |
30 | return [ function(){gl.disable(gl.CULL_FACE)}, | 31 | function () { gl.enable(gl.DEPTH_TEST) } ] |
31 | function(){gl.enable(gl.DEPTH_TEST)}] | 32 | }; |
32 | } | 33 | */ |
33 | // this chunk of data contains uniform storage references set the data with RDGEUniform.set (ie RDGEUniform.set("u_name", UNIFORMTYPE.FLOAT4, myData); ) | 34 | |
34 | function CreateMasterList() { | 35 | // this chunk of data contains uniform storage references set the data with RDGEUniform.set (ie RDGEUniform.set("u_name", RDGE.UNIFORMTYPE.FLOAT4, myData); ) |
35 | _MasterUniformList = | 36 | RDGE.CreateMasterList = function () { |
37 | _MasterUniformList = | ||
36 | [ | 38 | [ |
37 | { 'uniform': projMatrixUniform = 0, 'name': "u_projMatrix", 'type': UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, | 39 | { 'uniform': projMatrixUniform = 0, 'name': "u_projMatrix", 'type': RDGE.UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, |
38 | { 'uniform': mvMatrixUniform = 0, 'name': "u_mvMatrix", 'type': UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, | 40 | { 'uniform': mvMatrixUniform = 0, 'name': "u_mvMatrix", 'type': RDGE.UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, |
39 | { 'uniform': normalMatrixUniform = 0, 'name': "u_normalMatrix", 'type': UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, | 41 | { 'uniform': normalMatrixUniform = 0, 'name': "u_normalMatrix", 'type': RDGE.UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, |
40 | { 'uniform': worldMatrixUniform = 0, 'name': "u_worldMatrix", 'type': UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, | 42 | { 'uniform': worldMatrixUniform = 0, 'name': "u_worldMatrix", 'type': RDGE.UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, |
41 | { 'uniform': lightPos = 0, 'name': "u_lightPos", 'type': UNIFORMTYPE.FLOAT3, 'value': new Float32Array(3) }, | 43 | { 'uniform': lightPos = 0, 'name': "u_lightPos", 'type': RDGE.UNIFORMTYPE.FLOAT3, 'value': new Float32Array(3) }, |
42 | { 'uniform': lightDiff = 0, 'name': "u_lightDiff", 'type': UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, | 44 | { 'uniform': lightDiff = 0, 'name': "u_lightDiff", 'type': RDGE.UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, |
43 | { 'uniform': lightAmb = 0, 'name': "u_lightAmb", 'type': UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, | 45 | { 'uniform': lightAmb = 0, 'name': "u_lightAmb", 'type': RDGE.UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, |
44 | { 'uniform': colMap = 0, 'name': "colMap", 'type': UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) }, | 46 | { 'uniform': colMap = 0, 'name': "colMap", 'type': RDGE.UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) }, |
45 | { 'uniform': envMap = 0, 'name': "envMap", 'type': UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) }, | 47 | { 'uniform': envMap = 0, 'name': "envMap", 'type': RDGE.UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) }, |
46 | { 'uniform': normalMap = 0, 'name': "normalMap", 'type': UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) }, | 48 | { 'uniform': normalMap = 0, 'name': "normalMap", 'type': RDGE.UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) }, |
47 | { 'uniform': glowMap = 0, 'name': "glowMap", 'type': UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) }, | 49 | { 'uniform': glowMap = 0, 'name': "glowMap", 'type': RDGE.UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) }, |
48 | { 'uniform': matAmbient = 0, 'name': "u_matAmbient", 'type': UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, | 50 | { 'uniform': matAmbient = 0, 'name': "u_matAmbient", 'type': RDGE.UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, |
49 | { 'uniform': matDiffuse = 0, 'name': "u_matDiffuse", 'type': UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, | 51 | { 'uniform': matDiffuse = 0, 'name': "u_matDiffuse", 'type': RDGE.UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, |
50 | { 'uniform': matSpecular = 0, 'name': "u_matSpecular", 'type': UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, | 52 | { 'uniform': matSpecular = 0, 'name': "u_matSpecular", 'type': RDGE.UNIFORMTYPE.FLOAT4, 'value': new Float32Array(4) }, |
51 | { 'uniform': matShininess = 0, 'name': "u_matShininess", 'type': UNIFORMTYPE.FLOAT, 'value': new Float32Array(1) }, | 53 | { 'uniform': matShininess = 0, 'name': "u_matShininess", 'type': RDGE.UNIFORMTYPE.FLOAT, 'value': new Float32Array(1) }, |
52 | { 'uniform': matEmission = 0, 'name': "u_matEmission", 'type': UNIFORMTYPE.FLOAT, 'value': new Float32Array(4) }, | 54 | { 'uniform': matEmission = 0, 'name': "u_matEmission", 'type': RDGE.UNIFORMTYPE.FLOAT, 'value': new Float32Array(4) }, |
53 | { 'uniform': frustumFarZ = 0, 'name': "u_frustumFarZ", 'type': UNIFORMTYPE.FLOAT, 'value': new Float32Array(1) }, | 55 | { 'uniform': frustumFarZ = 0, 'name': "u_frustumFarZ", 'type': RDGE.UNIFORMTYPE.FLOAT, 'value': new Float32Array(1) }, |
54 | { 'uniform': shadowLightWorld = 0, 'name': "u_shadowLightWorld", 'type': UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, | 56 | { 'uniform': shadowLightWorld = 0, 'name': "u_shadowLightWorld", 'type': RDGE.UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, |
55 | { 'uniform': shadowBiasMatrix = 0, 'name': "u_shadowBiasMatrix", 'type': UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, | 57 | { 'uniform': shadowBiasMatrix = 0, 'name': "u_shadowBiasMatrix", 'type': RDGE.UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, |
56 | { 'uniform': vShadowLight = 0, 'name': "u_vShadowLight", 'type': UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, | 58 | { 'uniform': vShadowLight = 0, 'name': "u_vShadowLight", 'type': RDGE.UNIFORMTYPE.MATRIX4, 'value': new Float32Array(16) }, |
57 | { 'uniform': depthMap = 0, 'name': "depthMap", 'type': UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) } | 59 | { 'uniform': depthMap = 0, 'name': "depthMap", 'type': RDGE.UNIFORMTYPE.TEXTURE2D, 'value': new Int32Array(1) } |
58 | ]; | 60 | ]; |
59 | |||
60 | return _MasterUniformList; | ||
61 | } | ||
62 | |||
63 | function RDGEUniformInit() | ||
64 | { | ||
65 | this.uniformList = CreateMasterList(); | ||
66 | this.uniformMap=[]; | ||
67 | for(var idx = 0; idx < this.uniformList.length; ++idx) | ||
68 | { | ||
69 | this.uniformMap[this.uniformList[idx].name] = this.uniformList[idx]; | ||
70 | } | ||
71 | } | ||
72 | 61 | ||
73 | RDGEUniformInit.prototype.SetUni = function(name, _value) | 62 | return _MasterUniformList; |
74 | { | 63 | }; |
75 | //this.uniformMap[name].value.set(_value); | ||
76 | 64 | ||
77 | this.uniformMap[name].value = _value; | 65 | RDGE.RDGEUniformInit = function () { |
78 | } | 66 | this.uniformList = RDGE.CreateMasterList(); |
67 | this.uniformMap = []; | ||
68 | for (var idx = 0; idx < this.uniformList.length; ++idx) { | ||
69 | this.uniformMap[this.uniformList[idx].name] = this.uniformList[idx]; | ||
70 | } | ||
71 | }; | ||
79 | 72 | ||
80 | // Globally available uniform storage | 73 | RDGE.RDGEUniformInit.prototype.SetUni = function (name, _value) { |
81 | RDGEUniform = new RDGEUniformInit(); | 74 | //this.uniformMap[name].value.set(_value); |
82 | |||
83 | |||
84 | function RenderContext() | ||
85 | { | ||
86 | |||
87 | this.shaderProg = null; | ||
88 | this.uniforms =[]; | ||
89 | this.textureList =[]; | ||
90 | this.curRenderProc = null; | ||
91 | this.light0Color = [1, 1, 1, 0]; | ||
92 | this.parentID = 0; | ||
93 | this.world = mat4.identity(); | ||
94 | this.hide = false; | ||
95 | enableNormalMapping=true; | ||
96 | this.lights = [ null, null, null, null]; | ||
97 | |||
98 | // the camera | ||
99 | this.cam; | ||
100 | |||
101 | // state settings - set functions in the array that set states or 'other' so long as it makes since | ||
102 | this.stateSettings = []; | ||
103 | 75 | ||
104 | } | 76 | this.uniformMap[name].value = _value; |
77 | }; | ||
105 | 78 | ||
106 | RenderContext.prototype.Load = function(ctx) | 79 | // Globally available uniform storage |
107 | { | 80 | RDGE.RDGEUniform = new RDGE.RDGEUniformInit(); |
108 | this.shaderProg = ctx.shaderProg; | 81 | |
109 | this.uniforms = ctx.uniforms.slice(); | 82 | RDGE.RenderContext = function () { |
110 | this.textureList = ctx.textureList.slice(); | 83 | this.shaderProg = null; |
111 | this.stateSettings = ctx.stateSettings.slice(); | 84 | this.uniforms = []; |
112 | this.curRenderProc = ctx.curRenderProc; | 85 | this.textureList = []; |
113 | this.light0Color = ctx.light0Color.slice(); | 86 | this.curRenderProc = null; |
114 | this.parentID = ctx.parentID; | 87 | this.light0Color = [1, 1, 1, 0]; |
115 | this.world = mat4.copy(ctx.world); | 88 | this.parentID = 0; |
116 | this.lights = ctx.lights.slice(); | 89 | this.world = RDGE.mat4.identity(); |
117 | 90 | this.hide = false; | |
118 | // the camera | 91 | enableNormalMapping = true; |
119 | this.cam = this.cam; | 92 | this.lights = [null, null, null, null]; |
120 | 93 | ||
121 | // state settings - set functions in the array that set states or 'other' so long as it makes since | 94 | // the camera |
122 | this.stateSettings = this.stateSettings.slice(); | 95 | this.cam; |
123 | } | 96 | |
97 | // state settings - set functions in the array that set states or 'other' so long as it makes since | ||
98 | this.stateSettings = []; | ||
99 | }; | ||
124 | 100 | ||
101 | RDGE.RenderContext.prototype.Load = function (ctx) { | ||
102 | this.shaderProg = ctx.shaderProg; | ||
103 | this.uniforms = ctx.uniforms.slice(); | ||
104 | this.textureList = ctx.textureList.slice(); | ||
105 | this.stateSettings = ctx.stateSettings.slice(); | ||
106 | this.curRenderProc = ctx.curRenderProc; | ||
107 | this.light0Color = ctx.light0Color.slice(); | ||
108 | this.parentID = ctx.parentID; | ||
109 | this.world = RDGE.mat4.copy(ctx.world); | ||
110 | this.lights = ctx.lights.slice(); | ||
111 | |||
112 | // the camera | ||
113 | this.cam = this.cam; | ||
114 | |||
115 | // state settings - set functions in the array that set states or 'other' so long as it makes since | ||
116 | this.stateSettings = this.stateSettings.slice(); | ||
117 | }; | ||