Esempio n. 1
0
        /// <summary>
        /// Apply this state to a shader program.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used to share common state between shaders.
        /// </param>
        /// <param name="shaderProgram">
        /// A <see cref="ShaderProgram"/> that specify this uniform state.
        /// </param>
        /// <param name="uniformScope">
        /// A <see cref="String"/> that specify the scope the uniform variable.
        /// </param>
        private void ApplyState(GraphicsContext ctx, ShaderProgram shaderProgram, string uniformScope)
        {
            if (shaderProgram == null)
            {
                throw new ArgumentNullException("shaderProgram");
            }

            GraphicsResource.CheckCurrentContext(ctx);

            if (UniformBlockTag != null && UniformBuffer != null && shaderProgram.IsActiveUniformBlock(UniformBlockTag))
            {
                // Update uniform buffer
                UniformBuffer.Map(ctx, BufferAccess.WriteOnly);
                try {
                    ApplyState(ctx, UniformBuffer, null, UniformState.Values, this);
                } finally {
                    UniformBuffer.Unmap(ctx);
                }
                // All uniforms at once
                shaderProgram.SetUniformBlock(ctx, UniformBlockTag, UniformBuffer);
            }
            else
            {
                ApplyState(ctx, shaderProgram, null, UniformState.Values, this);
            }
        }