Beispiel #1
0
 /// <summary>
 /// Draw all elements.
 /// </summary>
 /// <param name="ctx">
 /// The <see cref="GraphicsContext"/> used for rendering.
 /// </param>
 /// <param name="shader">
 /// The <see cref="ShaderProgram"/> used for drawing the vertex arrays.
 /// </param>
 public void Draw(GraphicsContext ctx, ShaderProgram shader)
 {
     Draw(ctx, shader, null);
 }
Beispiel #2
0
 /// <summary>
 /// Draw a specific element set.
 /// </summary>
 /// <param name="ctx">
 /// The <see cref="GraphicsContext"/> used for rendering.
 /// </param>
 /// <param name="shader">
 /// The <see cref="ShaderProgram"/> used for drawing the vertex arrays.
 /// </param>
 /// <param name="elementIndex">
 /// A <see cref="Int32"/> that specifies the index of the element to draw. If it is less than 0, it draws
 /// all elements set. The index can be obtained by the value returned by <see cref="SetElementArray"/>.
 /// </param>
 public void Draw(GraphicsContext ctx, ShaderProgram shader, int elementIndex)
 {
     Draw(ctx, shader, GetElementArray(elementIndex));
 }
Beispiel #3
0
        /// <summary>
        /// Set the vertex arrays state for the shader program.
        /// </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 SetVertexArrayState(GraphicsContext ctx, ShaderProgram shaderProgram)
        {
            CheckThisExistence(ctx);

            // Set vertex array state all at once...
            ctx.Bind(this, true);

            if (shaderProgram != null)
            {
                ICollection <string> activeAttributes = shaderProgram.ActiveAttributes;
                uint attributesSet = 0;

                // Set vertex array state
                foreach (string attributeName in activeAttributes)
                {
                    IVertexArray shaderVertexArray = GetVertexArray(attributeName, shaderProgram);
                    if (shaderVertexArray == null)
                    {
                        continue;
                    }

                    ShaderProgram.AttributeBinding attributeBinding = shaderProgram.GetActiveAttribute(attributeName);

                    IVertexArray currentVertexArray = _VertexArrayState[attributeBinding.Location];
                    //if (ReferenceEquals(shaderVertexArray, currentVertexArray) == false) {
                    shaderVertexArray.SetVertexAttribute(ctx, attributeBinding, attributeName);
                    _VertexArrayState[attributeBinding.Location] = shaderVertexArray;
                    //}

                    attributesSet++;
                }

                if (attributesSet == 0)
                {
                    throw new InvalidOperationException("no attribute is set");
                }
            }
            else
            {
                IVertexArray attributeArray;

                // No shader program: using fixed pipeline program. ATM enable all attributes having a semantic
                if ((attributeArray = GetVertexArray(VertexArraySemantic.Position)) == null)
                {
                    throw new InvalidOperationException("no position semantic array defined");
                }
                attributeArray.SetVertexAttribute(ctx, null, VertexArraySemantic.Position);

                // Optional attributes
                if ((attributeArray = GetVertexArray(VertexArraySemantic.Color)) != null)
                {
                    attributeArray.SetVertexAttribute(ctx, null, VertexArraySemantic.Color);
                }
                if ((attributeArray = GetVertexArray(VertexArraySemantic.Normal)) != null)
                {
                    attributeArray.SetVertexAttribute(ctx, null, VertexArraySemantic.Normal);
                }
                if ((attributeArray = GetVertexArray(VertexArraySemantic.TexCoord)) != null)
                {
                    attributeArray.SetVertexAttribute(ctx, null, VertexArraySemantic.TexCoord);
                }
            }
        }