diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/RenderProcs.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/RenderProcs.js | 787 |
1 files changed, 369 insertions, 418 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/RenderProcs.js b/js/helper-classes/RDGE/src/core/script/RenderProcs.js index 6d3b02df..4d7c055c 100755 --- a/js/helper-classes/RDGE/src/core/script/RenderProcs.js +++ b/js/helper-classes/RDGE/src/core/script/RenderProcs.js | |||
@@ -4,533 +4,484 @@ 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 | // RDGE namespaces | ||
8 | var RDGE = RDGE || {}; | ||
9 | |||
7 | /** | 10 | /** |
8 | * supported uniform types | 11 | * supported uniform types |
9 | */ | 12 | */ |
10 | function __UNIFORMTYPE() | 13 | RDGE.UNIFORMTYPE = function () { |
11 | { | 14 | this.INT = 0x3F0; |
12 | this.INT = 0x3F0; | 15 | this.FLOAT = 0x3E8; |
13 | this.FLOAT = 0x3E8; | 16 | this.FLOAT2 = 0x3E9; |
14 | this.FLOAT2 = 0x3E9; | 17 | this.FLOAT3 = 0x3EA; |
15 | this.FLOAT3 = 0x3EA; | 18 | this.FLOAT4 = 0x3EB; |
16 | this.FLOAT4 = 0x3EB; | 19 | this.MATRIX3 = 0x3EC; |
17 | this.MATRIX3 = 0x3EC; | 20 | this.MATRIX4 = 0x3ED; |
18 | this.MATRIX4 = 0x3ED; | 21 | this.TEXTURE2D = 0x3EE; |
19 | this.TEXTURE2D = 0x3EE; | 22 | this.TEXTURECUBE = 0x3EF; |
20 | this.TEXTURECUBE = 0x3EF; | 23 | }; |
21 | } | ||
22 | UNIFORMTYPE = new __UNIFORMTYPE(); | ||
23 | 24 | ||
24 | /** | 25 | /** |
25 | * RenderObject - contains references to all the data need to render, including vertex buffers, uniform handles, and matrices | 26 | * RDGE.RenderObject - contains references to all the data need to render, including vertex buffers, uniform handles, and matrices |
26 | * @param shaderHandle | 27 | * @param shaderHandle |
27 | */ | 28 | */ |
28 | function RenderObject(shaderHandle) | 29 | RDGE.RenderObject = function (shaderHandle) { |
29 | { | 30 | this.shader = shaderHandle; |
30 | this.shader = shaderHandle; | 31 | this.world = null; |
31 | this.world = null; | 32 | this.bindings = new RDGE.ShaderData(); |
32 | this.bindings = new ShaderData(); | 33 | this.initRenderProc = null; |
33 | this.initRenderProc = null; | 34 | this.renderProc = null; |
34 | this.renderProc = null; | 35 | this.postRenderProc = null; |
35 | this.postRenderProc = null; | 36 | }; |
36 | } | ||
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Adds a uniform to the render object to bound during render | 39 | * Adds a uniform to the render object to bound during render |
40 | * @param name - name of the uniform | 40 | * @param name - name of the uniform |
41 | * @param value - reference to value that will get bound (will be referenced from now on, don't delete the ref) | 41 | * @param value - reference to value that will get bound (will be referenced from now on, don't delete the ref) |
42 | * @param type - type of uniform, use UNIFORMTYPE | 42 | * @param type - type of uniform, use RDGE.UNIFORMTYPE |
43 | */ | ||
44 | RenderObject.prototype.addUniform = function(name, value, type) | ||
45 | { | ||
46 | var uniform = gl.getUniformLocation(this.shader, name); | ||
47 | if(uniform) | ||
48 | { | ||
49 | uniform.debugName = name; | ||
50 | this.bindings.uniforms.push( new UniformPair(uniform, value, type)); | ||
51 | } | ||
52 | /* | ||
53 | else | ||
54 | { | ||
55 | gl.console.log("ERROR: uniform - " + name + " not found!"); | ||
56 | } | ||
57 | */ | 43 | */ |
44 | RDGE.RenderObject.prototype.addUniform = function (name, value, type) { | ||
45 | var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name); | ||
46 | if (uniform) { | ||
47 | uniform.debugName = name; | ||
48 | this.bindings.uniforms.push(new RDGE.UniformPair(uniform, value, type)); | ||
49 | } | ||
50 | /* | ||
51 | else | ||
52 | { | ||
53 | gl.console.log("ERROR: uniform - " + name + " not found!"); | ||
54 | } | ||
55 | */ | ||
58 | }; | 56 | }; |
59 | 57 | ||
60 | /** | 58 | /** |
61 | * Adds a uniform to the render object to bound during render | 59 | * Adds a uniform to the render object to bound during render |
62 | * @param name - name of the uniform | 60 | * @param name - name of the uniform |
63 | * @param value - reference to value that will get bound (will be referenced from now on, don't delete the ref) | 61 | * @param value - reference to value that will get bound (will be referenced from now on, don't delete the ref) |
64 | * @param type - type of uniform, use UNIFORMTYPE | 62 | * @param type - type of uniform, use RDGE.UNIFORMTYPE |
65 | */ | 63 | */ |
66 | RenderObject.prototype.addUniformArray = function(name, value, type, size) | 64 | RDGE.RenderObject.prototype.addUniformArray = function (name, value, type, size) { |
67 | { | 65 | var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name); |
68 | var uniform = gl.getUniformLocation(this.shader, name); | 66 | if (uniform) { |
69 | if (uniform) | 67 | for (var index = 0; index < size; index) { |
70 | { | 68 | uniform.debugName = name + index; |
71 | for (var index=0; index<size; index) | 69 | this.bindings.uniforms.push(new RDGE.UniformPair(uniform, value[index], type)); |
72 | { | 70 | uniform += value[index].length; |
73 | uniform.debugName = name+index; | 71 | value++; |
74 | this.bindings.uniforms.push( new UniformPair(uniform, value[index], type)); | 72 | } |
75 | uniform+=value[index].length; | ||
76 | value++; | ||
77 | } | ||
78 | } | 73 | } |
79 | /* | 74 | /* |
80 | else | 75 | else |
81 | { | 76 | { |
82 | gl.console.log("ERROR: uniform - " + name + " not found!"); | 77 | gl.console.log("ERROR: uniform - " + name + " not found!"); |
83 | }*/ | 78 | }*/ |
84 | }; | 79 | }; |
80 | |||
85 | /** | 81 | /** |
86 | * Add texture to uniform | 82 | * Add texture to uniform |
87 | * @param name - handle to the texture | 83 | * @param name - handle to the texture |
88 | * @param unit - texture slot to use | 84 | * @param unit - texture slot to use |
89 | * @param type - UNIFORMTYPE.TEXTURE2D or TEXTURE2D.TEXTURECUBE | 85 | * @param type - RDGE.UNIFORMTYPE.TEXTURE2D or TEXTURE2D.TEXTURECUBE |
90 | */ | ||
91 | RenderObject.prototype.addTexture = function(name, unit, type) | ||
92 | { | ||
93 | var uniform = gl.getUniformLocation(this.shader, name); | ||
94 | if(uniform) | ||
95 | { | ||
96 | this.bindings.textures.push( new TexUniform(uniform, unit, type)); | ||
97 | } | ||
98 | /* | ||
99 | else | ||
100 | { | ||
101 | gl.console.log("ERROR: texture uniform - " + name + " not found!"); | ||
102 | } | ||
103 | */ | 86 | */ |
87 | RDGE.RenderObject.prototype.addTexture = function (name, unit, type) { | ||
88 | var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name); | ||
89 | if (uniform) { | ||
90 | this.bindings.textures.push(new RDGE.TexUniform(uniform, unit, type)); | ||
91 | } | ||
92 | /* | ||
93 | else | ||
94 | { | ||
95 | gl.console.log("ERROR: texture uniform - " + name + " not found!"); | ||
96 | } | ||
97 | */ | ||
104 | }; | 98 | }; |
105 | 99 | ||
106 | /** | 100 | /** |
107 | * Adds a vertex buffer to the render object | 101 | * Adds a vertex buffer to the render object |
108 | * @param buffer - buffer to use | 102 | * @param buffer - buffer to use |
109 | * @param glBufferType - type of buffer i.e. gl.ARRAY_BUFFER | 103 | * @param glBufferType - type of buffer i.e. gl.ARRAY_BUFFER |
110 | * @param attribSize - if using attrib the size of an element (3 for vec3) | 104 | * @param attribSize - if using attrib the size of an element (3 for vec3) |
111 | * @param attribIndex - the index slot the attrib goes in | 105 | * @param attribIndex - the index slot the attrib goes in |
112 | * @param glAttribType - type of the attrib i.e. gl.FLOAT | 106 | * @param glAttribType - type of the attrib i.e. gl.FLOAT |
113 | */ | 107 | */ |
114 | RenderObject.prototype.addBuffers = function(buffer, glBufferType, attribSize, attribIndex, glAttribType) | 108 | RDGE.RenderObject.prototype.addBuffers = function (buffer, glBufferType, attribSize, attribIndex, glAttribType) { |
115 | { | 109 | //gl.useProgram(this.shader); |
116 | //gl.useProgram(this.shader); | 110 | if (attribSize == undefined || attribIndex == undefined || glAttribType == undefined || |
117 | if( attribSize == undefined || attribIndex == undefined || glAttribType == undefined || | 111 | attribSize == null || attribIndex == null || glAttribType == null) { |
118 | attribSize == null || attribIndex == null || glAttribType == null ) | 112 | this.bindings.buffers.push(new RDGE.BufferAttrib(buffer, glBufferType, null, null, null)); |
119 | { | 113 | } |
120 | this.bindings.buffers.push( new BufferAttrib(buffer, glBufferType, null, null, null)); | 114 | else { |
121 | } | 115 | this.bindings.buffers.push(new RDGE.BufferAttrib(buffer, glBufferType, attribSize, attribIndex, glAttribType)); |
122 | else | 116 | } |
123 | { | 117 | //gl.useProgram(null); |
124 | this.bindings.buffers.push( new BufferAttrib(buffer, glBufferType, attribSize, attribIndex, glAttribType)); | ||
125 | } | ||
126 | //gl.useProgram(null); | ||
127 | }; | 118 | }; |
128 | 119 | ||
129 | /** | 120 | /** |
130 | * bind the matrices, vertices and floats to shader uniforms | 121 | * bind the matrices, vertices and floats to shader uniforms |
131 | */ | 122 | */ |
132 | RenderObject.prototype.bindUniforms = function() | 123 | RDGE.RenderObject.prototype.bindUniforms = function () { |
133 | { | 124 | for (var uniIndex = 0; uniIndex < this.bindings.uniforms.length; uniIndex++) { |
134 | for(var uniIndex = 0; uniIndex < this.bindings.uniforms.length; uniIndex++) |