Esempio n. 1
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">
        /// A <see cref="GraphicsState"/> to compare to this GraphicsState.
        /// </param>
        /// <returns>
        /// It returns true if the current object is equal to <paramref name="other"/>.
        /// </returns>
        /// <remarks>
        /// <para>
        /// This method test only whether <paramref name="other"/> type equals to this type.
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// This exception is thrown if the parameter <paramref name="other"/> is null.
        /// </exception>
        public override bool Equals(IGraphicsState other)
        {
            if (base.Equals(other) == false)
            {
                return(false);
            }
            Debug.Assert(other is PolygonOffsetState);

            PolygonOffsetState otherState = (PolygonOffsetState)other;

            if (_Modes != otherState._Modes)
            {
                return(false);
            }
            if (Math.Abs(_Factor - otherState._Factor) >= Single.Epsilon)
            {
                return(false);
            }
            if (Math.Abs(_Units - otherState._Units) >= Single.Epsilon)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        private void ApplyStateCore(GraphicsContext ctx, ShaderProgram program, PolygonOffsetState currentState)
        {
            if (currentState._Modes != _Modes)
            {
                bool currentMode, thisMode;

                currentMode = (currentState._Modes & Mode.Point) != 0;
                thisMode    = (_Modes & Mode.Point) != 0;
                if (currentMode != thisMode)
                {
                    if (thisMode)
                    {
                        Gl.Enable(EnableCap.PolygonOffsetPoint);
                    }
                    else
                    {
                        Gl.Disable(EnableCap.PolygonOffsetPoint);
                    }
                }

                currentMode = (currentState._Modes & Mode.Line) != 0;
                thisMode    = (_Modes & Mode.Line) != 0;
                if (currentMode != thisMode)
                {
                    if (thisMode)
                    {
                        Gl.Enable(EnableCap.PolygonOffsetLine);
                    }
                    else
                    {
                        Gl.Disable(EnableCap.PolygonOffsetLine);
                    }
                }

                currentMode = (currentState._Modes & Mode.Fill) != 0;
                thisMode    = (_Modes & Mode.Fill) != 0;
                if (currentMode != thisMode)
                {
                    if (thisMode)
                    {
                        Gl.Enable(EnableCap.PolygonOffsetFill);
                    }
                    else
                    {
                        Gl.Disable(EnableCap.PolygonOffsetFill);
                    }
                }
            }

            // Set polygon offset
            if (Math.Abs(currentState._Factor - _Factor) >= Single.Epsilon || Math.Abs(currentState._Units - _Units) >= Single.Epsilon)
            {
                Gl.PolygonOffset(_Factor, _Units);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Merge this state with another one.
        /// </summary>
        /// <param name="state">
        /// A <see cref="IGraphicsState"/> having the same <see cref="StateIdentifier"/> of this state.
        /// </param>
        public override void Merge(IGraphicsState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            PolygonOffsetState otherState = state as PolygonOffsetState;

            if (otherState == null)
            {
                throw new ArgumentException("not a PolygonOffsetState", "state");
            }

            _Modes  = otherState._Modes;
            _Factor = otherState._Factor;
            _Units  = otherState._Units;
        }
Esempio n. 4
0
        /// <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)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }

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

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

            ctx.SetCurrentState(this);
        }