- * @param {cc.math.Matrix4} [mat4]
- */
-cc.math.Matrix4 = function (mat4) {
- if(mat4 && mat4.mat){
- this.mat = new Float32Array(mat4.mat);
- } else {
- this.mat = new Float32Array(16);
- }
-};
-var proto = cc.math.Matrix4.prototype;
-
-/**
- * Fills a cc.math.Matrix4 structure with the values from a 16 element array of floats
- * @param {Array} scalarArr
- */
-proto.fill = function(scalarArr){ //cc.kmMat4Fill
- var mat = this.mat;
- for(var i = 0; i < 16; i++){
- mat[i] = scalarArr[i];
- }
- return this;
-};
-
-/**
- * Sets pOut to an identity matrix returns pOut
- * @Params pOut - A pointer to the matrix to set to identity
- * @Return Returns pOut so that the call can be nested
- */
-cc.math.mat4Identity = function (pOut) {
- var mat = pOut.mat;
- mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7]
- = mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
- mat[0] = mat[5] = mat[10] = mat[15] = 1.0;
- return pOut;
-};
-
-/**
- * Sets matrix to identity value.
- * @returns {cc.math.Matrix4}
- */
-proto.identity = function(){
- var mat = this.mat;
- mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7]
- = mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
- mat[0] = mat[5] = mat[10] = mat[15] = 1.0;
- return this;
-};
-
-proto.get = function(row, col){
- return this.mat[row + 4 * col];
-};
-
-proto.set = function(row, col, value){
- this.mat[row + 4 * col] = value;
-};
-
-proto.swap = function(r1, c1, r2, c2) {
-/* var tmp = this.get(r1, c1);
- this.set(r1, c1, this.get(r2, c2));
- this.set(r2, c2, tmp);*/
- var mat = this.mat, tmp = mat[r1 + 4 * c1];
- mat[r1 + 4 * c1] = mat[r2 + 4 * c2];
- mat[r2 + 4 * c2] = tmp;
-};
-
-//Returns an upper and a lower triangular matrix which are L and R in the Gauss algorithm
-cc.math.Matrix4._gaussj = function (a, b) {
- var i, icol = 0, irow = 0, j, k, l, ll, n = 4, m = 4, selElement;
- var big, dum, pivinv;
- var indxc = [0, 0, 0, 0], indxr = [0, 0, 0, 0], ipiv = [0, 0, 0, 0];
-
- /* for (j = 0; j < n; j++) {
- ipiv[j] = 0;
- }*/
-
- for (i = 0; i < n; i++) {
- big = 0.0;
- for (j = 0; j < n; j++) {
- if (ipiv[j] !== 1) {
- for (k = 0; k < n; k++) {
- if (ipiv[k] === 0) {
- selElement = Math.abs(a.get(j, k));
- if (selElement >= big) {
- big = selElement;
- irow = j;
- icol = k;
- }
- }
- }
- }
- }
- ++(ipiv[icol]);
- if (irow !== icol) {
- for (l = 0; l < n; l++)
- a.swap(irow, l, icol, l);
- for (l = 0; l < m; l++)
- b.swap(irow, l, icol, l);
- }
- indxr[i] = irow;
- indxc[i] = icol;
- if (a.get(icol, icol) === 0.0)
- return false;
-
- pivinv = 1.0 / a.get(icol, icol);
- a.set(icol, icol, 1.0);
- for (l = 0; l < n; l++)
- a.set(icol, l, a.get(icol, l) * pivinv);
-
- for (l = 0; l < m; l++)
- b.set(icol, l, b.get(icol, l) * pivinv);
-
- for (ll = 0; ll < n; ll++) {
- if (ll !== icol) {
- dum = a.get(ll, icol);
- a.set(ll, icol, 0.0);
- for (l = 0; l < n; l++)
- a.set(ll, l, a.get(ll, l) - a.get(icol, l) * dum);
-
- for (l = 0; l < m; l++)
- b.set(ll, l, a.get(ll, l) - b.get(icol, l) * dum);
- }
- }
- }
- // This is the end of the main loop over columns of the reduction. It only remains to unscram-
- // ble the solution in view of the column interchanges. We do this by interchanging pairs of
- // columns in the reverse order that the permutation was built up.
- for (l = n - 1; l >= 0; l--) {
- if (indxr[l] !== indxc[l]) {
- for (k = 0; k < n; k++)
- a.swap(k, indxr[l], k, indxc[l]);
- }
- }
- return true;
-};
-
-var identityMatrix = new cc.math.Matrix4().identity();
-/**
- * Calculates the inverse of pM and stores the result in pOut.
- * Please use matrix4's inverse function instead.
- * @Return Returns NULL if there is no inverse, else pOut
- */
-cc.math.mat4Inverse = function (pOut, pM) {
- var inv = new cc.math.Matrix4(pM);
- var tmp = new cc.math.Matrix4(identityMatrix);
- if (cc.math.Matrix4._gaussj(inv, tmp) === false)
- return null;
- pOut.assignFrom(inv);
- return pOut;
-};
-
-/**
- * Calculates the inverse of current matrix.
- * @returns {cc.math.Matrix4} Returns null if there is no inverse, else returns a new inverse matrix object
- */
-proto.inverse = function(){ //cc.kmMat4Inverse
- var inv = new cc.math.Matrix4(this);
- var tmp = new cc.math.Matrix4(identityMatrix);
- if (cc.math.Matrix4._gaussj(inv, tmp) === false)
- return null;
- return inv;
-};
-
-/**
- * Returns true if current matrix is an identity matrix, false otherwise
- */
-proto.isIdentity = function () { // cc.kmMat4IsIdentity
- var mat = this.mat;
- return (mat[0] === 1 && mat[1] === 0 && mat[2] === 0 && mat[3] === 0
- && mat[4] === 0 && mat[5] === 1 && mat[6] === 0 && mat[7] === 0
- && mat[8] === 0 && mat[9] === 0 && mat[10] === 1 && mat[11] === 0
- && mat[12] === 0 && mat[13] === 0 && mat[14] === 0 && mat[15] === 1);
-};
-
-/**
- * transpose the current matrix
- */
-proto.transpose = function() { // cc.kmMat4Transpose
- var mat = this.mat;
- var m1 = mat[1], m2 = mat[2], m3 = mat[3],
- m4 = mat[4], m6 = mat[6], m7 = mat[7],
- m8 = mat[8], m9 = mat[9], m11 = mat[11],
- m12 = mat[12], m13 = mat[13], m14 = mat[14];
- mat[1] = m4;
- mat[2] = m8;
- mat[3] = m12;
-
- mat[4] = m1;
- mat[6] = m9;
- mat[7] = m13;
-
- mat[8] = m2;
- mat[9] = m6;
- mat[11] = m14;
-
- mat[12] = m3;
- mat[13] = m7;
- mat[14] = m11;
- return this;
-};
-
-/**
- * Multiplies pM1 with pM2, stores the result in pOut, returns pOut
- */
-cc.math.mat4Multiply = function (pOut, pM1, pM2) {
- // Cache the matrix values (makes for huge speed increases!)
- var outArray = pOut.mat, mat1 = pM1.mat, mat2 = pM2.mat;
- var a00 = mat1[0], a01 = mat1[1], a02 = mat1[2], a03 = mat1[3];
- var a10 = mat1[4], a11 = mat1[5], a12 = mat1[6], a13 = mat1[7];
- var a20 = mat1[8], a21 = mat1[9], a22 = mat1[10], a23 = mat1[11];
- var a30 = mat1[12], a31 = mat1[13], a32 = mat1[14], a33 = mat1[15];
-
- var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
- var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
- var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
- var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];
-
- outArray[0] = b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30;
- outArray[1] = b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31;
- outArray[2] = b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32;
- outArray[3] = b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33;
- outArray[4] = b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30;
- outArray[5] = b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31;
- outArray[6] = b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32;
- outArray[7] = b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33;
- outArray[8] = b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30;
- outArray[9] = b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31;
- outArray[10] = b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32;
- outArray[11] = b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33;
- outArray[12] = b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30;
- outArray[13] = b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31;
- outArray[14] = b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32;
- outArray[15] = b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33;
- return pOut;
-};
-
-/**
- * current matrix multiplies with other matrix mat4
- * @param {cc.math.Matrix4} mat4
- * @returns {cc.math.Matrix4}
- */
-proto.multiply = function(mat4){
- // Cache the matrix values (makes for huge speed increases!)
- var mat = this.mat, mat2 = mat4.mat;
- var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
- var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
- var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
- var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
-
- var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
- var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
- var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
- var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];
-
- mat[0] = b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30;
- mat[1] = b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31;
- mat[2] = b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32;
- mat[3] = b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33;
- mat[4] = b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30;
- mat[5] = b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31;
- mat[6] = b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32;
- mat[7] = b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33;
- mat[8] = b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30;
- mat[9] = b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31;
- mat[10] = b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32;
- mat[11] = b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33;
- mat[12] = b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30;
- mat[13] = b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31;
- mat[14] = b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32;
- mat[15] = b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33;
- return this;
-};
-
-cc.math.getMat4MultiplyValue = function (pM1, pM2) {
- var m1 = pM1.mat, m2 = pM2.mat;
- var mat = new Float32Array(16);
-
- mat[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3];
- mat[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3];
- mat[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3];
- mat[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3];
-
- mat[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7];
- mat[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7];
- mat[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7];
- mat[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7];
-
- mat[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11];
- mat[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11];
- mat[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11];
- mat[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11];
-
- mat[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15];
- mat[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15];
- mat[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15];
- mat[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15];
-
- return mat;
-};
-
-/**
- * Assigns the value of pIn to pOut
- */
-cc.math.mat4Assign = function (pOut, pIn) {
- if (pOut === pIn) {
- cc.logID(7901);
- return pOut;
- }
-
- var outArr = pOut.mat;
- var inArr = pIn.mat;
-
- outArr[0] = inArr[0];
- outArr[1] = inArr[1];
- outArr[2] = inArr[2];
- outArr[3] = inArr[3];
-
- outArr[4] = inArr[4];
- outArr[5] = inArr[5];
- outArr[6] = inArr[6];
- outArr[7] = inArr[7];
-
- outArr[8] = inArr[8];
- outArr[9] = inArr[9];
- outArr[10] = inArr[10];
- outArr[11] = inArr[11];
-
- outArr[12] = inArr[12];
- outArr[13] = inArr[13];
- outArr[14] = inArr[14];
- outArr[15] = inArr[15];
- return pOut;
-};
-
-/**
- * Assigns the value of current matrix from mat4
- * @param {cc.math.Matrix4} mat4
- * @returns {cc.math.Matrix4}
- */
-proto.assignFrom = function(mat4) {
- if (this === mat4) {
- cc.logID(7902);
- return this;
- }
- var outArr = this.mat, inArr = mat4.mat;
-
- outArr[0] = inArr[0];
- outArr[1] = inArr[1];
- outArr[2] = inArr[2];
- outArr[3] = inArr[3];
-
- outArr[4] = inArr[4];
- outArr[5] = inArr[5];
- outArr[6] = inArr[6];
- outArr[7] = inArr[7];
-
- outArr[8] = inArr[8];
- outArr[9] = inArr[9];
- outArr[10] = inArr[10];
- outArr[11] = inArr[11];
-
- outArr[12] = inArr[12];
- outArr[13] = inArr[13];
- outArr[14] = inArr[14];
- outArr[15] = inArr[15];
- return this;
-};
-
-/**
- * Returns true if current matrix equal mat4 (approximately)
- * @param {cc.math.Matrix4} mat4
- * @returns {boolean}
- */
-proto.equals = function(mat4) {
- if (this === mat4) {
- cc.logID(7903);
- return true;
- }
- var matA = this.mat, matB = mat4.mat, EPSILON = cc.math.EPSILON;
- for (var i = 0; i < 16; i++) {
- if (!(matA[i] + EPSILON > matB[i] && matA[i] - EPSILON < matB[i]))
- return false;
- }
- return true;
-};
-
-/**
- * Builds an X-axis rotation matrix and stores it in matrix, returns matrix, if matrix is null, create a new matrix
- * @param {Number} radians
- * @param {cc.math.Matrix4} [matrix]
- * @returns {cc.math.Matrix4}
- */
-cc.math.Matrix4.createByRotationX = function(radians, matrix) { //cc.kmMat4RotationX
- /*
- | 1 0 0 0 |
- M = | 0 cos(A) -sin(A) 0 |
- | 0 sin(A) cos(A) 0 |
- | 0 0 0 1 |
- */
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = 1.0;
- mat[3] = mat[2] = mat[1] = 0.0;
-
- mat[4] = 0.0;
- mat[5] = Math.cos(radians);
- mat[6] = Math.sin(radians);
- mat[7] = 0.0;
-
- mat[8] = 0.0;
- mat[9] = -Math.sin(radians);
- mat[10] = Math.cos(radians);
- mat[11] = 0.0;
-
- mat[14] = mat[13] = mat[12] = 0.0;
- mat[15] = 1.0;
- return matrix;
-};
-
-/**
- * Builds a rotation matrix using the rotation around the Y-axis, The result is stored in matrix, matrix is returned.
- * @param {Number} radians
- * @param {cc.math.Matrix4} [matrix]
- * @returns {*}
- */
-cc.math.Matrix4.createByRotationY = function(radians, matrix) { // cc.kmMat4RotationY
- /*
- | cos(A) 0 sin(A) 0 |
- M = | 0 1 0 0 |
- | -sin(A) 0 cos(A) 0 |
- | 0 0 0 1 |
- */
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = Math.cos(radians);
- mat[1] = 0.0;
- mat[2] = -Math.sin(radians);
- mat[3] = 0.0;
-
- mat[7] = mat[6] = mat[4] = 0.0;
- mat[5] = 1.0;
-
- mat[8] = Math.sin(radians);
- mat[9] = 0.0;
- mat[10] = Math.cos(radians);
- mat[11] = 0.0;
-
- mat[14] = mat[13] = mat[12] = 0.0;
- mat[15] = 1.0;
- return matrix;
-};
-
-/**
- * Builds a rotation matrix around the Z-axis. The resulting matrix is stored in matrix. matrix is returned.
- * @param {Number} radians
- * @param {cc.math.Matrix4} matrix
- * @return {cc.math.Matrix4}
- */
-cc.math.Matrix4.createByRotationZ = function(radians, matrix){ // cc.kmMat4RotationZ
- /*
- | cos(A) -sin(A) 0 0 |
- M = | sin(A) cos(A) 0 0 |
- | 0 0 1 0 |
- | 0 0 0 1 |
- */
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = Math.cos(radians);
- mat[1] = Math.sin(radians);
- mat[3] = mat[2] = 0.0;
-
- mat[4] = -Math.sin(radians);
- mat[5] = Math.cos(radians);
- mat[7] = mat[6] = 0.0;
-
- mat[11] = mat[9] = mat[8] = 0.0;
- mat[10] = 1.0;
-
- mat[14] = mat[13] = mat[12] = 0.0;
- mat[15] = 1.0;
-
- return matrix;
-};
-
-/**
- * Builds a rotation matrix from pitch, yaw and roll. The resulting matrix is stored in parameter matrix and returns.
- * @param {Number} pitch
- * @param {Number} yaw
- * @param {Number} roll
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
-cc.math.Matrix4.createByPitchYawRoll = function(pitch, yaw, roll, matrix) {
- matrix = matrix || new cc.math.Matrix4();
- var cr = Math.cos(pitch), sr = Math.sin(pitch);
- var cp = Math.cos(yaw), sp = Math.sin(yaw);
- var cy = Math.cos(roll), sy = Math.sin(roll);
- var srsp = sr * sp, crsp = cr * sp;
- var mat = matrix.mat;
-
- mat[0] = cp * cy;
- mat[4] = cp * sy;
- mat[8] = -sp;
-
- mat[1] = srsp * cy - cr * sy;
- mat[5] = srsp * sy + cr * cy;
- mat[9] = sr * cp;
-
- mat[2] = crsp * cy + sr * sy;
- mat[6] = crsp * sy - sr * cy;
- mat[10] = cr * cp;
-
- mat[3] = mat[7] = mat[11] = 0.0;
- mat[15] = 1.0;
- return matrix;
-};
-
-/**
- * Builds a matrix by a quaternion.
- * @param {cc.math.Quaternion} quaternion
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
-cc.math.Matrix4.createByQuaternion = function(quaternion, matrix) {
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = 1.0 - 2.0 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z );
- mat[1] = 2.0 * (quaternion.x * quaternion.y + quaternion.z * quaternion.w);
- mat[2] = 2.0 * (quaternion.x * quaternion.z - quaternion.y * quaternion.w);
- mat[3] = 0.0;
-
- // Second row
- mat[4] = 2.0 * ( quaternion.x * quaternion.y - quaternion.z * quaternion.w );
- mat[5] = 1.0 - 2.0 * ( quaternion.x * quaternion.x + quaternion.z * quaternion.z );
- mat[6] = 2.0 * (quaternion.z * quaternion.y + quaternion.x * quaternion.w );
- mat[7] = 0.0;
-
- // Third row
- mat[8] = 2.0 * ( quaternion.x * quaternion.z + quaternion.y * quaternion.w );
- mat[9] = 2.0 * ( quaternion.y * quaternion.z - quaternion.x * quaternion.w );
- mat[10] = 1.0 - 2.0 * ( quaternion.x * quaternion.x + quaternion.y * quaternion.y );
- mat[11] = 0.0;
-
- // Fourth row
- mat[14] = mat[13] = mat[12] = 0;
- mat[15] = 1.0;
- return matrix;
-};
-
-/**
- * Build a 4x4 OpenGL transformation matrix using a 3x3 rotation matrix, and a 3d vector representing a translation.
- * @param {cc.math.Matrix3} rotation
- * @param {cc.math.Vec3} translation
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
-cc.math.Matrix4.createByRotationTranslation = function(rotation, translation, matrix) {
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat, rMat = rotation.mat;
- mat[0] = rMat[0];
- mat[1] = rMat[1];
- mat[2] = rMat[2];
- mat[3] = 0.0;
-
- mat[4] = rMat[3];
- mat[5] = rMat[4];
- mat[6] = rMat[5];
- mat[7] = 0.0;
-
- mat[8] = rMat[6];
- mat[9] = rMat[7];
- mat[10] = rMat[8];
- mat[11] = 0.0;
-
- mat[12] = translation.x;
- mat[13] = translation.y;
- mat[14] = translation.z;
- mat[15] = 1.0;
- return matrix;
-};
-
-/**
- * Builds a scaling matrix
- * @param {Number} x
- * @param {Number} y
- * @param {Number} z
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
-cc.math.Matrix4.createByScale = function(x, y, z, matrix) { //cc.kmMat4Scaling
- matrix = matrix || new cc.math.Matrix4();
- var mat = matrix.mat;
- mat[0] = x;
- mat[5] = y;
- mat[10] = z;
- mat[15] = 1.0;
- mat[1] = mat[2] = mat[3] = mat[4] = mat[6] = mat[7] =
- mat[8] = mat[9] = mat[11] = mat[12] = mat[13] = mat[14] = 0;
- return matrix;
-};
-
-/**
- * Builds a translation matrix. All other elements in the matrix
- * will be set to zero except for the diagonal which is set to 1.0
- */
-cc.math.mat4Translation = function (pOut, x, y, z) {
- //FIXME: Write a test for this
- pOut.mat[0] = pOut.mat[5] = pOut.mat[10] = pOut.mat[15] = 1.0;
- pOut.mat[1] = pOut.mat[2] = pOut.mat[3] =
- pOut.mat[4] = pOut.mat[6] = pOut.mat[7] =
- pOut.mat[8] = pOut.mat[9] = pOut.mat[11] = 0.0;
- pOut.mat[12] = x;
- pOut.mat[13] = y;
- pOut.mat[14] = z;
- return pOut;
-};
-
-/**
- * Builds a translation matrix.
- * @param {Number} x
- * @param {Number} y
- * @param {Number} z
- * @param {cc.math.Matrix4} [matrix] if matrix is undefined, creates a new matrix.
- * @returns {cc.math.Matrix4}
- */
-cc.math.Matrix4.createByTranslation = function(x, y, z, matrix){ //cc.kmMat4Translation
- matrix = matrix || new cc.math.Matrix4();
- matrix.identity();
- matrix.mat[12] = x;
- matrix.mat[13] = y;
- matrix.mat[14] = z;
- return matrix;
-};
-
-/**
- * Get the up vector from a matrix.
- * @returns {cc.math.Vec3}
- */
-proto.getUpVec3 = function() {
- var mat = this.mat;
- var ret = new cc.math.Vec3(mat[4],mat[5], mat[6]);
- return ret.normalize();
-};
-
-/**
- * Extract the right vector from a 4x4 matrix.
- * @returns {cc.math.Vec3}
- */
-proto.getRightVec3 = function(){
- var mat = this.mat;
- var ret = new cc.math.Vec3(mat[0],mat[1], mat[2]);
- return ret.normalize();
-};
-
-/**
- * Extract the forward vector from a 4x4 matrix.
- * @returns {cc.math.Vec3}
- */
-proto.getForwardVec3 = function() {
- var mat = this.mat;
- var ret = new cc.math.Vec3(mat[8],mat[9], mat[10]);
- return ret.normalize();
-};
-
-/**
- * Creates a perspective projection matrix in the
- * same way as gluPerspective
- */
-cc.math.mat4PerspectiveProjection = function (pOut, fovY, aspect, zNear, zFar) {
- var r = cc.degreesToRadians(fovY / 2);
- var deltaZ = zFar - zNear;
- var s = Math.sin(r);
-
- if (deltaZ === 0 || s === 0 || aspect === 0)
- return null;
-
- //cos(r) / sin(r) = cot(r)
- var cotangent = Math.cos(r) / s;
- pOut.identity();
- pOut.mat[0] = cotangent / aspect;
- pOut.mat[5] = cotangent;
- pOut.mat[10] = -(zFar + zNear) / deltaZ;
- pOut.mat[11] = -1;
- pOut.mat[14] = -2 * zNear * zFar / deltaZ;
- pOut.mat[15] = 0;
-
- return pOut;
-};
-
-/**
- * Creates a perspective projection matrix in the same way as gluPerspective
- * @param {Number} fovY
- * @param {Number} aspect
- * @param {Number} zNear
- * @param {Number} zFar
- * @returns {cc.math.Matrix4|Null}
- */
-cc.math.Matrix4.createPerspectiveProjection = function(fovY, aspect, zNear, zFar){
- var r = cc.degreesToRadians(fovY / 2), deltaZ = zFar - zNear;
- var s = Math.sin(r);
-
- if (deltaZ === 0 || s === 0 || aspect === 0)
- return null;
-
- //cos(r) / sin(r) = cot(r)
- var cotangent = Math.cos(r) / s;
- var matrix = new cc.math.Matrix4(), mat = matrix.mat;
- matrix.identity();
- mat[0] = cotangent / aspect;
- mat[5] = cotangent;
- mat[10] = -(zFar + zNear) / deltaZ;
- mat[11] = -1;
- mat[14] = -2 * zNear * zFar / deltaZ;
- mat[15] = 0;
- return matrix;
-};
-
-/** Creates an orthographic projection matrix like glOrtho */
-cc.math.mat4OrthographicProjection = function (pOut, left, right, bottom, top, nearVal, farVal) {
- pOut.identity();
- pOut.mat[0] = 2 / (right - left);
- pOut.mat[5] = 2 / (top - bottom);
- pOut.mat[10] = -2 / (farVal - nearVal);
- pOut.mat[12] = -((right + left) / (right - left));
- pOut.mat[13] = -((top + bottom) / (top - bottom));
- pOut.mat[14] = -((farVal + nearVal) / (farVal - nearVal));
- return pOut;
-};
-
-/**
- * Creates an orthographic projection matrix like glOrtho
- * @param {Number} left
- * @param {Number} right
- * @param {Number} bottom
- * @param {Number} top
- * @param {Number} nearVal
- * @param {Number} farVal
- * @returns {cc.math.Matrix4}
- */
-cc.math.Matrix4.createOrthographicProjection = function (left, right, bottom, top, nearVal, farVal) {
- var matrix = new cc.math.Matrix4(), mat = matrix.mat;
- matrix.identity();
- mat[0] = 2 / (right - left);
- mat[5] = 2 / (top - bottom);
- mat[10] = -2 / (farVal - nearVal);
- mat[12] = -((right + left) / (right - left));
- mat[13] = -((top + bottom) / (top - bottom));
- mat[14] = -((farVal + nearVal) / (farVal - nearVal));
- return matrix;
-};
-
-/**
- * Builds a translation matrix in the same way as gluLookAt()
- * the resulting matrix is stored in pOut. pOut is returned.
- */
-cc.math.mat4LookAt = function (pOut, pEye, pCenter, pUp) {
- var f = new cc.math.Vec3(pCenter), up = new cc.math.Vec3(pUp);
- f.subtract(pEye);
- f.normalize();
- up.normalize();
-
- var s = new cc.math.Vec3(f);
- s.cross(up);
- s.normalize();
-
- var u = new cc.math.Vec3(s);
- u.cross(f);
- s.normalize();
-
- pOut.identity();
-
- pOut.mat[0] = s.x;
- pOut.mat[4] = s.y;
- pOut.mat[8] = s.z;
-
- pOut.mat[1] = u.x;
- pOut.mat[5] = u.y;
- pOut.mat[9] = u.z;
-
- pOut.mat[2] = -f.x;
- pOut.mat[6] = -f.y;
- pOut.mat[10] = -f.z;
-
- var translate = cc.math.Matrix4.createByTranslation(-pEye.x, -pEye.y, -pEye.z);
- pOut.multiply(translate);
- return pOut;
-};
-
-var tempMatrix = new cc.math.Matrix4(); // an internal matrix
-proto.lookAt = function(eyeVec, centerVec, upVec) {
- var f = new cc.math.Vec3(centerVec), up = new cc.math.Vec3(upVec), mat = this.mat;
- f.subtract(eyeVec);
- f.normalize();
- up.normalize();
-
- var s = new cc.math.Vec3(f);
- s.cross(up);
- s.normalize();
-
- var u = new cc.math.Vec3(s);
- u.cross(f);
- s.normalize();
-
- this.identity();
- mat[0] = s.x;
- mat[4] = s.y;
- mat[8] = s.z;
-
- mat[1] = u.x;
- mat[5] = u.y;
- mat[9] = u.z;
-
- mat[2] = -f.x;
- mat[6] = -f.y;
- mat[10] = -f.z;
-
- tempMatrix = cc.math.Matrix4.createByTranslation(-eyeVec.x, -eyeVec.y, -eyeVec.z, tempMatrix);
- this.multiply(tempMatrix);
- return this;
-};
-
-/**
- * Build a rotation matrix from an axis and an angle. Result is stored in pOut.
- * pOut is returned.
- */
-cc.math.mat4RotationAxisAngle = function (pOut, axis, radians) {
- var rcos = Math.cos(radians), rsin = Math.sin(radians);
-
- var normalizedAxis = new cc.math.Vec3(axis);
- normalizedAxis.normalize();
-
- pOut.mat[0] = rcos + normalizedAxis.x * normalizedAxis.x * (1 - rcos);
- pOut.mat[1] = normalizedAxis.z * rsin + normalizedAxis.y * normalizedAxis.x * (1 - rcos);
- pOut.mat[2] = -normalizedAxis.y * rsin + normalizedAxis.z * normalizedAxis.x * (1 - rcos);
- pOut.mat[3] = 0.0;
-
- pOut.mat[4] = -normalizedAxis.z * rsin + normalizedAxis.x * normalizedAxis.y * (1 - rcos);
- pOut.mat[5] = rcos + normalizedAxis.y * normalizedAxis.y * (1 - rcos);
- pOut.mat[6] = normalizedAxis.x * rsin + normalizedAxis.z * normalizedAxis.y * (1 - rcos);
- pOut.mat[7] = 0.0;
-
- pOut.mat[8] = normalizedAxis.y * rsin + normalizedAxis.x * normalizedAxis.z * (1 - rcos);
- pOut.mat[9] = -normalizedAxis.x * rsin + normalizedAxis.y * normalizedAxis.z * (1 - rcos);
- pOut.mat[10] = rcos + normalizedAxis.z * normalizedAxis.z * (1 - rcos);
- pOut.mat[11] = 0.0;
-
- pOut.mat[12] = 0.0;
- pOut.mat[13] = 0.0;
- pOut.mat[14] = 0.0;
- pOut.mat[15] = 1.0;
-
- return pOut;
-};
-
-/**
- * Build a rotation matrix from an axis and an angle.
- * @param {cc.math.Vec3} axis
- * @param {Number} radians
- * @param {cc.math.Matrix4} [matrix]
- * @returns {cc.math.Matrix4}
- */
-cc.math.Matrix4.createByAxisAndAngle = function(axis, radians, matrix) {
- matrix = matrix || new cc.math.Matrix4();
- var mat = this.mat, rcos = Math.cos(radians), rsin = Math.sin(radians) ;
-
- var normalizedAxis = new cc.math.Vec3(axis);
- normalizedAxis.normalize();
-
- mat[0] = rcos + normalizedAxis.x * normalizedAxis.x * (1 - rcos);
- mat[1] = normalizedAxis.z * rsin + normalizedAxis.y * normalizedAxis.x * (1 - rcos);
- mat[2] = -normalizedAxis.y * rsin + normalizedAxis.z * normalizedAxis.x * (1 - rcos);
- mat[3] = 0.0;
-
- mat[4] = -normalizedAxis.z * rsin + normalizedAxis.x * normalizedAxis.y * (1 - rcos);
- mat[5] = rcos + normalizedAxis.y * normalizedAxis.y * (1 - rcos);
- mat[6] = normalizedAxis.x * rsin + normalizedAxis.z * normalizedAxis.y * (1 - rcos);
- mat[7] = 0.0;
-
- mat[8] = normalizedAxis.y * rsin + normalizedAxis.x * normalizedAxis.z * (1 - rcos);
- mat[9] = -normalizedAxis.x * rsin + normalizedAxis.y * normalizedAxis.z * (1 - rcos);
- mat[10] = rcos + normalizedAxis.z * normalizedAxis.z * (1 - rcos);
- mat[11] = 0.0;
-
- mat[12] = mat[13] = mat[14] = 0.0;
- mat[15] = 1.0;
- return matrix;
-};
-
-/**
- * Extract a 3x3 rotation matrix from the input 4x4 transformation.
- * @returns {cc.math.Matrix3}
- */
-proto.extractRotation = function(){
- var matrix = new cc.math.Matrix3(), mat4 = this.mat, mat3 = matrix.mat;
- mat3[0] = mat4[0];
- mat3[1] = mat4[1];
- mat3[2] = mat4[2];
-
- mat3[3] = mat4[4];
- mat3[4] = mat4[5];
- mat3[5] = mat4[6];
-
- mat3[6] = mat4[8];
- mat3[7] = mat4[9];
- mat3[8] = mat4[10];
- return matrix;
-};
-
-proto.extractPlane = function(planeType) {
- var plane = new cc.math.Plane(), mat = this.mat;
- switch (planeType) {
- case cc.math.Plane.RIGHT:
- plane.a = mat[3] - mat[0];
- plane.b = mat[7] - mat[4];
- plane.c = mat[11] - mat[8];
- plane.d = mat[15] - mat[12];
- break;
- case cc.math.Plane.LEFT:
- plane.a = mat[3] + mat[0];
- plane.b = mat[7] + mat[4];
- plane.c = mat[11] + mat[8];
- plane.d = mat[15] + mat[12];
- break;
- case cc.math.Plane.BOTTOM:
- plane.a = mat[3] + mat[1];
- plane.b = mat[7] + mat[5];
- plane.c = mat[11] + mat[9];
- plane.d = mat[15] + mat[13];
- break;
- case cc.math.Plane.TOP:
- plane.a = mat[3] - mat[1];
- plane.b = mat[7] - mat[5];
- plane.c = mat[11] - mat[9];
- plane.d = mat[15] - mat[13];
- break;
- case cc.math.Plane.FAR:
- plane.a = mat[3] - mat[2];
- plane.b = mat[7] - mat[6];
- plane.c = mat[11] - mat[10];
- plane.d = mat[15] - mat[14];
- break;
- case cc.math.Plane.NEAR:
- plane.a = mat[3] + mat[2];
- plane.b = mat[7] + mat[6];
- plane.c = mat[11] + mat[10];
- plane.d = mat[15] + mat[14];
- break;
- default:
- cc.logID(7904);
- break;
- }
-
- var t = Math.sqrt(plane.a * plane.a + plane.b * plane.b + plane.c * plane.c);
- plane.a /= t;
- plane.b /= t;
- plane.c /= t;
- plane.d /= t;
- return plane;
-};
-
-/**
- * Take the rotation from a 4x4 transformation matrix, and return it as an axis and an angle (in radians)
- * @returns {*|{axis: cc.math.Vec3, angle: number}}
- */
-proto.toAxisAndAngle = function() {
- /*Surely not this easy?*/
- var rotation = this.extractRotation();
- var temp = cc.math.Quaternion.rotationMatrix(rotation);
- return temp.toAxisAndAngle();
-};
diff --git a/cocos2d/kazmath/mat4SIMD.js b/cocos2d/kazmath/mat4SIMD.js
deleted file mode 100644
index 6da1f8c34e..0000000000
--- a/cocos2d/kazmath/mat4SIMD.js
+++ /dev/null
@@ -1,424 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-var proto = cc.math.Matrix4.prototype;
-
-cc.math.mat4InverseSIMD = function (pOut, pM) {
- pOut = pM.inverseSIMD();
- return pOut;
-};
-
-proto.inverseSIMD = function(){
- var inv = new cc.math.Matrix4();
- var src = this.mat;
- var dest = inv.mat;
- var src0, src1, src2, src3;
- var row0, row1, row2, row3;
- var tmp1;
- var minor0, minor1, minor2, minor3;
- var det;
-
- // Load the 4 rows
- var src0 = SIMD.float32x4.load(src, 0);
- var src1 = SIMD.float32x4.load(src, 4);
- var src2 = SIMD.float32x4.load(src, 8);
- var src3 = SIMD.float32x4.load(src, 12);
-
- // Transpose the source matrix. Sort of. Not a true transpose operation
-
- tmp1 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5);
- row1 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5);
- row0 = SIMD.float32x4.shuffle(tmp1, row1, 0, 2, 4, 6);
- row1 = SIMD.float32x4.shuffle(row1, tmp1, 1, 3, 5, 7);
-
- tmp1 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7);
- row3 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7);
- row2 = SIMD.float32x4.shuffle(tmp1, row3, 0, 2, 4, 6);
- row3 = SIMD.float32x4.shuffle(row3, tmp1, 1, 3, 5, 7);
-
- // ----
- tmp1 = SIMD.float32x4.mul(row2, row3);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor0 = SIMD.float32x4.mul(row1, tmp1);
- minor1 = SIMD.float32x4.mul(row0, tmp1);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor0 = SIMD.float32x4.sub(SIMD.float32x4.mul(row1, tmp1), minor0);
- minor1 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor1);
- minor1 = SIMD.float32x4.swizzle(minor1, 2, 3, 0, 1); // 0x4E = 01001110
-
- // ----
- tmp1 = SIMD.float32x4.mul(row1, row2);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor0);
- minor3 = SIMD.float32x4.mul(row0, tmp1);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row3, tmp1));
- minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor3);
- minor3 = SIMD.float32x4.swizzle(minor3, 2, 3, 0, 1); // 0x4E = 01001110
-
- // ----
- tmp1 = SIMD.float32x4.mul(SIMD.float32x4.swizzle(row1, 2, 3, 0, 1), row3); // 0x4E = 01001110
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- row2 = SIMD.float32x4.swizzle(row2, 2, 3, 0, 1); // 0x4E = 01001110
- minor0 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor0);
- minor2 = SIMD.float32x4.mul(row0, tmp1);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor0 = SIMD.float32x4.sub(minor0, SIMD.float32x4.mul(row2, tmp1));
- minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row0, tmp1), minor2);
- minor2 = SIMD.float32x4.swizzle(minor2, 2, 3, 0, 1); // 0x4E = 01001110
-
- // ----
- tmp1 = SIMD.float32x4.mul(row0, row1);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor2);
- minor3 = SIMD.float32x4.sub(SIMD.float32x4.mul(row2, tmp1), minor3);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor2 = SIMD.float32x4.sub(SIMD.float32x4.mul(row3, tmp1), minor2);
- minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row2, tmp1));
-
- // ----
- tmp1 = SIMD.float32x4.mul(row0, row3);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row2, tmp1));
- minor2 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor2);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row2, tmp1), minor1);
- minor2 = SIMD.float32x4.sub(minor2, SIMD.float32x4.mul(row1, tmp1));
-
- // ----
- tmp1 = SIMD.float32x4.mul(row0, row2);
- tmp1 = SIMD.float32x4.swizzle(tmp1, 1, 0, 3, 2); // 0xB1 = 10110001
- minor1 = SIMD.float32x4.add(SIMD.float32x4.mul(row3, tmp1), minor1);
- minor3 = SIMD.float32x4.sub(minor3, SIMD.float32x4.mul(row1, tmp1));
- tmp1 = SIMD.float32x4.swizzle(tmp1, 2, 3, 0, 1); // 0x4E = 01001110
- minor1 = SIMD.float32x4.sub(minor1, SIMD.float32x4.mul(row3, tmp1));
- minor3 = SIMD.float32x4.add(SIMD.float32x4.mul(row1, tmp1), minor3);
-
- // Compute determinant
- det = SIMD.float32x4.mul(row0, minor0);
- det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 2, 3, 0, 1), det); // 0x4E = 01001110
- det = SIMD.float32x4.add(SIMD.float32x4.swizzle(det, 1, 0, 3, 2), det); // 0xB1 = 10110001
- tmp1 = SIMD.float32x4.reciprocalApproximation(det);
- det = SIMD.float32x4.sub(SIMD.float32x4.add(tmp1, tmp1), SIMD.float32x4.mul(det, SIMD.float32x4.mul(tmp1, tmp1)));
- det = SIMD.float32x4.swizzle(det, 0, 0, 0, 0);
-
- // Compute final values by multiplying with 1/det
- minor0 = SIMD.float32x4.mul(det, minor0);
- minor1 = SIMD.float32x4.mul(det, minor1);
- minor2 = SIMD.float32x4.mul(det, minor2);
- minor3 = SIMD.float32x4.mul(det, minor3);
-
- SIMD.float32x4.store(dest, 0, minor0);
- SIMD.float32x4.store(dest, 4, minor1);
- SIMD.float32x4.store(dest, 8, minor2);
- SIMD.float32x4.store(dest, 12, minor3);
-
- return inv;
-};
-
-var identityMatrix = new cc.math.Matrix4().identity();
-proto.isIdentitySIMD = function () {
- var inx4 = SIMD.float32x4.load(this.mat, 0);
- var identityx4 = SIMD.float32x4.load(identityMatrix.mat, 0);
- var ret = SIMD.float32x4.equal(inx4, identityx4);
- if(ret.signMask === 0x00)
- return false;
-
- inx4 = SIMD.float32x4.load(this.mat, 4);
- identityx4 = SIMD.float32x4.load(identityMatrix.mat, 4);
- ret = SIMD.float32x4.equal(inx4, identityx4);
- if(ret.signMask === 0x00)
- return false;
-
- inx4 = SIMD.float32x4.load(this.mat, 8);
- identityx4 = SIMD.float32x4.load(identityMatrix.mat, 8);
- ret = SIMD.float32x4.equal(inx4, identityx4);
- if(ret.signMask === 0x00)
- return false;
-
- inx4 = SIMD.float32x4.load(this.mat, 12);
- identityx4 = SIMD.float32x4.load(identityMatrix.mat, 12);
- ret = SIMD.float32x4.equal(inx4, identityx4);
- if(ret.signMask === 0x00)
- return false;
- return true;
-};
-
-proto.transposeSIMD = function () {
- var outArr = this.mat, inArr = this.mat;
- var src0 = SIMD.float32x4.load(inArr, 0);
- var src1 = SIMD.float32x4.load(inArr, 4);
- var src2 = SIMD.float32x4.load(inArr, 8);
- var src3 = SIMD.float32x4.load(inArr, 12);
- var dst0;
- var dst1;
- var dst2;
- var dst3;
- var tmp01;
- var tmp23;
-
- tmp01 = SIMD.float32x4.shuffle(src0, src1, 0, 1, 4, 5);
- tmp23 = SIMD.float32x4.shuffle(src2, src3, 0, 1, 4, 5);
- dst0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
- dst1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
-
- tmp01 = SIMD.float32x4.shuffle(src0, src1, 2, 3, 6, 7);
- tmp23 = SIMD.float32x4.shuffle(src2, src3, 2, 3, 6, 7);
- dst2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
- dst3 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
-
- SIMD.float32x4.store(outArr, 0, dst0);
- SIMD.float32x4.store(outArr, 4, dst1);
- SIMD.float32x4.store(outArr, 8, dst2);
- SIMD.float32x4.store(outArr, 12, dst3);
- return this;
-};
-
-cc.math.mat4MultiplySIMD = function (pOut, pM1, pM2) {
- pOut = new cc.math.Matrix4(pM1);
- return pOut.multiplySIMD(pM2);
-};
-
-proto.multiplySIMD = function(mat4) {
- var a = this.mat;
- var b = mat4.mat;
- var out = this.mat;
-
- var a0 = SIMD.float32x4.load(a,0);
- var a1 = SIMD.float32x4.load(a,4);
- var a2 = SIMD.float32x4.load(a,8);
- var a3 = SIMD.float32x4.load(a,12);
- var b0 = SIMD.float32x4.load(b, 0);
- SIMD.float32x4.store(out, 0, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3)))));
- var b1 = SIMD.float32x4.load(b, 4);
- SIMD.float32x4.store(out, 4, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3)))));
- var b2 = SIMD.float32x4.load(b, 8);
- SIMD.float32x4.store(out, 8, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3)))));
- var b3 = SIMD.float32x4.load(b, 12);
- SIMD.float32x4.store(out, 12, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3)))));
-
- return this;
-};
-
-cc.math.getMat4MultiplyValueSIMD = function (pM1, pM2) {
- var mat = new cc.math.Matrix4(pM1);
- return mat.multiplySIMD(pM2);
-};
-
-cc.math.mat4AssignSIMD = function (pOut, pIn) {
- if(pOut == pIn) {
- cc.logID(7905);//TODO: ADD SIMD?
- return pOut;
- }
-
- return pOut.assignFromSIMD(pIn);
-};
-
-proto.assignFromSIMD = function (mat4) {
- if(this == mat4) {
- cc.logID(7906);//TODO: ADD SIMD?
- return this;
- }
-
- var outArr = this.mat;
- var inArr = mat4.mat;
-
- SIMD.float32x4.store(outArr, 0, SIMD.float32x4.load(inArr, 0));
- SIMD.float32x4.store(outArr, 4, SIMD.float32x4.load(inArr, 4));
- SIMD.float32x4.store(outArr, 8, SIMD.float32x4.load(inArr, 8));
- SIMD.float32x4.store(outArr, 12, SIMD.float32x4.load(inArr, 12));
-
- return this;
-};
-
-proto.equalsSIMD = function (mat4) {
- if(this === mat4){
- cc.logID(7907);
- return true;
- }
- var m10 = SIMD.float32x4.load(this.mat, 0);
- var m20 = SIMD.float32x4.load(mat4.mat, 0);
-
- var epsilon = SIMD.float32x4.splat(cc.math.EPSILON);
-
- var ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m10, m20)), epsilon);
- if (ret.signMask === 0)
- return false;
-
- var m11 = SIMD.float32x4.load(this.mat, 4);
- var m21 = SIMD.float32x4.load(mat4.mat, 4);
- ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m11, m21)), epsilon);
- if (ret.signMask === 0)
- return false;
-
- var m12 = SIMD.float32x4.load(this.mat, 8);
- var m22 = SIMD.float32x4.load(mat4.mat, 8);
- ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m12, m22)), epsilon);
- if (ret.signMask === 0)
- return false;
-
- var m13 = SIMD.float32x4.load(this.mat, 12);
- var m23 = SIMD.float32x4.load(mat4.mat, 12);
- ret = SIMD.float32x4.lessThanOrEqual(SIMD.float32x4.abs(SIMD.float32x4.sub(m13, m23)), epsilon);
- if (ret.signMask === 0)
- return false;
- return true;
-};
-
-cc.math.mat4LookAtSIMD = function (pOut, pEye, pCenter, pUp) {
- return pOut.lookAtSIMD(pEye, pCenter, pUp);
-};
-
-proto.lookAtSIMD = function(eyeVec, centerVec, upVec) {
- var out = this.mat;
-
- var center = SIMD.float32x4(centerVec.x, centerVec.y, centerVec.z, 0.0);
- var eye = SIMD.float32x4(eyeVec.x, eyeVec.y, eyeVec.z, 0.0);
- var up = SIMD.float32x4(upVec.x, upVec.y, upVec.z, 0.0);
-
- // cc.math.Vec3Subtract(f, pCenter, pEye);
- var f = SIMD.float32x4.sub(center, eye);
- // cc.math.Vec3Normalize(f, f);
- var tmp = SIMD.float32x4.mul(f, f);
- tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
- f = SIMD.float32x4.mul(f, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
-
- // cc.math.Vec3Assign(up, pUp);
- // cc.math.Vec3Normalize(up, up);
- tmp = SIMD.float32x4.mul(up, up);
- tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
- up = SIMD.float32x4.mul(up, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
-
- // cc.math.Vec3Cross(s, f, up);
- var s = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 1, 2, 0, 3), SIMD.float32x4.swizzle(up, 2, 0, 1, 3)),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(f, 2, 0, 1, 3), SIMD.float32x4.swizzle(up, 1, 2, 0, 3)));
- // cc.math.Vec3Normalize(s, s);
- tmp = SIMD.float32x4.mul(s, s);
- tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
- s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
-
- // cc.math.Vec3Cross(u, s, f);
- var u = SIMD.float32x4.sub(SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 1, 2, 0, 3), SIMD.float32x4.swizzle(f, 2, 0, 1, 3)),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(s, 2, 0, 1, 3), SIMD.float32x4.swizzle(f, 1, 2, 0, 3)));
- // cc.math.Vec3Normalize(s, s);
- tmp = SIMD.float32x4.mul(s, s);
- tmp = SIMD.float32x4.add(tmp, SIMD.float32x4.add(SIMD.float32x4.swizzle(tmp, 1, 2, 0, 3), SIMD.float32x4.swizzle(tmp, 2, 0, 1, 3)));
- s = SIMD.float32x4.mul(s, SIMD.float32x4.reciprocalSqrtApproximation(tmp));
-
- //cc.math.mat4Identity(pOut);
- //pOut.mat[0] = s.x;
- //pOut.mat[4] = s.y;
- //pOut.mat[8] = s.z;
- //pOut.mat[1] = u.x;
- //pOut.mat[5] = u.y;
- //pOut.mat[9] = u.z;
- //pOut.mat[2] = -f.x;
- //pOut.mat[6] = -f.y;
- //pOut.mat[10] = -f.z;
- var zero = SIMD.float32x4.splat(0.0);
- f = SIMD.float32x4.neg(f);
- var tmp01 = SIMD.float32x4.shuffle(s, u, 0, 1, 4, 5);
- var tmp23 = SIMD.float32x4.shuffle(f, zero, 0, 1, 4, 5);
- var a0 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
- var a1 = SIMD.float32x4.shuffle(tmp01, tmp23, 1, 3, 5, 7);
-
- var tmp01 = SIMD.float32x4.shuffle(s, u, 2, 3, 6, 7);
- var tmp23 = SIMD.float32x4.shuffle(f, zero, 2, 3, 6, 7);
- var a2 = SIMD.float32x4.shuffle(tmp01, tmp23, 0, 2, 4, 6);
- var a3 = SIMD.float32x4(0.0, 0.0, 0.0, 1.0);
-
- // cc.math.mat4Translation(translate, -pEye.x, -pEye.y, -pEye.z);
- var b0 = SIMD.float32x4(1.0, 0.0, 0.0, 0.0);
- var b1 = SIMD.float32x4(0.0, 1.0, 0.0, 0.0);
- var b2 = SIMD.float32x4(0.0, 0.0, 1.0, 0.0);
- var b3 = SIMD.float32x4.neg(eye);
- b3 = SIMD.float32x4.withW(b3, 1.0);
-
- // cc.math.mat4Multiply(pOut, pOut, translate);
- SIMD.float32x4.store(out, 0, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b0, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b0, 3, 3, 3, 3), a3)))));
- SIMD.float32x4.store(out, 4, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b1, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b1, 3, 3, 3, 3), a3)))));
- SIMD.float32x4.store(out, 8, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b2, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b2, 3, 3, 3, 3), a3)))));
- SIMD.float32x4.store(out, 12, SIMD.float32x4.add(
- SIMD.float32x4.mul(
- SIMD.float32x4.swizzle(b3, 0, 0, 0, 0), a0),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 1, 1, 1, 1), a1),
- SIMD.float32x4.add(
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 2, 2, 2, 2), a2),
- SIMD.float32x4.mul(SIMD.float32x4.swizzle(b3, 3, 3, 3, 3), a3)))));
- return this;
-};
diff --git a/cocos2d/kazmath/plane.js b/cocos2d/kazmath/plane.js
deleted file mode 100644
index 852b5ff6d8..0000000000
--- a/cocos2d/kazmath/plane.js
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-cc.math.Plane = function (a, b, c, d) {
- if (a && b === undefined) {
- this.a = a.a;
- this.b = a.b;
- this.c = a.c;
- this.d = a.d;
- } else {
- this.a = a || 0;
- this.b = b || 0;
- this.c = c || 0;
- this.d = d || 0;
- }
-};
-var proto = cc.math.Plane.prototype;
-
-cc.math.Plane.LEFT = 0;
-
-cc.math.Plane.RIGHT = 1;
-
-cc.math.Plane.BOTTOM = 2;
-
-cc.math.Plane.TOP = 3;
-
-cc.math.Plane.NEAR = 4;
-
-cc.math.Plane.FAR = 5;
-
-cc.math.Plane.POINT_INFRONT_OF_PLANE = 0;
-
-cc.math.Plane.POINT_BEHIND_PLANE = 1;
-
-cc.math.Plane.POINT_ON_PLANE = 2;
-
-proto.dot = function(vec4){ //cc.kmPlaneDot
- return (this.a * vec4.x + this.b * vec4.y + this.c * vec4.z + this.d * vec4.w);
-};
-
-proto.dotCoord = function(vec3) { //=cc.kmPlaneDotCoord
- return (this.a * vec3.x + this.b * vec3.y + this.c * vec3.z + this.d);
-};
-
-proto.dotNormal = function(vec3) { //=cc.kmPlaneDotNormal
- return (this.a * vec3.x + this.b * vec3.y + this.c * vec3.z);
-};
-
-cc.math.Plane.fromPointNormal = function(vec3, normal) { //cc.kmPlaneFromPointNormal
- /*
- Planea = Nx
- Planeb = Ny
- Planec = Nz
- Planed = −N⋅P
- */
- return new cc.math.Plane(normal.x, normal.y, normal.z, -normal.dot(vec3));
-};
-
-cc.math.Plane.fromPoints = function(vec1, vec2, vec3) { //cc.kmPlaneFromPoints
- /*
- v = (B − A) × (C − A)
- n = 1⁄|v| v
- Outa = nx
- Outb = ny
- Outc = nz
- Outd = −n⋅A
- */
- var v1 = new cc.math.Vec3(vec2), v2 = new cc.math.Vec3(vec3), plane = new cc.math.Plane();
- v1.subtract(vec1); //Create the vectors for the 2 sides of the triangle
- v2.subtract(vec1);
- v1.cross(v2); // Use the cross product to get the normal
- v1.normalize(); //Normalize it and assign to pOut.m_N
-
- plane.a = v1.x;
- plane.b = v1.y;
- plane.c = v1.z;
- plane.d = v1.scale(-1.0).dot(vec1);
- return plane;
-};
-
-proto.normalize = function(){ //cc.kmPlaneNormalize
- var n = new cc.math.Vec3(this.a, this.b, this.c), l = 1.0 / n.length(); //Get 1/length
- n.normalize(); //Normalize the vector and assign to pOut
- this.a = n.x;
- this.b = n.y;
- this.c = n.z;
- this.d = this.d * l; //Scale the D value and assign to pOut
- return this;
-};
-
-proto.classifyPoint = function(vec3) {
- // This function will determine if a point is on, in front of, or behind
- // the plane. First we store the dot product of the plane and the point.
- var distance = this.a * vec3.x + this.b * vec3.y + this.c * vec3.z + this.d;
-
- // Simply put if the dot product is greater than 0 then it is infront of it.
- // If it is less than 0 then it is behind it. And if it is 0 then it is on it.
- if(distance > 0.001)
- return cc.math.Plane.POINT_INFRONT_OF_PLANE;
- if(distance < -0.001)
- return cc.math.Plane.POINT_BEHIND_PLANE;
- return cc.math.Plane.POINT_ON_PLANE;
-};
diff --git a/cocos2d/kazmath/quaternion.js b/cocos2d/kazmath/quaternion.js
deleted file mode 100644
index 1035f3fb27..0000000000
--- a/cocos2d/kazmath/quaternion.js
+++ /dev/null
@@ -1,443 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * The Quaternion class
- * @param {Number|cc.math.Quaternion} [x=0]
- * @param {Number} [y=0]
- * @param {Number} [z=0]
- * @param {Number} [w=0]
- *
- */
-cc.math.Quaternion = function (x, y, z, w) {
- if (x && y === undefined) {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- this.w = x.w;
- } else {
- this.x = x || 0;
- this.y = y || 0;
- this.z = z || 0;
- this.w = w || 0;
- }
-};
-var proto = cc.math.Quaternion.prototype;
-
-/**
- * Sets the conjugate of quaternion to self
- * @param {cc.math.Quaternion} quaternion
- */
-proto.conjugate = function (quaternion) { //= cc.kmQuaternionConjugate
- this.x = -quaternion.x;
- this.y = -quaternion.y;
- this.z = -quaternion.z;
- this.w = quaternion.w;
- return this;
-};
-
-/**
- * Returns the dot product of the current quaternion and parameter quaternion
- * @param quaternion
- * @returns {number}
- */
-proto.dot = function(quaternion) { // = cc.kmQuaternionDot
- // A dot B = B dot A = AtBt + AxBx + AyBy + AzBz
- return (this.w * quaternion.w + this.x * quaternion.x + this.y * quaternion.y + this.z * quaternion.z);
-};
-
-/**
- * Returns the exponential of the quaternion, this function doesn't implemented.
- * @returns {cc.math.Quaternion}
- */
-proto.exponential = function(){ //=cc.kmQuaternionExp
- return this;
-};
-
-/**
- * Makes the current quaternion an identity quaternion
- */
-proto.identity = function(){ //=cc.kmQuaternionIdentity
- this.x = 0.0;
- this.y = 0.0;
- this.z = 0.0;
- this.w = 1.0;
- return this;
-};
-
-/**
- * Inverses the value of current Quaternion
- */
-proto.inverse = function(){ //=cc.kmQuaternionInverse
- var len = this.length();
- if (Math.abs(len) > cc.math.EPSILON) {
- this.x = 0.0;
- this.y = 0.0;
- this.z = 0.0;
- this.w = 0.0;
- return this;
- }
-
- ///Get the conjugute and divide by the length
- this.conjugate(this).scale(1.0 / len);
- return this;
-};
-
-/**
- * Returns true if the quaternion is an identity quaternion
- * @returns {boolean}
- */
-proto.isIdentity = function(){ //=cc.kmQuaternionIsIdentity
- return (this.x === 0.0 && this.y === 0.0 && this.z === 0.0 && this.w === 1.0);
-};
-
-/**
- * Returns the length of the quaternion
- * @returns {number}
- */
-proto.length = function() { //=cc.kmQuaternionLength
- return Math.sqrt(this.lengthSq());
-};
-
-/**
- * Returns the length of the quaternion squared (prevents a sqrt)
- * @returns {number}
- */
-proto.lengthSq = function() { //=cc.kmQuaternionLengthSq
- return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
-};
-
-/**
- * Uses current quaternion multiplies other quaternion.
- * @param {cc.math.Quaternion} quaternion
- * @returns {cc.math.Quaternion}
- */
-proto.multiply = function(quaternion) { //cc.kmQuaternionMultiply
- var x = this.x, y = this.y, z = this.z, w = this.w;
- this.w = w * quaternion.w - x * quaternion.x - y * quaternion.y - z * quaternion.z;
- this.x = w * quaternion.x + x * quaternion.w + y * quaternion.z - z * quaternion.y;
- this.y = w * quaternion.y + y * quaternion.w + z * quaternion.x - x * quaternion.z;
- this.z = w * quaternion.z + z * quaternion.w + x * quaternion.y - y * quaternion.x;
- return this;
-};
-
-/**
- * Normalizes a quaternion
- * @returns {cc.math.Quaternion}
- */
-proto.normalize = function(){ //=cc.kmQuaternionNormalize
- var length = this.length();
- if (Math.abs(length) <= cc.math.EPSILON)
- throw new Error(cc._getError(7909));
- this.scale(1.0 / length);
- return this;
-};
-
-/**
- * Rotates a quaternion around an axis and an angle
- * @param {cc.math.Vec3} axis
- * @param {Number} angle
- */
-proto.rotationAxis = function(axis, angle){ //cc.kmQuaternionRotationAxis
- var rad = angle * 0.5, scale = Math.sin(rad);
- this.w = Math.cos(rad);
- this.x = axis.x * scale;
- this.y = axis.y * scale;
- this.z = axis.z * scale;
- return this;
-};
-
-/**
- * Creates a quaternion from a rotation matrix
- * @param mat3
- * @returns {*}
- */
-cc.math.Quaternion.rotationMatrix = function (mat3) { //cc.kmQuaternionRotationMatrix
- if (!mat3)
- return null;
-
- var x, y, z, w;
- var m4x4 = [], mat = mat3.mat, scale = 0.0;
-
- /* 0 3 6
- 1 4 7
- 2 5 8
-
- 0 1 2 3
- 4 5 6 7
- 8 9 10 11
- 12 13 14 15*/
- m4x4[0] = mat[0];
- m4x4[1] = mat[3];
- m4x4[2] = mat[6];
- m4x4[4] = mat[1];
- m4x4[5] = mat[4];
- m4x4[6] = mat[7];
- m4x4[8] = mat[2];
- m4x4[9] = mat[5];
- m4x4[10] = mat[8];
- m4x4[15] = 1;
- var pMatrix = m4x4[0];
-
- var diagonal = pMatrix[0] + pMatrix[5] + pMatrix[10] + 1;
- if (diagonal > cc.math.EPSILON) {
- // Calculate the scale of the diagonal
- scale = Math.sqrt(diagonal) * 2;
-
- // Calculate the x, y, x and w of the quaternion through the respective equation
- x = ( pMatrix[9] - pMatrix[6] ) / scale;
- y = ( pMatrix[2] - pMatrix[8] ) / scale;
- z = ( pMatrix[4] - pMatrix[1] ) / scale;
- w = 0.25 * scale;
- } else {
- // If the first element of the diagonal is the greatest value
- if (pMatrix[0] > pMatrix[5] && pMatrix[0] > pMatrix[10]) {
- // Find the scale according to the first element, and double that value
- scale = Math.sqrt(1.0 + pMatrix[0] - pMatrix[5] - pMatrix[10]) * 2.0;
-
- // Calculate the x, y, x and w of the quaternion through the respective equation
- x = 0.25 * scale;
- y = (pMatrix[4] + pMatrix[1] ) / scale;
- z = (pMatrix[2] + pMatrix[8] ) / scale;
- w = (pMatrix[9] - pMatrix[6] ) / scale;
- }
- // Else if the second element of the diagonal is the greatest value
- else if (pMatrix[5] > pMatrix[10]) {
- // Find the scale according to the second element, and double that value
- scale = Math.sqrt(1.0 + pMatrix[5] - pMatrix[0] - pMatrix[10]) * 2.0;
-
- // Calculate the x, y, x and w of the quaternion through the respective equation
- x = (pMatrix[4] + pMatrix[1] ) / scale;
- y = 0.25 * scale;
- z = (pMatrix[9] + pMatrix[6] ) / scale;
- w = (pMatrix[2] - pMatrix[8] ) / scale;
- } else {
- // Else the third element of the diagonal is the greatest value
-
- // Find the scale according to the third element, and double that value
- scale = Math.sqrt(1.0 + pMatrix[10] - pMatrix[0] - pMatrix[5]) * 2.0;
-
- // Calculate the x, y, x and w of the quaternion through the respective equation
- x = (pMatrix[2] + pMatrix[8] ) / scale;
- y = (pMatrix[9] + pMatrix[6] ) / scale;
- z = 0.25 * scale;
- w = (pMatrix[4] - pMatrix[1] ) / scale;
- }
- }
- return new cc.math.Quaternion(x, y, z, w);
-};
-
-/**
- * Create a quaternion from yaw, pitch and roll
- * @param yaw
- * @param pitch
- * @param roll
- * @returns {cc.math.Quaternion}
- */
-cc.math.Quaternion.rotationYawPitchRoll = function (yaw, pitch, roll) { //cc.kmQuaternionRotationYawPitchRoll
- var ex, ey, ez; // temp half euler angles
- var cr, cp, cy, sr, sp, sy, cpcy, spsy; // temp vars in roll,pitch yaw
-
- ex = cc.degreesToRadians(pitch) / 2.0; // convert to rads and half them
- ey = cc.degreesToRadians(yaw) / 2.0;
- ez = cc.degreesToRadians(roll) / 2.0;
-
- cr = Math.cos(ex);
- cp = Math.cos(ey);
- cy = Math.cos(ez);
-
- sr = Math.sin(ex);
- sp = Math.sin(ey);
- sy = Math.sin(ez);
-
- cpcy = cp * cy;
- spsy = sp * sy;
-
- var ret = new cc.math.Quaternion();
- ret.w = cr * cpcy + sr * spsy;
- ret.x = sr * cpcy - cr * spsy;
- ret.y = cr * sp * cy + sr * cp * sy;
- ret.z = cr * cp * sy - sr * sp * cy;
- ret.normalize();
- return ret;
-};
-
-/**
- * Interpolate with other quaternions
- * @param {cc.math.Quaternion} quaternion
- * @param {Number} t
- * @returns {cc.math.Quaternion}
- */
-proto.slerp = function(quaternion, t) { //=cc.kmQuaternionSlerp
- if (this.x === quaternion.x && this.y === quaternion.y && this.z === quaternion.z && this.w === quaternion.w) {
- return this;
- }
- var ct = this.dot(quaternion), theta = Math.acos(ct), st = Math.sqrt(1.0 - cc.math.square(ct));
- var stt = Math.sin(t * theta) / st, somt = Math.sin((1.0 - t) * theta) / st;
- var temp2 = new cc.math.Quaternion(quaternion);
- this.scale(somt);
- temp2.scale(stt);
- this.add(temp2);
- return this;
-};
-
-/**
- * Get the axis and angle of rotation from a quaternion
- * @returns {{axis: cc.math.Vec3, angle: number}}
- */
-proto.toAxisAndAngle = function(){ //=cc.kmQuaternionToAxisAngle
- var tempAngle; // temp angle
- var scale; // temp vars
- var retAngle, retAxis = new cc.math.Vec3();
-
- tempAngle = Math.acos(this.w);
- scale = Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z));
-
- if (((scale > -cc.math.EPSILON) && scale < cc.math.EPSILON)
- || (scale < 2 * Math.PI + cc.math.EPSILON && scale > 2 * Math.PI - cc.math.EPSILON)) { // angle is 0 or 360 so just simply set axis to 0,0,1 with angle 0
- retAngle = 0.0;
- retAxis.x = 0.0;
- retAxis.y = 0.0;
- retAxis.z = 1.0;
- } else {
- retAngle = tempAngle * 2.0; // angle in radians
- retAxis.x = this.x / scale;
- retAxis.y = this.y / scale;
- retAxis.z = this.z / scale;
- retAxis.normalize();
- }
- return {axis: retAxis, angle: retAngle};
-};
-
-/**
- * Scale a quaternion
- * @param {Number} scale
- */
-proto.scale = function(scale) { //cc.kmQuaternionScale
- this.x *= scale;
- this.y *= scale;
- this.z *= scale;
- this.w *= scale;
- return this;
-};
-
-/**
- * Assign current quaternion value from a quaternion.
- * @param {cc.math.Quaternion} quaternion
- * @returns {cc.math.Quaternion} current quaternion
- */
-proto.assignFrom = function(quaternion){ //=cc.kmQuaternionAssign
- this.x = quaternion.x;
- this.y = quaternion.y;
- this.z = quaternion.z;
- this.w = quaternion.w;
- return this;
-};
-
-/**
- * Adds other quaternion
- * @param {cc.math.Quaternion} quaternion
- * @returns {cc.math.Quaternion}
- */
-proto.add = function(quaternion) { //cc.kmQuaternionAdd
- this.x += quaternion.x;
- this.y += quaternion.y;
- this.z += quaternion.z;
- this.w += quaternion.w;
- return this;
-};
-
-/**
- *
- * Adapted from the OGRE engine!
- * Gets the shortest arc quaternion to rotate this vector to the destination vector.
- * @remarks
- * If you call this with a destination vector that is close to the inverse
- * of this vector, we will rotate 180 degrees around the 'fallbackAxis'
- * (if specified, or a generated axis if not) since in this case ANY axis of rotation is valid.
- *
- * @param {cc.math.Vec3} vec1
- * @param {cc.math.Vec3} vec2
- * @param {cc.math.Vec3} fallback
- * @returns {cc.math.Quaternion}
- */
-cc.math.Quaternion.rotationBetweenVec3 = function(vec1, vec2, fallback) { //cc.kmQuaternionRotationBetweenVec3
- var v1 = new cc.math.Vec3(vec1), v2 = new cc.math.Vec3(vec2);
- v1.normalize();
- v2.normalize();
- var a = v1.dot(v2), quaternion = new cc.math.Quaternion();
-
- if (a >= 1.0) {
- quaternion.identity();
- return quaternion;
- }
-
- if (a < (1e-6 - 1.0)) {
- if (Math.abs(fallback.lengthSq()) < cc.math.EPSILON) {
- quaternion.rotationAxis(fallback, Math.PI);
- } else {
- var axis = new cc.math.Vec3(1.0, 0.0, 0.0);
- axis.cross(vec1);
-
- //If axis is zero
- if (Math.abs(axis.lengthSq()) < cc.math.EPSILON) {
- axis.fill(0.0, 1.0, 0.0);
- axis.cross(vec1);
- }
- axis.normalize();
- quaternion.rotationAxis(axis, Math.PI);
- }
- } else {
- var s = Math.sqrt((1 + a) * 2), invs = 1 / s;
- v1.cross(v2);
- quaternion.x = v1.x * invs;
- quaternion.y = v1.y * invs;
- quaternion.z = v1.z * invs;
- quaternion.w = s * 0.5;
- quaternion.normalize();
- }
- return quaternion;
-};
-
-/**
- * Current quaternion multiplies a vec3
- * @param {cc.math.Vec3} vec
- * @returns {cc.math.Vec3}
- */
-proto.multiplyVec3 = function(vec){ //=cc.kmQuaternionMultiplyVec3
- var x = this.x, y = this.y, z = this.z, retVec = new cc.math.Vec3(vec);
- var uv = new cc.math.Vec3(x, y, z), uuv = new cc.math.Vec3(x, y, z);
- uv.cross(vec);
- uuv.cross(uv);
- uv.scale((2.0 * q.w));
- uuv.scale(2.0);
-
- retVec.add(uv);
- retVec.add(uuv);
- return retVec;
-};
diff --git a/cocos2d/kazmath/ray2.js b/cocos2d/kazmath/ray2.js
deleted file mode 100644
index 1c39326214..0000000000
--- a/cocos2d/kazmath/ray2.js
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-cc.math.Ray2 = function (start, dir) { // = cc.kmRay2
- this.start = start || new cc.math.Vec2();
- this.dir = dir || new cc.math.Vec2();
-};
-
-cc.math.Ray2.prototype.fill = function (px, py, vx, vy) { // = cc.kmRay2Fill
- this.start.x = px;
- this.start.y = py;
- this.dir.x = vx;
- this.dir.y = vy;
-};
-
-cc.math.Ray2.prototype.intersectLineSegment = function (p1, p2, intersection) { // = cc.kmRay2IntersectLineSegment
- var x1 = this.start.x, y1 = this.start.y;
- var x2 = this.start.x + this.dir.x, y2 = this.start.y + this.dir.y;
- var x3 = p1.x, y3 = p1.y;
- var x4 = p2.x, y4 = p2.y;
-
- var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
- var ua, x, y;
- //If denom is zero, the lines are parallel
- if (denom > -cc.math.EPSILON && denom < cc.math.EPSILON)
- return false;
-
- ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denom;
- //var ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denom;
-
- x = x1 + ua * (x2 - x1);
- y = y1 + ua * (y2 - y1);
-
- if (x < Math.min(p1.x, p2.x) - cc.math.EPSILON ||
- x > Math.max(p1.x, p2.x) + cc.math.EPSILON ||
- y < Math.min(p1.y, p2.y) - cc.math.EPSILON ||
- y > Math.max(p1.y, p2.y) + cc.math.EPSILON) {
- //Outside of line
- //printf("Outside of line, %f %f (%f %f)(%f, %f)\n", x, y, p1.x, p1.y, p2.x, p2.y);
- return false;
- }
-
- if (x < Math.min(x1, x2) - cc.math.EPSILON ||
- x > Math.max(x1, x2) + cc.math.EPSILON ||
- y < Math.min(y1, y2) - cc.math.EPSILON ||
- y > Math.max(y1, y2) + cc.math.EPSILON) {
- //printf("Outside of ray, %f %f (%f %f)(%f, %f)\n", x, y, x1, y1, x2, y2);
- return false;
- }
-
- intersection.x = x;
- intersection.y = y;
- return true;
-};
-
-function calculate_line_normal(p1, p2, normalOut){
- var tmp = new cc.math.Vec2(p2);
- tmp.subtract(p1);
-
- normalOut.x = -tmp.y;
- normalOut.y = tmp.x;
- normalOut.normalize();
- //TODO: should check that the normal is pointing out of the triangle
-}
-
-cc.math.Ray2.prototype.intersectTriangle = function(p1, p2, p3, intersection, normal_out){
- var intersect = new cc.math.Vec2(), final_intersect = new cc.math.Vec2();
- var normal = new cc.math.Vec2(), distance = 10000.0, intersected = false;
- var this_distance;
-
- if(this.intersectLineSegment(p1, p2, intersect)) {
- intersected = true;
- this_distance = intersect.subtract(this.start).length();
- if(this_distance < distance) {
- final_intersect.x = intersect.x;
- final_intersect.y = intersect.y;
- distance = this_distance;
- calculate_line_normal(p1, p2, normal);
- }
- }
-
- if(this.intersectLineSegment(p2, p3, intersect)) {
- intersected = true;
- this_distance = intersect.subtract(this.start).length();
- if(this_distance < distance) {
- final_intersect.x = intersect.x;
- final_intersect.y = intersect.y;
- distance = this_distance;
- calculate_line_normal(p2, p3, normal);
- }
- }
-
- if(this.intersectLineSegment(p3, p1, intersect)) {
- intersected = true;
- this_distance = intersect.subtract(this.start).length();
- if(this_distance < distance) {
- final_intersect.x = intersect.x;
- final_intersect.y = intersect.y;
- distance = this_distance;
- calculate_line_normal(p3, p1, normal);
- }
- }
-
- if(intersected) {
- intersection.x = final_intersect.x;
- intersection.y = final_intersect.y;
- if(normal_out) {
- normal_out.x = normal.x;
- normal_out.y = normal.y;
- }
- }
- return intersected;
-};
diff --git a/cocos2d/kazmath/simd_benchmark/base.js b/cocos2d/kazmath/simd_benchmark/base.js
deleted file mode 100644
index 7bbb84533e..0000000000
--- a/cocos2d/kazmath/simd_benchmark/base.js
+++ /dev/null
@@ -1,139 +0,0 @@
-// SIMD Kernel Benchmark Harness
-// Author: Peter Jensen
-
-function Benchmark (config) {
- this.config = config;
- this.initOk = true; // Initialize all properties used on a Benchmark object
- this.cleanupOk = true;
- this.useAutoIterations = true;
- this.autoIterations = 0;
- this.actualIterations = 0;
- this.simdTime = 0;
- this.nonSimdTime = 0;
-}
-
-function Benchmarks () {
- this.benchmarks = [];
-}
-
-Benchmarks.prototype.add = function (benchmark) {
- this.benchmarks.push (benchmark);
- return this.benchmarks.length - 1;
-};
-
-Benchmarks.prototype.runOne = function (benchmark) {
-
- function timeKernel(kernel, iterations) {
- var start, stop;
- start = Date.now();
- kernel(iterations);
- stop = Date.now();
- return stop - start;
- }
-
- function computeIterations() {
- var desiredRuntime = 1000; // milliseconds for longest running kernel
- var testIterations = 10; // iterations used to determine time for desiredRuntime
-
- // Make the slowest kernel run for at least 500ms
- var simdTime = timeKernel(benchmark.config.kernelSimd, testIterations);
- var nonSimdTime = timeKernel(benchmark.config.kernelNonSimd, testIterations);
- var maxTime = simdTime > nonSimdTime ? simdTime : nonSimdTime;
- while (maxTime < 500) {
- testIterations *= 2;
- simdTime = timeKernel(benchmark.config.kernelSimd, testIterations);
- nonSimdTime = timeKernel(benchmark.config.kernelNonSimd, testIterations);
- maxTime = simdTime > nonSimdTime ? simdTime : nonSimdTime;
- }
- maxTime = simdTime > nonSimdTime ? simdTime : nonSimdTime;
-
- // Compute iteration count for 1 second run of slowest kernel
- var iterations = Math.ceil(desiredRuntime * testIterations / maxTime);
- return iterations;
- }
-
- // Initialize the kernels and check the correctness status
- if (!benchmark.config.kernelInit()) {
- benchmark.initOk = false;
- return false;
- }
-
- // Determine how many iterations to use.
- if (benchmark.useAutoIterations) {
- benchmark.autoIterations = computeIterations();
- benchmark.actualIterations = benchmark.autoIterations;
- }
- else {
- benchmark.actualIterations = benchmark.config.kernelIterations;
- }
-
- // Run the SIMD kernel
- benchmark.simdTime = timeKernel(benchmark.config.kernelSimd, benchmark.actualIterations);
-
- // Run the non-SIMD kernel
- benchmark.nonSimdTime = timeKernel(benchmark.config.kernelNonSimd, benchmark.actualIterations);
-
- // Do the final sanity check
- if (!benchmark.config.kernelCleanup()) {
- benchmark.cleanupOk = false;
- return false;
- }
-
- return true;
-};
-
-Benchmarks.prototype.report = function (benchmark, outputFunctions) {
-
- function fillRight(str, width) {
- str += ""; // make sure it's a string
- while (str.length < width) {
- str += " ";
- }
- return str;
- }
-
- function fillLeft(str, width) {
- str += ""; // make sure it's a string
- while (str.length < width) {
- str = " " + str;
- }
- return str;
- }
-
- if (!benchmark.initOk) {
- outputFunctions.notifyError(fillRight(benchmark.config.kernelName + ": ", 23) + "FAILED INIT");
- return;
- }
- if (!benchmark.cleanupOk) {
- outputFunctions.notifyError(fillRight(benchmark.config.kernelName + ": ", 23) + "FAILED CLEANUP");
- return;
- }
-
- var ratio = benchmark.nonSimdTime / benchmark.simdTime;
- ratio = ratio.toFixed(2);
- outputFunctions.notifyResult(
- fillRight(benchmark.config.kernelName + ": ", 23) +
- "Iterations(" + fillLeft(benchmark.actualIterations, 10) + ")" +
- ", SIMD(" + fillLeft(benchmark.simdTime + "ms)", 8) +
- ", Non-SIMD(" + fillLeft(benchmark.nonSimdTime + "ms)", 8) +
- ", Speedup(" + ratio + ")");
- outputFunctions.timeData.labels.push(benchmark.config.kernelName);
- outputFunctions.timeData.datasets[0].data.push(benchmark.simdTime);
- outputFunctions.timeData.datasets[1].data.push(benchmark.nonSimdTime);
- outputFunctions.speedupData.labels.push(benchmark.config.kernelName);
- outputFunctions.speedupData.datasets[0].data.push(ratio);
-};
-
-Benchmarks.prototype.runAll = function (outputFunctions, useAutoIterations) {
- if (typeof useAutoIterations === "undefined") {
- useAutoIterations = false;
- }
- for (var i = 0, n = this.benchmarks.length; i < n; ++i) {
- var benchmark = this.benchmarks[i];
- benchmark.useAutoIterations = useAutoIterations;
- this.runOne(benchmark);
- this.report(benchmark, outputFunctions);
- }
-};
-
-var benchmarks = new Benchmarks ();
diff --git a/cocos2d/kazmath/simd_benchmark/index.html b/cocos2d/kazmath/simd_benchmark/index.html
deleted file mode 100644
index 5b115d91c9..0000000000
--- a/cocos2d/kazmath/simd_benchmark/index.html
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
- Kazmath SIMD benchmarks
-
-
-
-
Running benchmarks...
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/cocos2d/kazmath/simd_benchmark/kernel-template.js b/cocos2d/kazmath/simd_benchmark/kernel-template.js
deleted file mode 100644
index d7c377585d..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kernel-template.js
+++ /dev/null
@@ -1,64 +0,0 @@
-// Kernel template
-// Author: Peter Jensen
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "Test",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 100000000
- };
-
- // Hook up to the harness
- benchmarks.add (new Benchmark (kernelConfig));
-
- // Kernel Initializer
- function init () {
- // Do initial sanity check and initialize data for the kernels.
- // The sanity check should verify that the simd and nonSimd results
- // are the same.
- // It is recommended to do minimal object creation in the kernels
- // themselves. If global data needs to be initialized, here would
- // be the place to do it.
- // If the sanity checks fails the kernels will not be executed
- // Returns:
- // true: First run (unoptimized) of the kernels passed
- // false: First run (unoptimized) of the kernels failed
- return simd (1) === nonSimd (1);
- }
-
- // Kernel Cleanup
- function cleanup () {
- // Do final sanity check and perform cleanup.
- // This function is called when all the kernel iterations have been
- // executed, so they should be in their final optimized version. The
- // sanity check done during initialization will probably be of the
- // initial unoptimized version.
- // Returns:
- // true: Last run (optimized) of the kernels passed
- // false: last run (optimized) of the kernels failed
- return simd (1) === nonSimd (1);
- }
-
- // SIMD version of the kernel
- function simd (n) {
- var s = 0;
- for (var i = 0; i < n; ++i) {
- s += i;
- }
- return s;
- }
-
- // Non SIMD version of the kernel
- function nonSimd (n) {
- var s = 0;
- for (var i = 0; i < n; ++i) {
- s += i;
- }
- return s;
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js b/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js
deleted file mode 100644
index 8d7c48ba60..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kmMat4AreEqual.js
+++ /dev/null
@@ -1,77 +0,0 @@
-// kmMat4AreEqual
-
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "kmMat4AreEqual",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 10000
- };
-
- // Hook up to the harness
- benchmarks.add(new Benchmark(kernelConfig));
-
- // Benchmark data, initialization and kernel functions
- var T1 = new cc.math.Matrix4();
- var T2 = new cc.math.Matrix4();
- var T1x4 = new cc.math.Matrix4();
- var T2x4 = new cc.math.Matrix4();
- var areEqual, areEqualSIMD;
-
- function equals(A, B) {
- for (var i = 0; i < 16; ++i) {
- if (A[i] != B[i])
- return false;
- }
- return true;
- }
-
- function init() {
- T1.mat[0] = 1.0;
- T1.mat[5] = 1.0;
- T1.mat[10] = 1.0;
- T1.mat[15] = 1.0;
-
- T2.mat[0] = 1.0;
- T2.mat[5] = 1.0;
- T2.mat[10] = 1.0;
- T2.mat[15] = 1.0;
-
- T1x4.mat[0] = 1.0;
- T1x4.mat[5] = 1.0;
- T1x4.mat[10] = 1.0;
- T1x4.mat[15] = 1.0;
-
- T2x4.mat[0] = 1.0;
- T2x4.mat[5] = 1.0;
- T2x4.mat[10] = 1.0;
- T2x4.mat[15] = 1.0;
-
- nonSimd(1);
- simd(1);
-
- return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat) && (areEqual === areEqualSIMD);
-
- }
-
- function cleanup() {
- return init(); // Sanity checking before and after are the same
- }
-
- function nonSimd(n) {
- for (var i = 0; i < n; i++) {
- areEqual = T1.equals(T2);
- }
- }
-
- function simd(n) {
- for (var i = 0; i < n; i++) {
- areEqualSIMD = T1x4.equalsSIMD(T2x4);
- }
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js b/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js
deleted file mode 100644
index 47b6bb7f1f..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kmMat4Assign.js
+++ /dev/null
@@ -1,68 +0,0 @@
-// kmMat4Assign
-
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "kmMat4Assign",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 10000
- };
-
- // Hook up to the harness
- benchmarks.add(new Benchmark(kernelConfig));
-
- // Benchmark data, initialization and kernel functions
- var T1 = new cc.math.Matrix4();
- var T2 = new cc.math.Matrix4();
- var T1x4 = new cc.math.Matrix4();
- var T2x4 = new cc.math.Matrix4();
-
- function equals(A, B) {
- for (var i = 0; i < 16; ++i) {
- if (A[i] != B[i])
- return false;
- }
- return true;
- }
-
- function init() {
- T1.mat[0] = 1.0;
- T1.mat[5] = 1.0;
- T1.mat[10] = 1.0;
- T1.mat[15] = 1.0;
-
- T1x4.mat[0] = 1.0;
- T1x4.mat[5] = 1.0;
- T1x4.mat[10] = 1.0;
- T1x4.mat[15] = 1.0;
-
- nonSimd(1);
- simd(1);
-
- return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat);
-
- }
-
- function cleanup() {
- return init(); // Sanity checking before and after are the same
- }
-
- function nonSimd(n) {
- for (var i = 0; i < n; i++) {
- //cc.math.mat4Assign(T2, T1);
- T2.assignFrom(T1);
- }
- }
-
- function simd(n) {
- for (var i = 0; i < n; i++) {
- //cc.math.mat4AssignSIMD(T2x4, T1x4);
- T2x4.assignFromSIMD(T1x4);
- }
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js b/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js
deleted file mode 100644
index ca2723d565..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kmMat4Inverse.js
+++ /dev/null
@@ -1,116 +0,0 @@
-// kmMat4Inverse
-
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "kmMat4Inverse",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 10000
- };
-
- // Hook up to the harness
- benchmarks.add(new Benchmark(kernelConfig));
-
- // Benchmark data, initialization and kernel functions
- var src = new cc.math.Matrix4();
- var dst = new cc.math.Matrix4();
- var srcx4 = new cc.math.Matrix4();
- var dstx4 = new cc.math.Matrix4();
- var ident = new Float32Array(
- [1,0,0,0,
- 0,1,0,0,
- 0,0,1,0,
- 0,0,0,1]);
-
- function equals(A, B) {
- for (var i = 0; i < 16; ++i) {
- if (Math.abs (A[i] - B[i]) > 5)
- return false;
- }
- return true;
- }
-
- function initMatrix(matrix) {
- // These values were chosen somewhat randomly, but they will at least yield a solution.
- matrix [0] = 0; matrix[1] = 1; matrix[2] = 2; matrix[3] = 3;
- matrix [4] = -1; matrix[5] = -2; matrix[6] = -3; matrix[7] = -4;
- matrix [8] = 0; matrix[9] = 0; matrix[10] = 2; matrix[11] = 3;
- matrix [12] = -1; matrix[13] = -2; matrix[14] = 0; matrix[15] = -4;
- }
-
- function mulMatrix(dst, op1, op2) {
- for (var r = 0; r < 4; ++r) {
- for (var c = 0; c < 4; ++c) {
- var ri = 4*r;
- dst[ri + c] = op1[ri]*op2[c] + op1[ri+1]*op2[c+4] + op1[ri+2]*op2[c+8] + op1[ri+3]*op2[c+12];
- }
- }
- }
-
- function printMatrix(matrix, str) {
- print('--------matrix ' + str + '----------');
- for (var r = 0; r < 4; ++r) {
- var str = "";
- var ri = r*4;
- for (var c = 0; c < 4; ++c) {
- var value = matrix[ri + c];
- str += " " + value.toFixed(2);
- }
- print(str);
- }
- }
-
- function checkMatrix(src, dst) {
- // when multiplied with the src matrix it should yield the identity matrix
- var tmp = new Float32Array(16);
- mulMatrix(tmp, src, dst);
- for (var i = 0; i < 16; ++i) {
- if (Math.abs (tmp[i] - ident[i]) > 0.00001) {
- return false;
- }
- }
- return true;
- }
-
- function init() {
- initMatrix(src.mat);
- // printMatrix(src);
- nonSimd(1);
- // printMatrix(dst);
- if (!checkMatrix(src.mat, dst.mat)) {
- return false;
- }
-
- initMatrix(srcx4.mat);
- simd(1);
- // printMatrix(dst);
- if (!checkMatrix(srcx4.mat, dstx4.mat)) {
- return false;
- }
-
- return true;
- }
-
- function cleanup() {
- return init(); // Sanity checking before and after are the same
- }
-
- function nonSimd(n) {
- for (var i = 0; i < n; i++) {
- //cc.math.mat4Inverse(dst, src);
- dst = src.inverse();
- }
- }
-
- function simd(n) {
- for (var i = 0; i < n; i++) {
- //cc.math.mat4InverseSIMD(dstx4, srcx4);
- dstx4 = srcx4.inverseSIMD();
- }
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js b/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js
deleted file mode 100644
index 703fad5303..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kmMat4IsIdentity.js
+++ /dev/null
@@ -1,65 +0,0 @@
-// kmMat4IsIdentity
-
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "kmMat4IsIdentity",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 10000
- };
-
- // Hook up to the harness
- benchmarks.add(new Benchmark(kernelConfig));
-
- // Benchmark data, initialization and kernel functions
- var T1 = new cc.math.Matrix4();
- var T1x4 = new cc.math.Matrix4();
- var isIdentity, isIdentitySIMD;
-
- function equals(A, B) {
- for (var i = 0; i < 16; ++i) {
- if (A[i] != B[i])
- return false;
- }
- return true;
- }
-
- function init() {
- T1.mat[0] = 1.0;
- T1.mat[5] = 1.0;
- T1.mat[10] = 1.0;
- T1.mat[15] = 1.0;
-
- T1x4.mat[0] = 1.0;
- T1x4.mat[5] = 1.0;
- T1x4.mat[10] = 1.0;
- T1x4.mat[15] = 1.0;
-
- nonSimd(1);
- simd(1);
-
- return equals(T1.mat, T1x4.mat) && (isIdentity === isIdentitySIMD);
-
- }
-
- function cleanup() {
- return init(); // Sanity checking before and after are the same
- }
-
- function nonSimd(n) {
- for (var i = 0; i < n; i++) {
- isIdentity = T1.isIdentity();
- }
- }
-
- function simd(n) {
- for (var i = 0; i < n; i++) {
- isIdentitySIMD = T1x4.isIdentitySIMD();
- }
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js b/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js
deleted file mode 100644
index d214bd6edb..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kmMat4LookAt.js
+++ /dev/null
@@ -1,94 +0,0 @@
-// kmMat4LookAt
-
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "kmMat4LookAt",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 10000
- };
-
- // Hook up to the harness
- benchmarks.add(new Benchmark(kernelConfig));
-
- // Benchmark data, initialization and kernel functions
- var eye = new cc.math.Vec3(), center = new cc.math.Vec3(), up = new cc.math.Vec3();
- var T1 = new cc.math.Matrix4();
- var eye1 = new cc.math.Vec3(), center1 = new cc.math.Vec3(), up1 = new cc.math.Vec3();
- var T1x4 = new cc.math.Matrix4();
-
- function printMatrix(matrix) {
- print('--------matrix----------');
- for (var r = 0; r < 4; ++r) {
- var str = "";
- var ri = r*4;
- for (var c = 0; c < 4; ++c) {
- var value = matrix[ri + c];
- str += " " + value.toFixed(2);
- }
- print(str);
- }
- }
-
- function equals(A, B) {
- for (var i = 0; i < 16; ++i) {
- if (Math.abs (A[i] - B[i]) > 0.001) {
- return false;
- }
- }
- return true;
- }
-
- function init() {
-
- eye.fill(0, 1, 2);
- center.fill(2, 1, 0);
- up.fill(1, 1, 1);
-
- eye1.fill(0, 1, 2);
- center1.fill(2, 1, 0);
- up1.fill(1, 1, 1);
- /*
- eye1.data[0] = 0;
- eye1.data[1] = 1;
- eye1.data[2] = 2;
-
- center1.data[0] = 2;
- center1.data[1] = 1;
- center1.data[2] = 0;
-
- up1.data[0] = 1;
- up1.data[1] = 1;
- up1.data[2] = 1;
- */
- nonSimd(1);
- //printMatrix(T1.mat);
- simd(1);
- //printMatrix(T1x4.mat);
-
- return equals(T1.mat, T1x4.mat);
- }
-
- function cleanup() {
- return init(); // Sanity checking before and after are the same
- }
-
- function nonSimd(n) {
- for (var i = 0; i < n; i++) {
- //cc.math.mat4LookAt(T1, eye, center, up);
- T1.lookAt(eye, center, up);
- }
- }
-
- function simd(n) {
- for (var i = 0; i < n; i++) {
- //cc.math.mat4LookAtSIMD(T1x4, eye1, center1, up1);
- T1x4.lookAtSIMD(eye1, center1, up1);
- }
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js b/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js
deleted file mode 100644
index 5082d921df..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kmMat4Multiply.js
+++ /dev/null
@@ -1,74 +0,0 @@
-// kmMat4Multiply
-
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "kmMat4Multiply",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 10000
- };
-
- // Hook up to the harness
- benchmarks.add(new Benchmark(kernelConfig));
-
- // Benchmark data, initialization and kernel functions
- var T1 = new cc.math.Matrix4();
- var T2 = new cc.math.Matrix4();
- var T1x4 = new cc.math.Matrix4();
- var T2x4 = new cc.math.Matrix4();
-
- function equals(A, B) {
- for (var i = 0; i < 16; ++i) {
- if (A[i] != B[i])
- return false;
- }
- return true;
- }
-
- function init() {
- T1.mat[0] = 1.0;
- T1.mat[5] = 1.0;
- T1.mat[10] = 1.0;
- T1.mat[15] = 1.0;
-
- T2.mat[0] = 1.0;
- T2.mat[5] = 1.0;
- T2.mat[10] = 1.0;
- T2.mat[15] = 1.0;
-
- T1x4.mat[0] = 1.0;
- T1x4.mat[5] = 1.0;
- T1x4.mat[10] = 1.0;
- T1x4.mat[15] = 1.0;
-
- T2x4.mat[0] = 1.0;
- T2x4.mat[5] = 1.0;
- T2x4.mat[10] = 1.0;
- T2x4.mat[15] = 1.0;
-
- nonSimd(1);
- simd(1);
- return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat);
- }
-
- function cleanup() {
- return init(); // Sanity checking before and after are the same
- }
-
- function nonSimd(n) {
- for (var i = 0; i < n; i++) {
- T1.multiply(T2);
- }
- }
-
- function simd(n) {
- for (var i = 0; i < n; i++) {
- T1x4.multiplySIMD(T2x4);
- }
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js b/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js
deleted file mode 100644
index 2892ba95da..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kmMat4Transpose.js
+++ /dev/null
@@ -1,82 +0,0 @@
-// kmMat4Transpose
-
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "kmMat4Transpose",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 10000
- };
-
- // Hook up to the harness
- benchmarks.add(new Benchmark(kernelConfig));
-
- // Benchmark data, initialization and kernel functions
- var T1 = new cc.math.Matrix4();
- var T2 = new cc.math.Matrix4();
- var T1x4 = new cc.math.Matrix4();
- var T2x4 = new cc.math.Matrix4();
-
- function equals(A, B) {
- for (var i = 0; i < 16; ++i) {
- if (A[i] != B[i])
- return false;
- }
- return true;
- }
-
- function printMatrix(matrix) {
- print('--------matrix----------');
- for (var r = 0; r < 4; ++r) {
- var str = "";
- var ri = r*4;
- for (var c = 0; c < 4; ++c) {
- var value = matrix[ri + c];
- str += " " + value.toFixed(2);
- }
- print(str);
- }
- }
-
- function init() {
- T1.mat [0] = 0; T1.mat[1] = 1; T1.mat[2] = 2; T1.mat[3] = 3;
- T1.mat [4] = -1; T1.mat[5] = -2; T1.mat[6] = -3; T1.mat[7] = -4;
- T1.mat [8] = 0; T1.mat[9] = 0; T1.mat[10] = 2; T1.mat[11] = 3;
- T1.mat [12] = -1; T1.mat[13] = -2; T1.mat[14] = 0; T1.mat[15] = -4;
-
- T1x4.mat [0] = 0; T1x4.mat[1] = 1; T1x4.mat[2] = 2; T1x4.mat[3] = 3;
- T1x4.mat [4] = -1; T1x4.mat[5] = -2; T1x4.mat[6] = -3; T1x4.mat[7] = -4;
- T1x4.mat [8] = 0; T1x4.mat[9] = 0; T1x4.mat[10] = 2; T1x4.mat[11] = 3;
- T1x4.mat [12] = -1; T1x4.mat[13] = -2; T1x4.mat[14] = 0; T1x4.mat[15] = -4;
-
- nonSimd(1);
- //printMatrix(T2.mat);
- simd(1);
- //printMatrix(T2x4.mat);
- return equals(T1.mat, T1x4.mat) && equals(T2.mat, T2x4.mat);
-
- }
-
- function cleanup() {
- return init(); // Sanity checking before and after are the same
- }
-
- function nonSimd(n) {
- for (var i = 0; i < n; i++) {
- T2 = T1.transpose();
- //T1.transpose();
- }
- }
-
- function simd(n) {
- for (var i = 0; i < n; i++) {
- T2x4 = T1x4.transposeSIMD();
- //T1x4.transposeSIMD();
- }
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js b/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js
deleted file mode 100644
index 0bb25e8e12..0000000000
--- a/cocos2d/kazmath/simd_benchmark/kmVec3TransformCoord.js
+++ /dev/null
@@ -1,65 +0,0 @@
-// kmVec3TransformCoord
-
-(function () {
-
- // Kernel configuration
- var kernelConfig = {
- kernelName: "kmVec3TransformCoord",
- kernelInit: init,
- kernelCleanup: cleanup,
- kernelSimd: simd,
- kernelNonSimd: nonSimd,
- kernelIterations: 10000
- };
-
- // Hook up to the harness
- benchmarks.add(new Benchmark(kernelConfig));
-
- // Benchmark data, initialization and kernel functions
- var V = new cc.math.Vec3();
- var T = new cc.math.Matrix4();
- var Out = new cc.math.Vec3();
- var Vx4 = new cc.math.Vec3();
- var Tx4 = new cc.math.Matrix4();
- var Outx4 = new cc.math.Vec3();
-
- function init() {
- T.mat[0] = 1.0;
- T.mat[5] = 1.0;
- T.mat[10] = 1.0;
- T.mat[15] = 1.0;
-
- V.fill(0.0, 1.0, 0.0);
-
- Tx4.mat[0] = 1.0;
- Tx4.mat[5] = 1.0;
- Tx4.mat[10] = 1.0;
- Tx4.mat[15] = 1.0;
-
- Vx4.fill(0.0, 1.0, 0.0);
-
- nonSimd(1);
- simd(1);
- //console.log(V);
- //console.log(Vx4);
- return V.equals(Vx4);
-
- }
-
- function cleanup() {
- return init(); // Sanity checking before and after are the same
- }
-
- function nonSimd(n) {
- for (var i = 0; i < n; i++) {
- V.transformCoord(T);
- }
- }
-
- function simd(n) {
- for (var i = 0; i < n; i++) {
- Vx4.transformCoordSIMD(Tx4);
- }
- }
-
-} ());
diff --git a/cocos2d/kazmath/simd_benchmark/run.js b/cocos2d/kazmath/simd_benchmark/run.js
deleted file mode 100644
index 693b17f704..0000000000
--- a/cocos2d/kazmath/simd_benchmark/run.js
+++ /dev/null
@@ -1,40 +0,0 @@
-"use strict";
-
-var cc = {};
-
-load ('base.js');
-
-load ('../utility.js');
-load ('../vec3.js');
-load ('../vec4.js');
-load ('../mat4.js');
-load ('../vec3SIMD.js');
-load ('../mat4SIMD.js');
-
-// load individual benchmarks
-load ('kernel-template.js');
-load ('kmMat4Multiply.js');
-load ('kmMat4Assign.js');
-load ('kmMat4AreEqual.js');
-load ('kmMat4Inverse.js');
-load ('kmMat4IsIdentity.js');
-load ('kmMat4Transpose.js');
-load ('kmMat4LookAt.js');
-load ('kmVec3TransformCoord.js');
-
-function printResult (str) {
- print (str);
-}
-
-function printError (str) {
- print (str);
-}
-
-function printScore (str) {
- print (str);
-}
-
-benchmarks.runAll ({notifyResult: printResult,
- notifyError: printError,
- notifyScore: printScore},
- true);
diff --git a/cocos2d/kazmath/simd_benchmark/run_browser.js b/cocos2d/kazmath/simd_benchmark/run_browser.js
deleted file mode 100644
index 5d2d0cdd74..0000000000
--- a/cocos2d/kazmath/simd_benchmark/run_browser.js
+++ /dev/null
@@ -1,80 +0,0 @@
-var echo = document.getElementById('echo');
-
-function printResult(str) {
- console.log(str);
- echo.innerHTML += str + ' ';
-}
-
-function printError(str) {
- console.log(str);
- echo.innerHTML += str + ' ';
-}
-
-function printScore(str) {
- console.log(str);
- echo.innerHTML += str + ' ';
-}
-
-var timeData = {
- labels: [],
- datasets: [
- {
- labels: 'Non-SIMD',
- fillColor: "rgba(220,220,220,0.5)",
- strokeColor: "rgba(220,220,220,0.8)",
- highlightFill: "rgba(220,220,220,0.75)",
- highlightStroke: "rgba(220,220,220,1)",
- data: []
- },
- {
- labels: 'SIMD',
- fillColor: "rgba(151,187,205,0.5)",
- strokeColor: "rgba(151,187,205,0.8)",
- highlightFill: "rgba(151,187,205,0.75)",
- highlightStroke: "rgba(151,187,205,1)",
- data: []
- }
- ]
-};
-
-var speedupData ={
- labels: [],
- datasets: [
- {
- labels: 'SIMD',
- fillColor: "rgba(151,187,205,0.5)",
- strokeColor: "rgba(151,187,205,0.8)",
- highlightFill: "rgba(151,187,205,0.75)",
- highlightStroke: "rgba(151,187,205,1)",
- data: []
- }
- ]
-};
-
-window.onload = function() {
- if (typeof(SIMD) === 'undefined') {
- var head = document.getElementById('head');
- head.innerHTML = 'SIMD is not implemented in your browser, stops.';
- return;
- }
- console.log('Running benchmarks.');
- benchmarks.runAll({notifyResult: printResult,
- notifyError: printError,
- notifyScore: printScore,
- timeData: timeData,
- speedupData: speedupData}, true);
- document.getElementById('head').innerHTML = 'Results';
- document.getElementById('time').innerHTML = 'Time';
- document.getElementById('speedup').innerHTML = 'Speedup';
- var ctx1 = document.getElementById("canvasTime").getContext("2d");
- window.Bar1 = new Chart(ctx1).Bar(timeData, {
- scaleLabel: "<%=value%>ms",
- responsive: true
- });
- var ctx2 = document.getElementById("canvasSpeedup").getContext("2d");
- window.Bar2 = new Chart(ctx2).Bar(speedupData, {
- scaleLabel: " <%=value%>",
- responsive: true
- });
- console.log('Benchmarks completed.');
-};
diff --git a/cocos2d/kazmath/utility.js b/cocos2d/kazmath/utility.js
deleted file mode 100644
index f3f8ab188f..0000000000
--- a/cocos2d/kazmath/utility.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-/**
- *
The main namespace of Cocos2d-html5's math library,
- * all math core classes, functions, properties and constants are defined in this namespace
- * @namespace
- * @name cc.math
- */
-cc.math = cc.math || {};
-
-//cc.kmPIOver180 = 0.017453; please use cc.macro.RAD
-
-//cc.kmPIUnder180 = 57.295779; please use cc.macro.DEG
-
-cc.math.EPSILON = 1.0 / 64.0; //cc.kmEpsilon
-
-/**
- * Returns the square of s (e.g. s*s)
- * @param {Number} s
- */
-cc.math.square = function(s){
- return s*s;
-};
-
-cc.math.almostEqual = function(lhs,rhs){
- return (lhs + cc.math.EPSILON > rhs && lhs - cc.math.EPSILON < rhs);
-};
diff --git a/cocos2d/kazmath/vec2.js b/cocos2d/kazmath/vec2.js
deleted file mode 100644
index a0650c92eb..0000000000
--- a/cocos2d/kazmath/vec2.js
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-cc.math.Vec2 = function (x, y) {
- if(y === undefined){
- this.x = x.x;
- this.y = x.y;
- }else{
- this.x = x || 0;
- this.y = y || 0;
- }
-};
-
-var proto = cc.math.Vec2.prototype;
-proto.fill = function(x, y){ // = cc.kmVec2Fill
- this.x = x;
- this.y = y;
-};
-
-proto.length = function(){ // = cc.kmVec2Length
- return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y));
-};
-
-proto.lengthSq = function(){ // = cc.kmVec2LengthSq
- return cc.math.square(this.x) + cc.math.square(this.y);
-};
-
-proto.normalize = function(){ // = cc.kmVec2Normalize
- var l = 1.0 / this.length();
- this.x *= l;
- this.y *= l;
- return this;
-};
-
-cc.math.Vec2.add = function (pOut, pV1, pV2) { // = cc.kmVec2Add
- pOut.x = pV1.x + pV2.x;
- pOut.y = pV1.y + pV2.y;
- return pOut
-};
-
-proto.add = function(vec){ // = cc.kmVec2Add
- this.x += vec.x;
- this.y += vec.y;
- return this;
-};
-
-proto.dot = function (vec) { //cc.kmVec2Dot
- return this.x * vec.x + this.y * vec.y;
-};
-
-cc.math.Vec2.subtract = function (pOut, pV1, pV2) { // = cc.kmVec2Subtract
- pOut.x = pV1.x - pV2.x;
- pOut.y = pV1.y - pV2.y;
- return pOut;
-};
-
-proto.subtract = function(vec){ // = cc.kmVec2Subtract
- this.x -= vec.x;
- this.y -= vec.y;
- return this;
-};
-
-proto.transform = function (mat3) { // = cc.kmVec2Transform
- var x = this.x, y = this.y;
- this.x = x * mat3.mat[0] + y * mat3.mat[3] + mat3.mat[6];
- this.y = x * mat3.mat[1] + y * mat3.mat[4] + mat3.mat[7];
- return this;
-};
-
-cc.math.Vec2.scale = function (pOut, pIn, s) { // = cc.kmVec2Scale
- pOut.x = pIn.x * s;
- pOut.y = pIn.y * s;
- return pOut;
-};
-
-proto.scale = function(s) { // = cc.kmVec2Scale
- this.x *= s;
- this.y *= s;
- return this;
-};
-
-proto.equals = function (vec) { // = cc.kmVec2AreEqual
- return (this.x < vec.x + cc.math.EPSILON && this.x > vec.x - cc.math.EPSILON) &&
- (this.y < vec.y + cc.math.EPSILON && this.y > vec.y - cc.math.EPSILON);
-};
-
diff --git a/cocos2d/kazmath/vec3.js b/cocos2d/kazmath/vec3.js
deleted file mode 100644
index a1918b981a..0000000000
--- a/cocos2d/kazmath/vec3.js
+++ /dev/null
@@ -1,189 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-cc.math.Vec3 = cc.math.Vec3 = function (x, y, z) {
- if(x && y === undefined){
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- } else {
- this.x = x || 0;
- this.y = y || 0;
- this.z = z || 0;
- }
-};
-
-cc.math.vec3 = function(x, y, z){
- return new cc.math.Vec3(x, y, z);
-};
-
-var proto = cc.math.Vec3.prototype;
-
-proto.fill = function (x, y, z) { // =cc.math.Vec3Fill
- if (x && y === undefined) {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- } else {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- return this;
-};
-
-proto.length = function () { //=cc.math.Vec3Length
- return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z));
-};
-
-proto.lengthSq = function () { //=cc.math.Vec3LengthSq
- return cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z)
-};
-
-proto.normalize = function () { //= cc.math.Vec3Normalize
- var l = 1.0 / this.length();
- this.x *= l;
- this.y *= l;
- this.z *= l;
- return this;
-};
-
-proto.cross = function (vec3) { //= cc.math.Vec3Cross
- var x = this.x, y = this.y, z = this.z;
- this.x = (y * vec3.z) - (z * vec3.y);
- this.y = (z * vec3.x) - (x * vec3.z);
- this.z = (x * vec3.y) - (y * vec3.x);
- return this;
-};
-
-proto.dot = function (vec) { //= cc.math.Vec3Dot
- return ( this.x * vec.x + this.y * vec.y + this.z * vec.z );
-};
-
-proto.add = function(vec){ //= cc.math.Vec3Add
- this.x += vec.x;
- this.y += vec.y;
- this.z += vec.z;
- return this;
-};
-
-proto.subtract = function (vec) { // = cc.math.Vec3Subtract
- this.x -= vec.x;
- this.y -= vec.y;
- this.z -= vec.z;
- return this;
-};
-
-proto.transform = function (mat4) { // = cc.math.Vec3Transform
- var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
- this.x = x * mat[0] + y * mat[4] + z * mat[8] + mat[12];
- this.y = x * mat[1] + y * mat[5] + z * mat[9] + mat[13];
- this.z = x * mat[2] + y * mat[6] + z * mat[10] + mat[14];
- return this;
-};
-
-proto.transformNormal = function(mat4){
- /*
- a = (Vx, Vy, Vz, 0)
- b = (a×M)T
- Out = (bx, by, bz)
- */
- //Omits the translation, only scaling + rotating
- var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
- this.x = x * mat[0] + y * mat[4] + z * mat[8];
- this.y = x * mat[1] + y * mat[5] + z * mat[9];
- this.z = x * mat[2] + y * mat[6] + z * mat[10];
- return this;
-};
-
-proto.transformCoord = function(mat4){ // = cc.math.Vec3TransformCoord
- /*
- a = (Vx, Vy, Vz, 1)
- b = (a×M)T
- Out = 1⁄bw(bx, by, bz)
- */
- var v = new cc.math.Vec4(this.x, this.y, this.z, 1.0);
- v.transform(mat4);
- this.x = v.x / v.w;
- this.y = v.y / v.w;
- this.z = v.z / v.w;
- return this;
-};
-
-proto.scale = function(scale){ // = cc.math.Vec3Scale
- this.x *= scale;
- this.y *= scale;
- this.z *= scale;
- return this;
-};
-
-proto.equals = function(vec){ // = cc.math.Vec3AreEqual
- var EPSILON = cc.math.EPSILON;
- return (this.x < (vec.x + EPSILON) && this.x > (vec.x - EPSILON)) &&
- (this.y < (vec.y + EPSILON) && this.y > (vec.y - EPSILON)) &&
- (this.z < (vec.z + EPSILON) && this.z > (vec.z - EPSILON));
-};
-
-proto.inverseTransform = function(mat4){ //= cc.math.Vec3InverseTransform
- var mat = mat4.mat;
- var v1 = new cc.math.Vec3(this.x - mat[12], this.y - mat[13], this.z - mat[14]);
- this.x = v1.x * mat[0] + v1.y * mat[1] + v1.z * mat[2];
- this.y = v1.x * mat[4] + v1.y * mat[5] + v1.z * mat[6];
- this.z = v1.x * mat[8] + v1.y * mat[9] + v1.z * mat[10];
- return this;
-};
-
-proto.inverseTransformNormal = function(mat4){ // = cc.math.Vec3InverseTransformNormal
- var x = this.x, y = this.y, z = this.z, mat = mat4.mat;
- this.x = x * mat[0] + y * mat[1] + z * mat[2];
- this.y = x * mat[4] + y * mat[5] + z * mat[6];
- this.z = x * mat[8] + y * mat[9] + z * mat[10];
- return this;
-};
-
-proto.assignFrom = function(vec){
- if(!vec)
- return this;
- this.x = vec.x;
- this.y = vec.y;
- this.z = vec.z;
- return this;
-};
-
-cc.math.Vec3.zero = function(vec){ // = cc.math.Vec3Zero
- vec.x = vec.y = vec.z = 0.0;
- return vec;
-};
-
-proto.toTypeArray = function(){ //cc.math.Vec3ToTypeArray
- var tyArr = new Float32Array(3);
- tyArr[0] = this.x;
- tyArr[1] = this.y;
- tyArr[2] = this.z;
- return tyArr;
-};
diff --git a/cocos2d/kazmath/vec3SIMD.js b/cocos2d/kazmath/vec3SIMD.js
deleted file mode 100644
index 31dcbcd715..0000000000
--- a/cocos2d/kazmath/vec3SIMD.js
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-require('./vec3');
-
-var proto = cc.math.Vec3.prototype;
-
-proto.transformCoordSIMD = function(mat4){
- var vec = SIMD.float32x4(this.x, this.y, this.z, 0.0);
- var mat0 = SIMD.float32x4.load(mat4.mat, 0);
- var mat1 = SIMD.float32x4.load(mat4.mat, 4);
- var mat2 = SIMD.float32x4.load(mat4.mat, 8);
- var mat3 = SIMD.float32x4.load(mat4.mat, 12);
-
- //cc.kmVec4Transform(v, inV,pM);
- var out = SIMD.float32x4.add(
- SIMD.float32x4.add(SIMD.float32x4.mul(mat0, SIMD.float32x4.swizzle(vec, 0, 0, 0, 0)),
- SIMD.float32x4.mul(mat1, SIMD.float32x4.swizzle(vec, 1, 1, 1, 1))),
- SIMD.float32x4.add(SIMD.float32x4.mul(mat2, SIMD.float32x4.swizzle(vec, 2, 2, 2, 2)),
- mat3));
-
- out = SIMD.float32x4.div(out, SIMD.float32x4.swizzle(out, 3, 3, 3, 3));
- this.fill(out);
-
- return this;
-};
diff --git a/cocos2d/kazmath/vec4.js b/cocos2d/kazmath/vec4.js
deleted file mode 100644
index 3761f4acb9..0000000000
--- a/cocos2d/kazmath/vec4.js
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright (c) 2008, Luke Benstead.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-cc.math.Vec4 = function (x, y, z, w) {
- if (x && y === undefined) {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- this.w = x.w;
- } else {
- this.x = x || 0;
- this.y = y || 0;
- this.z = z || 0;
- this.w = w || 0;
- }
-};
-var proto = cc.math.Vec4.prototype;
-
-proto.fill = function (x, y, z, w) { //=cc.kmVec4Fill
- if (x && y === undefined) {
- this.x = x.x;
- this.y = x.y;
- this.z = x.z;
- this.w = x.w;
- } else {
- this.x = x;
- this.y = y;
- this.z = z;
- this.w = w;
- }
-};
-
-proto.add = function(vec) { //cc.kmVec4Add
- if(!vec)
- return this;
- this.x += vec.x;
- this.y += vec.y;
- this.z += vec.z;
- this.w += vec.w;
- return this;
-};
-
-proto.dot = function(vec){ //cc.kmVec4Dot
- return ( this.x * vec.x + this.y * vec.y + this.z * vec.z + this.w * vec.w );
-};
-
-proto.length = function(){ //=cc.kmVec4Length
- return Math.sqrt(cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z) + cc.math.square(this.w));
-};
-
-proto.lengthSq = function(){ //=cc.kmVec4LengthSq
- return cc.math.square(this.x) + cc.math.square(this.y) + cc.math.square(this.z) + cc.math.square(this.w);
-};
-
-proto.lerp = function(vec, t){ //= cc.kmVec4Lerp
- //not implemented
- return this;
-};
-
-proto.normalize = function() { // cc.kmVec4Normalize
- var l = 1.0 / this.length();
- this.x *= l;
- this.y *= l;
- this.z *= l;
- this.w *= l;
- return this;
-};
-
-proto.scale = function(scale){ //= cc.kmVec4Scale
- /// Scales a vector to the required length. This performs a Normalize before multiplying by S.
- this.normalize();
- this.x *= scale;
- this.y *= scale;
- this.z *= scale;
- this.w *= scale;
- return this;
-};
-
-proto.subtract = function(vec) {
- this.x -= vec.x;
- this.y -= vec.y;
- this.z -= vec.z;
- this.w -= vec.w;
-};
-
-proto.transform = function(mat4) {
- var x = this.x, y = this.y, z = this.z, w = this.w, mat = mat4.mat;
- this.x = x * mat[0] + y * mat[4] + z * mat[8] + w * mat[12];
- this.y = x * mat[1] + y * mat[5] + z * mat[9] + w * mat[13];
- this.z = x * mat[2] + y * mat[6] + z * mat[10] + w * mat[14];
- this.w = x * mat[3] + y * mat[7] + z * mat[11] + w * mat[15];
- return this;
-};
-
-cc.math.Vec4.transformArray = function(vecArray, mat4){
- var retArray = [];
- for (var i = 0; i < vecArray.length; i++) {
- var selVec = new cc.math.Vec4(vecArray[i]);
- selVec.transform(mat4);
- retArray.push(selVec);
- }
- return retArray;
-};
-
-proto.equals = function(vec){ //=cc.kmVec4AreEqual
- var EPSILON = cc.math.EPSILON;
- return (this.x < vec.x + EPSILON && this.x > vec.x - EPSILON) &&
- (this.y < vec.y + EPSILON && this.y > vec.y - EPSILON) &&
- (this.z < vec.z + EPSILON && this.z > vec.z - EPSILON) &&
- (this.w < vec.w + EPSILON && this.w > vec.w - EPSILON);
-};
-
-proto.assignFrom = function(vec) { //= cc.kmVec4Assign
- this.x = vec.x;
- this.y = vec.y;
- this.z = vec.z;
- this.w = vec.w;
- return this;
-};
-
-proto.toTypeArray = function(){ //cc.kmVec4ToTypeArray
- var tyArr = new Float32Array(4);
- tyArr[0] = this.x;
- tyArr[1] = this.y;
- tyArr[2] = this.z;
- tyArr[3] = this.w;
- return tyArr;
-};
diff --git a/cocos2d/shaders/CCGLProgram.js b/cocos2d/shaders/CCGLProgram.js
deleted file mode 100644
index 80b14d74e1..0000000000
--- a/cocos2d/shaders/CCGLProgram.js
+++ /dev/null
@@ -1,796 +0,0 @@
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
- Copyright 2011 Jeff Lamarche
- Copyright 2012 Goffredo Marocchi
-
- http://www.cocos2d-x.org
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var macro = cc.macro;
-var math = cc.math;
-
-/**
- * Class that implements a WebGL program
- * @class
- * @extends cc._Class
- */
-cc.GLProgram = cc._Class.extend(/** @lends cc.GLProgram# */{
-
- // Uniform cache
- _updateUniformLocation: function (location) {
- if (!location)
- return false;
-
- var updated;
- var element = this._hashForUniforms[location];
-
- if (!element) {
- element = [
- arguments[1],
- arguments[2],
- arguments[3],
- arguments[4]
- ];
- this._hashForUniforms[location] = element;
- updated = true;
- } else {
- updated = false;
- var count = arguments.length-1;
- for (var i = 0; i < count; ++i) {
- if (arguments[i+1] !== element[i]) {
- element[i] = arguments[i+1];
- updated = true;
- }
- }
- }
-
- return updated;
- },
-
- _description: function () {
- return "";
- },
-
- _compileShader: function (shader, type, source) {
- if (!source || !shader)
- return false;
-
- var preStr = cc.GLProgram._isHighpSupported() ? "precision highp float;\n" : "precision mediump float;\n";
- source = preStr
- + "uniform mat4 CC_PMatrix;\n"
- + "uniform mat4 CC_MVMatrix;\n"
- + "uniform mat4 CC_MVPMatrix;\n"
- + "uniform vec4 CC_Time;\n"
- + "uniform vec4 CC_SinTime;\n"
- + "uniform vec4 CC_CosTime;\n"
- + "uniform vec4 CC_Random01;\n"
- + "uniform sampler2D CC_Texture0;\n"
- + "//CC INCLUDES END\n" + source;
-
- this._glContext.shaderSource(shader, source);
- this._glContext.compileShader(shader);
- var status = this._glContext.getShaderParameter(shader, this._glContext.COMPILE_STATUS);
-
- if (!status) {
- cc.logID(8100, this._glContext.getShaderSource(shader));
- if (type === this._glContext.VERTEX_SHADER)
- cc.log("cocos2d: \n" + this.vertexShaderLog());
- else
- cc.log("cocos2d: \n" + this.fragmentShaderLog());
- }
- return ( status === true );
- },
-
- /**
- * Create a cc.GLProgram object
- * @param {String} vShaderFileName
- * @param {String} fShaderFileName
- * @returns {cc.GLProgram}
- */
- ctor: function (vShaderFileName, fShaderFileName, glContext) {
- this._uniforms = {};
- this._hashForUniforms = {};
- this._glContext = glContext || cc._renderContext;
- this._programObj = null;
- this._vertShader = null;
- this._fragShader = null;
- this._usesTime = false;
- this._projectionUpdated = -1;
- vShaderFileName && fShaderFileName && this.init(vShaderFileName, fShaderFileName);
- },
-
- /**
- * destroy program
- */
- destroyProgram: function () {
- this._vertShader = null;
- this._fragShader = null;
- this._uniforms = null;
- this._hashForUniforms = null;
-
- this._glContext.deleteProgram(this._programObj);
- },
-
- /**
- * Initializes the cc.GLProgram with a vertex and fragment with string
- * @param {String} vertShaderStr
- * @param {String} fragShaderStr
- * @return {Boolean}
- */
- initWithVertexShaderByteArray: function (vertShaderStr, fragShaderStr) {
- var locGL = this._glContext;
- this._programObj = locGL.createProgram();
- this._projectionUpdated = -1;
-
- this._vertShader = null;
- this._fragShader = null;
-
- if (vertShaderStr) {
- this._vertShader = locGL.createShader(locGL.VERTEX_SHADER);
- if (!this._compileShader(this._vertShader, locGL.VERTEX_SHADER, vertShaderStr)) {
- cc.logID(8101);
- }
- }
-
- // Create and compile fragment shader
- if (fragShaderStr) {
- this._fragShader = locGL.createShader(locGL.FRAGMENT_SHADER);
- if (!this._compileShader(this._fragShader, locGL.FRAGMENT_SHADER, fragShaderStr)) {
- cc.logID(8102);
- }
- }
-
- if (this._vertShader)
- locGL.attachShader(this._programObj, this._vertShader);
-
- if (this._fragShader)
- locGL.attachShader(this._programObj, this._fragShader);
-
- for (var key in this._hashForUniforms) {
- delete this._hashForUniforms[key];
- }
-
- if (CC_DEV)
- cc.checkGLErrorDebug();
- return true;
- },
-
- /**
- * Initializes the cc.GLProgram with a vertex and fragment with string
- * @param {String} vertShaderStr
- * @param {String} fragShaderStr
- * @return {Boolean}
- */
- initWithString: function (vertShaderStr, fragShaderStr) {
- return this.initWithVertexShaderByteArray(vertShaderStr, fragShaderStr);
- },
-
- /**
- * Initializes the CCGLProgram with a vertex and fragment with contents of filenames
- * @param {String} vShaderFilename
- * @param {String} fShaderFileName
- * @return {Boolean}
- */
- initWithVertexShaderFilename: function (vShaderFilename, fShaderFileName) {
- var vertexSource = cc.loader.getRes(vShaderFilename);
- if (!vertexSource) throw new Error(cc._getError(8106, vShaderFilename));
- var fragmentSource = cc.loader.getRes(fShaderFileName);
- if (!fragmentSource) throw new Error(cc._getError(8106, fShaderFileName));
- return this.initWithVertexShaderByteArray(vertexSource, fragmentSource);
- },
-
- /**
- * Initializes the CCGLProgram with a vertex and fragment with contents of filenames
- * @param {String} vShaderFilename
- * @param {String} fShaderFileName
- * @return {Boolean}
- */
- init: function (vShaderFilename, fShaderFileName) {
- return this.initWithVertexShaderFilename(vShaderFilename, fShaderFileName);
- },
-
- /**
- * It will add a new attribute to the shader
- * @param {String} attributeName
- * @param {Number} index
- */
- addAttribute: function (attributeName, index) {
- this._glContext.bindAttribLocation(this._programObj, index, attributeName);
- },
-
- /**
- * links the glProgram
- * @return {Boolean}
- */
- link: function () {
- if(!this._programObj) {
- cc.logID(8103);
- return false;
- }
-
- this._glContext.linkProgram(this._programObj);
-
- if (this._vertShader)
- this._glContext.deleteShader(this._vertShader);
- if (this._fragShader)
- this._glContext.deleteShader(this._fragShader);
-
- this._vertShader = null;
- this._fragShader = null;
-
- if (cc.game.config[cc.game.CONFIG_KEY.debugMode]) {
- var status = this._glContext.getProgramParameter(this._programObj, this._glContext.LINK_STATUS);
- if (!status) {
- cc.logID(8104, this._glContext.getProgramInfoLog(this._programObj));
- cc.gl.deleteProgram(this._programObj);
- this._programObj = null;
- return false;
- }
- }
-
- return true;
- },
-
- /**
- * it will call gl.useProgram()
- */
- use: function () {
- cc.gl.useProgram(this._programObj);
- },
-
- /**
- * It will create 4 uniforms:
- * cc.macro.UNIFORM_PMATRIX
- * cc.macro.UNIFORM_MVMATRIX
- * cc.macro.UNIFORM_MVPMATRIX
- * cc.macro.UNIFORM_SAMPLER
- */
- updateUniforms: function () {
- this._uniforms[macro.UNIFORM_PMATRIX] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_PMATRIX_S);
- this._uniforms[macro.UNIFORM_MVMATRIX] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_MVMATRIX_S);
- this._uniforms[macro.UNIFORM_MVPMATRIX] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_MVPMATRIX_S);
- this._uniforms[macro.UNIFORM_TIME] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_TIME_S);
- this._uniforms[macro.UNIFORM_SINTIME] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_SINTIME_S);
- this._uniforms[macro.UNIFORM_COSTIME] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_COSTIME_S);
-
- this._usesTime = (this._uniforms[macro.UNIFORM_TIME] != null || this._uniforms[macro.UNIFORM_SINTIME] != null || this._uniforms[macro.UNIFORM_COSTIME] != null);
-
- this._uniforms[macro.UNIFORM_RANDOM01] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_RANDOM01_S);
- this._uniforms[macro.UNIFORM_SAMPLER] = this._glContext.getUniformLocation(this._programObj, macro.UNIFORM_SAMPLER_S);
-
- this.use();
- // Since sample most probably won't change, set it to 0 now.
- this.setUniformLocationWith1i(this._uniforms[macro.UNIFORM_SAMPLER], 0);
- },
-
- _addUniformLocation: function (name) {
- var location = this._glContext.getUniformLocation(this._programObj, name);
- this._uniforms[name] = location;
- },
-
- /**
- * calls retrieves the named uniform location for this shader program.
- * @param {String} name
- * @returns {Number}
- */
- getUniformLocationForName: function (name) {
- if (!name)
- throw new Error(cc._getError(8107));
- if (!this._programObj)
- throw new Error(cc._getError(8108));
-
- var location = this._uniforms[name] || this._glContext.getUniformLocation(this._programObj, name);
- return location;
- },
-
- /**
- * get uniform MVP matrix
- * @returns {WebGLUniformLocation}
- */
- getUniformMVPMatrix: function () {
- return this._uniforms[macro.UNIFORM_MVPMATRIX];
- },
-
- /**
- * get uniform sampler
- * @returns {WebGLUniformLocation}
- */
- getUniformSampler: function () {
- return this._uniforms[macro.UNIFORM_SAMPLER];
- },
-
- /**
- * calls glUniform1i only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} i1
- */
- setUniformLocationWith1i: function (location, i1) {
- var gl = this._glContext;
- if (typeof location === 'string') {
- var updated = this._updateUniformLocation(location, i1);
- if (updated) {
- var locObj = this.getUniformLocationForName(location);
- gl.uniform1i(locObj, i1);
- }
- }
- else {
- gl.uniform1i(location, i1);
- }
- },
-
- /**
- * calls glUniform2i only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} i1
- * @param {Number} i2
- */
- setUniformLocationWith2i: function (location, i1, i2) {
- var gl = this._glContext;
- if (typeof location === 'string') {
- var updated = this._updateUniformLocation(location, i1, i2);
- if (updated) {
- var locObj = this.getUniformLocationForName(location);
- gl.uniform2i(locObj, i1, i2);
- }
- }
- else {
- gl.uniform2i(location, i1, i2);
- }
- },
-
- /**
- * calls glUniform3i only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} i1
- * @param {Number} i2
- * @param {Number} i3
- */
- setUniformLocationWith3i: function (location, i1, i2, i3) {
- var gl = this._glContext;
- if (typeof location === 'string') {
- var updated = this._updateUniformLocation(location, i1, i2, i3);
- if (updated) {
- var locObj = this.getUniformLocationForName(location);
- gl.uniform3i(locObj, i1, i2, i3);
- }
- }
- else {
- gl.uniform3i(location, i1, i2, i3);
- }
- },
-
- /**
- * calls glUniform4i only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} i1
- * @param {Number} i2
- * @param {Number} i3
- * @param {Number} i4
- */
- setUniformLocationWith4i: function (location, i1, i2, i3, i4) {
- var gl = this._glContext;
- if (typeof location === 'string') {
- var updated = this._updateUniformLocation(location, i1, i2, i3, i4);
- if (updated) {
- var locObj = this.getUniformLocationForName(location);
- gl.uniform4i(locObj, i1, i2, i3, i4);
- }
- }
- else {
- gl.uniform4i(location, i1, i2, i3, i4);
- }
- },
-
- /**
- * calls glUniform2iv only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Int32Array} intArray
- * @param {Number} numberOfArrays
- */
- setUniformLocationWith2iv: function (location, intArray) {
- var locObj = typeof location === 'string' ? this.getUniformLocationForName(location) : location;
- this._glContext.uniform2iv(locObj, intArray);
- },
-
- /**
- * calls glUniform3iv only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Int32Array} intArray
- * @param {Number} numberOfArrays
- */
- setUniformLocationWith3iv:function(location, intArray){
- var locObj = typeof location === 'string' ? this.getUniformLocationForName(location) : location;
- this._glContext.uniform3iv(locObj, intArray);
- },
-
- /**
- * calls glUniform4iv only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Int32Array} intArray
- */
- setUniformLocationWith4iv:function(location, intArray){
- var locObj = typeof location === 'string' ? this.getUniformLocationForName(location) : location;
- this._glContext.uniform4iv(locObj, intArray);
- },
-
- /**
- * calls glUniform1i only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} i1
- */
- setUniformLocationI32: function (location, i1) {
- this.setUniformLocationWith1i(location, i1);
- },
-
- /**
- * calls glUniform1f only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} f1
- */
- setUniformLocationWith1f: function (location, f1) {
- var gl = this._glContext;
- if (typeof location === 'string') {
- var updated = this._updateUniformLocation(location, f1);
- if (updated) {
- var locObj = this.getUniformLocationForName(location);
- gl.uniform1f(locObj, f1);
- }
- }
- else {
- gl.uniform1f(location, f1);
- }
- },
-
- /**
- * calls glUniform2f only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} f1
- * @param {Number} f2
- */
- setUniformLocationWith2f: function (location, f1, f2) {
- var gl = this._glContext;
- if (typeof location === 'string') {
- var updated = this._updateUniformLocation(location, f1, f2);
- if (updated) {
- var locObj = this.getUniformLocationForName(location);
- gl.uniform2f(locObj, f1, f2);
- }
- }
- else {
- gl.uniform2f(location, f1, f2);
- }
- },
-
- /**
- * calls glUniform3f only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} f1
- * @param {Number} f2
- * @param {Number} f3
- */
- setUniformLocationWith3f: function (location, f1, f2, f3) {
- var gl = this._glContext;
- if (typeof location === 'string') {
- var updated = this._updateUniformLocation(location, f1, f2, f3);
- if (updated) {
- var locObj = this.getUniformLocationForName(location);
- gl.uniform3f(locObj, f1, f2, f3);
- }
- }
- else {
- gl.uniform3f(location, f1, f2, f3);
- }
- },
-
- /**
- * calls glUniform4f only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Number} f1
- * @param {Number} f2
- * @param {Number} f3
- * @param {Number} f4
- */
- setUniformLocationWith4f: function (location, f1, f2, f3, f4) {
- var gl = this._glContext;
- if (typeof location === 'string') {
- var updated = this._updateUniformLocation(location, f1, f2, f3, f4);
- if (updated) {
- var locObj = this.getUniformLocationForName(location);
- gl.uniform4f(locObj, f1, f2, f3, f4);
- }
- }
- else {
- gl.uniform4f(location, f1, f2, f3, f4);
- }
- },
-
- /**
- * calls glUniform2fv only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Float32Array} floatArray
- */
- setUniformLocationWith2fv: function (location, floatArray) {
- var locObj = typeof location === 'string' ? this.getUniformLocationForName(location) : location;
- this._glContext.uniform2fv(locObj, floatArray);
- },
-
- /**
- * calls glUniform3fv only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Float32Array} floatArray
- */
- setUniformLocationWith3fv: function (location, floatArray) {
- var locObj = typeof location === 'string' ? this.getUniformLocationForName(location) : location;
- this._glContext.uniform3fv(locObj, floatArray);
- },
-
- /**
- * calls glUniform4fv only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Float32Array} floatArray
- */
- setUniformLocationWith4fv: function (location, floatArray) {
- var locObj = typeof location === 'string' ? this.getUniformLocationForName(location) : location;
- this._glContext.uniform4fv(locObj, floatArray);
- },
-
- /**
- * calls glUniformMatrix3fv only if the values are different than the previous call for this same shader
- * @param {WebGLUniformLocation} location
- * @param {Float32Array} matrixArray
- */
- setUniformLocationWithMatrix3fv: function (location, matrixArray) {
- var locObj = typeof location === 'string' ? this.getUniformLocationForName(location) : location;
- this._glContext.uniformMatrix3fv(locObj, false, matrixArray);
- },
-
- /**
- * calls glUniformMatrix4fv only if the values are different than the previous call for this same shader program.
- * @param {WebGLUniformLocation} location
- * @param {Float32Array} matrixArray
- */
- setUniformLocationWithMatrix4fv: function (location, matrixArray) {
- var locObj = typeof location === 'string' ? this.getUniformLocationForName(location) : location;
- this._glContext.uniformMatrix4fv(locObj, false, matrixArray);
- },
-
- setUniformLocationF32: function (p1, p2, p3, p4, p5) {
- 'use strict';
- switch (arguments.length) {
- case 0:
- case 1:
- return;
- case 2:
- this.setUniformLocationWith1f(p1, p2);
- break;
- case 3:
- this.setUniformLocationWith2f(p1, p2, p3);
- break;
- case 4:
- this.setUniformLocationWith3f(p1, p2, p3, p4);
- break;
- case 5:
- this.setUniformLocationWith4f(p1, p2, p3, p4, p5);
- break;
- }
- },
-
- /**
- * will update the builtin uniforms if they are different than the previous call for this same shader program.
- */
- setUniformsForBuiltins: function () {
- var matrixP = new math.Matrix4();
- var matrixMV = new math.Matrix4();
- var matrixMVP = new math.Matrix4();
-
- math.glGetMatrix(math.KM_GL_PROJECTION, matrixP);
- math.glGetMatrix(math.KM_GL_MODELVIEW, matrixMV);
-
- math.mat4Multiply(matrixMVP, matrixP, matrixMV);
-
- this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], matrixP.mat, 1);
- this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], matrixMV.mat, 1);
- this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_MVPMATRIX], matrixMVP.mat, 1);
-
- if (this._usesTime) {
- var director = cc.director;
- // This doesn't give the most accurate global time value.
- // Cocos2D doesn't store a high precision time value, so this will have to do.
- // Getting Mach time per frame per shader using time could be extremely expensive.
- var time = director.getTotalFrames() * director.getAnimationInterval();
-
- this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4);
- this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time));
- this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time));
- }
-
- if (this._uniforms[macro.UNIFORM_RANDOM01] !== -1)
- this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random());
- },
-
- _setUniformsForBuiltinsForRenderer: function (node) {
- if(!node || !node._renderCmd)
- return;
-
- var matrixP = new math.Matrix4();
- //var matrixMV = new math.Matrix4();
- var matrixMVP = new math.Matrix4();
-
- math.glGetMatrix(math.KM_GL_PROJECTION, matrixP);
- //math.glGetMatrix(math.KM_GL_MODELVIEW, node._stackMatrix);
-
- math.mat4Multiply(matrixMVP, matrixP, node._renderCmd._stackMatrix);
-
- this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], matrixP.mat, 1);
- this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], node._renderCmd._stackMatrix.mat, 1);
- this.setUniformLocationWithMatrix4fv(this._uniforms[macro.UNIFORM_MVPMATRIX], matrixMVP.mat, 1);
-
- if (this._usesTime) {
- var director = cc.director;
- // This doesn't give the most accurate global time value.
- // Cocos2D doesn't store a high precision time value, so this will have to do.
- // Getting Mach time per frame per shader using time could be extremely expensive.
- var time = director.getTotalFrames() * director.getAnimationInterval();
-
- this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_TIME], time / 10.0, time, time * 2, time * 4);
- this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_SINTIME], time / 8.0, time / 4.0, time / 2.0, Math.sin(time));
- this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_COSTIME], time / 8.0, time / 4.0, time / 2.0, Math.cos(time));
- }
-
- if (this._uniforms[macro.UNIFORM_RANDOM01] !== -1)
- this.setUniformLocationWith4f(this._uniforms[macro.UNIFORM_RANDOM01], Math.random(), Math.random(), Math.random(), Math.random());
- },
-
- /**
- * will update the MVP matrix on the MVP uniform if it is different than the previous call for this same shader program.
- */
- setUniformForModelViewProjectionMatrix: function () {
- this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVPMATRIX], false,
- math.getMat4MultiplyValue(math.projection_matrix_stack.top, math.modelview_matrix_stack.top));
- },
-
- setUniformForModelViewProjectionMatrixWithMat4: function (swapMat4) {
- math.mat4Multiply(swapMat4, math.projection_matrix_stack.top, math.modelview_matrix_stack.top);
- this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVPMATRIX], false, swapMat4.mat);
- },
-
- setUniformForModelViewAndProjectionMatrixWithMat4: function () {
- this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], false, math.modelview_matrix_stack.top.mat);
- this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], false, math.projection_matrix_stack.top.mat);
- },
-
- _setUniformForMVPMatrixWithMat4: function(modelViewMatrix){
- if(!modelViewMatrix)
- throw new Error(cc._getError(8109));
- this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_MVMATRIX], false, modelViewMatrix.mat);
- this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], false, math.projection_matrix_stack.top.mat);
- },
-
- _updateProjectionUniform: function () {
- var stack = math.projection_matrix_stack;
-
- if (stack.lastUpdated !== this._projectionUpdated) {
- this._glContext.uniformMatrix4fv(this._uniforms[macro.UNIFORM_PMATRIX], false, stack.top.mat);
- this._projectionUpdated = stack.lastUpdated;
- }
- },
-
- /**
- * returns the vertexShader error log
- * @return {String}
- */
- vertexShaderLog: function () {
- return this._glContext.getShaderInfoLog(this._vertShader);
- },
-
- /**
- * returns the vertexShader error log
- * @return {String}
- */
- getVertexShaderLog: function () {
- return this._glContext.getShaderInfoLog(this._vertShader);
- },
-
- /**
- * returns the fragmentShader error log
- * @returns {String}
- */
- getFragmentShaderLog: function () {
- return this._glContext.getShaderInfoLog(this._vertShader);
- },
-
- /**
- * returns the fragmentShader error log
- * @return {String}
- */
- fragmentShaderLog: function () {
- return this._glContext.getShaderInfoLog(this._fragShader);
- },
-
- /**
- * returns the program error log
- * @return {String}
- */
- programLog: function () {
- return this._glContext.getProgramInfoLog(this._programObj);
- },
-
- /**
- * returns the program error log
- * @return {String}
- */
- getProgramLog: function () {
- return this._glContext.getProgramInfoLog(this._programObj);
- },
-
- /**
- * reload all shaders, this function is designed for android
- * when opengl context lost, so don't call it.
- */
- reset: function () {
- this._vertShader = null;
- this._fragShader = null;
- this._uniforms.length = 0;
-
- // it is already deallocated by android
- //cc.gl.deleteProgram(m_uProgram);
- this._glContext.deleteProgram(this._programObj);
- this._programObj = null;
-
- // Purge uniform hash
- for (var key in this._hashForUniforms) {
- this._hashForUniforms[key].length = 0;
- delete this._hashForUniforms[key];
- }
- },
-
- /**
- * get WebGLProgram object
- * @return {WebGLProgram}
- */
- getProgram: function () {
- return this._programObj;
- },
-
- /**
- * Currently JavaScript Bindings (JSB), in some cases, needs to use retain and release. This is a bug in JSB,
- * and the ugly workaround is to use retain/release. So, these 2 methods were added to be compatible with JSB.
- * This is a hack, and should be removed once JSB fixes the retain/release bug
- */
- retain: function () {
- },
- release: function () {
- }
-});
-
-cc.GLProgram._highpSupported = null;
-
-cc.GLProgram._isHighpSupported = function () {
- var ctx = cc._renderContext;
- if (ctx.getShaderPrecisionFormat && cc.GLProgram._highpSupported == null) {
- var highp = ctx.getShaderPrecisionFormat(ctx.FRAGMENT_SHADER, ctx.HIGH_FLOAT);
- cc.GLProgram._highpSupported = highp.precision !== 0;
- }
- return cc.GLProgram._highpSupported;
-};
diff --git a/cocos2d/shaders/CCGLStateCache.js b/cocos2d/shaders/CCGLStateCache.js
deleted file mode 100644
index cf4f258692..0000000000
--- a/cocos2d/shaders/CCGLStateCache.js
+++ /dev/null
@@ -1,265 +0,0 @@
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
-
- http://www.cocos2d-x.org
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var _currentProjectionMatrix = -1;
-
-var macro = cc.macro;
-var ENABLE_GL_STATE_CACHE = macro.ENABLE_GL_STATE_CACHE;
-
-var MAX_ACTIVETEXTURE = 0,
- _currentShaderProgram = 0,
- _currentBoundTexture = null,
- _blendingSource = 0,
- _blendingDest = 0,
- _GLServerState = 0;
-if (ENABLE_GL_STATE_CACHE) {
- MAX_ACTIVETEXTURE = 16;
- _currentShaderProgram = -1;
- _currentBoundTexture = new Array(MAX_ACTIVETEXTURE);
- _blendingSource = -1;
- _blendingDest = -1;
- _GLServerState = 0;
-}
-
-// GL State Cache functions
-
-cc.gl = {};
-
-/*
- * Invalidates the GL state cache.
- * If cc.macro.ENABLE_GL_STATE_CACHE it will reset the GL state cache.
- * @function
- */
-cc.gl.invalidateStateCache = function () {
- cc.math.glFreeAll();
- _currentProjectionMatrix = -1;
- if (ENABLE_GL_STATE_CACHE) {
- _currentShaderProgram = -1;
- for (var i = 0; i < MAX_ACTIVETEXTURE; i++) {
- _currentBoundTexture[i] = null;
- }
- _blendingSource = -1;
- _blendingDest = -1;
- _GLServerState = 0;
- }
-};
-
-/*
- * Uses the GL program in case program is different than the current one.
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will use glContext.useProgram() directly.
- * @function
- * @param {WebGLProgram} program
- */
-cc.gl.useProgram = ENABLE_GL_STATE_CACHE ? function (program) {
- if (program !== _currentShaderProgram) {
- _currentShaderProgram = program;
- cc._renderContext.useProgram(program);
- }
-} : function (program) {
- cc._renderContext.useProgram(program);
-};
-
-/*
- * Deletes the GL program. If it is the one that is being used, it invalidates it.
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will use gl.deleteProgram() directly.
- * @function
- * @param {WebGLProgram} program
- */
-cc.gl.deleteProgram = function (program) {
- if (ENABLE_GL_STATE_CACHE) {
- if (program === _currentShaderProgram)
- _currentShaderProgram = -1;
- }
- gl.deleteProgram(program);
-};
-
-/**
- * @function
- * @param {Number} sfactor
- * @param {Number} dfactor
- */
-cc.gl.setBlending = function (sfactor, dfactor) {
- var gl = cc._renderContext;
- if ((sfactor === gl.ONE) && (dfactor === gl.ZERO)) {
- gl.disable(gl.BLEND);
- } else {
- gl.enable(gl.BLEND);
- gl.blendFunc(sfactor,dfactor);
- //TODO need fix for WebGL
- // gl.blendFuncSeparate(sfactor, dfactor, sfactor, dfactor);
- }
-};
-
-/*
- * Uses a blending function in case it not already used.
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will use glContext.blendFunc() directly.
- * @function
- * @param {Number} sfactor
- * @param {Number} dfactor
- */
-cc.gl.blendFunc = ENABLE_GL_STATE_CACHE ? function (sfactor, dfactor) {
- if ((sfactor !== _blendingSource) || (dfactor !== _blendingDest)) {
- _blendingSource = sfactor;
- _blendingDest = dfactor;
- cc.gl.setBlending(sfactor, dfactor);
- }
-} : cc.gl.setBlending;
-
-/**
- * @function
- * @param {Number} sfactor
- * @param {Number} dfactor
- */
-cc.gl.blendFuncForParticle = function(sfactor, dfactor) {
- if ((sfactor !== _blendingSource) || (dfactor !== _blendingDest)) {
- _blendingSource = sfactor;
- _blendingDest = dfactor;
- var ctx = cc._renderContext;
- if ((sfactor === ctx.ONE) && (dfactor === ctx.ZERO)) {
- ctx.disable(ctx.BLEND);
- } else {
- ctx.enable(ctx.BLEND);
- // TODO need fix for WebGL
- // DO NOT TOUCH THIS, YOU MAY NOT BE ABLE TO FIX EVERYTHING
- ctx.blendFuncSeparate(ctx.SRC_ALPHA, dfactor, sfactor, dfactor);
- }
- }
-};
-
-/**
- * Resets the blending mode back to the cached state in case you used glBlendFuncSeparate() or glBlendEquation().
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will just set the default blending mode using GL_FUNC_ADD.
- * @function
- */
-cc.gl.blendResetToCache = function () {
- var ctx = cc._renderContext;
- ctx.blendEquation(ctx.FUNC_ADD);
- if (ENABLE_GL_STATE_CACHE)
- cc.gl.setBlending(_blendingSource, _blendingDest);
- else
- cc.gl.setBlending(ctx.BLEND_SRC, ctx.BLEND_DST);
-};
-
-/**
- * sets the projection matrix as dirty
- * @function
- */
-cc.gl.setProjectionMatrixDirty = function () {
- _currentProjectionMatrix = -1;
-};
-
-/**
- * If the texture is not already bound, it binds it.
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
- * @function
- * @param {Texture2D} texture
- */
-cc.gl.bindTexture2D = function (texture) {
- cc.gl.bindTexture2DN(0, texture);
-};
-
-/**
- * If the texture is not already bound to a given unit, it binds it.
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glBindTexture() directly.
- * @function
- * @param {Number} textureUnit
- * @param {Texture2D} texture
- */
-cc.gl.bindTexture2DN = ENABLE_GL_STATE_CACHE ? function (textureUnit, texture) {
- if (_currentBoundTexture[textureUnit] === texture)
- return;
- _currentBoundTexture[textureUnit] = texture;
-
- var ctx = cc._renderContext;
- ctx.activeTexture(ctx.TEXTURE0 + textureUnit);
- if(texture)
- ctx.bindTexture(ctx.TEXTURE_2D, texture._glID);
- else
- ctx.bindTexture(ctx.TEXTURE_2D, null);
-} : function (textureUnit, texture) {
- var ctx = cc._renderContext;
- ctx.activeTexture(ctx.TEXTURE0 + textureUnit);
- if(texture)
- ctx.bindTexture(ctx.TEXTURE_2D, texture._glID);
- else
- ctx.bindTexture(ctx.TEXTURE_2D, null);
-};
-
-/**
- * It will delete a given texture. If the texture was bound, it will invalidate the cached.
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
- * @function
- * @param {Texture2D} texture
- */
-cc.gl.deleteTexture2D = function (texture) {
- cc.gl.deleteTexture2DN(0, texture);
-};
-
-/**
- * It will delete a given texture. If the texture was bound, it will invalidate the cached for the given texture unit.
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly.
- * @function
- * @param {Number} textureUnit
- * @param {Texture2D} texture
- */
-cc.gl.deleteTexture2DN = function (textureUnit, texture) {
- if (ENABLE_GL_STATE_CACHE) {
- if (texture === _currentBoundTexture[ textureUnit ])
- _currentBoundTexture[ textureUnit ] = null;
- }
- cc._renderContext.deleteTexture(texture._glID);
-};
-
-/**
- * It will enable / disable the server side GL states.
- * If cc.macro.ENABLE_GL_STATE_CACHE is disabled, it will call glEnable() directly.
- * @function
- * @param {Number} flags
- */
-cc.gl.enable = function (flags) {
- if (ENABLE_GL_STATE_CACHE) {
- /*var enabled;
-
- */
- /* GL_BLEND */
- /*
- if ((enabled = (flags & cc.GL_BLEND)) != (_GLServerState & cc.GL_BLEND)) {
- if (enabled) {
- cc._renderContext.enable(cc._renderContext.BLEND);
- _GLServerState |= cc.GL_BLEND;
- } else {
- cc._renderContext.disable(cc._renderContext.BLEND);
- _GLServerState &= ~cc.GL_BLEND;
- }
- }*/
- } else {
- /*if ((flags & cc.GL_BLEND))
- cc._renderContext.enable(cc._renderContext.BLEND);
- else
- cc._renderContext.disable(cc._renderContext.BLEND);*/
- }
-};
-
diff --git a/cocos2d/shaders/CCShaderCache.js b/cocos2d/shaders/CCShaderCache.js
deleted file mode 100644
index 33b8447e89..0000000000
--- a/cocos2d/shaders/CCShaderCache.js
+++ /dev/null
@@ -1,265 +0,0 @@
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2014 Chukong Technologies Inc.
-
- http://www.cocos2d-x.org
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-var shaders = cc.PresetShaders;
-var macro = cc.macro;
-
-/**
- * cc.shaderCache is a singleton object that stores manages GL shaders
- * @class
- * @name cc.shaderCache
- */
-cc.shaderCache = /** @lends cc.shaderCache# */{
-
- /**
- * Position Texture Color shader
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_POSITION_TEXTURECOLOR: 0,
- /**
- * Position Texture Color alpha test
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_POSITION_TEXTURECOLOR_ALPHATEST: 1,
- /**
- * Position, Color shader
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_POSITION_COLOR: 2,
- /**
- * Position Texture shader
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_POSITION_TEXTURE: 3,
- /**
- * Position, Texture attribs, 1 Color as uniform shader
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_POSITION_TEXTURE_UCOLOR: 4,
- /**
- * Position Texture A8 Color shader
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_POSITION_TEXTURE_A8COLOR: 5,
- /**
- * Position and 1 color passed as a uniform (to similate glColor4ub )
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_POSITION_UCOLOR: 6,
- /**
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_POSITION_LENGTH_TEXTURECOLOR: 7,
- /**
- * Sprite Position Texture Color shader
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_SPRITE_POSITION_TEXTURECOLOR: 8,
- /**
- * Sprite Position Texture Color alpha shader
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_SPRITE_POSITION_TEXTURECOLOR_ALPHATEST: 9,
- /**
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_SPRITE_POSITION_COLOR: 10,
- /**
- * @public
- * @constant
- * @type {Number}
- */
- TYPE_MAX: 10,
-
- _programs: {},
-
- _init: function () {
- this.loadDefaultShaders();
- return true;
- },
-
- _loadDefaultShader: function (program, type) {
- switch (type) {
- case macro.SHADER_POSITION_TEXTURECOLOR:
- program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_COLOR_VERT, shaders.POSITION_TEXTURE_COLOR_FRAG);
-
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
- break;
- case macro.SHADER_SPRITE_POSITION_TEXTURECOLOR:
- program.initWithVertexShaderByteArray(shaders.SPRITE_POSITION_TEXTURE_COLOR_VERT, shaders.POSITION_TEXTURE_COLOR_FRAG);
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
- break;
- case macro.SHADER_POSITION_TEXTURECOLORALPHATEST:
- program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_COLOR_VERT, shaders.POSITION_TEXTURE_COLOR_ALPHATEST_FRAG);
-
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
- break;
- case macro.SHADER_SPRITE_POSITION_TEXTURECOLORALPHATEST:
- program.initWithVertexShaderByteArray(shaders.SPRITE_POSITION_TEXTURE_COLOR_VERT, shaders.POSITION_TEXTURE_COLOR_ALPHATEST_FRAG);
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
- break;
- case macro.SHADER_POSITION_COLOR:
- program.initWithVertexShaderByteArray(shaders.POSITION_COLOR_VERT, shaders.POSITION_COLOR_FRAG);
-
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
- break;
- case macro.SHADER_SPRITE_POSITION_COLOR:
- program.initWithVertexShaderByteArray(shaders.SPRITE_POSITION_COLOR_VERT, shaders.POSITION_COLOR_FRAG);
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
- break;
- case macro.SHADER_POSITION_TEXTURE:
- program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_VERT, shaders.POSITION_TEXTURE_FRAG);
-
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
- break;
- case macro.SHADER_POSITION_TEXTURE_UCOLOR:
- program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_UCOLOR_VERT, shaders.POSITION_TEXTURE_UCOLOR_FRAG);
-
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
- break;
- case macro.SHADER_POSITION_TEXTUREA8COLOR:
- program.initWithVertexShaderByteArray(shaders.POSITION_TEXTURE_A8COLOR_VERT, shaders.POSITION_TEXTURE_A8COLOR_FRAG);
-
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
- program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
- break;
- case macro.SHADER_POSITION_UCOLOR:
- program.initWithVertexShaderByteArray(shaders.POSITION_UCOLOR_VERT, shaders.POSITION_UCOLOR_FRAG);
- program.addAttribute("aVertex", macro.VERTEX_ATTRIB_POSITION);
- break;
- case macro.SHADER_POSITION_LENGTHTEXTURECOLOR:
- program.initWithVertexShaderByteArray(shaders.POSITION_COLOR_LENGTH_TEXTURE_VERT, shaders.POSITION_COLOR_LENGTH_TEXTURE_FRAG);
-
- program.addAttribute(macro.ATTRIBUTE_NAME_POSITION, macro.VERTEX_ATTRIB_POSITION);
- program.addAttribute(macro.ATTRIBUTE_NAME_TEX_COORD, macro.VERTEX_ATTRIB_TEX_COORDS);
- program.addAttribute(macro.ATTRIBUTE_NAME_COLOR, macro.VERTEX_ATTRIB_COLOR);
- break;
- default:
- cc.logID(8105);
- return;
- }
-
- program.link();
- program.updateUniforms();
-
- //cc.checkGLErrorDebug();
- },
-
- _reloadShader: function (type) {
- var program = this.programForKey(type);
- program.reset();
- this._loadDefaultShader(program, type);
- },
-
- /**
- * loads the default shaders
- */
- loadDefaultShaders: function () {
- },
-
- /**
- * reload the default shaders
- */
- reloadDefaultShaders: function () {
- // reset all default programs and reload them
- this._reloadShader(macro.SHADER_POSITION_TEXTURECOLOR);
- this._reloadShader(macro.SHADER_SPRITE_POSITION_TEXTURECOLOR);
- this._reloadShader(macro.SHADER_POSITION_TEXTURECOLORALPHATEST);
- this._reloadShader(macro.SHADER_SPRITE_POSITION_TEXTURECOLORALPHATEST);
- this._reloadShader(macro.SHADER_POSITION_COLOR);
- this._reloadShader(macro.SHADER_POSITION_TEXTURE);
- this._reloadShader(macro.SHADER_POSITION_TEXTURE_UCOLOR);
- this._reloadShader(macro.SHADER_POSITION_TEXTUREA8COLOR);
- this._reloadShader(macro.SHADER_POSITION_UCOLOR);
- },
-
- /**
- * returns a GL program for a given key
- * @param {String} key
- */
- programForKey: function (key) {
- if (!this._programs[key]) {
- var program = new cc.GLProgram();
- this._loadDefaultShader(program, key);
- this._programs[key] = program;
- }
-
- return this._programs[key];
- },
-
- /**
- * returns a GL program for a shader name
- * @param {String} shaderName
- * @return {cc.GLProgram}
- */
- getProgram: function (shaderName) {
- return this.programForKey(shaderName);
- },
-
- /**
- * adds a CCGLProgram to the cache for a given name
- * @param {cc.GLProgram} program
- * @param {String} key
- */
- addProgram: function (program, key) {
- this._programs[key] = program;
- }
-};
diff --git a/cocos2d/shaders/CCShaders.js b/cocos2d/shaders/CCShaders.js
deleted file mode 100644
index 96e92386bb..0000000000
--- a/cocos2d/shaders/CCShaders.js
+++ /dev/null
@@ -1,297 +0,0 @@
-/****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2011-2012 cocos2d-x.org
- Copyright (c) 2013-2016 Chukong Technologies Inc.
-
- http://www.cocos2d-x.org
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-//-----------------------Shader_Position_uColor Shader Source--------------------------
-
-/**
- * Predefined propertys
- * @class PresetShaders
- * @readonly
- * @type {Object}
- * @static
- * @namespace cc
- */
-cc.PresetShaders = {
- /**
- * @property POSITION_UCOLOR_FRAG
- * @type {String}
- */
- POSITION_UCOLOR_FRAG : "precision lowp float;\n"
- + "varying vec4 v_fragmentColor;\n"
- + "void main()\n"
- + "{\n"
- + "gl_FragColor = v_fragmentColor;\n"
- + "}",
-
- /**
- * @property POSITION_UCOLOR_VERT
- * @type {String}
- */
- POSITION_UCOLOR_VERT : "attribute vec4 a_position;\n"
- + "uniform vec4 u_color;\n"
- + "uniform float u_pointSize;\n"
- + "varying lowp vec4 v_fragmentColor;\n"
- + "void main(void)\n"
- + "{\n"
- + "gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;\n"
- + "gl_PointSize = u_pointSize;\n"
- + "v_fragmentColor = u_color;\n"
- + "}",
-
- //---------------------Shader_PositionColor Shader Source-----------------------
- /**
- * @property POSITION_COLOR_FRAG
- * @type {String}
- */
- POSITION_COLOR_FRAG : "precision lowp float;\n"
- + "varying vec4 v_fragmentColor;\n"
- + "void main()\n"
- + "{\n"
- + "gl_FragColor = v_fragmentColor;\n"
- + "}",
-
- /**
- * @property POSITION_COLOR_VERT
- * @type {String}
- */
- POSITION_COLOR_VERT : "attribute vec4 a_position;\n"
- + "attribute vec4 a_color;\n"
- + "varying lowp vec4 v_fragmentColor;\n"
- + "void main()\n"
- + "{\n"
- + "gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;\n"
- + "v_fragmentColor = a_color;\n"
- + "}",
-
- /**
- * @property SPRITE_POSITION_COLOR_VERT
- * @type {String}
- */
- SPRITE_POSITION_COLOR_VERT : "attribute vec4 a_position;\n"
- + "attribute vec4 a_color;\n"
- + "varying lowp vec4 v_fragmentColor;\n"
- + "void main()\n"
- + "{\n"
- + "gl_Position = CC_PMatrix * a_position;\n"
- + "v_fragmentColor = a_color;\n"
- + "}",
-
- // --------------------- Shader_PositionColorLengthTexture Shader source------------------------
- /**
- * @property POSITION_COLOR_LENGTH_TEXTURE_FRAG
- * @type {String}
- */
- POSITION_COLOR_LENGTH_TEXTURE_FRAG :
- "//#extension GL_OES_standard_derivatives : enable\n"
- + "varying mediump vec4 v_color;\n"
- + "varying mediump vec2 v_texcoord;\n"
- + "void main()\n"
- + "{\n"
- + "//#if defined GL_OES_standard_derivatives\n"
- + "//gl_FragColor=v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0-length(v_texcoord));\n"
- + "//#else\n"
- + "gl_FragColor = v_color * step(0.0, 1.0 - length(v_texcoord));\n"
- + "//#endif\n"
- + "}",
-
- /**
- * @property POSITION_COLOR_LENGTH_TEXTURE_VERT
- * @type {String}
- */
- POSITION_COLOR_LENGTH_TEXTURE_VERT : "attribute mediump vec4 a_position;\n"
- + "attribute mediump vec2 a_texcoord;\n"
- + "attribute mediump vec4 a_color;\n"
- + "varying mediump vec4 v_color;\n"
- + "varying mediump vec2 v_texcoord;\n"
- + "void main()\n"
- + "{\n"
- + "v_color = a_color;\n"//vec4(a_color.rgb*a_color.a, a_color.a);
- + "v_texcoord = a_texcoord;\n"
- + "gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;\n"
- + "}",
-
- // ----------------------Shader_PositionTexture Shader Source-------------------------------------
- /**
- * @property POSITION_TEXTURE_FRAG
- * @type {String}
- */
- POSITION_TEXTURE_FRAG : "precision lowp float;\n"
- + "varying vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_FragColor = texture2D(CC_Texture0, v_texCoord);\n"
- + "}",
-
- /**
- * @property POSITION_TEXTURE_VERT
- * @type {String}
- */
- POSITION_TEXTURE_VERT : "attribute vec4 a_position;\n"
- + "attribute vec2 a_texCoord;\n"
- + "varying mediump vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;\n"
- + "v_texCoord = a_texCoord;\n"
- + "}",
-
- // ------------------------Shader_PositionTexture_uColor Shader Source-------------------------------
- /**
- * @property POSITION_TEXTURE_UCOLOR_FRAG
- * @type {String}
- */
- POSITION_TEXTURE_UCOLOR_FRAG : "precision lowp float;\n"
- + "uniform vec4 u_color;\n"
- + "varying vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_FragColor=texture2D(CC_Texture0, v_texCoord) * u_color;\n"
- + "}",
-
- /**
- * @property POSITION_TEXTURE_UCOLOR_VERT
- * @type {String}
- */
- POSITION_TEXTURE_UCOLOR_VERT : "attribute vec4 a_position;\n"
- + "attribute vec2 a_texCoord;\n"
- + "varying mediump vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;\n"
- + "v_texCoord = a_texCoord;\n"
- + "}",
-
- //---------------------Shader_PositionTextureA8Color Shader source-------------------------------
- /**
- * @property POSITION_TEXTURE_A8COLOR_FRAG
- * @type {String}
- */
- POSITION_TEXTURE_A8COLOR_FRAG : "precision lowp float;\n"
- + "varying vec4 v_fragmentColor;\n"
- + "varying vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_FragColor = vec4(v_fragmentColor.rgb,\n"// RGB from uniform
- + "v_fragmentColor.a * texture2D(CC_Texture0, v_texCoord).a);\n"// A from texture and uniform
- + "}",
-
- /**
- * @property POSITION_TEXTURE_A8COLOR_VERT
- * @type {String}
- */
- POSITION_TEXTURE_A8COLOR_VERT : "attribute vec4 a_position;\n"
- + "attribute vec2 a_texCoord;\n"
- + "attribute vec4 a_color;\n"
- + "varying lowp vec4 v_fragmentColor;\n"
- + "varying mediump vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;\n"
- + "v_fragmentColor = a_color;\n"
- + "v_texCoord = a_texCoord;\n"
- + "}",
-
- // ------------------------Shader_PositionTextureColor Shader source------------------------------------
- /**
- * @property POSITION_TEXTURE_COLOR_FRAG
- * @type {String}
- */
- POSITION_TEXTURE_COLOR_FRAG : "precision lowp float;\n"
- + "varying vec4 v_fragmentColor;\n"
- + "varying vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord);\n"
- + "}",
-
- /**
- * @property POSITION_TEXTURE_COLOR_VERT
- * @type {String}
- */
- POSITION_TEXTURE_COLOR_VERT : "attribute vec4 a_position;\n"
- + "attribute vec2 a_texCoord;\n"
- + "attribute vec4 a_color;\n"
- + "varying lowp vec4 v_fragmentColor;\n"
- + "varying mediump vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_Position = (CC_PMatrix * CC_MVMatrix) * a_position;\n"
- + "v_fragmentColor = a_color;\n"
- + "v_texCoord = a_texCoord;\n"
- + "}",
-
- /**
- * @property SPRITE_POSITION_TEXTURE_COLOR_VERT
- * @type {String}
- */
- SPRITE_POSITION_TEXTURE_COLOR_VERT : "attribute vec4 a_position;\n"
- + "attribute vec2 a_texCoord;\n"
- + "attribute vec4 a_color;\n"
- + "varying lowp vec4 v_fragmentColor;\n"
- + "varying mediump vec2 v_texCoord;\n"
- + "void main()\n"
- + "{\n"
- + "gl_Position = CC_PMatrix * a_position;\n"
- + "v_fragmentColor = a_color;\n"
- + "v_texCoord = a_texCoord;\n"
- + "}",
-
- //-----------------------Shader_PositionTextureColorAlphaTest_frag Shader Source----------------------------
- /**
- * @property POSITION_TEXTURE_COLOR_ALPHATEST_FRAG
- * @type {String}
- */
- POSITION_TEXTURE_COLOR_ALPHATEST_FRAG : "precision lowp float;\n"
- + "varying vec4 v_fragmentColor;\n"
- + "varying vec2 v_texCoord;\n"
- + "uniform float CC_alpha_value;\n"
- + "void main()\n"
- + "{\n"
- + "vec4 texColor=texture2D(CC_Texture0, v_texCoord);\n"
- + "if(texColor.a <= CC_alpha_value)\n"
- + " discard; \n"
- + "gl_FragColor=texColor*v_fragmentColor;\n"
- + "}",
-
- //-----------------------ShaderEx_SwitchMask_frag Shader Source----------------------------
- /**
- * @property EX_SWITCHMASK_FRAG
- * @type {String}
- */
- EX_SWITCHMASK_FRAG : "precision lowp float;\n"
- + "varying vec4 v_fragmentColor;\n"
- + "varying vec2 v_texCoord;\n"
- + "uniform sampler2D u_texture;\n"
- + "uniform sampler2D u_mask;\n"
- + "void main()\n"
- + "{\n"
- + "vec4 texColorc=texture2D(u_texture, v_texCoord);\n"
- + "vec4 maskColor=texture2D(u_mask, v_texCoord);\n"
- + "vec4 finalColor=vec4(texColor.r, texColor.g, texColor.b, maskColor.a*texColor.a);\n"
- + "gl_FragColor=v_fragmentColor*finalColor;\n"
- + "}"
-
-};
diff --git a/cocos2d/shaders/index.js b/cocos2d/shaders/index.js
deleted file mode 100644
index 49a1aeb233..0000000000
--- a/cocos2d/shaders/index.js
+++ /dev/null
@@ -1,29 +0,0 @@
-/****************************************************************************
- Copyright (c) 2013-2016 Chukong Technologies Inc.
-
- http://www.cocos.com
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated engine source code (the "Software"), a limited,
- worldwide, royalty-free, non-assignable, revocable and non-exclusive license
- to use Cocos Creator solely to develop games on your target platforms. You shall
- not use Cocos Creator software for developing other software or tools that's
- used for developing games. You are not granted to publish, distribute,
- sublicense, and/or sell copies of Cocos Creator.
-
- The software or tools in this License Agreement are licensed, not sold.
- Chukong Aipu reserves all rights not expressly granted to you.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
-
-require('./CCShaders');
-require('./CCShaderCache');
-require('./CCGLProgram');
-require('./CCGLStateCache');
\ No newline at end of file
diff --git a/index.js b/index.js
index 500658ff1f..b4ba4e59b9 100644
--- a/index.js
+++ b/index.js
@@ -168,7 +168,6 @@ if (!(CC_EDITOR && Editor.isMainProcess)) {
require('./polyfill/typescript');
}
-require('./cocos2d/kazmath');
require('./cocos2d/core/predefine');
_global.ccs = {};
@@ -177,7 +176,6 @@ _global.cp = {};
// LOAD COCOS2D ENGINE CODE
if (!(CC_EDITOR && Editor.isMainProcess)) {
- require('./cocos2d/shaders');
require('./CCBoot');
require('./cocos2d');
}