LPDIRECT3DTEXTURE9 C2DRender::RenderMergeTextures( /*CPoint pt, */CTexture *pTop, CTexture *pBottom, int nWidth, int nHeight, float fPercentageTop )
{
if( !pTop || !pBottom )
return NULL;
int nHeightBot = (int)((float)nHeight * (1 - fPercentageTop));
if( nHeightBot == 0 )
{
//RenderTexture( pt, pTop );
return pTop->m_pTexture;
}else if( nHeightBot == nHeight )
{
//RenderTexture( pt, pBottom );
return pBottom->m_pTexture;
}else if( nHeightBot > nHeight || nHeightBot < 0 )
{
Error("C2DRender::RenderMergeTextures() nHeightBot = %d wrong format", nHeightBot );
return NULL;
}
LPDIRECT3DTEXTURE9 pOut, pBot;
LPDIRECT3DSURFACE9 pRenderSurface;
m_pd3dDevice->CreateTexture(nWidth, nHeightBot, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pBot, NULL );
pBot->GetSurfaceLevel( 0, &pRenderSurface );
m_pd3dDevice->SetRenderTarget( 0, pRenderSurface );
RenderTexture_2(CPoint(0, nHeightBot - nHeight) , pBottom );
m_pd3dDevice->CreateTexture(nWidth, nHeight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pOut, NULL);
pOut->GetSurfaceLevel(0, &pRenderSurface);
m_pd3dDevice->SetRenderTarget( 0, pRenderSurface );
RenderTexture_2(CPoint(0,0), pTop, 160);
RenderTextureNative(CPoint(0,nHeight - nHeightBot), pBot, nHeightBot, nWidth);
m_pd3dDevice->SetRenderTarget(0, m_pBackBuffer);
if (g_Option.m_bMSAAFiltering)
m_pd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
SAFE_RELEASE( pBot );
SAFE_RELEASE( pRenderSurface );
return pOut;
}
void C2DRender::RenderTextureNative( CPoint pt, LPDIRECT3DTEXTURE9 pTexture, int nHeight, int nWidth, BOOL bOrigin )
{
if( !pTexture )
return;
if(bOrigin)
pt += m_ptOrigin;
FLOAT left = (FLOAT)( pt.x );
FLOAT top = (FLOAT)( pt.y );
FLOAT right = (FLOAT)pt.x + ( nWidth );
FLOAT bottom = (FLOAT)pt.y + ( nHeight );
TEXTUREVERTEX vertex[ 4 ];//4
TEXTUREVERTEX* pVertices = vertex;
SetTextureVertex( pVertices, left, top, 0.0f, 0.0f );
pVertices++;
SetTextureVertex( pVertices, right, top, 1.0f, 0.0f);
pVertices++;
SetTextureVertex( pVertices, left, bottom, 0.0f, 1.0f);
pVertices++;
SetTextureVertex( pVertices, right, bottom, 1.0f, 1.0f);
pVertices++;
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( 255, 0, 0, 0 ) );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
m_pd3dDevice->SetVertexShader( NULL );
m_pd3dDevice->SetTexture( 0, pTexture );
m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX ) );
m_pd3dDevice->SetTexture( 0, NULL );
}
void C2DRender::RenderTexture_2( CPoint pt, CTexture* pTexture, DWORD dwBlendFactorAlhpa, FLOAT fScaleX , FLOAT fScaleY )
{
if( !pTexture )
return;
CPoint ptCenter = pTexture->m_ptCenter;
ptCenter.x = (LONG)( ptCenter.x * fScaleX );
ptCenter.y = (LONG)( ptCenter.y * fScaleY );
pt -= ptCenter;
FLOAT left = (FLOAT)( pt.x );
FLOAT top = (FLOAT)( pt.y );
FLOAT right = pt.x + ( fScaleX * pTexture->m_size.cx );
FLOAT bottom = pt.y + ( fScaleY * pTexture->m_size.cy );
TEXTUREVERTEX vertex[ 4 ];//4
TEXTUREVERTEX* pVertices = vertex;
SetTextureVertex( pVertices, left, top, pTexture->m_fuLT, pTexture->m_fvLT );
pVertices++;
SetTextureVertex( pVertices, right, top, pTexture->m_fuRT, pTexture->m_fvRT);
pVertices++;
SetTextureVertex( pVertices, left, bottom, pTexture->m_fuLB, pTexture->m_fvLB);
pVertices++;
SetTextureVertex( pVertices, right, bottom, pTexture->m_fuRB, pTexture->m_fvRB);
pVertices++;
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( dwBlendFactorAlhpa, 0, 0, 0 ) );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
m_pd3dDevice->SetVertexShader( NULL );
m_pd3dDevice->SetTexture( 0, pTexture->m_pTexture );
m_pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vertex, sizeof( TEXTUREVERTEX ) );
m_pd3dDevice->SetTexture( 0, NULL );
}
It is exactly as it shows in Virtous's source for v19 and still doesn't work with MSAA!