Esempio n. 1
0
        public void setProgramConstantsFromMatrix(string programType, int firstRegister, Matrix3D matrix,
                                                  bool transposedMatrix = false)
        {
            // GLES does not support transposed uniform setting so do it manually
            if (transposedMatrix)
            {
                //    0  1  2  3
                //    4  5  6  7
                //    8  9 10 11
                //   12 13 14 15
                double[] source = matrix.mData;
                mTemp[0] = (float)source[0];
                mTemp[1] = (float)source[4];
                mTemp[2] = (float)source[8];
                mTemp[3] = (float)source[12];

                mTemp[4] = (float)source[1];
                mTemp[5] = (float)source[5];
                mTemp[6] = (float)source[9];
                mTemp[7] = (float)source[13];

                mTemp[8]  = (float)source[2];
                mTemp[9]  = (float)source[6];
                mTemp[10] = (float)source[10];
                mTemp[11] = (float)source[14];

                mTemp[12] = (float)source[3];
                mTemp[13] = (float)source[7];
                mTemp[14] = (float)source[11];
                mTemp[15] = (float)source[15];
            }
            else
            {
                // convert double->float
                convertDoubleToFloat(mTemp, matrix.mData, 16);
            }

            bool isVertex = (programType == "vertex");

            // set uniform registers
            Program3D.Uniform uniform = mProgram.getUniform(isVertex, firstRegister);
            if (uniform != null)
            {
                GL.UniformMatrix4(uniform.Location, 1, false, mTemp);
            }
            else
            {
                if (enableErrorChecking)
                {
                    Console.WriteLine("warning: program register not found: {0}", firstRegister);
                }
            }
        }
Esempio n. 2
0
        public void setProgramConstantsFromVector(string programType, int firstRegister, Vector <double> data, int numRegisters = -1)
        {
            if (numRegisters == 0)
            {
                return;
            }

            if (numRegisters == -1)
            {
                numRegisters = (int)(data.length / 4);
            }

            bool isVertex = (programType == "vertex");

            // set all registers
            int register  = firstRegister;
            int dataIndex = 0;

            while (numRegisters > 0)
            {
                // get uniform mapped to register
                Program3D.Uniform uniform = mProgram.getUniform(isVertex, register);
                if (uniform == null)
                {
                    // skip this register
                    register     += 1;
                    numRegisters -= 1;
                    dataIndex    += 4;

                    if (enableErrorChecking)
                    {
//						Console.WriteLine ("warning: program register not found: {0}", register);
                    }
                    continue;
                }
                // convert source data into floating point
                int tempIndex = 0;
                for (int i = 0; i < uniform.RegCount; i++)
                {
                    // debug print the constant data
//					Console.WriteLine ("{5}[{0}]: {1}, {2}, {3}, {4}", register + i, data[dataIndex+0], data[dataIndex+1], data[dataIndex+2], data[dataIndex+3], programType);

                    // convert vector4 double->float
                    mTemp[tempIndex++] = (float)data[dataIndex++];
                    mTemp[tempIndex++] = (float)data[dataIndex++];
                    mTemp[tempIndex++] = (float)data[dataIndex++];
                    mTemp[tempIndex++] = (float)data[dataIndex++];
                }

                // set uniforms based on type
                switch (uniform.Type)
                {
                case ActiveUniformType.FloatMat2:
                    GL.UniformMatrix2(uniform.Location, uniform.Size, false, mTemp);
                    break;

                case ActiveUniformType.FloatMat3:
                    GL.UniformMatrix3(uniform.Location, uniform.Size, false, mTemp);
                    break;

                case ActiveUniformType.FloatMat4:
                    GL.UniformMatrix4(uniform.Location, uniform.Size, false, mTemp);
                    break;

                default:
                    GL.Uniform4(uniform.Location, uniform.Size, mTemp);
                    break;
                }

                // advance register number
                register     += uniform.RegCount;
                numRegisters -= uniform.RegCount;
            }
        }