Add gs_blend_function_separate

This allows the ability to separate the blend states of color and alpha.

The default blend state has also changed so that alpha is always added
together to ensure that the destination image always gets an alpha value
that is actually usable after the operation (for render targets).

Old default state:
  color source: GS_BLEND_SRCALPHA, color dest: GS_BLEND_INVSRCALPHA
  alpha source: GS_BLEND_SRCALPHA, alpha dest: GS_BLEND_INVSRCALPHA

New default state:
  color source: GS_BLEND_SRCALPHA, color dest: GS_BLEND_INVSRCALPHA
  alpha source: GS_BLEND_ONE,      alpha dest: GS_BLEND_ONE
This commit is contained in:
jp9000
2015-03-27 11:18:02 -07:00
parent 95f5a3c260
commit be52fa26f9
8 changed files with 102 additions and 24 deletions

View File

@@ -302,13 +302,13 @@ ID3D11BlendState *gs_device::AddBlendState()
bd.RenderTarget[i].BlendOp = D3D11_BLEND_OP_ADD;
bd.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_ADD;
bd.RenderTarget[i].SrcBlend =
ConvertGSBlendType(blendState.srcFactor);
ConvertGSBlendType(blendState.srcFactorC);
bd.RenderTarget[i].DestBlend =
ConvertGSBlendType(blendState.destFactor);
ConvertGSBlendType(blendState.destFactorC);
bd.RenderTarget[i].SrcBlendAlpha =
bd.RenderTarget[i].SrcBlend;
ConvertGSBlendType(blendState.srcFactorA);
bd.RenderTarget[i].DestBlendAlpha =
bd.RenderTarget[i].DestBlend;
ConvertGSBlendType(blendState.destFactorA);
bd.RenderTarget[i].RenderTargetWriteMask =
D3D11_COLOR_WRITE_ENABLE_ALL;
}
@@ -1388,15 +1388,36 @@ void device_enable_color(gs_device_t *device, bool red, bool green,
void device_blend_function(gs_device_t *device, enum gs_blend_type src,
enum gs_blend_type dest)
{
if (device->blendState.srcFactor == src &&
device->blendState.destFactor == dest)
if (device->blendState.srcFactorC == src &&
device->blendState.destFactorC == dest &&
device->blendState.srcFactorA == src &&
device->blendState.destFactorA == dest)
return;
device->blendState.srcFactor = src;
device->blendState.destFactor = dest;
device->blendState.srcFactorC = src;
device->blendState.destFactorC= dest;
device->blendState.srcFactorA = src;
device->blendState.destFactorA= dest;
device->blendStateChanged = true;
}
void device_blend_function_separate(gs_device_t *device,
enum gs_blend_type src_c, enum gs_blend_type dest_c,
enum gs_blend_type src_a, enum gs_blend_type dest_a)
{
if (device->blendState.srcFactorC == src_c &&
device->blendState.destFactorC == dest_c &&
device->blendState.srcFactorA == src_a &&
device->blendState.destFactorA == dest_a)
return;
device->blendState.srcFactorC = src_c;
device->blendState.destFactorC = dest_c;
device->blendState.srcFactorA = src_a;
device->blendState.destFactorA = dest_a;
device->blendStateChanged = true;
}
void device_depth_function(gs_device_t *device, enum gs_depth_test test)
{
if (device->zstencilState.depthFunc == test)

View File

@@ -495,8 +495,10 @@ struct gs_swap_chain {
struct BlendState {
bool blendEnabled;
gs_blend_type srcFactor;
gs_blend_type destFactor;
gs_blend_type srcFactorC;
gs_blend_type destFactorC;
gs_blend_type srcFactorA;
gs_blend_type destFactorA;
bool redEnabled;
bool greenEnabled;
@@ -505,8 +507,10 @@ struct BlendState {
inline BlendState()
: blendEnabled (true),
srcFactor (GS_BLEND_SRCALPHA),
destFactor (GS_BLEND_INVSRCALPHA),
srcFactorC (GS_BLEND_SRCALPHA),
destFactorC (GS_BLEND_INVSRCALPHA),
srcFactorA (GS_BLEND_ONE),
destFactorA (GS_BLEND_ONE),
redEnabled (true),
greenEnabled (true),
blueEnabled (true),