Fixed issue#26 blend factor logic.

This commit is contained in:
bkaradzic 2013-03-30 09:44:13 -07:00
parent bcd1dee746
commit a26e06929e
2 changed files with 51 additions and 36 deletions

View File

@ -35,22 +35,29 @@ namespace bgfx
{ D3DMULTISAMPLE_16_SAMPLES, 0 }, { D3DMULTISAMPLE_16_SAMPLES, 0 },
}; };
static const D3DBLEND s_blendFactor[][2] = struct Blend
{ {
{ (D3DBLEND)0, (D3DBLEND)0 }, // ignored D3DBLEND m_src;
{ D3DBLEND_ZERO, D3DBLEND_ZERO }, D3DBLEND m_dst;
{ D3DBLEND_ONE, D3DBLEND_ONE }, bool m_factor;
{ D3DBLEND_SRCCOLOR, D3DBLEND_SRCCOLOR }, };
{ D3DBLEND_INVSRCCOLOR, D3DBLEND_INVSRCCOLOR },
{ D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA }, static const Blend s_blendFactor[] =
{ D3DBLEND_INVSRCALPHA, D3DBLEND_INVSRCALPHA }, {
{ D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA }, { (D3DBLEND)0, (D3DBLEND)0, false }, // ignored
{ D3DBLEND_INVDESTALPHA, D3DBLEND_INVDESTALPHA }, { D3DBLEND_ZERO, D3DBLEND_ZERO, false },
{ D3DBLEND_DESTCOLOR, D3DBLEND_DESTCOLOR }, { D3DBLEND_ONE, D3DBLEND_ONE, false },
{ D3DBLEND_INVDESTCOLOR, D3DBLEND_INVDESTCOLOR }, { D3DBLEND_SRCCOLOR, D3DBLEND_SRCCOLOR, false },
{ D3DBLEND_SRCALPHASAT, D3DBLEND_ONE }, { D3DBLEND_INVSRCCOLOR, D3DBLEND_INVSRCCOLOR, false },
{ D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR }, { D3DBLEND_SRCALPHA, D3DBLEND_SRCALPHA, false },
{ D3DBLEND_INVBLENDFACTOR, D3DBLEND_INVBLENDFACTOR }, { D3DBLEND_INVSRCALPHA, D3DBLEND_INVSRCALPHA, false },
{ D3DBLEND_DESTALPHA, D3DBLEND_DESTALPHA, false },
{ D3DBLEND_INVDESTALPHA, D3DBLEND_INVDESTALPHA, false },
{ D3DBLEND_DESTCOLOR, D3DBLEND_DESTCOLOR, false },
{ D3DBLEND_INVDESTCOLOR, D3DBLEND_INVDESTCOLOR, false },
{ D3DBLEND_SRCALPHASAT, D3DBLEND_ONE, false },
{ D3DBLEND_BLENDFACTOR, D3DBLEND_BLENDFACTOR, true },
{ D3DBLEND_INVBLENDFACTOR, D3DBLEND_INVBLENDFACTOR, true },
}; };
static const D3DCMPFUNC s_depthFunc[] = static const D3DCMPFUNC s_depthFunc[] =
@ -2394,16 +2401,17 @@ namespace bgfx
uint32_t src = blend&0xf; uint32_t src = blend&0xf;
uint32_t dst = (blend>>4)&0xf; uint32_t dst = (blend>>4)&0xf;
DX_CHECK(device->SetRenderState(D3DRS_SRCBLEND, s_blendFactor[src][0]) ); DX_CHECK(device->SetRenderState(D3DRS_SRCBLEND, s_blendFactor[src].m_src) );
DX_CHECK(device->SetRenderState(D3DRS_DESTBLEND, s_blendFactor[dst][1]) ); DX_CHECK(device->SetRenderState(D3DRS_DESTBLEND, s_blendFactor[dst].m_dst) );
// DX_CHECK(device->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_SRCALPHA) ); // DX_CHECK(device->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_SRCALPHA) );
// DX_CHECK(device->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_INVSRCALPHA) ); // DX_CHECK(device->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_INVSRCALPHA) );
if (0 != (blend&(BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_FACTOR, BGFX_STATE_BLEND_FACTOR) ) ) if ( (s_blendFactor[src].m_factor || s_blendFactor[dst].m_factor)
&& blendFactor != state.m_rgba) && blendFactor != state.m_rgba)
{ {
blendFactor = state.m_rgba; blendFactor = state.m_rgba;
DX_CHECK(device->SetRenderState(D3DRS_BLENDFACTOR, blendFactor) ); D3DCOLOR color = D3DCOLOR_RGBA(blendFactor>>24, (blendFactor>>16)&0xff, (blendFactor>>8)&0xff, blendFactor&0xff);
DX_CHECK(device->SetRenderState(D3DRS_BLENDFACTOR, color) );
} }
} }
} }

View File

@ -556,22 +556,29 @@ namespace bgfx
GL_FLOAT, GL_FLOAT,
}; };
static const GLenum s_blendFactor[][2] = struct Blend
{ {
{ 0, 0 }, // ignored GLenum m_src;
{ GL_ZERO, GL_ZERO }, GLenum m_dst;
{ GL_ONE, GL_ONE }, bool m_factor;
{ GL_SRC_COLOR, GL_SRC_COLOR }, };
{ GL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR },
{ GL_SRC_ALPHA, GL_SRC_ALPHA }, static const Blend s_blendFactor[] =
{ GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, {
{ GL_DST_ALPHA, GL_DST_ALPHA }, { 0, 0, false }, // ignored
{ GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }, { GL_ZERO, GL_ZERO, false },
{ GL_DST_COLOR, GL_DST_COLOR }, { GL_ONE, GL_ONE, false },
{ GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_DST_COLOR }, { GL_SRC_COLOR, GL_SRC_COLOR, false },
{ GL_SRC_ALPHA_SATURATE, GL_ONE }, { GL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, false },
{ GL_CONSTANT_COLOR, GL_CONSTANT_COLOR }, { GL_SRC_ALPHA, GL_SRC_ALPHA, false },
{ GL_ONE_MINUS_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR }, { GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, false },
{ GL_DST_ALPHA, GL_DST_ALPHA, false },
{ GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, false },
{ GL_DST_COLOR, GL_DST_COLOR, false },
{ GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_DST_COLOR, false },
{ GL_SRC_ALPHA_SATURATE, GL_ONE, false },
{ GL_CONSTANT_COLOR, GL_CONSTANT_COLOR, true },
{ GL_ONE_MINUS_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, true },
}; };
static const GLenum s_depthFunc[] = static const GLenum s_depthFunc[] =
@ -2651,9 +2658,9 @@ namespace bgfx
uint32_t src = blend&0xf; uint32_t src = blend&0xf;
uint32_t dst = (blend>>4)&0xf; uint32_t dst = (blend>>4)&0xf;
GL_CHECK(glEnable(GL_BLEND) ); GL_CHECK(glEnable(GL_BLEND) );
GL_CHECK(glBlendFunc(s_blendFactor[src][0], s_blendFactor[dst][1]) ); GL_CHECK(glBlendFunc(s_blendFactor[src].m_src, s_blendFactor[dst].m_dst) );
if (0 != (blend&(BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_FACTOR, BGFX_STATE_BLEND_FACTOR) ) ) if ( (s_blendFactor[src].m_factor || s_blendFactor[dst].m_factor)
&& blendFactor != state.m_rgba) && blendFactor != state.m_rgba)
{ {
blendFactor = state.m_rgba; blendFactor = state.m_rgba;