public RenderState GetRenderState(RenderStateType type, String techName, int passIndex) { RenderStateRecord[] records; if (!_map.TryGetValue(techName, out records)) { return(null); } if (passIndex >= 0 && passIndex < records.Length) { RenderStateRecord record = records[passIndex]; switch (type) { case RenderStateType.BlendState: return(record.BlendState); case RenderStateType.DepthStencilState: return(record.DepthStencilState); case RenderStateType.RasterizerState: return(record.RasterizerState); default: return(null); } } else { throw new ArgumentOutOfRangeException("Pass index out of range"); } }
/// <summary> /// Clears the specific render state from the renderer. /// </summary> /// <param name="stateType">State type to clear</param> public void ClearEnforcedState(RenderStateType stateType) { if (stateType == RenderStateType.SamplerState) { return; } _enforcedStates[stateType] = null; }
/// <summary> /// Returns the enforced state specified by its type, if it exists. /// </summary> /// <param name="stateType">State's type</param> /// <returns> /// Enforced state, or null if this state type is not enforced /// </returns> public RenderState GetEnforcedState(RenderStateType stateType) { if (stateType == RenderStateType.SamplerState) { return(null); } return(_enforcedStates[stateType]); }
/// <summary> /// Returns the current renderstate of the specified type that has been set to the device, and is present in the cache. /// </summary> /// <param name="stateType">State type to query</param> /// <returns> /// The render state /// </returns> public RenderState GetRenderState(RenderStateType stateType) { if (stateType == RenderStateType.SamplerState) { return(null); } return(_renderStateCache[stateType]); }
public RenderState GetRenderState(RenderStateType type, String techniqueName, int passIndex) { if (IsValid) { return(_renderStateMap.GetRenderState(type, techniqueName, passIndex)); } else { throw new ArgumentNullException("Material does not have a valid effect loaded, cannot set RenderState. Call LoadEffect() first"); } }
public RenderState GetRenderState(RenderStateType type) { if (IsValid && _currentTechnique != null) { return(_renderStateMap.GetRenderState(type, _currentTechnique.Name, 0)); } else { throw new ArgumentNullException("Material does not have a valid effect loaded, cannot set RenderState. Call LoadEffect() first"); } }
/// <summary> /// Applies the render state to the device. If the state is null, then the default state for its type is used instead. If the renderer is /// enforcing a state for the specified state type, that is used instead. If the state to be applied already is present in the cache, the renderer returns, /// preventing redundant state switching. /// It is important to let the renderer take care of state management, and not to set states directly in your shader program, in your effect pass. Otherwise, /// the render states may be inconsistent to what is present in the cache. /// </summary> /// <param name="stateType">Enumerated render state type to apply</param> /// <param name="state">Render state to apply to the device, if null the default state is used based on the enumerated type.</param> public void ApplyRenderState(RenderStateType stateType, RenderState state) { //Silently fail if someone is trying to give us a sampler state. if (stateType == RenderStateType.SamplerState || state is SamplerState) { return; } //Get the enforced state RenderState tempState = GetEnforcedState(stateType); //Is enforced state null? If so, use supplied state if (tempState == null) { tempState = state; } //If we're STILL null, we then have to use the default state, so query it if (tempState == null) { tempState = GetDefaultState(stateType); } //Get the cached state RenderState cachedState = GetRenderState(stateType); //Do we have a cached state? Usually we should. if (cachedState != null) { //Have we already applied the same state? If so, do nothing if (cachedState.RenderStateKey == tempState.RenderStateKey) { return; } else { //Otherwise set to the device and cache it ApplyConcreteState(tempState); _renderStateCache[stateType] = tempState; } } else { //Since the cached state is null, we don't know what's on the device, so we apply the state and set it in the cache //This should only occur at startup when we clear the states for the first time ApplyConcreteState(tempState); _renderStateCache[stateType] = tempState; } }
/// <summary> /// Gets or sets the render state based on type. If type is sampler state, /// null will return or setting will be ignored. /// </summary> /// <param name="type">State type</param> /// <returns>Corresponding state, or null if not present</returns> public RenderState this[RenderStateType type] { get { if (type == RenderStateType.SamplerState) { return(null); } return(_renderStates[(int)type]); } set { if (type == RenderStateType.SamplerState) { return; } _renderStates[(int)type] = value; } }
//Helper method for getting the default state based on enumeration type. private RenderState GetDefaultState(RenderStateType stateType) { switch (stateType) { case RenderStateType.BlendState: return(RenderStateList.DefaultBlendState); case RenderStateType.DepthStencilState: return(RenderStateList.DefaultDepthStencilState); case RenderStateType.RasterizerState: return(RenderStateList.DefaultRasterizerState); default: return(null); //Shouldn't occur } }
public RenderState GetRenderState(RenderStateType type, int techniqueIndex, int passIndex) { if (IsValid) { IEffectTechnique technique = _effect.Techniques[techniqueIndex]; if (technique != null) { return(_renderStateMap.GetRenderState(type, technique.Name, passIndex)); } else { return(null); } } else { throw new ArgumentNullException("Material does not have a valid effect loaded, cannot set RenderState. Call LoadEffect() first"); } }
public RenderState SetRenderState(RenderStateType type, String techniqueName, String passName) { if (IsValid) { IEffectTechnique technique = _effect.Techniques[techniqueName]; if (technique != null) { for (int i = 0; i < technique.Passes.Count; i++) { IEffectPass pass = technique.Passes[i]; if (pass.Name.Equals(passName)) { return(_renderStateMap.GetRenderState(type, techniqueName, i)); } } } } else { throw new ArgumentNullException("Material does not have a valid effect loaded, cannot set RenderState. Call LoadEffect() first"); } return(null); }
/// <summary> /// Creates a new RenderStateKey, initializing all fields. /// </summary> /// <param name="key">State key, usually hash code</param> /// <param name="stateType">State type, for identification</param> public RenderStateKey(int key, RenderStateType stateType) { _key = key; _type = stateType; }
/// <summary> /// Clears the state of the render. /// </summary> /// <param name="type">The type.</param> public void ClearRenderState(RenderStateType type) { ApplyRenderState(type, null); }