D3DXCreateTextureFromFileInMemoryEx with empty texture

Started by
5 comments, last by prux 15 years, 7 months ago
good evening, I'm currently correcting my 2D engine to have better intelligence: when a 2D texture is in the system memory, my drawing function has to create a temporary texture with DEFAULT flag, draw it and release it. So: I would like to create that temporary texture with D3DXCreateTextureFromFileInMemoryEx but lets just stop here. It needs a picture input! But should I? The next UpdateSurface will fill up that texture anyway. at this point I only have the texture to draw, nothing else at all. I must convert my original texture to bitmap, convert it to a "picture format" (TGA mostly) and pass it to the D3DXCreateTextureFromFileInMemoryEx? D3DXCreateTexture wont work because it doesn't deal with Color Key.
Advertisement
Hi

If you just want to create an empty texture why not simply call IDirect3DDevice9::CreateTexture?

Also, I hope you're not trying to allocate->update->render->deallocate everytime you call draw() (or some other draw method) on a node that has assigned to it a texture present only in system memory. Why don't you use D3DPOOL_SYSTEMMEM instead?
Quote:Original post by Kamikaze15
Also, I hope you're not trying to allocate->update->render->deallocate everytime you call draw() (or some other draw method) on a node that has assigned to it a texture present only in system memory. Why don't you use D3DPOOL_SYSTEMMEM instead?
You can't usually render textures in D3DPOOL_SYSTEMMEM. D3DPOOL_MANAGED should be fine though.

I also really hope you're not allocating a default pool resource every time you want to draw, that's really going to hurt frame rate, may fragment VRAM, and is generally a really really bad idea.

Why not just use D3DPOOL_MANAGED everywhere? That's exactly what it's for.
sometimes the videomemory isnt enough, when its full how to create textures with MANAGED? Some big textures must be created with SYSTEMMEM to not take much memory, they are rendered rarely so I dont think this could cause big FPS
I will post 2 sollution. The 2nd one is faster two times: DestT will be the texture to draw, and "Texture" is the source. "Desc" is its information queried by GetLevelDesc

1;
D3DXCreateTexture (Device, Desc.Width,Desc.Height, 0,0,Desc.Format, D3DPOOL_MANAGED, DestT);DestT.LockRect (0, Locked, nil, D3DLOCK_DISCARD);Texture.LockRect (0, Locked2, nil, D3DLOCK_DISCARD or D3DLOCK_READONLY);Move (Locked2.pBits^, Locked.pBits^, Desc.Size);Unlock 2 two textures



2;
Texture.LockRect(0, Locked, nil, D3DLOCK_DISCARD);Texture.UnLockRect (0); // its very strange but I do have to lock and unlock, otherwise the output looks dullD3DXCreateTexture (Device, Desc.Width,Desc.Height, 0, 0, Desc.Format, D3DPOOL_DEFAULT, DestT);Device.UpdateTexture (Whattodraw, DestT);
That looks like it just happens to work on your card. Firstly, locking a texture with Discard means "Throw away everything on that texture surface; I'm not using it any more". So you should get gibberish.
Secondly, you can't use the Discard flag except with dynamic textures, which you don't appear to be using. The Debug Runtimes would scream and shout about this, but you don't appear to be using them - you really should be.

The second option you have is faster because you're letting the driver update the texture (With the UpdateTexture() call), not having to copy everything around in main memory.

I really hope you're not caslling D3DXCreateTExture every frame, that's going to be terrible for your frame rate. You definitely want to create all your resources at load time, and then just lock them or whatever in your main loop.

Textures in the managed pool are pretty much just two copies off the texture; one in video memory (The default pool), and one in system memory. D3D will move textures in and out of video memory as required, if you have too many textures to fit into VRAM.

Basically; unless you have a very good reason otherwise, you should put all of your resources in the managed pool except for dynamic resources, and they should I.e. have to be) in the default pool.
yea, it only works here, the debugger really stops the app :) thx all infos.

This topic is closed to new replies.

Advertisement