0

There is a window with its own Direct3D device, lets call it mainWindow. mainWindow and its things are created by some other people. They have given me some Direct3D Surfaces (IDirect3DSurface9 pointers) which they are drawing on the mainWindow.
I have started a thread from one of their callbacks and created my own window using winAPI. ( i had a little bit similar case at this question )
I want to draw those RTT outputs on my window. so i am trying to copy the surfaces into surfaces/textures that i have created in my own directx device which draws on my window.

some stuff i found while trying to do this,

  • this can be done easily using D3DXSaveSurfaceToFileInMemory(...) and D3DXCreateTextureFromFileInMemory(...) functions.
  • StrechRect(...) function doesn't work for two surfaces which are created with two devices.

i tried locking surfaces and copying data from one to another, but it didn't seem to work. but i will try it again. ( is locking surfaces from two different devices at once illegal? )

is there any way you people know or suggest to do this?

---EDIT---
MSDN says (link to the page)

In Windows Vista CreateTexture can create a texture from a system memory pointer allowing the application more flexibility over the use, allocation and deletion of the system memory. For example, an application could pass a GDI system memory bitmap pointer and get a Direct3D texture interface around it. Using a system memory pointer with CreateTexture has the following restrictions.

  • The pitch of the texture must be equal to the width multiplied by the number of bytes per pixel.
  • Only textures with a single mipmap level are supported. The Levels argument must be 1.
  • The Pool argument must be D3DPOOL_SYSTEMMEM.
  • The pSharedHandle argument must be a valid pointer to a buffer that can hold the system memory point; *pSharedHandle must be a valid pointer to system memory with a size in bytes of texture width * texture height * bytes per pixel of the texture format.

I couldn't find any example for creating texture in this way ,but I tried to do it and all I got was an output full of noise and nothing else. if someone can help me in that, I guess my problem will be solved to some extent.... are there any good examples to what msdn says in here..??

Community
  • 1
  • 1
Deamonpog
  • 757
  • 1
  • 7
  • 21
  • is your tow surfaces are create two process or one process? – RolandXu Jun 06 '12 at 07:19
  • single process, i started a thread of my own from a call back so that my thread starts and shows the window when user sends a certain command to open it. – Deamonpog Jun 06 '12 at 09:13
  • I tried locking both texture surface (level 0) and other surface and copying data. well, that worked. but i want to know how good is the `CreateTexture` thing. according to the MSDN page, i must pass a `void *` which points to the pixel data as the last parameter of the `CreateTexture` function, rite? for example: `void * _pt; CreateTexture(Width,Height,1,D3DUSAGE_DYNAMIC,Format,D3DPOOL_SYSTEMMEM,&mytexture,(HANDLE*)_pt);` – Deamonpog Jun 06 '12 at 09:21

1 Answers1

2

if you are in vista/win7/win8, you can use Sharing_Resources Then you don't need any copy to it.

RolandXu
  • 3,098
  • 2
  • 12
  • 20