|
|
I create a rendertarget texture and draw some object in its surface.
Now I want to get each pixel color in the surface.
But LockRect function always returns -2005530516 (D3DERR_INVALIDCALL).
How do I get the pixel color in surface (rendertarget texture)?
- // setup shadow map objects
- V_RETURN(m_pd3dDevice->CreateTexture(
- SHADOW_RESULT_MAP_SIZE_WIDTH,
- SHADOW_RESULT_MAP_SIZE_HEIGHT,
- 1,
- D3DUSAGE_RENDERTARGET,//<====render target
- SHADOW_MAP_FORMAT,
- D3DPOOL_DEFAULT,
- &m_pShadowMapTex,
- NULL
- ));
- V_RETURN(m_pShadowMapTex->GetSurfaceLevel(0, &m_pShadowMapSurf));
- V_RETURN(m_pd3dDevice->CreateDepthStencilSurface(
- SHADOW_RESULT_MAP_SIZE_WIDTH,
- SHADOW_RESULT_MAP_SIZE_HEIGHT,
- D3DFMT_D24S8,
- D3DMULTISAMPLE_NONE,
- 0,
- TRUE,
- &m_pShadowMapZ,
- NULL
- ));
- //lock surface and get color
- D3DLOCKED_RECT lrect;
- D3DSURFACE_DESC Desc;
- m_pShadowMapSurf->GetDesc(&Desc);
- hr=m_pShadowMapSurf->LockRect(&lrect,NULL,D3DLOCK_DONOTWAIT|D3DLOCK_READONLY );//<==hr=-2005530516 D3DERR_INVALIDCALL
- for (int y=0;y<Desc.Height;y++)
- {
- for (int x=0;Desc.Width;x++)
- {
- float dwColor = ((float*)lrect.pBits)[y*(lrect.Pitch/sizeof(float))+x];//Y*Width+X
- int r=(int)(dwColor*255.0f);
- if (dwColor<0.3f)
- {
- nPixel++;
- }
- }
- }
- m_pShadowMapSurf->UnlockRect();
复制代码 |
|