/// <summary> /// Set a shader resource (<paramref name="value"/>) associated with this material. The <paramref name="value"/> will be bound /// to the <see cref="Shader"/> when objects with this material are being rendered. /// </summary> /// <param name="binding">The binding that represents where the resource value will be bound to the <see cref="Shader"/>.</param> /// <param name="value">The resource / value to bind.</param> public void SetMaterialResource <TValue>(BaseShaderResourceBinding <TValue> binding, TValue value) where TValue : class { Assure.True(Shader.ContainsBinding(binding), "Binding is not attributed to the FragmentShader set for this material."); using (RenderingModule.RenderStateBarrier.AcquirePermit(withLock: instanceMutationLock)) { fragmentShaderResources.SetValue(binding, value); } }
/// <summary> /// Sets the resource for the given <paramref name="binding"/>. /// </summary> /// <typeparam name="TValue">The resource type specified by the supplied <paramref name="binding"/>.</typeparam> /// <param name="binding">The <see cref="IShaderResourceBinding"/> to pair a resource with.</param> /// <param name="value">The resource to pair to the <paramref name="binding"/>.</param> public void SetValue <TValue>(BaseShaderResourceBinding <TValue> binding, TValue value) where TValue : class { if (binding is ConstantBufferBinding) { SetValue((ConstantBufferBinding)(object)binding, (IntPtr)(object)value); return; } lock (instanceMutationLock) { Assure.False(binding is ConstantBufferBinding, "Can not set value for Constant Buffer Bindings."); this.bindings[binding] = value; } }
public TValue GetValue <TValue>(BaseShaderResourceBinding <TValue> binding) where TValue : class { if (binding is ConstantBufferBinding) { return((TValue)(object)GetValue((ConstantBufferBinding)(object)binding)); } lock (instanceMutationLock) { Assure.NotNull(binding); if (bindings.ContainsKey(binding)) { return((TValue)bindings[binding]); } else { return(binding.GetBoundResource()); } } }