PDA

View Full Version : RenderTarget lost...



NecroDOME
10-05-2005, 09:46 PM
Hello,

I have created a RenderTarget, but when the device is lost, I need to reset the device. This wil cause to release all data in D3DPOOL_DEFAULT, where my render target is created...

I use this for lightmapping, so what can I do to prevent that I "lose" the texture ?

(I don't want to save it to a file...)

Thnxz in advance

Clootie
11-05-2005, 07:18 AM
err.. Nothing...

You can try to get RT data by IDirect3DDevice9.GetRenderTargetData function, but it's slow. Also you can try to use D3DXLoadSurfaceFromSurface function (but I doubt it will be speedier).

NecroDOME
11-05-2005, 07:49 AM
Ill give it a try...

Thnxz

NecroDOME
11-05-2005, 03:29 PM
Well.... i'm still trying to free the texture from the video memory:

Texture := nil;
FreeAndNil( Texture );

I get the same result every time :|

So is there a function to release everything from the D3DPOOL_DEFAULT ?

Clootie
11-05-2005, 08:15 PM
I don't get it...
Correct way: "Texture := nil;"
But next you say you are getting, what..?


So is there a function to release everything from the D3DPOOL_DEFAULT ?You are responsible for allocationg and releasing any resource in DEFAULT pool in Direct3D. So be careful when creating and releasing resources. The only way to free resource is to release all references to it.

alexione
12-05-2005, 01:08 PM
I use this for lightmapping, so what can I do to prevent that I "lose" the texture ?
How do you use created RenderTarget?
1) You update it once at the beginning, and then use it later.
2) You update it every frame.

In the first case, just copy data form RT to some D3DPOOL_MANAGED texture, and destroy RT.

In the second case, you have to destroy RT texture before Reset-ing your device, and recreate it after Reset.



Texture := nil;
FreeAndNil( Texture );


Texture := nil;
will do the job:)

Best regards...

NecroDOME
12-05-2005, 01:29 PM
Thnxz for the repleys,

I have created an empy project to see what i was doing wrong. It worked prerfectly, so there's a little bug in my own code smewhere...

[Edit] I have succesfully removed the bug :D

@alexondr

Lightmaps are created when I load the map or when I call the function Create Lightmaps in my editor ...so I create them once...

alexione
14-05-2005, 01:06 PM
You can do the following

1) Create RenderTarget in D3DPOOL_DEFAULT
2) Render LightMap
3) Create temporary texture in D3DPOOL_SYSTEMMEM
4) Use GetRenderTargetData to copy data from D3DPOOL_DEFAULT to D3DPOOL_SYSTEMMEM
5) Destroy RenderTarget
6) Create ordinary texture in D3DPOOL_MANAGED
7) Use UpdateTexture to copy data from D3DPOOL_SYSTEMMEM to D3DPOOL_MANAGED
8) Destroy temporary texture
9) Use managed texture, and forget about device reset!

The first thing: I haven't tried all of this, but it should work:)
The only drawback of this approach is that it's slow. But since it's slow once, if that isn't problem for you...