Beispiel #1
0
        public void on_glUniform4iv(MyBinStream stream)
        {
            int location = stream.readInt();
            int count    = stream.readInt();

            if (location < 0 || count <= 0)
            {
                return;
            }
            for (int i = 0; i < m_uniformsCount; i++)
            {
                KPVar uni = m_uniforms[i];

                if (uni.Location == location)
                {
                    var res = "";
                    for (int j = 0; j < count; j++)
                    {
                        res += string.Format("({0}, {1}, {2}, {3})", stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt());
                        if (j < count - 1)
                        {
                            res += ", ";
                        }
                    }
                    uni.Value = res;
                    break;
                }
            }
        }
Beispiel #2
0
        public List <uint> getDrawingTextures()
        {
            m_drawingTextures.Clear();

            KPProgram prog = this.CurrentProgramObject;

            if (prog == null)
            {
                return(m_drawingTextures);
            }

            for (int i = 0; i < prog.UniformsCount; i++)
            {
                KPVar uni = prog.Uniforms[i];
                if (uni.Type == gl2.GL_SAMPLER_2D || uni.Type == gl2.GL_SAMPLER_CUBE)
                {
                    uint[] listTu = uni.Type == gl2.GL_SAMPLER_2D ? m_listTexUnits_2D : m_listTexUnits_CubeMap;

                    string[] texUnits = uni.Value.Split(m_sValueSeparate, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string texIdStr in texUnits)
                    {
                        uint tu = uint.Parse(texIdStr.Trim());
                        Utils.assert(tu >= 0 && tu < KPClient.MAX_TEX_UNITS_NUMBER);
                        m_drawingTextures.Add(listTu[tu]);
                    }
                }
            }
            return(m_drawingTextures);
        }
Beispiel #3
0
 public void copyFrom(KPVar var)
 {
     m_name     = var.Name;
     m_value    = var.Value;
     m_location = var.Location;
     m_size     = var.Size;
     m_type     = var.Type;
 }
Beispiel #4
0
 private void init()
 {
     m_attributes = new KPVar[MAX_ATTRIBUTES_NUMBER];
     for (int i = 0; i < MAX_ATTRIBUTES_NUMBER; i++)
     {
         m_attributes[i] = new KPVar();
     }
     m_uniforms = new KPVar[MAX_UNIFORMS_NUMBER];
     for (int i = 0; i < MAX_UNIFORMS_NUMBER; i++)
     {
         m_uniforms[i] = new KPVar();
     }
 }
Beispiel #5
0
        public void on_glUniform4i(MyBinStream stream)
        {
            int location = stream.readInt();

            if (location < 0)
            {
                return;
            }
            for (int i = 0; i < m_uniformsCount; i++)
            {
                KPVar uni = m_uniforms[i];

                if (uni.Location == location)
                {
                    uni.Value = string.Format("{0}, {1}, {2}, {3}", stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt());
                    break;
                }
            }
        }
Beispiel #6
0
        public void on_glUniformMatrix(MyBinStream stream, int size)
        {
            int location = stream.readInt();
            int count    = stream.readInt();

            if (location < 0 || count <= 0)
            {
                return;
            }
            byte transpose = stream.readByte();

            for (int i = 0; i < m_uniformsCount; i++)
            {
                KPVar uni = m_uniforms[i];

                if (uni.Location == location)
                {
                    uni.Value = Utils.makeMatrixString(stream, count, size);
                    break;
                }
            }
        }
Beispiel #7
0
        public void fromStream(MyBinStream stream)
        {
            m_id   = stream.readUInt();
            m_vsId = stream.readUInt();
            m_fsId = stream.readUInt();

            //
            m_attributesCount = stream.readInt();
            for (int i = 0; i < m_attributesCount; i++)
            {
                KPVar var = m_attributes[i];

                var.Location = stream.readInt();
                var.Size     = stream.readInt();
                var.Type     = stream.readUInt();

                int strLen = stream.readInt();
                var.Name = stream.readString(strLen);
            }

            //
            m_uniformsCount = stream.readInt();

            for (int i = 0; i < m_uniformsCount; i++)
            {
                KPVar var = m_uniforms[i];

                var.Location = stream.readInt();
                var.Size     = stream.readInt();
                var.Type     = stream.readUInt();

                int strLen = stream.readInt();
                var.Name = stream.readString(strLen);

                int    dataLen = stream.readInt();
                string res     = "";

                if (dataLen > 0)
                {
                    switch (var.Type)
                    {
                        #region FLOAT
                    case gl2.GL_FLOAT:
                    {
                        Utils.assert(dataLen % 4 == 0);
                        int count = dataLen / 4;
                        for (int j = 0; j < count; j++)
                        {
                            res += stream.readFloat();
                            if (j < count - 1)
                            {
                                res += ", ";
                            }
                        }
                        break;
                    }

                    case gl2.GL_FLOAT_VEC2:
                    {
                        Utils.assert(dataLen % 8 == 0);
                        int count = dataLen / 8;
                        for (int j = 0; j < count; j++)
                        {
                            res += string.Format("({0}, {1})", stream.readFloat(), stream.readFloat());
                            if (j < count - 1)
                            {
                                res += ", ";
                            }
                        }
                        break;
                    }

                    case gl2.GL_FLOAT_VEC3:
                    {
                        Utils.assert(dataLen % 12 == 0);
                        int count = dataLen / 12;
                        for (int j = 0; j < count; j++)
                        {
                            res += string.Format("({0}, {1}, {2})", stream.readFloat(), stream.readFloat(), stream.readFloat());
                            if (j < count - 1)
                            {
                                res += ", ";
                            }
                        }
                        break;
                    }

                    case gl2.GL_FLOAT_VEC4:
                    {
                        Utils.assert(dataLen % 16 == 0);
                        int count = dataLen / 16;
                        for (int j = 0; j < count; j++)
                        {
                            res += string.Format("({0}, {1}, {2}, {3})", stream.readFloat(), stream.readFloat(), stream.readFloat(), stream.readFloat());
                            if (j < count - 1)
                            {
                                res += ", ";
                            }
                        }
                        break;
                    }
                        #endregion

                        #region INT, BOOL, SAMPLER
                    case gl2.GL_INT:
                    case gl2.GL_SAMPLER_2D:
                    case gl2.GL_SAMPLER_3D:
                    case gl2.GL_SAMPLER_CUBE:
                    case gl2.GL_BOOL:
                    {
                        Utils.assert(dataLen % 4 == 0);
                        int count = dataLen / 4;
                        for (int j = 0; j < count; j++)
                        {
                            res += stream.readInt();
                            if (j < count - 1)
                            {
                                res += ", ";
                            }
                        }
                        break;
                    }

                    case gl2.GL_INT_VEC2:
                    case gl2.GL_BOOL_VEC2:
                    {
                        Utils.assert(dataLen % 8 == 0);
                        int count = dataLen / 8;
                        for (int j = 0; j < count; j++)
                        {
                            res += string.Format("({0}, {1})", stream.readInt(), stream.readInt());
                            if (j < count - 1)
                            {
                                res += ", ";
                            }
                        }
                        break;
                    }

                    case gl2.GL_INT_VEC3:
                    case gl2.GL_BOOL_VEC3:
                    {
                        Utils.assert(dataLen % 12 == 0);
                        int count = dataLen / 12;
                        for (int j = 0; j < count; j++)
                        {
                            res += string.Format("({0}, {1}, {2})", stream.readInt(), stream.readInt(), stream.readInt());
                            if (j < count - 1)
                            {
                                res += ", ";
                            }
                        }
                        break;
                    }

                    case gl2.GL_INT_VEC4:
                    case gl2.GL_BOOL_VEC4:
                    {
                        Utils.assert(dataLen % 16 == 0);
                        int count = dataLen / 16;
                        for (int j = 0; j < count; j++)
                        {
                            res += string.Format("({0}, {1}, {2}, {3})", stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt());
                            if (j < count - 1)
                            {
                                res += ", ";
                            }
                        }
                        break;
                    }
                        #endregion

                        #region MATRIX
                    case gl2.GL_FLOAT_MAT2:
                    case gl2.GL_FLOAT_MAT3:
                    case gl2.GL_FLOAT_MAT4:
                    {
                        int size  = (var.Type == gl2.GL_FLOAT_MAT2) ? 2 : (var.Type == gl2.GL_FLOAT_MAT3 ? 3 : 4);
                        int bytes = size * size * 4;
                        Utils.assert(dataLen % bytes == 0);
                        int count = dataLen / bytes;
                        res = Utils.makeMatrixString(stream, count, size);
                        break;
                    }
                        #endregion

                    default:
                    {
                        Utils.assert(false);
                        break;
                    }
                    }                     // switch (var.Type)
                }

                var.Value = res;
            }
        }