public override bool Link() { bool result = base.Link(); Unlink(); if (result) { boneIndices = Attributes["BoneIndices"]; boneWeights = Attributes["BoneWeights"]; normal = Attributes["Normal"]; position = Attributes["Position"]; texel = Attributes["Texel"]; (ambientLight = Uniforms["AmbientLight"]).Set(ref ambientLightValue); (diffuseColor = Uniforms["DiffuseColor"]).Set(ref diffuseColorValue); (diffuseMap = Uniforms["DiffuseMap"]).Set(diffuseMapValue ?? Device.WhiteTexture); (displayMode = Uniforms["DisplayMode"]).Set((int)displayModeValue); (projection = Uniforms["Projection"]).Set(ref projectionValue); (view = Uniforms["View"]).Set(ref viewValue); (world = Uniforms["World"]).Set(ref worldValue); } return(result); }
private TriangleProgram() : base( vertex: new VertexShader(typeof(TriangleProgram).GetAssociatedResource("Vertex.glsl")), fragment: new FragmentShader(typeof(TriangleProgram).GetAssociatedResource("Fragment.glsl")) ) { Position = GetAttribute <Vector3>("positionAttrib"); Color = GetAttribute <Color4ub>("colorAttrib", normalized: true); Projection = GetUniform <Matrix4>("projection"); }
private SpriteProgram() : base( vertex: new VertexShader(typeof(SpriteProgram).GetAssociatedResource("Vertex.glsl")), fragment: new FragmentShader(typeof(SpriteProgram).GetAssociatedResource("Fragment.glsl")) ) { Position = GetAttribute <Vector3>("positionAttrib"); Transform = GetAttribute <Matrix4>("transformAttrib"); //Color = GetAttribute<Vector4>("colorAttrib"); TextureOrigin = GetAttribute <Vector2>("textOriginAttrib"); TextureTarget = GetAttribute <Vector2>("textTargetAttrib"); Texture = GetUniform <Texture2D>("texture"); Projection = GetUniform <Matrix4>("projection"); }
private QuadProgram() : base(vertex: new VertexShader(typeof(QuadProgram).GetAssociatedResource("Vertex.glsl")), fragment: new FragmentShader(typeof(QuadProgram).GetAssociatedResource("Fragment.glsl"))) { Textures = new ProgramUniform<Texture2D>[] { GetUniform<Texture2D>("texture0", GL.TEXTURE0), GetUniform<Texture2D>("texture1", GL.TEXTURE1), GetUniform<Texture2D>("texture2", GL.TEXTURE2), GetUniform<Texture2D>("texture3", GL.TEXTURE3), GetUniform<Texture2D>("texture4", GL.TEXTURE4), GetUniform<Texture2D>("texture5", GL.TEXTURE5), GetUniform<Texture2D>("texture6", GL.TEXTURE6), GetUniform<Texture2D>("texture7", GL.TEXTURE7) }; Vertex = GetAttribute<Vector2>("vertex"); Transform = GetAttribute<Matrix3x2>("transform"); Color = GetAttribute<Color4ub>("color", normalized: true); Texture = GetAttribute<int>("texture"); TextureCoordinates0 = GetAttribute<Vector2>("texture_coordinates0"); TextureCoordinates1 = GetAttribute<Vector2>("texture_coordinates1"); }
private QuadProgram() : base( vertex: new VertexShader(typeof(QuadProgram).GetAssociatedResource("Vertex.glsl")), fragment: new FragmentShader(typeof(QuadProgram).GetAssociatedResource("Fragment.glsl")) ) { Textures = new ProgramUniform <Texture2D>[] { GetUniform <Texture2D>("texture0", GL.TEXTURE0), GetUniform <Texture2D>("texture1", GL.TEXTURE1), GetUniform <Texture2D>("texture2", GL.TEXTURE2), GetUniform <Texture2D>("texture3", GL.TEXTURE3), GetUniform <Texture2D>("texture4", GL.TEXTURE4), GetUniform <Texture2D>("texture5", GL.TEXTURE5), GetUniform <Texture2D>("texture6", GL.TEXTURE6), GetUniform <Texture2D>("texture7", GL.TEXTURE7) }; Vertex = GetAttribute <Vector2>("vertex"); Transform = GetAttribute <Matrix3x2>("transform"); Color = GetAttribute <Color4ub>("color", normalized: true); Texture = GetAttribute <int>("texture"); TextureCoordinates0 = GetAttribute <Vector2>("texture_coordinates0"); TextureCoordinates1 = GetAttribute <Vector2>("texture_coordinates1"); }
void Unlink() { ambientLight = diffuseColor = diffuseMap = projection = view = world = null; boneIndices = boneWeights = normal = position = texel = null; }
public override bool Link() { bool result = base.Link(); Unlink(); if (result) { boneIndices = Attributes["BoneIndices"]; boneWeights = Attributes["BoneWeights"]; normal = Attributes["Normal"]; position = Attributes["Position"]; texel = Attributes["Texel"]; (ambientLight = Uniforms["AmbientLight"]).Set(ref ambientLightValue); (diffuseColor = Uniforms["DiffuseColor"]).Set(ref diffuseColorValue); (diffuseMap = Uniforms["DiffuseMap"]).Set(diffuseMapValue ?? Device.WhiteTexture); (displayMode = Uniforms["DisplayMode"]).Set((int)displayModeValue); (projection = Uniforms["Projection"]).Set(ref projectionValue); (view = Uniforms["View"]).Set(ref viewValue); (world = Uniforms["World"]).Set(ref worldValue); } return result; }
private static List <ProgramUniform> GetUniforms(IEnumerable <ShaderSourceContent> sources) { List <ProgramUniform> uniforms = new List <ProgramUniform>(); List <int> shaderIDs = new List <int>(); int programID = GL.CreateProgram(); int status; foreach (ShaderSourceContent content in sources) { int shaderID = GL.CreateShader(content.ShaderType); GL.ShaderSource(shaderID, content.Source); GL.CompileShader(shaderID); GL.GetShader(shaderID, ShaderParameter.CompileStatus, out status); if (status == 0) { string l = GL.GetShaderInfoLog(shaderID); GL.DeleteShader(shaderID); foreach (int id in shaderIDs) { GL.DeleteShader(id); } GL.DeleteProgram(programID); throw new ContentException(string.Format("Error compiling shader: {0}", content.FileName)); } GL.AttachShader(programID, shaderID); shaderIDs.Add(shaderID); } GL.LinkProgram(programID); GL.GetProgram(programID, ProgramParameter.LinkStatus, out status); if (status == 0) { foreach (int id in shaderIDs) { GL.DeleteShader(id); } GL.DeleteProgram(programID); throw new LinkFailedException(string.Format("Error linking program:")); } // shaders no longer needed. foreach (int id in shaderIDs) { GL.DeleteShader(id); } // now map the uniform attributes int count = 0; GL.GetProgram(programID, ProgramParameter.ActiveUniforms, out count); for (int i = 0; i < count; i++) { int size; ActiveUniformType type; string name = GL.GetActiveUniform(programID, i, out size, out type); int slot = GL.GetUniformLocation(programID, name); ProgramUniform attribute = new ProgramUniform(name, slot, size, type); uniforms.Add(attribute); } GL.DeleteProgram(programID); return(uniforms); }