m_ModelMesh = NULL;
m_MaterialBuffer = NULL;
m_NumMaterials = NULL;
m_MeshMaterials = NULL;
m_MeshTextures = NULL;
m_NumMaterials = NULL;
std::string ModelPath = filepath + "/" + filename;
D3DXLoadMeshFromX(ModelPath.c_str(), D3DXMESH_SYSTEMMEM, Direct3DDevice, NULL, &m_MaterialBuffer,NULL, &m_NumMaterials,
&m_ModelMesh);
D3DXMATERIAL* d3dxMaterials;
d3dxMaterials = (D3DXMATERIAL*)m_MaterialBuffer->GetBufferPointer();
m_MeshMaterials = new D3DMATERIAL9[m_NumMaterials];
m_MeshTextures = new LPDIRECT3DTEXTURE9[m_NumMaterials];
for (DWORD i=0; i<m_NumMaterials; i++)
{
m_MeshMaterials = d3dxMaterials.MatD3D;
m_MeshMaterials.Ambient = m_MeshMaterials.Diffuse;
m_MeshTextures = NULL;
if (d3dxMaterials.pTextureFilename)
{
std::string TexturePath = filepath + "/" + d3dxMaterials.pTextureFilename;
D3DXCreateTextureFromFile(Direct3DDevice, TexturePath.c_str(), &m_MeshTextures);
}
}
m_MaterialBuffer->Release();
Does anyone have any idea's what could be causing this? Ive no doubt Direct3D should be able to easily load in 40 models without using this much memory.
Thanks in advance,
Magnumwolf
Memory usage problem in Direct3D
Hi,
Im having some problems with loading in models from .x files in Direct3D.
The problem is that once ive loaded in my models my game is using 1.8GB of memory
Im only loading 40~ low poly models, the models and textures take a total of 60 MB of space when not loaded in.
I cant find any thing that would be causing memory leaks so i really have no idea whats causing this problem
Here is my loading in code
How do you know how much memory you're using? Do you have memory leaks?
How big are the textures? Do multiple meshes use the same texture or meshes use multiple textures? Since you create a new set of textures for every mesh (even if they're duplicates):
On disk: 40 models + n textures
In memory: 40 models + 40 textures * number of textures per model
If you don't load the textures (just comment out the texture load code, leaving m_MeshTextures==NULL), does memory usage (however you're determining that) go down?
How big are the textures? Do multiple meshes use the same texture or meshes use multiple textures? Since you create a new set of textures for every mesh (even if they're duplicates):
On disk: 40 models + n textures
In memory: 40 models + 40 textures * number of textures per model
If you don't load the textures (just comment out the texture load code, leaving m_MeshTextures==NULL), does memory usage (however you're determining that) go down?
Im looking at Task manager to see how much memory is being used.
I commented out the texture loading code and i can confirm that this is the cause of the problem.
Most of the models have 2-3 textures each that are either 256x256 or 512x512
None of the models reuse the same textures.
I commented out the texture loading code and i can confirm that this is the cause of the problem.
Most of the models have 2-3 textures each that are either 256x256 or 512x512
None of the models reuse the same textures.
Read this and see if you're calculating memory useage correctly. If you're just looking at the process list or the graph, that can be very misleading.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement