mercredi 27 septembre 2023

DirectX issue about new GPU

causes an issue and it affects the other texture because of the code culprit with the new GPU settings i am currently using DirectX 9

BOOL C2DRender::RenderTextureALPHA(CPoint pt, CTexture* pTexture, CTexture* pTextureBG, FLOAT fRadian, FLOAT fScaleX, FLOAT fScaleY, DWORD dwBlendFactorAlhpa)
{
    if (!pTexture || !pTextureBG)
        return FALSE;

    m_pd3dDevice->SetRenderTarget(0, m_pBackBuffer);
    pt += m_ptOrigin;
    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);

    FLOAT cx = _left + ((_right - _left) / 2);
    FLOAT cy = _top + ((_bottom - _top) / 2);

    _left -= cx;
    _right -= cx;
    _top -= cy;
    _bottom -= cy;

    D3DXVECTOR2 v1, v2, v3, v4;
    D3DXMATRIX  mRot;

    v1.x = _left;   v1.y = _top;
    v2.x = _right;  v2.y = _top;
    v3.x = _left;   v3.y = _bottom;
    v4.x = _right;  v4.y = _bottom;

    D3DXMatrixRotationZ(&mRot, fRadian);
    D3DXVec2TransformCoord(&v1, &v1, &mRot);
    D3DXVec2TransformCoord(&v2, &v2, &mRot);
    D3DXVec2TransformCoord(&v3, &v3, &mRot);
    D3DXVec2TransformCoord(&v4, &v4, &mRot);

    TEXTUREVERTEX vertex[4];
    TEXTUREVERTEX* pVertices = vertex;

    SetTextureVertex(pVertices, cx + v1.x, cy + v1.y, pTexture->m_fuLT, pTexture->m_fvLT);
    pVertices++;
    SetTextureVertex(pVertices, cx + v2.x, cy + v2.y, pTexture->m_fuRT, pTexture->m_fvRT);
    pVertices++;
    SetTextureVertex(pVertices, cx + v3.x, cy + v3.y, pTexture->m_fuLB, pTexture->m_fvLB);
    pVertices++;
    SetTextureVertex(pVertices, cx + v4.x, cy + v4.y, 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));

    if (dwBlendFactorAlhpa >= 200)
    {
        m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
        m_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)70);
        m_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
        m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
    }
    else
    {
        m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
    }

    m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
    
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);

    m_pd3dDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
    m_pd3dDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

    m_pd3dDevice->SetVertexShader(0);

    m_pd3dDevice->SetTexture(1, pTexture->m_pTexture);
    m_pd3dDevice->SetTexture(0, pTextureBG->m_pTexture);
    m_pd3dDevice->SetTexture(2, 0);

    m_pd3dDevice->SetFVF(D3DFVF_TEXTUREVERTEX);
    m_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertex, sizeof(TEXTUREVERTEX));
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);

    m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
    m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    m_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);

    m_pd3dDevice->SetSamplerState(0, D3DSAMP_SRGBTEXTURE, 0);
    m_pd3dDevice->SetSamplerState(1, D3DSAMP_SRGBTEXTURE, 0);

    m_pd3dDevice->SetTexture(0, 0);
    m_pd3dDevice->SetTexture(1, 0);
    m_pd3dDevice->SetTexture(2, 0);

    return TRUE;
};

in latest GPU setting i am having an issue in this portion will let my texture missing

    m_pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT);
    m_pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);

while if i disable the optimization it goes back to normal what do you think the possible solution in this code

Aucun commentaire:

Enregistrer un commentaire