public void ApplyPerObjectInput(ConstantBufferDataProvider dataProvider) { if (_perObjectBufferBindings.Length != 1) { throw new InvalidOperationException( "ApplyPerObjectInput can only be used when a material has exactly one per-object input."); } PerObjectConstantBufferBinding binding = _perObjectBufferBindings[0]; dataProvider.SetData(binding.ConstantBuffer); }
public void Apply() { foreach (GlobalConstantBufferBinding cbBinding in _constantBufferBindings) { cbBinding.UpdateBuffer(); cbBinding.BindToShaderSlots(_device.ImmediateContext); } for (int i = 0; i < _perObjectBufferBindings.Length; i++) { PerObjectConstantBufferBinding binding = _perObjectBufferBindings[i]; binding.BindToShaderSlots(_device.ImmediateContext); } }
public void ApplyPerObjectInputs(ConstantBufferDataProvider[] dataProviders) { if (_perObjectBufferBindings.Length != dataProviders.Length) { throw new InvalidOperationException( "dataProviders must contain the exact number of per-object buffer bindings used in the material."); } for (int i = 0; i < _perObjectBufferBindings.Length; i++) { PerObjectConstantBufferBinding binding = _perObjectBufferBindings[i]; ConstantBufferDataProvider provider = dataProviders[i]; provider.SetData(binding.ConstantBuffer); } }
public D3DShaderConstantBindings( RenderContext rc, Device device, ShaderSet shaderSet, MaterialInputs <MaterialGlobalInputElement> globalInputs, MaterialInputs <MaterialPerObjectInputElement> perObjectInputs) { _device = device; ShaderReflection vsReflection = new ShaderReflection(((D3DVertexShader)shaderSet.VertexShader).Bytecode.Data); ShaderReflection psReflection = new ShaderReflection(((D3DFragmentShader)shaderSet.FragmentShader).Bytecode.Data); ShaderReflection gsReflection = null; if (shaderSet.GeometryShader != null) { gsReflection = new ShaderReflection(((D3DGeometryShader)shaderSet.GeometryShader).Bytecode.Data); } int numGlobalElements = globalInputs.Elements.Length; _constantBufferBindings = (numGlobalElements > 0) ? new GlobalConstantBufferBinding[numGlobalElements] : Array.Empty <GlobalConstantBufferBinding>(); for (int i = 0; i < numGlobalElements; i++) { var genericElement = globalInputs.Elements[i]; BufferProviderPair pair; GlobalConstantBufferBinding cbb; bool isVsBuffer = DoesConstantBufferExist(vsReflection, i, genericElement.Name); bool isPsBuffer = DoesConstantBufferExist(psReflection, i, genericElement.Name); bool isGsBuffer = false; if (gsReflection != null) { isGsBuffer = DoesConstantBufferExist(gsReflection, i, genericElement.Name); } if (genericElement.UseGlobalNamedBuffer) { pair = rc.GetNamedGlobalBufferProviderPair(genericElement.GlobalProviderName); cbb = new GlobalConstantBufferBinding(i, pair, false, isVsBuffer, isGsBuffer, isPsBuffer); } else { D3DConstantBuffer constantBuffer = new D3DConstantBuffer(device, genericElement.DataProvider.DataSizeInBytes); pair = new BufferProviderPair(constantBuffer, genericElement.DataProvider); cbb = new GlobalConstantBufferBinding(i, pair, true, isVsBuffer, isGsBuffer, isPsBuffer); } _constantBufferBindings[i] = cbb; } int numPerObjectInputs = perObjectInputs.Elements.Length; _perObjectBufferBindings = (numPerObjectInputs > 0) ? new PerObjectConstantBufferBinding[numPerObjectInputs] : Array.Empty <PerObjectConstantBufferBinding>(); for (int i = 0; i < numPerObjectInputs; i++) { var genericElement = perObjectInputs.Elements[i]; int bufferSlot = i + numGlobalElements; bool isVsBuffer = DoesConstantBufferExist(vsReflection, bufferSlot, genericElement.Name); bool isPsBuffer = DoesConstantBufferExist(psReflection, bufferSlot, genericElement.Name); bool isGsBuffer = false; if (gsReflection != null) { isGsBuffer = DoesConstantBufferExist(gsReflection, bufferSlot, genericElement.Name); } D3DConstantBuffer constantBuffer = new D3DConstantBuffer(device, genericElement.BufferSizeInBytes); PerObjectConstantBufferBinding pocbb = new PerObjectConstantBufferBinding(bufferSlot, constantBuffer, isVsBuffer, isGsBuffer, isPsBuffer); _perObjectBufferBindings[i] = pocbb; } }