Sign in to follow this  
choffstein

D3DXCreateTexture

Recommended Posts

choffstein    1090
I am using D3DXCreateTexture to create a texture that I will be able to call LockRect() with. I know that you must call LockRect() from a texture created with D3DUSAGE_RENDERTARGET, and therefore not D3DPOOL_DEFAULT. They are lockable, however, when using D3DUSAGE_DYNAMIC, which means then that I must use D3DPOOL_SYSTEMMEM. So here is my creation method: D3DXCreateTexture( pd3dDevice, x, y, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture); pd3dDevice is legit, x and y are both between 1 and 10...and yet it fails every time. Where else in my program should I be looking to find out why? Thanks!

Share this post


Link to post
Share on other sites
Mezz    571
What error does it fail with?

Perhaps you can't create non-power-of-two textures (I don't know what your x/y values are...)
Also, if you're using D3DUSAGE_DYNAMIC you *can* use D3DPOOL_DEFAULT and it will be lockable.

-Mezz

Share this post


Link to post
Share on other sites
choffstein    1090
Indeed, I reread the directx info on msdn and you are right about the D3DPOOL_DEFAULT and D3DUSAGE_DYNAMIC. My x and y values are 16...which certainly are powers of 2...

Thanks for the help so far.

Share this post


Link to post
Share on other sites
choffstein    1090
The error I am getting is: D3DERR_NOTAVAILABLE, which means my device does not support my queried technique...which ain't cool.

Thoughts? Is there something I could change somewhere so that my device WOULD?

Share this post


Link to post
Share on other sites
choffstein    1090

D3DCAPS9 devCaps;
pd3dDevice->GetDeviceCaps(&devCaps);
if(!(devCaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES))
{
CLog::Log("Yay for dynamic textures");
}


Guess what showed up in my logs?

So, I can make em, but they aren't working? Sweet...

Share this post


Link to post
Share on other sites
circlesoft    1178
That code you posted will log "Yay for dynamic textures" if dynamic textures *aren't* supported.

You need to do this, instead:


D3DCAPS9 devCaps;
pd3dDevice->GetDeviceCaps(&devCaps);

if(devCaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES)
{
CLog::Log("Yay for dynamic textures");
}


Unfortunately, now you already know that your card doesn't support dynamic textures [wink]

Share this post


Link to post
Share on other sites
choffstein    1090
Yeah, I realized that after I crawled into bed...im such a moron when I am tired.

Any recommendations on what to do? Maybe I can user surfaces and UpdateTexture()?

Share this post


Link to post
Share on other sites
Mezz    571
Yeah, in this case UpdateTexture() UpdateSurface() or StretchRect() are your only probable options, which one you use depends on your texture formats and usages.

-Mezz

Share this post


Link to post
Share on other sites
neneboricua19    634
Wait a sec. You don't have to create a texture as a render target to be able to lock it. You just have to be able to access it from system memory. But that doesn't mean that it must ONLY reside in system memory. Use D3DPOOL_MANAGED and you'll be able to lock your textures just fine without having to make them rendertargets.

neneboricua

Share this post


Link to post
Share on other sites
neneboricua19    634
Quote:
Original post by Mezz
Yes, that is another solution, but that's very slow if you regularly lock your texture.

True, but the OP was just asking why he couldn't lock a texture. He never specified what he was going to use it for or what kind of performance he expected from it.

In general, it's always better to simply "make it work" first and later on you can "make it work faster".

neneboricua

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this