public ShaderUniformDeclaration(ShaderUniformType type, string name, int count = 1)
 {
     Type  = type;
     Name  = name;
     Count = count;
     Size  = type.GetDescription().Size *Count;
 }
예제 #2
0
        /// <summary>
        /// Get the number of slots occupied by an uniform type.
        /// </summary>
        /// <param name="uniformType"></param>
        /// <returns></returns>
        private static uint GetUniformSlotCount(ShaderUniformType uniformType)
        {
            switch (uniformType)
            {
            case ShaderUniformType.Float:
            case ShaderUniformType.Int:
            case ShaderUniformType.UInt:
            case ShaderUniformType.Bool:
                return(1);

            case ShaderUniformType.Vec2:
            case ShaderUniformType.IntVec2:
            case ShaderUniformType.UIntVec2:
            case ShaderUniformType.BoolVec2:
                return(2);

            case ShaderUniformType.Vec3:
            case ShaderUniformType.IntVec3:
            case ShaderUniformType.UIntVec3:
            case ShaderUniformType.BoolVec3:
                return(3);

            case ShaderUniformType.Vec4:
            case ShaderUniformType.IntVec4:
            case ShaderUniformType.UIntVec4:
            case ShaderUniformType.BoolVec4:
                return(4);

            case ShaderUniformType.Mat2x2:
                return(4);

            case ShaderUniformType.Mat3x3:
                return(9);

            case ShaderUniformType.Mat4x4:
                return(16);

            case ShaderUniformType.Mat2x3:
            case ShaderUniformType.Mat3x2:
                return(6);

            case ShaderUniformType.Mat2x4:
            case ShaderUniformType.Mat4x2:
                return(8);

            case ShaderUniformType.Mat3x4:
            case ShaderUniformType.Mat4x3:
                return(12);

            default:
                // Assume sampler type
                return(1);

            case ShaderUniformType.Unknown:
                throw new ArgumentException("invalid type", "uniformType");
            }
        }
예제 #3
0
        public static UniformTypeDescription GetDescription(this ShaderUniformType en)
        {
            Type type = en.GetType();

            MemberInfo[] memInfo = type.GetMember(en.ToString());
            if (memInfo != null && memInfo.Length > 0)
            {
                object[] attrs = memInfo[0].GetCustomAttributes(typeof(UniformTypeDescription), false);
                if (attrs != null && attrs.Length > 0)
                {
                    return((UniformTypeDescription)attrs[0]);
                }
            }
            throw new ArgumentException(string.Format("Uniform type {0} doesn't have a description.", en.ToString()));
        }
예제 #4
0
 public static extern int SetUniformValue(int handle, int index, int offset, ref Vector2 value, ShaderUniformType type);
예제 #5
0
 public static extern int GetUniformType(int handle, int index, out ShaderUniformType result);
예제 #6
0
 public static extern int SetUniformValue2(int handle, int index, int[] value, ShaderUniformType type, int to, int from, int count);
예제 #7
0
        void ParseCBuffer(string block)
        {
            string[] tokens = block.Split(new[] { " ", "\t", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int      index  = 1;

            string bufferName = tokens[index++];
            int    reg        = 0;

            if (tokens[index++] == ":") // Register specified
            {
                reg = int.Parse(Regex.Match(tokens[index++], @"\d+").Value);
            }

            ShaderUniformBufferDeclaration buffer = null;
            ShaderType shaderType = ShaderType.NONE;

            if (bufferName.StartsWith("VS"))
            {
                shaderType = ShaderType.VERTEX;
            }
            else if (bufferName.StartsWith("PS"))
            {
                shaderType = ShaderType.PIXEL;
            }
            else
            {
                Debug.Assert(false, "CBuffer no shader type");
            }

            index++; // {
            while (!tokens[index].Equals("}"))
            {
                string type = tokens[index++];
                string name = tokens[index++];

                // Strip ; from name if present
                name = name.Replace(";", "");

                if (buffer == null)
                {
                    buffer = new ShaderUniformBufferDeclaration(bufferName, reg, shaderType);
                    if (name.StartsWith("sys_"))
                    {
                        switch (shaderType)
                        {
                        case ShaderType.VERTEX: m_VSUniformBuffers.Add(buffer);
                            break;

                        case ShaderType.PIXEL: m_PSUniformBuffers.Add(buffer);
                            break;
                        }
                    }
                    else
                    {
                        switch (shaderType)
                        {
                        case ShaderType.VERTEX:
                            Debug.Assert(m_VSUserUniformBuffer == null);
                            m_VSUserUniformBuffer = buffer;
                            break;

                        case ShaderType.PIXEL:
                            Debug.Assert(m_PSUserUniformBuffer == null);
                            m_PSUserUniformBuffer = buffer;
                            break;
                        }
                    }
                }
                ShaderUniformType        t    = ShaderUniformTypeMethods.StringToUniformType(type);
                ShaderUniformDeclaration decl = null;
                if (t == ShaderUniformType.NONE)
                {
                    ShaderStruct s = FindStruct(type);
                    decl = new ShaderUniformDeclaration(s, name);
                }
                else
                {
                    decl = new ShaderUniformDeclaration(t, name);
                }
                buffer.PushUniform(decl);
            }
            buffer.Align();
        }
예제 #8
0
		/// <summary>
		/// Get the number of slots occupied by an uniform type.
		/// </summary>
		/// <param name="uniformType"></param>
		/// <returns></returns>
		private static uint GetUniformSlotCount(ShaderUniformType uniformType)
		{
			switch (uniformType) {
				case ShaderUniformType.Float:
				case ShaderUniformType.Int:
				case ShaderUniformType.UInt:
				case ShaderUniformType.Bool:
					return (1);
				case ShaderUniformType.Vec2:
				case ShaderUniformType.IntVec2:
				case ShaderUniformType.UIntVec2:
				case ShaderUniformType.BoolVec2:
					return (2);
				case ShaderUniformType.Vec3:
				case ShaderUniformType.IntVec3:
				case ShaderUniformType.UIntVec3:
				case ShaderUniformType.BoolVec3:
					return (3);
				case ShaderUniformType.Vec4:
				case ShaderUniformType.IntVec4:
				case ShaderUniformType.UIntVec4:
				case ShaderUniformType.BoolVec4:
					return (4);
				case ShaderUniformType.Mat2x2:
					return (4);
				case ShaderUniformType.Mat3x3:
					return (9);
				case ShaderUniformType.Mat4x4:
					return (16);
				case ShaderUniformType.Mat2x3:
				case ShaderUniformType.Mat3x2:
					return (6);
				case ShaderUniformType.Mat2x4:
				case ShaderUniformType.Mat4x2:
					return (8);
				case ShaderUniformType.Mat3x4:
				case ShaderUniformType.Mat4x3:
					return (12);
				default:
					// Assume sampler type
					return (1);
				case ShaderUniformType.Unknown:
					throw new ArgumentException("invalid type", "uniformType");
			}
		}
			/// <summary>
			/// Construct a UniformBinding.
			/// </summary>
			/// <param name="uniformName">
			/// A <see cref="String"/> that specify the uniform variable name.
			/// </param>
			/// <param name="uniformIndex">
			/// </param>
			/// <param name="uniformLocation">
			/// </param>
			/// <param name="uniformType">
			/// A <see cref="ShaderUniformType"/> that specify the uniform variable type.
			/// </param>
			public UniformBinding(string uniformName, uint uniformIndex, int uniformLocation, ShaderUniformType uniformType)
			{
				if (uniformName == null)
					throw new ArgumentNullException("uniformName");

				Name = uniformName;
				Index = uniformIndex;
				Location = uniformLocation;
				UniformType = uniformType;
			}