Beispiel #1
0
            /// <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);
            }