关于directX纹理的问题。 [英] A problem about directX texture.

查看:169
本文介绍了关于directX纹理的问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LPDIRECT3DSURFACE9 g_pSurface;

LPVOID pBits //指针指向HBITMAP;

LPDIRECT3DTEXTURE9 g_pTexture = NULL; //纹理的大小等于表面;

LPDIRECT3DSURFACE9 g_pSurface;
LPVOID pBits// a pointer point to a HBITMAP;
LPDIRECT3DTEXTURE9 g_pTexture=NULL;//The size of the texture is equal to the surface;

g_pd3dDevice->GetFrontBufferData(0, g_pSurface);
D3DLOCKED_RECT	lockedRect;
D3DLOCKED_RECT	lockedTexRect;
if(FAILED(g_pSurface>LockRect(&lockedRect,NULL,
D3DLOCK_NO_DIRTY_UPDATE|D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY)))
				{
					ErrorMessage("LockRect Failed!");	break;
				}
for(int i=0;i<g_ScreenRect.bottom;i++)
{
memcpy((BYTE*)pBits+(g_ScreenRect.bottom-i-1)*g_ScreenRect.right*BITSPERPIXEL/8,						(BYTE*)lockedRect.pBits+i*lockedRect.Pitch,g_ScreenRect.right*BITSPERPIXEL/8);
}
if(FAILED(hr=g_pTexture->LockRect(0,&lockedTexRect,
NULL,0)))
				{break;}
memcpy(lockedTexRect.pBits,lockedRect.pBits,lockedTexRect.Pitch*g_ScreenRect.Bottom);

pSurface->UnlockRect();
g_pTexture->UnlockRect(0);



我可以画出HBITMAP的成功,但是纹理更差。

memcpy函数纹理有什么问题吗?


I can draw the HBITMAP success,but the texture is worse.
Is there any wrong with the memcpy function to texture?

推荐答案

1。建议不要使用GetFrontBufferData,因为它很慢。

2.你正在进入系统内存的屏幕以及将它复制回纹理的内容?

3.你复制通过锁定这是不好的。



要解决您的问题,请参阅:

此API D3DXLoadSurfaceFromSurface usd可以在任何表面的loacation和colorspace转换从一个表面复制到另一个表面,因为它可能慢。如果表面都在GPU内存上使用 StretchRect 方法 - 但是看到对该方法的评论它们很重要。如果您需要从系统内存更新纹理表面并使用GPU上的纹理 UpdateSurface 。要获得使用的纹理表面 GetSurfaceLevel 方法纹理。



与屏幕截图相关,请参阅我的答案:使用DirectX9截取屏幕 [ ^ ]



问候,

Maxim。
1. GetFrontBufferData does not recommended to use as it slow.
2. You are getting screen into system memory and what for you copy it back to the texture?
3. You copy via Locking which is not good.

To solve your issues see:
This API D3DXLoadSurfaceFromSurface usd to copy from one surface to another at any surface loacation and colorspace conversion due that it maybe slow. In case if the surfaces are both on GPU memory used StretchRect method - but see the remarks to that method they are important. If you need update surface on texture from system memory and the texture on GPU used UpdateSurface. To get surface of the texture used GetSurfaceLevel method of the texture.

Related to the screen capture see my answer here: Taking Screenshot using DirectX9[^]

Regards,
Maxim.


这篇关于关于directX纹理的问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆