コード例 #1
0
        /// <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");
            }

            List <IGraphicsState> thisSetStates = new List <IGraphicsState>(States);

            // Merge states defined by stateSet
            foreach (GraphicsState state in thisSetStates)
            {
                IGraphicsState otherState = stateSet[state.StateIdentifier];

                if (otherState != null)
                {
                    state.Merge(otherState);
                }
            }
            // Include states not defined by this
            foreach (GraphicsState state in stateSet.States)
            {
                if (IsDefinedState(state.StateIdentifier) == false)
                {
                    DefineState(state.Copy());
                }
            }
        }
コード例 #2
0
        /// <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));

            sLog.Verbose("Detected current state set:");
            foreach (KeyValuePair <string, IGraphicsState> pair in renderStateSet._RenderStates)
            {
                sLog.Verbose(pair.Value.ToString());
            }

            return(renderStateSet);
        }
コード例 #3
0
        /// <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
            mStateSetStack.AddLast(defaultSet);
        }
コード例 #4
0
        /// <summary>
        /// Construct a GraphicsStateSetStack.
        /// </summary>
        public GraphicsStateSetStack()
        {
            GraphicsStateSet defaultSet = GraphicsStateSet.GetDefaultSet();

            // Avoid a disposition of this state set
            defaultSet.IncRef();
            // The stack always defines a current state
            _StateSetStack.AddLast(defaultSet);
        }
コード例 #5
0
        /// <summary>
        /// Clone this GraphicsStateSet.
        /// </summary>
        /// <returns>
        /// It returns a deep copy of this GraphicsStateSet.
        /// </returns>
        public GraphicsStateSet Copy()
        {
            GraphicsStateSet clone = new GraphicsStateSet();

            foreach (KeyValuePair <string, IGraphicsState> pair in mRenderStates)
            {
                clone.mRenderStates.Add(pair.Key, pair.Value.Copy());
            }

            return(clone);
        }
コード例 #6
0
        /// <summary>
        /// Clone this GraphicsStateSet.
        /// </summary>
        /// <returns>
        /// It returns a deep copy of this GraphicsStateSet.
        /// </returns>
        public GraphicsStateSet Copy()
        {
            GraphicsStateSet clone = new GraphicsStateSet();

            foreach (KeyValuePair <string, IGraphicsState> pair in _RenderStates)
            {
                clone.DefineState(pair.Value.Copy());
            }

            return(clone);
        }
コード例 #7
0
        /// <summary>
        /// Push a copy of the current state set onto the stack.
        /// </summary>
        public void Push()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException("GraphicsStateSetStack");
            }

            GraphicsStateSet currentStateSetCopy = Current.Copy();

            // Avoid a disposition of this state set
            currentStateSetCopy.IncRef();
            // Set the copy as the current state set
            mStateSetStack.AddLast(currentStateSetCopy);
        }
コード例 #8
0
        /// <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 (IsDisposed)
            {
                throw new ObjectDisposedException("GraphicsStateSetStack");
            }
            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);
        }
コード例 #9
0
		/// <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(UniformColorState.DefaultState);

			renderStateSet.DefineState(PolygonModeState.DefaultState);
			renderStateSet.DefineState(TransformState.DefaultState);
			renderStateSet.DefineState(BlendState.DefaultState);
			renderStateSet.DefineState(DepthTestState.DefaultState);
			renderStateSet.DefineState(CullFaceState.DefaultState);
			renderStateSet.DefineState(RenderBufferState.DefaultState);
			renderStateSet.DefineState(ViewportState.DefaultState);

			return (renderStateSet);
		}
コード例 #10
0
        /// <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(UniformColorState.DefaultState);
            renderStateSet.DefineState(TransformState.DefaultState);

            //renderStateSet.DefineState(PolygonModeState.DefaultState);
            //renderStateSet.DefineState(BlendState.DefaultState);
            //renderStateSet.DefineState(DepthTestState.DefaultState);
            //renderStateSet.DefineState(CullFaceState.DefaultState);
            //renderStateSet.DefineState(RenderBufferState.DefaultState);
            //renderStateSet.DefineState(ViewportState.DefaultState);

            return(renderStateSet);
        }
コード例 #11
0
        /// <summary>
        /// Pop the current state on top of the stack.
        /// </summary>
        public void Pop()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException("GraphicsStateSetStack");
            }
            if (mStateSetStack.Count == 1)
            {
                throw new InvalidOperationException("stack underflow");
            }

            GraphicsStateSet currentStateSet = Current;

            // Possibly dispose this state set
            currentStateSet.DecRef();
            // Restore previous state set
            mStateSetStack.RemoveLast();
        }
コード例 #12
0
        /// <summary>
        /// Apply the set of GraphicsState collected by this instance.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> defining the state vector.
        /// </param>
        /// <param name="program">
        /// A <see cref="ShaderProgram"/> defining the uniform state.
        /// </param>
        /// <param name="currentStateSet">
        ///
        /// </param>
        private void Apply(GraphicsContext ctx, ShaderProgram program, GraphicsStateSet currentStateSet)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }

            // Reset texture unit state
            if (program != null)
            {
                program.ResetTextureUnits();
            }

            // Apply known states
            foreach (KeyValuePair <string, IGraphicsState> pair in mRenderStates)
            {
                IGraphicsState state = pair.Value;

                if (state.IsContextBound && (currentStateSet != null) && (currentStateSet.IsDefinedState(state.StateIdentifier)))
                {
                    IGraphicsState currentState = currentStateSet[state.StateIdentifier];

                    if (currentState.Inheritable && state.Equals(currentState))
                    {
                        continue;
                    }
                }

                // Apply state if the state is context-bound, or a shader is currently in use
                if ((program != null) || (state.IsContextBound))
                {
                    state.ApplyState(ctx, program);
                }
            }

            // Apply custom states, if any
            foreach (GraphicsState customState in mCustomStates)
            {
                if ((program != null) || (customState.IsContextBound))
                {
                    customState.ApplyState(ctx, program);
                }
            }
        }
コード例 #13
0
        /// <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");
            }

            List <IGraphicsState> thisSetStates = new List <IGraphicsState>(States);

            // Merge states defined by stateSet
            foreach (GraphicsState state in thisSetStates)
            {
                IGraphicsState otherState = stateSet[state.StateIdentifier];

                if (state.Inheritable == false)
                {
                    // Do not include non-inheritable states
                    UndefineState(state.StateIdentifier);
                    // Include merged state, if defined
                    if (otherState != null)
                    {
                        DefineState(otherState);
                    }
                }
                else
                {
                    if (otherState != null)
                    {
                        state.Merge(otherState);
                    }
                }
            }
            // Include states not defined by this
            foreach (GraphicsState state in stateSet.States)
            {
                if (IsDefinedState(state.StateIdentifier) == false)
                {
                    DefineState(state);
                }
            }
        }
コード例 #14
0
ファイル: Technique.cs プロジェクト: lwansbrough/OpenGL.Net
        /// <summary>
        /// Construct a Technique.
        /// </summary>
        /// <param name="vertexArray">
        /// The vertex array feeding data to the GPU pipeline.
        /// </param>
        /// <param name="shaderProgram">
        /// Shader program used for drawing. If it is null, it is assumed that the OpenGL
        /// fixed pipeline program is used.
        /// </param>
        /// <param name="stateSet">
        /// The graphics state set applied before the technique is executed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="vertexArray"/> is null.
        /// </exception>
        public Technique(VertexArrayObject vertexArray, ShaderProgram shaderProgram, State.GraphicsStateSet stateSet)
        {
            if (vertexArray == null)
            {
                throw new ArgumentNullException("vertexArray");
            }

            VertexArray = vertexArray;
            Program     = shaderProgram;
            StateSet    = stateSet;

            LinkResource(vertexArray);
            if (shaderProgram != null)
            {
                LinkResource(shaderProgram);
            }
            if (stateSet != null)
            {
                LinkResource(stateSet);
            }
        }
コード例 #15
0
        /// <summary>
        /// Merge this GraphicsStateSet with a current state.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> defining the state vector.
        /// </param>
        /// <param name="program">
        /// A <see cref="ShaderProgram"/> defining the uniform state.
        /// </param>
        /// <param name="currentStateSet">
        ///
        /// </param>
        /// <returns></returns>
        internal GraphicsStateSet Merge(GraphicsContext ctx, ShaderProgram program, GraphicsStateSet currentStateSet)
        {
            GraphicsStateSet mergedState = new GraphicsStateSet();

            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            if (currentStateSet == null)
            {
                throw new ArgumentNullException("currentStateSet");
            }

            // Apply most recent states
            foreach (KeyValuePair <string, IGraphicsState> pair in _RenderStates)
            {
                mergedState.DefineState(pair.Value.Copy());
            }

            // Keep inherited states
            foreach (KeyValuePair <string, IGraphicsState> pair in currentStateSet._RenderStates)
            {
                IGraphicsState state = pair.Value;

                if (mergedState.IsDefinedState(state.StateIdentifier) == false)
                {
                    mergedState.DefineState(state.Copy());
                }
                else
                {
                    mergedState[state.StateIdentifier].Merge(state);
                }
            }

            mergedState.Apply(ctx, program);

            return(mergedState);
        }
コード例 #16
0
        /// <summary>
        /// Apply the set of GraphicsState collected by this instance.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> defining the state vector.
        /// </param>
        /// <param name="program">
        /// A <see cref="ShaderProgram"/> defining the uniform state.
        /// </param>
        /// <param name="currentStateSet">
        ///
        /// </param>
        private void Apply(GraphicsContext ctx, ShaderProgram program, GraphicsStateSet currentStateSet)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }

            // Reset texture unit state
            if (program != null)
            {
                program.ResetTextureUnits();
            }

            // Apply known states
            foreach (KeyValuePair <string, IGraphicsState> pair in _RenderStates)
            {
                IGraphicsState state = pair.Value;

                if (state.IsContextBound && (currentStateSet != null) && (currentStateSet.IsDefinedState(state.StateIdentifier)))
                {
                    IGraphicsState currentState = currentStateSet[state.StateIdentifier];

                    if (state.Equals(currentState))
                    {
                        continue;
                    }
                }

                // Apply state if:
                // - the state is context-bound, or
                // - the state is program-bound and a shader program is currently in use
                if (state.IsContextBound || (state.IsShaderProgramBound && program != null))
                {
                    state.ApplyState(ctx, program);
                }
            }
        }
コード例 #17
0
		/// <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));
			
			sLog.Verbose("Detected current state set:");
			foreach (KeyValuePair<string, IGraphicsState> pair in renderStateSet.mRenderStates)
				sLog.Verbose(pair.Value.ToString());
			
			return (renderStateSet);
		}
コード例 #18
0
		/// <summary>
		/// Apply the set of GraphicsState collected by this instance.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> defining the state vector.
		/// </param>
		/// <param name="program">
		/// A <see cref="ShaderProgram"/> defining the uniform state.
		/// </param>
		/// <param name="currentStateSet">
		/// 
		/// </param>
		private void Apply(GraphicsContext ctx, ShaderProgram program, GraphicsStateSet currentStateSet)
		{
			if (ctx == null)
				throw new ArgumentNullException("ctx");

			// Reset texture unit state
			if (program != null)
				program.ResetTextureUnits();

			// Apply known states
			foreach (KeyValuePair<string, IGraphicsState> pair in mRenderStates) {
				IGraphicsState state = pair.Value;
				
				if (state.IsContextBound && (currentStateSet != null) && (currentStateSet.IsDefinedState(state.StateIdentifier))) {
					IGraphicsState currentState = currentStateSet[state.StateIdentifier];

					if (currentState.Inheritable && state.Equals(currentState))
						continue;
				}

				// Apply state if the state is context-bound, or a shader is currently in use
				if ((program != null) || (state.IsContextBound))
					state.ApplyState(ctx, program);
			}

			// Apply custom states, if any
			foreach (GraphicsState customState in mCustomStates) {
				if ((program != null) || (customState.IsContextBound))
					customState.ApplyState(ctx, program);
			}
		}
コード例 #19
0
		/// <summary>
		/// Merge this GraphicsStateSet with a current state.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> defining the state vector.
		/// </param>
		/// <param name="program">
		/// A <see cref="ShaderProgram"/> defining the uniform state.
		/// </param>
		/// <param name="currentStateSet">
		/// 
		/// </param>
		/// <returns></returns>
		internal GraphicsStateSet Merge(GraphicsContext ctx, ShaderProgram program, GraphicsStateSet currentStateSet)
		{
			GraphicsStateSet mergedState = new GraphicsStateSet();

			if (ctx == null)
				throw new ArgumentNullException("ctx");
			if (currentStateSet == null)
				throw new ArgumentNullException("currentStateSet");

			// Apply most recent states
			foreach (KeyValuePair<string, IGraphicsState> pair in mRenderStates)
				mergedState.DefineState(pair.Value.Copy());

			// Keep inherited states
			foreach (KeyValuePair<string, IGraphicsState> pair in currentStateSet.mRenderStates) {
				IGraphicsState state = pair.Value;

				if (mergedState.IsDefinedState(state.StateIdentifier) == false)
					mergedState.DefineState(state.Copy());
				else
					mergedState[state.StateIdentifier].Merge(state);
			}

			mergedState.Apply(ctx, program);

			return (mergedState);
		}
コード例 #20
0
		/// <summary>
		/// Clone this GraphicsStateSet.
		/// </summary>
		/// <returns>
		/// It returns a deep copy of this GraphicsStateSet.
		/// </returns>
		public GraphicsStateSet Copy()
		{
			GraphicsStateSet clone = new GraphicsStateSet();

			foreach (KeyValuePair<string, IGraphicsState> pair in mRenderStates)
				clone.mRenderStates.Add(pair.Key, pair.Value.Copy());

			return (clone);
		}
コード例 #21
0
		/// <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");

			List<IGraphicsState> thisSetStates = new List<IGraphicsState>(States);

			// Merge states defined by stateSet
			foreach (GraphicsState state in thisSetStates) {
				IGraphicsState otherState = stateSet[state.StateIdentifier];

				if (state.Inheritable == false) {
					// Do not include non-inheritable states
					UndefineState(state.StateIdentifier);
					// Include merged state, if defined
					if (otherState != null)
						DefineState(otherState);
				} else {
					if (otherState != null)
						state.Merge(otherState);
				}
			}
			// Include states not defined by this
			foreach (GraphicsState state in stateSet.States)
				if (IsDefinedState(state.StateIdentifier) == false)
					DefineState(state);
		}
コード例 #22
0
		/// <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 (IsDisposed)
				throw new ObjectDisposedException("GraphicsStateSetStack");
			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);
		}