游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2745|回复: 1

inversion of GetRenderTargetData

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2008-3-21 07:29:00 | 显示全部楼层 |阅读模式
GetRenderTargetData is used to copys the render-target data from device memory to system memory. If I want to inverse the operation(from system memory to device memory), how do I do that?

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
 楼主| 发表于 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.


  1.         HRESULT hr;

  2.         ReleaseSMTexture();
  3.         //CreateSMTexture();

  4.         V_RETURN(m_pd3dDevice->CreateTexture(
  5.                 SHADOW_MAP_SIZE,
  6.                 SHADOW_MAP_SIZE,
  7.                 1,
  8.                 D3DUSAGE_RENDERTARGET,
  9.                 SHADOW_MAP_FORMAT,
  10.                 D3DPOOL_DEFAULT,
  11.                 &m_pShadowMapTex,
  12.                 NULL
  13.                 ));

  14.         V_RETURN(m_pShadowMapTex->GetSurfaceLevel(0, &m_pShadowMapSurf));

  15.         V_RETURN(m_pd3dDevice->CreateDepthStencilSurface(
  16.                 SHADOW_MAP_SIZE,
  17.                 SHADOW_MAP_SIZE,
  18.                 D3DFMT_D24S8,
  19.                 D3DMULTISAMPLE_NONE,
  20.                 0,
  21.                 TRUE,
  22.                 &m_pShadowMapZ,
  23.                 NULL
  24.                 ));
  25.                
  26.         LPDIRECT3DTEXTURE9 pTex;
  27.         LPDIRECT3DSURFACE9 pSourceSurface;

  28.         hr=D3DXCreateTextureFromFile( m_pd3dDevice, L"Texture.bmp", &pTex );
  29.         hr=pTex->GetSurfaceLevel(0,&pSourceSurface);

  30.         //StretchRect for Dest format=RT texture
  31. line29=>//hr=m_pd3dDevice->StretchRect(pSmTile->m_pShadowMapSurf,NULL,m_pShadowMapSurf,NULL,D3DTEXF_LINEAR); //S_OK
  32. line30=>//hr=m_pd3dDevice->StretchRect(pSourceSurface,NULL,m_pShadowMapSurf,NULL,D3DTEXF_LINEAR); //D3DERR_INVALIDCALL -2005530516
  33. line31=>hr=m_pd3dDevice->UpdateSurface(pSourceSurface,NULL,m_pShadowMapSurf,NULL); //D3DERR_INVALIDCALL -2005530516

  34.         hr=D3DXSaveTextureToFile(L"t1.png",D3DXIFF_PNG ,m_pShadowMapTex,NULL);

  35.         SAFE_RELEASE(pTex);
  36.         SAFE_RELEASE(pSourceSurface);
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-20 18:53

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表