Sign in to follow this  
becoolnike

problem with D3DXCreateTexture and D3DPOOL_SYSTEMMEM

Recommended Posts

I would like to create a texture and save to the system's ram instead of the video card. I use the following code for create a texture and save to the video card:

  if (D3DXCreateTexture( d3dDevice_,width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,  &text)==D3DERR_OUTOFVIDEOMEMORY  )
  exit(255);

i can lock it and write information to it. with this code.
D3DLOCKED_RECT lrDst;

text->LockRect( 0, &lrDst, 0, 0 );
DWORD* pDst       = (DWORD*)lrDst.pBits;

//draw 200 red pixels in to the texture
for (byte count=0, count<200, count++)
{
pDst[count] = ARGB ( 255, 255, 0, 0);      
}

text->UnlockRect(0);
BUT when i use the parameter D3DPOOL_SYSTEMMEM instead of D3DPOOL_DEFAULT in D3DXCreateTexture, I cant see any drawn pixel in the screen. I only see a completly white screen. what am i doing wrong?

Share this post


Link to post
Share on other sites
From the documentation for D3DPOOL_SYSTEMMEM:

Resources are placed in memory that is not typically accessible by the Direct3D device

This means that you can use textures placed in SYSTEMMEM like normal textures. Pretty much the only thing you can reliably do with them is call UpdateSurface or UpdateTexture.

On a side note...your error checking for D3DXCreateTexture looks really funky. Why are you only checking for one specific error code? You should instead probably use the FAILED or SUCCEEDED macro to check whether the function actually succeeded, and then if it fails you can use DXErrorDescription or DXTrace to pop up some useful information that will tell you what failed and how. The way you have it now, if you have an error the program will exit and you would have no idea what happened!

Share this post


Link to post
Share on other sites
I basically need to load 1200 textures from diffrent resolutions into the system's memory. So what i do now is to create a sysmem dinamic texture and a D3DUSAGE_RENDERTARGET video mem texture. i update the contains of the sysmem dinamic texture into the rendertarge videomem texture.

My question is: Do i have to make an sysmem copy of every rendertarget texture?
This will be the same situation, i will run out of video memory!
my video memory is limited to 128 mgs, i need to load like 200 mgs of textures!

Share this post


Link to post
Share on other sites
Quote:
Original post by becoolnike
I basically need to load 1200 textures from diffrent resolutions into the system's memory. So what i do now is to create a sysmem dinamic texture and a D3DUSAGE_RENDERTARGET video mem texture. i update the contains of the sysmem dinamic texture into the rendertarge videomem texture.

My question is: Do i have to make an sysmem copy of every rendertarget texture?
This will be the same situation, i will run out of video memory!
my video memory is limited to 128 mgs, i need to load like 200 mgs of textures
You can't render from system memory textures (Unless the D3DDEVCAPS_TEXTURESYSTEMMEMORY cap bit of the DevCaps in the D3DCAPS9 struct is set, which is pretty rare). So you'll need to use a D3DPOOL_DEFAULT version of the texture to render with.

If you need to render all textures at one time, then they'll all need to be in video memory. If the amount of textures exceeds the amount of free video memory, you'll sustain a massive frame rate drop because you'll have to create and destroy textures in a single frame.

Is there a reason you're not using D3DPOOL_MANAGED, which would do all this for you? Also, I'd highly recommend using the Debug Runtimes - they would tell you the reason for the white texture instead of having to ask us.

Share this post


Link to post
Share on other sites
So can a D3DPOOL_MANAGED texture can be lockable and renderble?

i use this code:

if FAILED(D3DXCreateTexture( ge.d3dDevice_, img->m_Xres, img->m_Yres, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &img->text))
return 0;


in the usage paramer when i use 0 zero instad of D3DUSAGE_RENDERTARGET or dinamic i am allowing the texture to be renderble and lockable?

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