如何复制frontBuffer数据到纹理DirectX 9 [英] How to copy frontBuffer data to texture DirectX 9

查看:180
本文介绍了如何复制frontBuffer数据到纹理DirectX 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎没有找到一种方法来创建一个纹理从我通过应用程序的前缓冲区数据获取的表面数据



这是代码I (Direct X 9,C ++)

  //捕获屏幕
IDirect3DSurface9 * pSurface;
g_pd3dDevice-> CreateOffscreenPlainSurface(640,480,
D3DFMT_A8R8G8B8,D3DPOOL_SCRATCH,& pSurface,NULL);
g_pd3dDevice-> GetFrontBufferData(0,pSurface);

现在我有了frontBufferData,我想创建一个IDirect3DTexture9对象。 / p>

这个函数/
D3DXCreateTextureFromFileInMemory /
似乎是最合乎逻辑的,但似乎没有做到。



我确定有办法做到这一点,坚韧我不确定如何。任何帮助将是非常欢迎!



谢谢!

解决方案

最好使用 GetRenderTargetData() $ c> GetFrontBufferData(),因为前者更快。这说,这不是真的的问题。您希望将从前台缓冲区获得的数据或您当前在屏幕上观察到的数据存储到纹理中。



首先, IDirect3DTexture9 IDirect3DSurface9 ,种类,兄弟姐妹,但他们相同,即使在他们的类中的某一点hiearchy他们收敛到 IDirect3DResource9 (这是逻辑,因为它们是资源)。两者都很整洁的是,他们实现了常见的功能,特别是 LockRect()的可能性,并手动从表面复制数据(这是粗略地,只是一个mipmap水平表面像素)到纹理(它可能包含多个mipmap级别)因此,你的目标是纹理对象的level0表面。



CreateOffscreenPlainSurface()被认为是独立的,我们找不到这个表面可能是一个孩子的一个父纹理(作为纹理的特定mipmap)长故事短,如果我们不LockRect两者和手动复制数据,我们可以使用 StretchRect()





因此,将其转换为粗略代码可以使我们:

  IDirect3DTexture9 * texture; //需要创建,当然
IDirect3DSurface9 * dest = NULL; // to be our level0 surface of the texture
texture-> GetSurfaceLevel(0,& dest);
g_pD3DDevice-> StretchRect(pSurface,NULL,dest,NULL,D3DTEXF_LINEAR);

在那里,一个IDirect3DTexture9去。先生,你想要炸薯条吗?请记住我在这里工作的记忆,我没有触摸DX9在相当长的一段时间(弃权DX10)。希望它有帮助。


I can't seem to find a way to create a texture from the surface data I acquire through the front buffer data of my application

This is the code I'm pretty sure is working (Direct X 9, C++)

// capture screen
IDirect3DSurface9* pSurface;
g_pd3dDevice->CreateOffscreenPlainSurface(640, 480,
    D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL);
g_pd3dDevice->GetFrontBufferData(0, pSurface);

Now that I've got my frontBufferData, I would like to create a IDirect3DTexture9 object with it.

This function / D3DXCreateTextureFromFileInMemory / seemed the most logical but doesn't seem to do the trick.

I'm pretty sure there is a way to do this, tough I am unsure how. Any help would be greatly welcome!

Thanks!

解决方案

It's preferable to utilize GetRenderTargetData() instead of GetFrontBufferData(), because the former is faster. With that said, that's not really the question. You wish to store the data you get from the frontbuffer, or the stuff you're currently observing on the screen, into a texture.

First of all, IDirect3DTexture9 and IDirect3DSurface9 are actually, kind of, siblings, but they're not the same even though at some point in their class hiearchy they converge to IDirect3DResource9 (which is logical, as they are resources). What's neat about both of them is that they implement common functionality, specifically the possibility of LockRect() and manually copying the data from the surface (which is, crudely, just one mipmap level surface (a bunch of pixels) to the texture (which may consist of multiple mipmap levels). Therefore, your target is the level0 surface of the texture object.

With that in mind, since all CreateOffscreenPlainSurface() are considered to stand alone, we cannot find a parent texture of which this surface might be a child of (being a particular mipmap of a texture). Long story short, if we don't LockRect both of them and manually copy the data, we can use StretchRect().

While its name might not give away one of its purpose, it'll help us out here. Remember about our comparison talk between textures and surfaces, surfaces kind of being their little brother. Well, if you define a texture properly (same as the surface), you're actually getting automated miplevels which you can manually define how many of them are there. But in essence, each of these levels is a surface. And "converting" from IDirect3DSurface9 to IDirect3DTexture9 is just a matter of filling in the proper miplevel surface (which in this case ought to be level0, since it is a screenshot basically).

Therefore, sipping this into coarse code gives us:

IDirect3DTexture9* texture; // needs to be created, of course
IDirect3DSurface9* dest = NULL; // to be our level0 surface of the texture
texture->GetSurfaceLevel(0, &dest);
g_pD3DDevice->StretchRect(pSurface, NULL, dest, NULL, D3DTEXF_LINEAR);

And there you go, one IDirect3DTexture9 to go. Would you like fries with that, sir? Do note I'm working off memory here, I haven't touched DX9 in quite a while (dropped in favor of DX10). Hope it helps.

这篇关于如何复制frontBuffer数据到纹理DirectX 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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