Add GPUContext::SetBlendFactor
This commit is contained in:
@@ -315,6 +315,12 @@ public:
|
|||||||
/// <param name="rts">The array with render targets to bind.</param>
|
/// <param name="rts">The array with render targets to bind.</param>
|
||||||
API_FUNCTION() virtual void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) = 0;
|
API_FUNCTION() virtual void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the blend factor that modulate values for a pixel shader, render target, or both.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">Blend factors, one for each RGBA component.</param>
|
||||||
|
API_FUNCTION() virtual void SetBlendFactor(const Float4& value) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unbinds all shader resource slots and flushes the change with the driver (used to prevent driver detection of resource hazards, eg. when down-scaling the texture).
|
/// Unbinds all shader resource slots and flushes the change with the driver (used to prevent driver detection of resource hazards, eg. when down-scaling the texture).
|
||||||
|
|||||||
@@ -181,116 +181,75 @@ uint32 GetHash(const BlendingMode& key)
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @formatter:off
|
||||||
|
|
||||||
BlendingMode BlendingMode::Opaque =
|
BlendingMode BlendingMode::Opaque =
|
||||||
{
|
{
|
||||||
false,
|
false, // AlphaToCoverageEnable
|
||||||
// AlphaToCoverageEnable
|
false, // BlendEnable
|
||||||
false,
|
Blend::One, // SrcBlend
|
||||||
// BlendEnable
|
Blend::Zero, // DestBlend
|
||||||
Blend::One,
|
Operation::Add, // BlendOp
|
||||||
// SrcBlend
|
Blend::One, // SrcBlendAlpha
|
||||||
Blend::Zero,
|
Blend::Zero, // DestBlendAlpha
|
||||||
// DestBlend
|
Operation::Add, // BlendOpAlpha
|
||||||
Operation::Add,
|
ColorWrite::All, // RenderTargetWriteMask
|
||||||
// BlendOp
|
|
||||||
Blend::One,
|
|
||||||
// SrcBlendAlpha
|
|
||||||
Blend::Zero,
|
|
||||||
// DestBlendAlpha
|
|
||||||
Operation::Add,
|
|
||||||
// BlendOpAlpha
|
|
||||||
ColorWrite::All,
|
|
||||||
// RenderTargetWriteMask
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BlendingMode BlendingMode::Additive =
|
BlendingMode BlendingMode::Additive =
|
||||||
{
|
{
|
||||||
false,
|
false, // AlphaToCoverageEnable
|
||||||
// AlphaToCoverageEnable
|
true, // BlendEnable
|
||||||
true,
|
Blend::SrcAlpha, // SrcBlend
|
||||||
// BlendEnable
|
Blend::One, // DestBlend
|
||||||
Blend::SrcAlpha,
|
Operation::Add, // BlendOp
|
||||||
// SrcBlend
|
Blend::SrcAlpha, // SrcBlendAlpha
|
||||||
Blend::One,
|
Blend::One, // DestBlendAlpha
|
||||||
// DestBlend
|
Operation::Add, // BlendOpAlpha
|
||||||
Operation::Add,
|
ColorWrite::All, // RenderTargetWriteMask
|
||||||
// BlendOp
|
|
||||||
Blend::SrcAlpha,
|
|
||||||
// SrcBlendAlpha
|
|
||||||
Blend::One,
|
|
||||||
// DestBlendAlpha
|
|
||||||
Operation::Add,
|
|
||||||
// BlendOpAlpha
|
|
||||||
ColorWrite::All,
|
|
||||||
// RenderTargetWriteMask
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BlendingMode BlendingMode::AlphaBlend =
|
BlendingMode BlendingMode::AlphaBlend =
|
||||||
{
|
{
|
||||||
false,
|
false, // AlphaToCoverageEnable
|
||||||
// AlphaToCoverageEnable
|
true, // BlendEnable
|
||||||
true,
|
Blend::SrcAlpha, // SrcBlend
|
||||||
// BlendEnable
|
Blend::InvSrcAlpha, // DestBlend
|
||||||
Blend::SrcAlpha,
|
Operation::Add, // BlendOp
|
||||||
// SrcBlend
|
Blend::One, // SrcBlendAlpha
|
||||||
Blend::InvSrcAlpha,
|
Blend::InvSrcAlpha, // DestBlendAlpha
|
||||||
// DestBlend
|
Operation::Add, // BlendOpAlpha
|
||||||
Operation::Add,
|
ColorWrite::All, // RenderTargetWriteMask
|
||||||
// BlendOp
|
|
||||||
Blend::One,
|
|
||||||
// SrcBlendAlpha
|
|
||||||
Blend::InvSrcAlpha,
|
|
||||||
// DestBlendAlpha
|
|
||||||
Operation::Add,
|
|
||||||
// BlendOpAlpha
|
|
||||||
ColorWrite::All,
|
|
||||||
// RenderTargetWriteMask
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BlendingMode BlendingMode::Add =
|
BlendingMode BlendingMode::Add =
|
||||||
{
|
{
|
||||||
false,
|
false, // AlphaToCoverageEnable
|
||||||
// AlphaToCoverageEnable
|
true, // BlendEnable
|
||||||
true,
|
Blend::One, // SrcBlend
|
||||||
// BlendEnable
|
Blend::One, // DestBlend
|
||||||
Blend::One,
|
Operation::Add, // BlendOp
|
||||||
// SrcBlend
|
Blend::One, // SrcBlendAlpha
|
||||||
Blend::One,
|
Blend::One, // DestBlendAlpha
|
||||||
// DestBlend
|
Operation::Add, // BlendOpAlpha
|
||||||
Operation::Add,
|
ColorWrite::All, // RenderTargetWriteMask
|
||||||
// BlendOp
|
|
||||||
Blend::One,
|
|
||||||
// SrcBlendAlpha
|
|
||||||
Blend::One,
|
|
||||||
// DestBlendAlpha
|
|
||||||
Operation::Add,
|
|
||||||
// BlendOpAlpha
|
|
||||||
ColorWrite::All,
|
|
||||||
// RenderTargetWriteMask
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BlendingMode BlendingMode::Multiply =
|
BlendingMode BlendingMode::Multiply =
|
||||||
{
|
{
|
||||||
false,
|
false, // AlphaToCoverageEnable
|
||||||
// AlphaToCoverageEnable
|
true, // BlendEnable
|
||||||
true,
|
Blend::Zero, // SrcBlend
|
||||||
// BlendEnable
|
Blend::SrcColor, // DestBlend
|
||||||
Blend::Zero,
|
Operation::Add, // BlendOp
|
||||||
// SrcBlend
|
Blend::Zero, // SrcBlendAlpha
|
||||||
Blend::SrcColor,
|
Blend::SrcAlpha, // DestBlendAlpha
|
||||||
// DestBlend
|
Operation::Add, // BlendOpAlpha
|
||||||
Operation::Add,
|
ColorWrite::All, // RenderTargetWriteMask
|
||||||
// BlendOp
|
|
||||||
Blend::Zero,
|
|
||||||
// SrcBlendAlpha
|
|
||||||
Blend::SrcAlpha,
|
|
||||||
// DestBlendAlpha
|
|
||||||
Operation::Add,
|
|
||||||
// BlendOpAlpha
|
|
||||||
ColorWrite::All,
|
|
||||||
// RenderTargetWriteMask
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// @formatter:on
|
||||||
|
|
||||||
FeatureLevel RenderTools::GetFeatureLevel(ShaderProfile profile)
|
FeatureLevel RenderTools::GetFeatureLevel(ShaderProfile profile)
|
||||||
{
|
{
|
||||||
switch (profile)
|
switch (profile)
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ void GPUContextDX11::FrameBegin()
|
|||||||
CurrentPS = nullptr;
|
CurrentPS = nullptr;
|
||||||
CurrentCS = nullptr;
|
CurrentCS = nullptr;
|
||||||
CurrentPrimitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
CurrentPrimitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
||||||
|
CurrentBlendFactor = Float4::One;
|
||||||
|
|
||||||
// Bind static samplers
|
// Bind static samplers
|
||||||
ID3D11SamplerState* samplers[] =
|
ID3D11SamplerState* samplers[] =
|
||||||
@@ -267,6 +268,13 @@ void GPUContextDX11::SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPU
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPUContextDX11::SetBlendFactor(const Float4& value)
|
||||||
|
{
|
||||||
|
CurrentBlendFactor = value;
|
||||||
|
if (CurrentBlendState)
|
||||||
|
_context->OMSetBlendState(CurrentBlendState, CurrentBlendFactor.Raw, D3D11_DEFAULT_SAMPLE_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
void GPUContextDX11::ResetSR()
|
void GPUContextDX11::ResetSR()
|
||||||
{
|
{
|
||||||
_srDirtyFlag = false;
|
_srDirtyFlag = false;
|
||||||
@@ -560,8 +568,7 @@ void GPUContextDX11::SetState(GPUPipelineState* state)
|
|||||||
if (CurrentBlendState != blendState)
|
if (CurrentBlendState != blendState)
|
||||||
{
|
{
|
||||||
CurrentBlendState = blendState;
|
CurrentBlendState = blendState;
|
||||||
FLOAT blendFactor[4] = { 1, 1, 1, 1 };
|
_context->OMSetBlendState(blendState, CurrentBlendFactor.Raw, D3D11_DEFAULT_SAMPLE_MASK);
|
||||||
_context->OMSetBlendState(blendState, blendFactor, D3D11_DEFAULT_SAMPLE_MASK);
|
|
||||||
}
|
}
|
||||||
if (CurrentVS != vs)
|
if (CurrentVS != vs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ private:
|
|||||||
GPUShaderProgramPSDX11* CurrentPS;
|
GPUShaderProgramPSDX11* CurrentPS;
|
||||||
GPUShaderProgramCSDX11* CurrentCS;
|
GPUShaderProgramCSDX11* CurrentCS;
|
||||||
D3D11_PRIMITIVE_TOPOLOGY CurrentPrimitiveTopology;
|
D3D11_PRIMITIVE_TOPOLOGY CurrentPrimitiveTopology;
|
||||||
|
Float4 CurrentBlendFactor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -115,6 +116,7 @@ public:
|
|||||||
void SetRenderTarget(GPUTextureView* rt) override;
|
void SetRenderTarget(GPUTextureView* rt) override;
|
||||||
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
||||||
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
||||||
|
void SetBlendFactor(const Float4& value) override;
|
||||||
void ResetSR() override;
|
void ResetSR() override;
|
||||||
void ResetUA() override;
|
void ResetUA() override;
|
||||||
void ResetCB() override;
|
void ResetCB() override;
|
||||||
|
|||||||
@@ -845,6 +845,11 @@ void GPUContextDX12::SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPU
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPUContextDX12::SetBlendFactor(const Float4& value)
|
||||||
|
{
|
||||||
|
_commandList->OMSetBlendFactor(value.Raw);
|
||||||
|
}
|
||||||
|
|
||||||
void GPUContextDX12::ResetSR()
|
void GPUContextDX12::ResetSR()
|
||||||
{
|
{
|
||||||
for (int32 slot = 0; slot < GPU_MAX_SR_BINDED; slot++)
|
for (int32 slot = 0; slot < GPU_MAX_SR_BINDED; slot++)
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ public:
|
|||||||
void SetRenderTarget(GPUTextureView* rt) override;
|
void SetRenderTarget(GPUTextureView* rt) override;
|
||||||
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
||||||
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
||||||
|
void SetBlendFactor(const Float4& value) override;
|
||||||
void ResetSR() override;
|
void ResetSR() override;
|
||||||
void ResetUA() override;
|
void ResetUA() override;
|
||||||
void ResetCB() override;
|
void ResetCB() override;
|
||||||
|
|||||||
@@ -84,6 +84,10 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetBlendFactor(const Float4& value) override
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void ResetSR() override
|
void ResetSR() override
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -966,6 +966,12 @@ void GPUContextVulkan::SetRenderTarget(GPUTextureView* depthBuffer, const Span<G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPUContextVulkan::SetBlendFactor(const Float4& value)
|
||||||
|
{
|
||||||
|
const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer();
|
||||||
|
vkCmdSetBlendConstants(cmdBuffer->GetHandle(), value.Raw);
|
||||||
|
}
|
||||||
|
|
||||||
void GPUContextVulkan::ResetSR()
|
void GPUContextVulkan::ResetSR()
|
||||||
{
|
{
|
||||||
Platform::MemoryClear(_srHandles, sizeof(_srHandles));
|
Platform::MemoryClear(_srHandles, sizeof(_srHandles));
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ public:
|
|||||||
void SetRenderTarget(GPUTextureView* rt) override;
|
void SetRenderTarget(GPUTextureView* rt) override;
|
||||||
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
void SetRenderTarget(GPUTextureView* depthBuffer, GPUTextureView* rt) override;
|
||||||
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
void SetRenderTarget(GPUTextureView* depthBuffer, const Span<GPUTextureView*>& rts) override;
|
||||||
|
void SetBlendFactor(const Float4& value) override;
|
||||||
void ResetSR() override;
|
void ResetSR() override;
|
||||||
void ResetUA() override;
|
void ResetUA() override;
|
||||||
void ResetCB() override;
|
void ResetCB() override;
|
||||||
|
|||||||
Reference in New Issue
Block a user