/// <summary> /// Get the number of components of the vertex array buffer item. /// </summary> /// <param name="shaderAttributeType"> /// A <see cref="ShaderAttributeType"/> that describe the vertex array buffer item. /// </param> /// <returns> /// It returns the count of the components of the vertex array buffer item. It will be a value /// from 1 (inclusive) to 4 (inclusive). For matrices, this value indicates the matrix height (column-major order). /// </returns> public static uint GetArrayLength(this ShaderAttributeType shaderAttributeType) { switch (shaderAttributeType) { case ShaderAttributeType.Float: case ShaderAttributeType.Double: case ShaderAttributeType.Int: case ShaderAttributeType.UInt: return(1); case ShaderAttributeType.Vec2: case ShaderAttributeType.DoubleVec2: case ShaderAttributeType.IntVec2: case ShaderAttributeType.UIntVec2: return(2); case ShaderAttributeType.Vec3: case ShaderAttributeType.DoubleVec3: case ShaderAttributeType.IntVec3: case ShaderAttributeType.UIntVec3: return(3); case ShaderAttributeType.Vec4: case ShaderAttributeType.DoubleVec4: case ShaderAttributeType.IntVec4: case ShaderAttributeType.UIntVec4: return(4); case ShaderAttributeType.Mat2x2: case ShaderAttributeType.Mat2x3: case ShaderAttributeType.Mat2x4: case ShaderAttributeType.DoubleMat2x2: case ShaderAttributeType.DoubleMat2x3: case ShaderAttributeType.DoubleMat2x4: return(2); case ShaderAttributeType.Mat3x2: case ShaderAttributeType.Mat3x3: case ShaderAttributeType.Mat3x4: case ShaderAttributeType.DoubleMat3x2: case ShaderAttributeType.DoubleMat3x3: case ShaderAttributeType.DoubleMat3x4: return(3); case ShaderAttributeType.Mat4x2: case ShaderAttributeType.Mat4x3: case ShaderAttributeType.Mat4x4: case ShaderAttributeType.DoubleMat4x2: case ShaderAttributeType.DoubleMat4x3: case ShaderAttributeType.DoubleMat4x4: return(4); default: throw new NotSupportedException("unsupported vertex array length of " + shaderAttributeType); } }
/// <summary> /// Get the array components base type of the vertex array buffer item. /// </summary> /// <param name="vertexArrayType"> /// A <see cref="ArrayBufferItemType"/> that describe the vertex array buffer item. /// </param> /// <returns> /// It returns a <see cref="VertexBaseType"/> indicating the type of the components of /// the vertex array buffer item. /// </returns> public static VertexBaseType GetVertexBaseType(this ShaderAttributeType vertexArrayType) { switch (vertexArrayType) { case ShaderAttributeType.Float: case ShaderAttributeType.Vec2: case ShaderAttributeType.Vec3: case ShaderAttributeType.Vec4: case ShaderAttributeType.Mat2x2: case ShaderAttributeType.Mat2x3: case ShaderAttributeType.Mat2x4: case ShaderAttributeType.Mat3x2: case ShaderAttributeType.Mat3x3: case ShaderAttributeType.Mat3x4: case ShaderAttributeType.Mat4x2: case ShaderAttributeType.Mat4x3: case ShaderAttributeType.Mat4x4: return(VertexBaseType.Float); #if !MONODROID case ShaderAttributeType.Double: case ShaderAttributeType.DoubleVec2: case ShaderAttributeType.DoubleVec3: case ShaderAttributeType.DoubleVec4: case ShaderAttributeType.DoubleMat2x2: case ShaderAttributeType.DoubleMat2x3: case ShaderAttributeType.DoubleMat2x4: case ShaderAttributeType.DoubleMat3x2: case ShaderAttributeType.DoubleMat3x3: case ShaderAttributeType.DoubleMat3x4: case ShaderAttributeType.DoubleMat4x2: case ShaderAttributeType.DoubleMat4x3: case ShaderAttributeType.DoubleMat4x4: return(VertexBaseType.Double); #endif case ShaderAttributeType.Int: case ShaderAttributeType.IntVec2: case ShaderAttributeType.IntVec3: case ShaderAttributeType.IntVec4: return(VertexBaseType.Int); case ShaderAttributeType.UInt: case ShaderAttributeType.UIntVec2: case ShaderAttributeType.UIntVec3: case ShaderAttributeType.UIntVec4: return(VertexBaseType.UInt); default: throw new NotSupportedException("unsupported vertex array base type of " + vertexArrayType); } }
/// <summary> /// Get the array components base type of the vertex array attribute item type. /// </summary> /// <param name="shaderAttributeType"> /// A <see cref="ShaderAttributeType"/> that describe the vertex array attribute item type. /// </param> /// <returns> /// It returns a <see cref="VertexBaseType"/> indicating the type of the components of /// the vertex array buffer item. /// </returns> public static VertexBaseType GetArrayBaseType(ShaderAttributeType shaderAttributeType) { switch (shaderAttributeType) { case ShaderAttributeType.Float: case ShaderAttributeType.Vec2: case ShaderAttributeType.Vec3: case ShaderAttributeType.Vec4: case ShaderAttributeType.Mat2x2: case ShaderAttributeType.Mat3x3: case ShaderAttributeType.Mat4x4: case ShaderAttributeType.Mat2x3: case ShaderAttributeType.Mat2x4: case ShaderAttributeType.Mat3x2: case ShaderAttributeType.Mat3x4: case ShaderAttributeType.Mat4x2: case ShaderAttributeType.Mat4x3: return(VertexBaseType.Float); case ShaderAttributeType.Int: case ShaderAttributeType.IntVec2: case ShaderAttributeType.IntVec3: case ShaderAttributeType.IntVec4: return(VertexBaseType.Int); case ShaderAttributeType.UInt: case ShaderAttributeType.UIntVec2: case ShaderAttributeType.UIntVec3: case ShaderAttributeType.UIntVec4: return(VertexBaseType.UInt); #if !MONODROID case ShaderAttributeType.Double: case ShaderAttributeType.DoubleVec2: case ShaderAttributeType.DoubleVec3: case ShaderAttributeType.DoubleVec4: case ShaderAttributeType.DoubleMat2x2: case ShaderAttributeType.DoubleMat3x3: case ShaderAttributeType.DoubleMat4x4: case ShaderAttributeType.DoubleMat2x3: case ShaderAttributeType.DoubleMat2x4: case ShaderAttributeType.DoubleMat3x2: case ShaderAttributeType.DoubleMat3x4: case ShaderAttributeType.DoubleMat4x2: case ShaderAttributeType.DoubleMat4x3: return(VertexBaseType.Double); #endif default: throw new ArgumentException(String.Format("unrecognized shader attribute type {0}", shaderAttributeType)); } }
/// <summary> /// Get the correponding type for the column of the matrix type. /// </summary> /// <param name="vertexArrayType"> /// A <see cref="ShaderAttributeType"/> that describe the vertex array buffer item. /// </param> /// <returns> /// It returns a boolean value indicating whether <paramref name="vertexArrayType"/> is a matrix type. /// </returns> public static ShaderAttributeType GetMatrixColumnType(this ShaderAttributeType vertexArrayType) { switch (vertexArrayType) { case ShaderAttributeType.Mat2x2: case ShaderAttributeType.Mat2x3: case ShaderAttributeType.Mat2x4: return(ShaderAttributeType.Vec2); case ShaderAttributeType.Mat3x2: case ShaderAttributeType.Mat3x3: case ShaderAttributeType.Mat3x4: return(ShaderAttributeType.Vec3); case ShaderAttributeType.Mat4x2: case ShaderAttributeType.Mat4x3: case ShaderAttributeType.Mat4x4: return(ShaderAttributeType.Vec4); #if !MONODROID case ShaderAttributeType.DoubleMat2x2: case ShaderAttributeType.DoubleMat2x3: case ShaderAttributeType.DoubleMat2x4: return(ShaderAttributeType.DoubleVec2); case ShaderAttributeType.DoubleMat3x2: case ShaderAttributeType.DoubleMat3x3: case ShaderAttributeType.DoubleMat3x4: return(ShaderAttributeType.DoubleVec3); case ShaderAttributeType.DoubleMat4x2: case ShaderAttributeType.DoubleMat4x3: case ShaderAttributeType.DoubleMat4x4: return(ShaderAttributeType.DoubleVec4); #endif default: throw new ArgumentException(); } }
public ShaderAttribute(ShaderAttributeType type, string name) { Type = type; Location = -1; Name = name; }
public bool HasAttribute(ShaderAttributeType type) { return _attributes.ContainsKey(type); }
public int GetAttributeLocation(ShaderAttributeType type) { return _attributes[type].Location; }
public static extern int GetAttributeType(int handle, int index, out ShaderAttributeType result);
/// <summary> /// Get whether a <see cref="ShaderAttributeType"/> is a matrix type (mat2, mat4, ...). /// </summary> /// <param name="vertexArrayType"> /// A <see cref="ShaderAttributeType"/> that describe the vertex array buffer item. /// </param> /// <returns> /// It returns a boolean value indicating whether <paramref name="vertexArrayType"/> is a matrix type. /// </returns> public static bool IsArrayMatrixType(this ShaderAttributeType vertexArrayType) { return(GetArrayRank(vertexArrayType) > 1); }
/// <summary> /// Construct a FeedbackBinding, specifing the type of the size of the feedback attribute. /// </summary> /// <param name="type"> /// A <see cref="ShaderAttributeType"/> that specify the type of the components of the feedback attribute. /// </param> /// <param name="size"> /// A <see cref="UInt32"/> that specify the feedback size, in terms of <see cref="type"/>. /// </param> public FeedbackBinding(ShaderAttributeType type, uint size) { Type = type; Size = size; }
/// <summary> /// Get the rank of the vertex array buffer item (that is, the number of <i>vec4</i> attributes requires). /// </summary> /// <param name="shaderAttributeType"> /// A <see cref="ShaderAttributeType"/> that describe the vertex array buffer item. /// </param> /// <returns> /// It returns the rank of the vertex array buffer item. It will be a value /// from 1 (inclusive) to 4 (inclusive). For matrices, this value indicates the matrix width (column-major order), /// while for simpler types the value will be 1. /// </returns> public static uint GetArrayRank(this ShaderAttributeType shaderAttributeType) { switch (shaderAttributeType) { case ShaderAttributeType.Mat2x2: case ShaderAttributeType.Mat3x2: case ShaderAttributeType.Mat4x2: #if !MONODROID case ShaderAttributeType.DoubleMat2x2: case ShaderAttributeType.DoubleMat3x2: case ShaderAttributeType.DoubleMat4x2: #endif return(2); case ShaderAttributeType.Mat2x3: case ShaderAttributeType.Mat3x3: case ShaderAttributeType.Mat4x3: #if !MONODROID case ShaderAttributeType.DoubleMat2x3: case ShaderAttributeType.DoubleMat3x3: case ShaderAttributeType.DoubleMat4x3: #endif return(3); case ShaderAttributeType.Mat2x4: case ShaderAttributeType.Mat3x4: case ShaderAttributeType.Mat4x4: #if !MONODROID case ShaderAttributeType.DoubleMat2x4: case ShaderAttributeType.DoubleMat3x4: case ShaderAttributeType.DoubleMat4x4: #endif return(4); case ShaderAttributeType.Float: #if !MONODROID case ShaderAttributeType.Double: #endif case ShaderAttributeType.Int: case ShaderAttributeType.UInt: case ShaderAttributeType.Vec2: #if !MONODROID case ShaderAttributeType.DoubleVec2: #endif case ShaderAttributeType.IntVec2: case ShaderAttributeType.UIntVec2: case ShaderAttributeType.Vec3: #if !MONODROID case ShaderAttributeType.DoubleVec3: #endif case ShaderAttributeType.IntVec3: case ShaderAttributeType.UIntVec3: case ShaderAttributeType.Vec4: #if !MONODROID case ShaderAttributeType.DoubleVec4: #endif case ShaderAttributeType.IntVec4: case ShaderAttributeType.UIntVec4: return(1); default: throw new NotSupportedException("unsupported vertex array rank of " + shaderAttributeType); } }
/// <summary> /// Enable the generic vertex attribute. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> on which the shader program is bound. /// </param> /// <param name="attributeBinding"> /// The <see cref="ShaderProgram.AttributeBinding"/> representing the generic vertex attribute. /// </param> internal override void EnableVertexAttribute(GraphicsContext ctx, uint location, ShaderAttributeType type) { // Base implementation base.EnableVertexAttribute(ctx, location, type); // Attribute divisor Gl.VertexAttribDivisor(location, Divisor); }
/// <summary> /// Enable the generic vertex attribute. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> on which the shader program is bound. /// </param> /// <param name="attributeBinding"> /// The <see cref="ShaderProgram.AttributeBinding"/> representing the generic vertex attribute. /// </param> internal virtual void EnableVertexAttribute(GraphicsContext ctx, uint location, ShaderAttributeType type) { ArrayBufferObjectBase.IArraySection arraySection = ArrayBuffer.GetArraySection(ArraySectionIndex); int arrayBaseType = (int)arraySection.ItemType.GetVertexBaseType(); int arrayLength = (int)arraySection.ItemType.GetArrayLength(); int arrayStride = arraySection.Stride.ToInt32(); // Avoid rendundant buffer binding and relative vertex array setup if (ctx.Extensions.VertexArrayObject_ARB && IsDirty == false) { // CheckVertexAttribute(ctx, location); return; } // Bind the array buffer ctx.Bind(ArrayBuffer); // Bind varying attribute to currently bound buffer object switch (ArrayBufferItem.GetArrayBaseType(type)) { case VertexBaseType.Float: Gl.VertexAttribPointer( location, arrayLength, arrayBaseType, arraySection.Normalized, arrayStride, arraySection.Offset ); break; case VertexBaseType.Int: case VertexBaseType.UInt: Gl.VertexAttribIPointer( location, arrayLength, arrayBaseType, arrayStride, arraySection.Offset ); break; case VertexBaseType.Double: Gl.VertexAttribLPointer( location, arrayLength, arrayBaseType, arrayStride, arraySection.Offset ); break; default: throw new NotSupportedException(String.Format("vertex attribute type {0} not supported", type)); } // Enable vertex attribute Gl.EnableVertexAttribArray(location); }
/// <summary> /// /// </summary> /// <param name="location"></param> /// <param name="type"></param> public AttributeBinding(uint location, ShaderAttributeType type) { Location = location; Type = type; }
/// <summary> /// Get whether a <see cref="ShaderAttributeType"/> is a vector type (vec2, vec3, ...). /// </summary> /// <param name="vertexArrayType"> /// A <see cref="ShaderAttributeType"/> that describe the vertex array buffer item. /// </param> /// <returns> /// It returns a boolean value indicating whether <paramref name="vertexArrayType"/> is a vector type. /// </returns> public static bool IsArrayVectorType(this ShaderAttributeType vertexArrayType) { return((vertexArrayType.GetArrayLength() > 1) && (vertexArrayType.GetArrayRank() == 1)); }