/// <summary> /// Set the vertex attribute. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for rendering. /// </param> /// <param name="shaderProgram"> /// The <see cref="ShaderProgram"/> that is used for rendering. /// </param> /// <param name="attributeName"> /// A <see cref="String"/> that specify the attribute which binds to this vertex array. /// </param> public void SetVertexAttribute(GraphicsContext ctx, ShaderProgram shaderProgram, string attributeName) { if (attributeName == null) { throw new ArgumentNullException("attributeName"); } ShaderProgram.AttributeBinding attributeBinding = shaderProgram.GetActiveAttribute(attributeName); switch (attributeBinding.Type) { case ShaderAttributeType.Float: Gl.VertexAttrib1(attributeBinding.Location, (float)DefaultValue.x); break; case ShaderAttributeType.Vec2: Gl.VertexAttrib2(attributeBinding.Location, (float)DefaultValue.x, (float)DefaultValue.y); break; case ShaderAttributeType.Vec3: Gl.VertexAttrib3(attributeBinding.Location, (float)DefaultValue.x, (float)DefaultValue.y, (float)DefaultValue.z); break; case ShaderAttributeType.Vec4: Gl.VertexAttrib4(attributeBinding.Location, (float)DefaultValue.x, (float)DefaultValue.y, (float)DefaultValue.z, (float)DefaultValue.w); break; default: throw new NotImplementedException(String.Format("default value for attributes of type {0} not implemented", attributeBinding.Type)); } }
/// <summary> /// Set the vertex attribute. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for rendering. /// </param> /// <param name="shaderProgram"> /// The <see cref="ShaderProgram"/> that is used for rendering. /// </param> /// <param name="attributeName"> /// A <see cref="String"/> that specify the attribute which binds to this vertex array. /// </param> public void SetVertexAttribute(GraphicsContext ctx, ShaderProgram shaderProgram, string attributeName) { if (attributeName == null) { throw new ArgumentNullException("attributeName"); } if (shaderProgram != null) { ShaderProgram.AttributeBinding attributeBinding = shaderProgram.GetActiveAttribute(attributeName); // Avoid rendundant buffer binding and relative vertex array setup if (ctx.Caps.GlExtensions.VertexArrayObject_ARB && IsDirty == false) { CheckVertexAttribute(ctx, attributeBinding); return; } // Enable/Disable shader attribute if (ArrayBuffer != null) { EnableVertexAttribute(ctx, attributeBinding); } else { DisableVertexAttribute(ctx, attributeBinding); } } else { switch (attributeName) { case VertexArraySemantic.Position: SetPositionAttribute(ctx); break; case VertexArraySemantic.Color: SetColorAttribute(ctx); break; case VertexArraySemantic.Normal: SetNormalAttribute(ctx); break; case VertexArraySemantic.TexCoord: SetTexCoordAttribute(ctx); break; default: throw new NotSupportedException(String.Format("attribute {0} not supported on fixed pipeline", attributeName)); } } // Next time do not set bindings and array state if GL_ARB_vertex_array_object is supported IsDirty = false; }
/// <summary> /// Utility routine for checking the vertex array state. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> on which the shader program is bound. /// </param> /// <param name="shaderProgram"> /// A <see cref="ShaderProgram"/> on which the vertex arrays shall be bound. /// </param> private void CheckVertexAttributes(GraphicsContext ctx, ShaderProgram shaderProgram) { // Vertex array state overall check foreach (string attributeName in shaderProgram.ActiveAttributes) { ShaderProgram.AttributeBinding attributeBinding = shaderProgram.GetActiveAttribute(attributeName); VertexArray shaderVertexArray = GetVertexArray(attributeName, shaderProgram); if (shaderVertexArray == null) { continue; } shaderVertexArray.CheckVertexAttribute(ctx, attributeBinding); } }
/// <summary> /// Utility routine for checking the vertex array state. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> on which the shader program is bound. /// </param> /// <param name="shaderProgram"> /// A <see cref="ShaderProgram"/> on which the vertex arrays shall be bound. /// </param> private void CheckVertexAttributes(GraphicsContext ctx, ShaderProgram shaderProgram) { // Vertex array state overall check foreach (string attributeName in shaderProgram.ActiveAttributes) { ShaderProgram.AttributeBinding attributeBinding = shaderProgram.GetActiveAttribute(attributeName); VertexArray shaderVertexArray = GetVertexArray(attributeName, shaderProgram); if (shaderVertexArray == null) continue; shaderVertexArray.CheckVertexAttribute(ctx, attributeBinding); } }
internal void SetVertexAttribute(GraphicsContext ctx, ShaderProgram shaderProgram, string attributeName) { if (attributeName == null) throw new ArgumentNullException("attributeName"); if (shaderProgram != null) { ShaderProgram.AttributeBinding attributeBinding = shaderProgram.GetActiveAttribute(attributeName); // Enable/Disable shader attribute if (ArrayBuffer != null) EnableVertexAttribute(ctx, attributeBinding); else DisableVertexAttribute(ctx, attributeBinding); } else { switch (attributeName) { case VertexArraySemantic.Position: SetPositionAttribute(ctx); break; case VertexArraySemantic.Color: SetColorAttribute(ctx); break; case VertexArraySemantic.Normal: SetNormalAttribute(ctx); break; case VertexArraySemantic.TexCoord: SetTexCoordAttribute(ctx); break; default: throw new NotSupportedException(String.Format("attribute {0} not supported on fixed pipeline", attributeName)); } } // Next time do not set bindings and array state if GL_ARB_vertex_array_object is supported IsDirty = false; }