Esempio n. 1
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);

            ctx.Bind(this, true);

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

                // Note: when the GL_ARB_vertex_array_object is supported, there's no need to define vertex attributes each time
                if (ctx.Extensions.VertexArrayObject_ARB && !_VertexArrayDirty)
                {
                    // CheckVertexAttributes(ctx, shaderProgram);
                    return;
                }

                uint attributesSet = 0;

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

                    // Set array attribute
                    shaderVertexArray.SetVertexAttribute(ctx, shaderProgram, attributeName);
                    attributesSet++;
                }

                if (attributesSet == 0)
                {
                    throw new InvalidOperationException("no attribute is set");
                }
                _VertexArrayCount = attributesSet;
            }
            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);
                }
            }

            // Next time do not set inputs if GL_ARB_vertex_array_object is supported
            _VertexArrayDirty = false;
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 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>
        protected void SetVertexArrayState(GraphicsContext ctx, ShaderProgram shaderProgram)
        {
            if (Exists(ctx) == false)
            {
                throw new InvalidOperationException("not existing");
            }

            if (ctx.Caps.GlExtensions.VertexArrayObject_ARB)
            {
                // Bind this vertex array
                Gl.BindVertexArray(ObjectName);
                // Short path?
                if (!_VertexArrayDirty)
                {
                    // CheckVertexAttributes(ctx, shaderProgram);
                    return;
                }
            }

            if (shaderProgram != null)
            {
                uint attributesSet = 0;

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

                    // Set array attribute
                    shaderVertexArray.SetVertexAttribute(ctx, shaderProgram, attributeName); 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);
                }
            }

            // Next time do not set inputs if GL_ARB_vertex_array_object is supported
            _VertexArrayDirty = false;
        }