public void LoadRawAsset() { if (this.RawRes != null || !File.Exists(this.AssetPath)) { return; } switch (this.ResourceType) { case EResoucresTypes.TextureType: RawRes = new TextureAttribute(this); break; case EResoucresTypes.MatrialType: RawRes = new MaterialAttribute(this); break; case EResoucresTypes.ShaderType: RawRes = new ShaderAttribute(this); break; case EResoucresTypes.MeshType: RawRes = new MeshAttribute(this); break; } }
public void AddAttribute(ShaderAttribute attribute) { if (attributes == null) { attributes = new List <ShaderAttribute>(); } attributes.Add(attribute); }
public ShaderProgram(Shader vs, Shader fs, ShaderAttribute[] attributes, ShaderAttribute[] secondaryAttributes, string[] uniforms) { m_VertexShader = vs; m_FragmentShader = fs; m_Id = GL.CreateProgram(); GL.AttachShader(m_Id, m_VertexShader.Id); GL.AttachShader(m_Id, m_FragmentShader.Id); GL.LinkProgram(m_Id); GL.UseProgram(m_Id); m_Attributes = new ShaderAttribute[attributes.Length]; if (secondaryAttributes != null) { m_SecondaryAttributes = new ShaderAttribute[secondaryAttributes.Length]; } m_Uniforms = new int[uniforms.Length]; int idx = 0; foreach (ShaderAttribute attribute in attributes) { int location = GL.GetAttribLocation(m_Id, attribute.Name); if (location == -1) { throw new ShaderLoadException(string.Format("Couln't find attribute {0} ({1} | {2}).", attribute.Name, vs.Filename, fs.Filename)); } m_Attributes[idx] = new ShaderAttribute(attribute, location); idx++; } if (secondaryAttributes != null) { idx = 0; foreach (ShaderAttribute attribute in secondaryAttributes) { int location = GL.GetAttribLocation(m_Id, attribute.Name); if (location == -1) { throw new ShaderLoadException(string.Format("Couln't find secondary attribute {0} ({1} | {2}).", attribute.Name, vs.Filename, fs.Filename)); } m_SecondaryAttributes[idx] = new ShaderAttribute(attribute, location); idx++; } } idx = 0; foreach (string u in uniforms) { int location = GL.GetUniformLocation(m_Id, u); if (location == -1) { //throw new ShaderLoadException(string.Format("Couln't find uniform {0} ({1} | {2}).", u, vs.Filename, fs.Filename)); Console.WriteLine(string.Format("Couln't find uniform {0} ({1} | {2}).", u, vs.Filename, fs.Filename)); } m_Uniforms[idx++] = location; } }
public ShaderAttribute(ShaderAttribute attribute, int position) { m_Name = attribute.m_Name; m_Position = position; m_Size = attribute.m_Size; m_Stride = attribute.m_Stride; m_StrideInBytes = attribute.m_StrideInBytes; m_Offset = attribute.m_Offset; }
public static Shader.StageOutput ParseStageOutput(ShaderAttribute attribute) { var parsedAttribute = new Shader.StageOutput() { Location = -1, Component = -1 }; // Parse from the C# attribute if it exists. if (attribute.Attribute != null) { foreach (var namedArg in attribute.Attribute.NamedArguments) { if (namedArg.Key == nameof(Shader.StageInput.Name)) { parsedAttribute.Name = namedArg.Value.ToString(); } else if (namedArg.Key == nameof(Shader.StageOutput.Location)) { parsedAttribute.Location = (int)namedArg.Value.Value; } else if (namedArg.Key == nameof(Shader.StageOutput.Component)) { parsedAttribute.Location = (int)namedArg.Value.Value; } } } // Also always check pre-parsed attributes foreach (var namedArg in attribute.Parameters) { if (namedArg.Name == nameof(Shader.StageInput.Name)) { parsedAttribute.Name = namedArg.Value.ToString(); } else if (namedArg.Name == nameof(Shader.StageOutput.Location)) { parsedAttribute.Location = (int)namedArg.Value; } else if (namedArg.Name == nameof(Shader.StageOutput.Component)) { parsedAttribute.Location = (int)namedArg.Value; } } return(parsedAttribute); }
public void AddAttribute(ShaderAttribute attribute) { Attributes.Add(attribute); }