/// <summary> /// Push a copy of the current state set onto the stack. /// </summary> public void Push() { GraphicsStateSet currentStateSetCopy = Current.Push(); // Set the copy as the current state set _StateSetStack.AddLast(currentStateSetCopy); }
/// <summary> /// Construct a GraphicsStateSetStack representing the current state. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> to query the state. /// </param> public GraphicsStateSetStack(GraphicsContext ctx) { GraphicsStateSet defaultSet = GraphicsStateSet.GetCurrentStateSet(ctx); // The stack always defines a current state _StateSetStack.AddLast(defaultSet); }
/// <summary> /// Construct a GraphicsStateSetStack. /// </summary> public GraphicsStateSetStack() { GraphicsStateSet defaultSet = GraphicsStateSet.GetDefaultSet(); // The stack always defines a current state _StateSetStack.AddLast(defaultSet); }
/// <summary> /// Construct a GraphicsStateSetStack representing the current state. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> to query the state. /// </param> public GraphicsStateSetStack(GraphicsContext ctx) { GraphicsStateSet defaultSet = GraphicsStateSet.GetCurrentStateSet(ctx); // Avoid a disposition of this state set defaultSet.IncRef(); // The stack always defines a current state _StateSetStack.AddLast(defaultSet); }
/// <summary> /// Push a copy of the current state set onto the stack. /// </summary> /// <param name="mergedState"> /// A <see cref="GraphicsStateSet"/> to be merged on current render state set after having pushed it /// onto the stack. /// </param> public void Push(GraphicsStateSet mergedState) { if (mergedState == null) { throw new ArgumentNullException("mergedState"); } // Push the current state onto the stack Push(); // Merge current state with the specified one Current.Merge(mergedState); }
/// <summary> /// Pop the current state on top of the stack. /// </summary> public void Pop() { if (_StateSetStack.Count == 1) { throw new InvalidOperationException("stack underflow"); } GraphicsStateSet currentStateSet = Current; // Restore previous state set _StateSetStack.RemoveLast(); }
/// <summary> /// Factory method for getting the default render state set. /// </summary> /// <returns> /// It returns a GraphicsStateSet representing the default state set. /// </returns> public static GraphicsStateSet GetDefaultSet() { GraphicsStateSet renderStateSet = new GraphicsStateSet(); // Instantiate all context-bound states renderStateSet.DefineState(TransformState.DefaultState); renderStateSet.DefineState(DepthTestState.DefaultState); renderStateSet.DefineState(BlendState.DefaultState); renderStateSet.DefineState(CullFaceState.DefaultState); renderStateSet.DefineState(PolygonOffsetState.DefaultState); return(renderStateSet); }
/// <summary> /// Push a copy of the current state set onto the stack. /// </summary> private void Push() { if (IsDisposed) { throw new ObjectDisposedException("GraphicsStateSetStack"); } GraphicsStateSet currentStateSetCopy = Current.Push(); // Avoid a disposition of this state set currentStateSetCopy.IncRef(); // Set the copy as the current state set _StateSetStack.AddLast(currentStateSetCopy); }
/// <summary> /// Clone this GraphicsStateSet. /// </summary> /// <returns> /// It returns a deep copy of this GraphicsStateSet. /// </returns> public GraphicsStateSet Push() { GraphicsStateSet clone = new GraphicsStateSet(); foreach (IGraphicsState state in _RenderStates) { if (state != null) { clone.DefineState(state.Push()); } } return(clone); }
/// <summary> /// Pop the current state on top of the stack. /// </summary> public void Pop() { if (IsDisposed) { throw new ObjectDisposedException("GraphicsStateSetStack"); } if (_StateSetStack.Count == 1) { throw new InvalidOperationException("stack underflow"); } GraphicsStateSet currentStateSet = Current; // Possibly dispose this state set currentStateSet.DecRef(); // Restore previous state set _StateSetStack.RemoveLast(); }
/// <summary> /// Factory method for getting the default render state set. /// </summary> /// <returns> /// It returns a GraphicsStateSet representing the default state set. /// </returns> public static GraphicsStateSet GetDefaultSet() { GraphicsStateSet renderStateSet = new GraphicsStateSet(); // Instantiate all context-bound states renderStateSet.DefineState(TransformState.DefaultState); renderStateSet.DefineState(DepthTestState.DefaultState); renderStateSet.DefineState(BlendState.DefaultState); renderStateSet.DefineState(CullFaceState.DefaultState); // renderStateSet.DefineState(UniformColorState.DefaultState); //renderStateSet.DefineState(PolygonModeState.DefaultState); //renderStateSet.DefineState(CullFaceState.DefaultState); //renderStateSet.DefineState(RenderBufferState.DefaultState); //renderStateSet.DefineState(ViewportState.DefaultState); return(renderStateSet); }
/// <summary> /// Merge this state set with another one. /// </summary> /// <param name="stateSet"> /// A <see cref="GraphicsStateSet"/> to be merged with this GraphicsStateSet. /// </param> /// <remarks> /// <para> /// After a call to this routine, this GraphicsStateSet store the union of the previous information /// and of the information of <paramref name="stateSet"/>. /// </para> /// <para> /// The semantic of the merge result is dependent by each <see cref="IGraphicsState"/> defined in both /// state sets. /// </para> /// <para> /// In the case a kind of GraphicsState is defined only in this GraphicsStateSet, the specific state remains /// unchanged, except when the state is not inheritable; in this case the specific state will be undefined. /// </para> /// <para> /// In the case a kind of GraphicsState is defined only in <paramref name="stateSet"/>, that state will be /// defined equally in this GraphicsStateSet. /// </para> /// <para> /// In the case a kind of GraphicsState is defined by both state sets, the state defined in this GraphicsStateSet /// will be merged with the one defined in <paramref name="stateSet"/>, by calling <see cref="IGraphicsState.Merge"/>. /// </para> /// </remarks> public void Merge(GraphicsStateSet stateSet) { if (stateSet == null) { throw new ArgumentNullException("stateSet"); } for (int i = 0; i < _RenderStates.Length; i++) { IGraphicsState currentState = _RenderStates[i]; IGraphicsState otherState = stateSet[i]; if (currentState != null && otherState != null) { _RenderStates[i].Merge(otherState); } else if (currentState == null && otherState != null) { _RenderStates[i] = otherState.Push(); } } }
/// <summary> /// Factory method for getting the current render state set. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> defining the state vector. /// </param> /// <returns> /// It returns a GraphicsStateSet representing the currently active state vector. /// </returns> public static GraphicsStateSet GetCurrentStateSet(GraphicsContext ctx) { if (ctx == null) { throw new ArgumentNullException("ctx"); } if (ctx.IsCurrent == false) { throw new ArgumentException("not current", "ctx"); } GraphicsStateSet renderStateSet = new GraphicsStateSet(); // Instantiate all context-bound states renderStateSet.DefineState(new PolygonModeState(ctx)); renderStateSet.DefineState(new BlendState(ctx)); renderStateSet.DefineState(new DepthTestState(ctx)); renderStateSet.DefineState(new CullFaceState(ctx)); //renderStateSet.DefineState(new RenderBufferState(ctx)); //renderStateSet.DefineState(new ViewportState(ctx)); renderStateSet.DefineState(new TransformState(ctx)); return(renderStateSet); }