|
|

楼主 |
发表于 2008-3-21 23:21:00
|
显示全部楼层
Re:inversion of GetRenderTargetData
I use DirectX9 and try to use StrechRect to copy texture. I just try the creation of texture. So my method is very strange.
In the line 29, pSmTile->m_pShadowMapSurf and m_pShadowMapSurf are RenderTraget Texture's surface. The copy between them is all right. But in the line 30, I try to copy the Texture Loading from file to RenderTraget Texture's surface.
The function of StretchRect always return "D3DERR_INVALIDCALL -2005530516". I see the MSDN that the StretchRect can support the Destination of RT texture no matter source format.
How do I solve this problem? And then let line 30 return S_OK.
I also try UpdateSurface in line31, it still return "D3DERR_INVALIDCALL -2005530516". I think the reason the source surface is not created with D3DPOOL_SYSTEMMEM. But how do I copy the texture loading from xfile to the RenderTarget texture? That is very strange.
- HRESULT hr;
- ReleaseSMTexture();
- //CreateSMTexture();
- V_RETURN(m_pd3dDevice->CreateTexture(
- SHADOW_MAP_SIZE,
- SHADOW_MAP_SIZE,
- 1,
- D3DUSAGE_RENDERTARGET,
- SHADOW_MAP_FORMAT,
- D3DPOOL_DEFAULT,
- &m_pShadowMapTex,
- NULL
- ));
- V_RETURN(m_pShadowMapTex->GetSurfaceLevel(0, &m_pShadowMapSurf));
- V_RETURN(m_pd3dDevice->CreateDepthStencilSurface(
- SHADOW_MAP_SIZE,
- SHADOW_MAP_SIZE,
- D3DFMT_D24S8,
- D3DMULTISAMPLE_NONE,
- 0,
- TRUE,
- &m_pShadowMapZ,
- NULL
- ));
-
- LPDIRECT3DTEXTURE9 pTex;
- LPDIRECT3DSURFACE9 pSourceSurface;
- hr=D3DXCreateTextureFromFile( m_pd3dDevice, L"Texture.bmp", &pTex );
- hr=pTex->GetSurfaceLevel(0,&pSourceSurface);
- //StretchRect for Dest format=RT texture
- line29=>//hr=m_pd3dDevice->StretchRect(pSmTile->m_pShadowMapSurf,NULL,m_pShadowMapSurf,NULL,D3DTEXF_LINEAR); //S_OK
- line30=>//hr=m_pd3dDevice->StretchRect(pSourceSurface,NULL,m_pShadowMapSurf,NULL,D3DTEXF_LINEAR); //D3DERR_INVALIDCALL -2005530516
- line31=>hr=m_pd3dDevice->UpdateSurface(pSourceSurface,NULL,m_pShadowMapSurf,NULL); //D3DERR_INVALIDCALL -2005530516
- hr=D3DXSaveTextureToFile(L"t1.png",D3DXIFF_PNG ,m_pShadowMapTex,NULL);
- SAFE_RELEASE(pTex);
- SAFE_RELEASE(pSourceSurface);
复制代码 |
|