void d3d9_render_msg_post(xdk360_video_font_t * font) { if( --font->m_dwNestedBeginCount > 0 ) return; // Restore state if( font->m_bSaveState ) { // Cache the global pointer into a register xdk_d3d_video_t *vid = (xdk_d3d_video_t*)driver.video_data; D3DDevice *pD3dDevice = vid->d3d_render_device; D3DDevice_SetTexture_Inline(pD3dDevice, 0, NULL); D3DDevice_SetVertexDeclaration(pD3dDevice, NULL); D3DDevice_SetVertexShader(pD3dDevice, NULL ); D3DDevice_SetPixelShader(pD3dDevice, NULL ); D3DDevice_SetRenderState_AlphaBlendEnable(pD3dDevice, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHABLENDENABLE ]); D3DDevice_SetRenderState_SrcBlend(pD3dDevice, font->m_dwSavedState[ SAVEDSTATE_D3DRS_SRCBLEND ] ); D3DDevice_SetRenderState_DestBlend( pD3dDevice, font->m_dwSavedState[ SAVEDSTATE_D3DRS_DESTBLEND ] ); D3DDevice_SetRenderState_BlendOp( pD3dDevice, font->m_dwSavedState[ SAVEDSTATE_D3DRS_BLENDOP ] ); pD3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHATESTENABLE ] ); pD3dDevice->SetRenderState( D3DRS_ALPHAREF, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAREF ] ); pD3dDevice->SetRenderState( D3DRS_ALPHAFUNC, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAFUNC ] ); pD3dDevice->SetRenderState( D3DRS_FILLMODE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_FILLMODE ] ); pD3dDevice->SetRenderState( D3DRS_CULLMODE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_CULLMODE ] ); pD3dDevice->SetRenderState( D3DRS_VIEWPORTENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_VIEWPORTENABLE ] ); D3DDevice_SetSamplerState_MinFilter(pD3dDevice, 0, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MINFILTER ] ); D3DDevice_SetSamplerState_MagFilter(pD3dDevice, 0, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MAGFILTER ] ); D3DDevice_SetSamplerState_AddressU_Inline(pD3dDevice, 0, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] ); D3DDevice_SetSamplerState_AddressV_Inline(pD3dDevice, 0, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ] ); } }
static void hlsl_use(unsigned index) { if (hlsl_active && prg[index].vprg && prg[index].fprg) { active_index = index; #ifdef _XBOX D3DDevice_SetVertexShader(d3d_device_ptr, prg[index].vprg); D3DDevice_SetPixelShader(d3d_device_ptr, prg[index].fprg); #else d3d_device_ptr->SetVertexShader(prg[index].vprg); d3d_device_ptr->SetPixelShader(prg[index].fprg); #endif } }
HRESULT d3d_set_vertex_shader(LPDIRECT3DDEVICE dev, unsigned index, void *data) { #if defined(_XBOX1) return dev->SetVertexShader(index); #elif defined(_XBOX360) LPDIRECT3DVERTEXSHADER shader = (LPDIRECT3DVERTEXSHADER)data; D3DDevice_SetVertexShader(dev, shader); return S_OK; #else LPDIRECT3DVERTEXSHADER shader = (LPDIRECT3DVERTEXSHADER)data; return dev->SetVertexShader(shader); #endif }
static void hlsl_use(void *data, unsigned index) { d3d_video_t *d3d = (d3d_video_t*)data; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)d3d->dev; if (hlsl_active && prg[index].vprg && prg[index].fprg) { active_index = index; #ifdef _XBOX D3DDevice_SetVertexShader(d3dr, prg[index].vprg); D3DDevice_SetPixelShader(d3dr, prg[index].fprg); #else d3dr->SetVertexShader(prg[index].vprg); d3dr->SetPixelShader(prg[index].fprg); #endif } }
//-------------------------------------------------------------------------------------- // Name: SetVertexShader() // Desc: Overloaded function to avoid redundant calls to D3D //-------------------------------------------------------------------------------------- D3DVOID WINAPI D3DDevice::SetVertexShader( D3DVertexShader* pShader ) { static D3DVertexShader* g_pShader = NULL; // Synchronize with current D3D device state, to catch subsystems that do not go // through this codepath D3DVertexShader* pCurrentVS = NULL; D3DDevice_GetVertexShader( this, &pCurrentVS ); g_pShader = pCurrentVS; if( pCurrentVS != NULL ) pCurrentVS->Release(); // Only update shader if it has changed if( g_pShader != pShader ) { D3DDevice_SetVertexShader( this, pShader ); g_pShader = pShader; } D3DVOIDRETURN; }
void d3d9_render_msg_pre(xdk360_video_font_t * font) { // Set state on the first call if( font->m_dwNestedBeginCount == 0 ) { // Cache the global pointer into a register xdk_d3d_video_t *vid = (xdk_d3d_video_t*)driver.video_data; D3DDevice *pD3dDevice = vid->d3d_render_device; // Save state if( font->m_bSaveState ) { pD3dDevice->GetRenderState( D3DRS_ALPHABLENDENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHABLENDENABLE ] ); pD3dDevice->GetRenderState( D3DRS_SRCBLEND, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_SRCBLEND ] ); pD3dDevice->GetRenderState( D3DRS_DESTBLEND, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_DESTBLEND ] ); pD3dDevice->GetRenderState( D3DRS_BLENDOP, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_BLENDOP ] ); pD3dDevice->GetRenderState( D3DRS_ALPHATESTENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHATESTENABLE ] ); pD3dDevice->GetRenderState( D3DRS_ALPHAREF, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAREF ] ); pD3dDevice->GetRenderState( D3DRS_ALPHAFUNC, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAFUNC ] ); pD3dDevice->GetRenderState( D3DRS_FILLMODE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_FILLMODE ] ); pD3dDevice->GetRenderState( D3DRS_CULLMODE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_CULLMODE ] ); pD3dDevice->GetRenderState( D3DRS_VIEWPORTENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_VIEWPORTENABLE ] ); font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MINFILTER ] = D3DDevice_GetSamplerState_MinFilter( pD3dDevice, 0 ); font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MAGFILTER ] = D3DDevice_GetSamplerState_MagFilter( pD3dDevice, 0 ); font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] = D3DDevice_GetSamplerState_AddressU( pD3dDevice, 0); font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ] = D3DDevice_GetSamplerState_AddressV( pD3dDevice, 0); } // Set the texture scaling factor as a vertex shader constant D3DSURFACE_DESC TextureDesc; D3DTexture_GetLevelDesc(font->m_pFontTexture, 0, &TextureDesc); // Get the description // Set render state D3DDevice_SetTexture_Inline(pD3dDevice, 0, font->m_pFontTexture); // Read the TextureDesc here to ensure no load/hit/store from GetLevelDesc() float vTexScale[4]; vTexScale[0] = 1.0f / TextureDesc.Width; // LHS due to int->float conversion vTexScale[1] = 1.0f / TextureDesc.Height; vTexScale[2] = 0.0f; vTexScale[3] = 0.0f; D3DDevice_SetRenderState_AlphaBlendEnable( pD3dDevice, TRUE ); D3DDevice_SetRenderState_SrcBlend(pD3dDevice, D3DBLEND_SRCALPHA ); D3DDevice_SetRenderState_DestBlend( pD3dDevice, D3DBLEND_INVSRCALPHA ); D3DDevice_SetRenderState_BlendOp( pD3dDevice, D3DBLENDOP_ADD ); pD3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); pD3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x08 ); pD3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL ); pD3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); pD3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); pD3dDevice->SetRenderState( D3DRS_VIEWPORTENABLE, FALSE ); D3DDevice_SetSamplerState_MinFilter(pD3dDevice, 0, D3DTEXF_LINEAR ); D3DDevice_SetSamplerState_MagFilter(pD3dDevice, 0, D3DTEXF_LINEAR ); D3DDevice_SetSamplerState_AddressU_Inline(pD3dDevice, 0, D3DTADDRESS_CLAMP ); D3DDevice_SetSamplerState_AddressV_Inline(pD3dDevice, 0, D3DTADDRESS_CLAMP ); D3DDevice_SetVertexDeclaration(pD3dDevice, s_FontLocals.m_pFontVertexDecl ); D3DDevice_SetVertexShader(pD3dDevice, s_FontLocals.m_pFontVertexShader ); D3DDevice_SetPixelShader(pD3dDevice, s_FontLocals.m_pFontPixelShader ); // Set the texture scaling factor as a vertex shader constant // Call here to avoid load hit store from writing to vTexScale above pD3dDevice->SetVertexShaderConstantF( 2, vTexScale, 1 ); } // Keep track of the nested begin/end calls. font->m_dwNestedBeginCount++; }