2
\$\begingroup\$

I was previously uploading textures to DirectX by creating texture in D3DPOOL_MANAGED and then calling LockRect to upload the texture data to DirectX. However, I have switched to using DirectX9 Ex, and can no longer use D3DPOOL_MANAGED, so in order to call LockRect I have to make the texture use D3DUSAGE_DYNAMIC. However, I would prefer not to have to use D3DUSAGE_DYNAMIC. Is my only other option to create a texture in system memory, and then call IDirect3DDevice9::UpdateTexture to get the texture data into video memory? I also see there is a D3DXFillTexture function. But what i really want is something equivalent to glTexImage2D where i can create a texture and pass it raw data.

Note that I have stripped down RGBA texture data, otherwise I would try using DXCreateTextureFromFileInMemory.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Other alternatives include using UpdateTexture or UpdateSurface from a D3DPOOL_SYSTEMMEM source.

Under Vista+ (which I assume you're targetting since you're using 9Ex) you can supply the texture data via the pSharedHandle arg to CreateTexture; per the documentation:

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.

Caveat: I haven't done this and can't vouch for it.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Per the documentation you cite, textures allocated with CreateTexture must be allocated in D3DPOOL_SYSTEMMEM. Which makes sense, cause the CreateTexture function is designed to create DX9 texture handles that are shareable between processes. But because the texture isn't put in device memory as in the cases of D3DPOOL_DEFAULT or previously D3DPOOL_MANAGED this isn't going to be a good plan. \$\endgroup\$ Commented Dec 31, 2013 at 14:11
  • \$\begingroup\$ When I tried LockRect I get an HRESULT of D3DERR_INVALIDCALL when I don't use D3DUSAGE_DYNAMIC, which was the point of my post...I don't want to use D3DUSAGE_DYNAMIC. Do you know of a magic way around this? \$\endgroup\$
    – default
    Commented Dec 31, 2013 at 15:09
  • \$\begingroup\$ Also, I agree with @Jonathan Mee above. The CreateTexture with a shared resource has to be created in the system memory. What I was really looking for is to be able to create D3DPOOL_DEFAULT texture without having to go through a D3DPOOL_SYSTEMMEM texture. It is a nice tip though, since it could be a little simpler than LockedRect \$\endgroup\$
    – default
    Commented Dec 31, 2013 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .