Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
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);
		}
Ejemplo n.º 5
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);
			}
		}