private void ApplyStateCore(GraphicsContext ctx, ShaderProgram program, PrimitiveRestartState currentState)
        {
            if (Enabled != currentState.Enabled)
            {
                if (Enabled)
                {
                    if (Gl.CurrentExtensions.PrimitiveRestart)
                    {
                        Gl.Enable(EnableCap.PrimitiveRestart);
                    }
                    else if (Gl.CurrentExtensions.PrimitiveRestart_NV)
                    {
                        Gl.EnableClientState(EnableCap.PrimitiveRestartNv);
                    }
                    else
                    {
                        throw new InvalidOperationException("primitive restart not supported");
                    }
                }
                else
                {
                    if (Gl.CurrentExtensions.PrimitiveRestart)
                    {
                        Gl.Disable(EnableCap.PrimitiveRestart);
                    }
                    else if (Gl.CurrentExtensions.PrimitiveRestart_NV)
                    {
                        Gl.DisableClientState(EnableCap.PrimitiveRestartNv);
                    }
                    else
                    {
                        throw new InvalidOperationException("primitive restart not supported");
                    }
                }
            }

            if (RestartIndex != currentState.RestartIndex)
            {
                if (Gl.CurrentExtensions.PrimitiveRestart)
                {
                    Gl.PrimitiveRestartIndex(RestartIndex);
                }
                else if (Gl.CurrentExtensions.PrimitiveRestart_NV)
                {
                    Gl.PrimitiveRestartIndexNV(RestartIndex);
                }
                else
                {
                    throw new InvalidOperationException("primitive restart not supported");
                }
            }
        }
        /// <summary>
        /// Set ShaderProgram state.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> which has defined the shader program <paramref name="program"/>.
        /// </param>
        /// <param name="program">
        /// The <see cref="ShaderProgram"/> which has the state set.
        /// </param>
        public override void Apply(GraphicsContext ctx, ShaderProgram program)
        {
            GraphicsResource.CheckCurrentContext(ctx);

            PrimitiveRestartState currentState = (PrimitiveRestartState)ctx.GetCurrentState(StateIndex);

            if (currentState != null)
            {
                ApplyStateCore(ctx, program, currentState);
            }
            else
            {
                ApplyStateCore(ctx, program);
            }

            ctx.SetCurrentState(this);
        }