D3DXLoadMeshFromXInMemory

Started by
4 comments, last by kubera 12 years, 2 months ago
I am trying to load a .x file from Memory using dx9, because i want to take the advantages of the for faster loading, but sadly I don't.


//my old code
//Loads a mesh from HDD
D3DXLoadMeshFromX(fileName,D3DXMESH_MANAGED,Device,&adjBuffer,&mtrlBuffer,0,&numMtrls,&mesh);
//the above line takes 530 milliseconds for a 11MB .x file



//my new code
//Loads .x file from HDD to memory
int fileXSize;
char * fileXBuffer;
ifstream fileX;
fileX.open(fileName, ios::binary);
fileX.seekg (0, ios::end);
fileXSize = fileX.tellg();
fileX.seekg (0, ios::beg);
fileXBuffer = new char [fileXSize];
fileX.read (fileXBuffer,fileXSize);
fileX.close();
//now the fileXBuffer conteins the data of the .x file


//my code that Loads a mesh from memory - that i use it when i want to load Mesh from memory
D3DXLoadMeshFromXInMemory(fileXBuffer,fileXSize,D3DXMESH_MANAGED,Device,&adjBuffer,&mtrlBuffer,0,&numMtrls,&mesh);
//the above line takes 530 milliseconds for a 11MB .x file this should take much less time sines it is loads the mesh from memory and not from the HDD right?

probably I am doing something wrong but i cannot figure out that it is.
Advertisement
It should take less time, yes - perhaps not much less time though. I imagine of those 530ms, only 30ms or so is spent actually reading the file from disk. I also expect that D3DXLoadMeshFromX will just do what you have above; read the file into memory and then follow the same code path as D3DXLoadMeshFromXInMemory().
My concern is why it takes the same time for both.

D3DXLoadMeshFromX - 530ms

My code that read the file into memory - takes 10ms

D3DXLoadMeshFromXInMemory - 530ms

I just don't get it why it takes 530ms to load a mesh from memory, while it takes 0.01ms to display this particular mesh.

Basically what I want to do is to load mesh's while the 3D application is ruining without producing stuttering. I have two threads one is the main and the other one that is loading mesh's whenever are needed, and the problem is that if both threads access the IDirect3DDevice9 object at the same time the application crash. If I synchronize the threads, then stuttering occurs. That is why i want to have the D3DXLoadMeshFromXInMemory, because I was hopping that will take only a few milliseconds.
Hi!

SDKMesh from DirectX SDK is being loaded much faster.
You would convert .x into SDK Mesh for example.
This solution would save time.

P. S.
.x format is complex and needs a parser.

Juji-PL
Hi! SDKMesh from DirectX SDK is being loaded much faster. You would convert .x into SDK Mesh for example. This solution would save time. P. S. .x format is complex and needs a parser. Juji-PL

Nice idea.

but i run in to a problem trying to do this.
I convert the file .x to .sdkmesh by doing this "meshconvert /o output.sdkmesh input.x" and it seems ok, but when I try to load the file with the "D3DXLoadMeshFromX" the mesh return as NULL.

Any ideas?
Hi!

These file formats are incompatible.
You shuold use class from DXUT/DXUT11.
(this is not for the mesh interface)

The other idea:
Maybe a good solution for you would be creating a custom format.
For example.
You would save your indicses, vertices and FVF into your own format.
And load it by locking vertices and indices into created mesh interface,
(it is from scratch, but a flat file you would load very quickly) into the mesh interface.
Simple:

  1. Create
  2. Load
  3. Lock
  4. Copy into the GPU
  5. Unlock

P. S.
I know that it would cost additional programmer time smile.png

This topic is closed to new replies.

Advertisement