aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/RenderProcs.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/RenderProcs.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/RenderProcs.js1023
1 files changed, 512 insertions, 511 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/RenderProcs.js b/js/helper-classes/RDGE/src/core/script/RenderProcs.js
index 1583ea14..356bb364 100755
--- a/js/helper-classes/RDGE/src/core/script/RenderProcs.js
+++ b/js/helper-classes/RDGE/src/core/script/RenderProcs.js
@@ -1,511 +1,512 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4
5 5Redistribution and use in source and binary forms, with or without
6Redistribution and use in source and binary forms, with or without 6modification, are permitted provided that the following conditions are met:
7modification, are permitted provided that the following conditions are met: 7
8 8* Redistributions of source code must retain the above copyright notice,
9 - Redistributions of source code must retain the above copyright notice, 9 this list of conditions and the following disclaimer.
10 this list of conditions and the following disclaimer. 10
11 - Redistributions in binary form must reproduce the above copyright 11* Redistributions in binary form must reproduce the above copyright notice,
12 notice, this list of conditions and the following disclaimer in the 12 this list of conditions and the following disclaimer in the documentation
13 documentation and/or other materials provided with the distribution. 13 and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors 14
15 may be used to endorse or promote products derived from this software 15* Neither the name of Motorola Mobility LLC nor the names of its
16 without specific prior written permission. 16 contributors may be used to endorse or promote products derived from this
17 17 software without specific prior written permission.
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28POSSIBILITY OF SUCH DAMAGE. 28ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29</copyright> */ 29POSSIBILITY OF SUCH DAMAGE.
30 30</copyright> */
31// RDGE namespaces 31
32var RDGE = RDGE || {}; 32// RDGE namespaces
33 33var RDGE = RDGE || {};
34/** 34
35* supported uniform types 35/**
36*/ 36* supported uniform types
37RDGE.UNIFORMTYPE = function () { 37*/
38 this.INT = 0x3F0; 38RDGE.UNIFORMTYPE = function () {
39 this.FLOAT = 0x3E8; 39 this.INT = 0x3F0;
40 this.FLOAT2 = 0x3E9; 40 this.FLOAT = 0x3E8;
41 this.FLOAT3 = 0x3EA; 41 this.FLOAT2 = 0x3E9;
42 this.FLOAT4 = 0x3EB; 42 this.FLOAT3 = 0x3EA;
43 this.MATRIX3 = 0x3EC; 43 this.FLOAT4 = 0x3EB;
44 this.MATRIX4 = 0x3ED; 44 this.MATRIX3 = 0x3EC;
45 this.TEXTURE2D = 0x3EE; 45 this.MATRIX4 = 0x3ED;
46 this.TEXTURECUBE = 0x3EF; 46 this.TEXTURE2D = 0x3EE;
47}; 47 this.TEXTURECUBE = 0x3EF;
48 48};
49/** 49
50* RDGE.RenderObject - contains references to all the data need to render, including vertex buffers, uniform handles, and matrices 50/**
51* @param shaderHandle 51* RDGE.RenderObject - contains references to all the data need to render, including vertex buffers, uniform handles, and matrices
52*/ 52* @param shaderHandle
53RDGE.RenderObject = function (shaderHandle) { 53*/
54 this.shader = shaderHandle; 54RDGE.RenderObject = function (shaderHandle) {
55 this.world = null; 55 this.shader = shaderHandle;
56 this.bindings = new RDGE.ShaderData(); 56 this.world = null;
57 this.initRenderProc = null; 57 this.bindings = new RDGE.ShaderData();
58 this.renderProc = null; 58 this.initRenderProc = null;
59 this.postRenderProc = null; 59 this.renderProc = null;
60}; 60 this.postRenderProc = null;
61 61};
62/** 62
63* Adds a uniform to the render object to bound during render 63/**
64* @param name - name of the uniform 64* Adds a uniform to the render object to bound during render
65* @param value - reference to value that will get bound (will be referenced from now on, don't delete the ref) 65* @param name - name of the uniform
66* @param type - type of uniform, use RDGE.UNIFORMTYPE 66* @param value - reference to value that will get bound (will be referenced from now on, don't delete the ref)
67*/ 67* @param type - type of uniform, use RDGE.UNIFORMTYPE
68RDGE.RenderObject.prototype.addUniform = function (name, value, type) { 68*/
69 var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name); 69RDGE.RenderObject.prototype.addUniform = function (name, value, type) {
70 if (uniform) { 70 var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name);
71 uniform.debugName = name; 71 if (uniform) {
72 this.bindings.uniforms.push(new RDGE.UniformPair(uniform, value, type)); 72 uniform.debugName = name;
73 } 73 this.bindings.uniforms.push(new RDGE.UniformPair(uniform, value, type));
74 /* 74 }
75 else 75 /*
76 { 76 else
77 gl.console.log("ERROR: uniform - " + name + " not found!"); 77 {
78 } 78 gl.console.log("ERROR: uniform - " + name + " not found!");
79 */ 79 }
80}; 80 */
81 81};
82/** 82
83* Adds a uniform to the render object to bound during render 83/**
84* @param name - name of the uniform 84* Adds a uniform to the render object to bound during render
85* @param value - reference to value that will get bound (will be referenced from now on, don't delete the ref) 85* @param name - name of the uniform
86* @param type - type of uniform, use RDGE.UNIFORMTYPE 86* @param value - reference to value that will get bound (will be referenced from now on, don't delete the ref)
87*/ 87* @param type - type of uniform, use RDGE.UNIFORMTYPE
88RDGE.RenderObject.prototype.addUniformArray = function (name, value, type, size) { 88*/
89 var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name); 89RDGE.RenderObject.prototype.addUniformArray = function (name, value, type, size) {
90 if (uniform) { 90 var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name);
91 for (var index = 0; index < size; index++) { 91 if (uniform) {
92 uniform.debugName = name + index; 92 for (var index = 0; index < size; index++) {
93 this.bindings.uniforms.push(new RDGE.UniformPair(uniform, value[index], type)); 93 uniform.debugName = name + index;
94 uniform += value[index].length; 94 this.bindings.uniforms.push(new RDGE.UniformPair(uniform, value[index], type));
95 value++; 95 uniform += value[index].length;
96 } 96 value++;
97 } 97 }
98 /* 98 }
99 else 99 /*
100 { 100 else
101 gl.console.log("ERROR: uniform - " + name + " not found!"); 101 {
102 }*/ 102 gl.console.log("ERROR: uniform - " + name + " not found!");
103}; 103 }*/
104 104};
105/** 105
106* Add texture to uniform 106/**
107* @param name - handle to the texture 107* Add texture to uniform
108* @param unit - texture slot to use 108* @param name - handle to the texture
109* @param type - RDGE.UNIFORMTYPE.TEXTURE2D or TEXTURE2D.TEXTURECUBE 109* @param unit - texture slot to use
110*/ 110* @param type - RDGE.UNIFORMTYPE.TEXTURE2D or TEXTURE2D.TEXTURECUBE
111RDGE.RenderObject.prototype.addTexture = function (name, unit, type) { 111*/
112 var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name); 112RDGE.RenderObject.prototype.addTexture = function (name, unit, type) {
113 if (uniform) { 113 var uniform = RDGE.globals.gl.getUniformLocation(this.shader, name);
114 this.bindings.textures.push(new RDGE.TexUniform(uniform, unit, type)); 114 if (uniform) {
115 } 115 this.bindings.textures.push(new RDGE.TexUniform(uniform, unit, type));
116 /* 116 }
117 else 117 /*
118 { 118 else
119 gl.console.log("ERROR: texture uniform - " + name + " not found!"); 119 {
120 } 120 gl.console.log("ERROR: texture uniform - " + name + " not found!");
121 */ 121 }
122}; 122 */
123 123};
124/** 124
125* Adds a vertex buffer to the render object 125/**
126* @param buffer - buffer to use 126* Adds a vertex buffer to the render object
127* @param glBufferType - type of buffer i.e. gl.ARRAY_BUFFER 127* @param buffer - buffer to use
128* @param attribSize - if using attrib the size of an element (3 for vec3) 128* @param glBufferType - type of buffer i.e. gl.ARRAY_BUFFER
129* @param attribIndex - the index slot the attrib goes in 129* @param attribSize - if using attrib the size of an element (3 for vec3)
130* @param glAttribType - type of the attrib i.e. gl.FLOAT 130* @param attribIndex - the index slot the attrib goes in
131*/ 131* @param glAttribType - type of the attrib i.e. gl.FLOAT
132RDGE.RenderObject.prototype.addBuffers = function (buffer, glBufferType, attribSize, attribIndex, glAttribType) { 132*/
133 //gl.useProgram(this.shader); 133RDGE.RenderObject.prototype.addBuffers = function (buffer, glBufferType, attribSize, attribIndex, glAttribType) {
134<