aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/rendercontext.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/rendercontext.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/rendercontext.js451
1 files changed, 224 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..02e185d8 100755
--- a/js/helper-classes/RDGE/src/core/script/rendercontext.js
+++ b/js/helper-classes/RDGE/src/core/script/rendercontext.js
@@ -4,265 +4,262 @@ 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 7var RDGE = RDGE || {};
8
9var g_whiteTex = null;
10var g_blackTex = null;
11var g_blueTex = null;
12 8
13function RDGEWebTexture() 9// render flags, handles, states
14{ 10RDGE.g_whiteTex = null;
15 this.handle; // gl handle 11RDGE.g_blackTex = null;
16 this.unit; // the texture slot/unit 12RDGE.g_blueTex = null;
17 this.type = UNIFORMTYPE.TEXTURE2D; 13
18} 14/* These objects appear to be unused so they are currently commented out
15RDGE.RDGEWebTexture = function () {
16 this.handle; // gl handle
17 this.unit; // the texture slot/unit
18 this.type = RDGE.UNIFORMTYPE.TEXTURE2D;
19};
19 20
20function RDGEWebUniformPair(uniform, value, type) { 21RDGE.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
28function defaultState() 29RDGE.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
34function 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 = 36RDGE.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
63function 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
73RDGEUniformInit.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; 65RDGE.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 73RDGE.RDGEUniformInit.prototype.SetUni = function (name, _value) {
81RDGEUniform = new RDGEUniformInit(); 74 //this.uniformMap[name].value.set(_value);
82
83
84function 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
106RenderContext.prototype.Load = function(ctx) 79// Globally available uniform storage
107{ 80RDGE.RDGEUniform = new RDGE.RDGEUniformInit();
108 this.shaderProg = ctx.shaderProg; 81
109 this.uniforms = ctx.uniforms.slice(); 82RDGE.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 // state settings - set functions in the array that set states or 'other' so long as it makes since
122 this.stateSettings = this.stateSettings.slice(); 95 this.stateSettings = [];
123} 96};
124 97
98RDGE.RenderContext.prototype.Load = function (ctx) {
99 this.shaderProg = ctx.shaderProg;
100 this.uniforms = ctx.uniforms.slice();
101 this.textureList = ctx.textureList.slice();
102 this.stateSettings = ctx.stateSettings.slice();
103 this.curRenderProc = ctx.curRenderProc;
104 this.light0Color = ctx.light0Color.slice();
105 this.parentID = ctx.parentID;
106 this.world = RDGE.mat4.copy(ctx.world);