Hiya.. Im just rendering a simpel pice of a bar disk....
But when i render it the fps peeks down from 2500 (Nothing rendering except som UI and Text and light
When i render the disk the ftp pops down to 1600 and with another one i go down to 1000.. I know it kind of hi FPS.. but i mean a full 3d scen consist of many more objects then that..
The following code i use to load the Mesh from an X file
I allso use
D3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
D3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE );
VOID Mesh::CreateFromFile(LPCTSTR Name, LPCTSTR FileName)
{
LPD3DXBUFFER D3DXMtrlBuffer;
Meshes.Name = Name;
if( FAILED( D3DXLoadMeshFromX( FileName, D3DXMESH_MANAGED,
D3DDevice, NULL,
&D3DXMtrlBuffer, NULL, &Meshes.NumMaterials,
&Meshes.Mesh ) ) )
{
MessageBox(NULL, "Could not find tiger.x", "Meshes.exe", MB_OK);
}
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)D3DXMtrlBuffer->GetBufferPointer();
Meshes.Materials = new D3DMATERIAL9[Meshes.NumMaterials];
Meshes.Textures = new LPDIRECT3DTEXTURE9[Meshes.NumMaterials];
for( DWORD i=0; i<Meshes.NumMaterials; i++ )
{
Meshes.Materials = d3dxMaterials.MatD3D;
Meshes.Materials.Ambient = Meshes.Materials.Diffuse;
Meshes.Textures = NULL;
if( d3dxMaterials.pTextureFilename != NULL &&
lstrlen(d3dxMaterials.pTextureFilename) > 0 )
D3DXCreateTextureFromFile( D3DDevice, d3dxMaterials.pTextureFilename, &Meshes.Textures );
}
DWORD *rgdwAdjacency = NULL;
rgdwAdjacency = new DWORD[Meshes.Mesh->GetNumFaces() * 3];
Meshes.Mesh->GenerateAdjacency(1e-6f,rgdwAdjacency);
Meshes.Mesh->OptimizeInplace(D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE,
rgdwAdjacency, NULL, NULL, NULL);
delete []rgdwAdjacency;
Meshes.SetPos = false;
Meshes.SetRot = false;
Meshes.SetScale = false;
D3DDevice->GetTransform( D3DTS_WORLD, &Meshes.PosMatrix);
D3DDevice->GetTransform( D3DTS_WORLD, &Meshes.RotMatrix);
D3DDevice->GetTransform( D3DTS_WORLD, &Meshes.ScaleMatrix);
D3DDevice->GetTransform( D3DTS_WORLD, &Meshes.WorldMatrix);
D3DXMtrlBuffer->Release();
}
and i use the folloing code to render
VOID Mesh::Render()
{
D3DXMATRIX WorldMatrix;
D3DXMATRIX TmpMatrix;
D3DXMATRIX TmpMatrix2;
D3DDevice->GetTransform( D3DTS_WORLD, &WorldMatrix);
if(Meshes.SetPos == true)
{
D3DDevice->GetTransform( D3DTS_WORLD, &Meshes.PosMatrix);
D3DXMatrixTranslation( &Meshes.PosMatrix, Meshes.Position.x, Meshes.Position.y, Meshes.Position.z);
}
if(Meshes.SetRot == true)
{
D3DDevice->GetTransform( D3DTS_WORLD, &Meshes.RotMatrix);
D3DXMatrixRotationYawPitchRoll( &Meshes.RotMatrix, Meshes.Rotation.x, Meshes.Rotation.y, Meshes.Rotation.z);
}
if(Meshes.SetScale == true)
{
D3DDevice->GetTransform( D3DTS_WORLD, &Meshes.ScaleMatrix);
D3DDevice->GetTransform( D3DTS_WORLD, &TmpMatrix2);
D3DXMatrixScaling( &Meshes.ScaleMatrix, Meshes.Scale.x, Meshes.Scale.y, Meshes.Scale.z);
D3DXMatrixMultiply(&Meshes.ScaleMatrix, &TmpMatrix2, &Meshes.ScaleMatrix);
}
if(Meshes.SetPos == true || Meshes.SetRot == true || Meshes.SetScale == true)
{
D3DXMatrixMultiply(&TmpMatrix, &Meshes.RotMatrix, &Meshes.ScaleMatrix);
D3DXMatrixMultiply(&TmpMatrix, &TmpMatrix, &Meshes.PosMatrix);
D3DXMatrixMultiply(&Meshes.WorldMatrix, &WorldMatrix, &TmpMatrix);
Meshes.SetScale = false;
Meshes.SetRot = false;
Meshes.SetPos = false;
}
D3DDevice->SetTransform( D3DTS_WORLD, &Meshes.WorldMatrix);
for( DWORD i=0; i<Meshes.NumMaterials; i++ )
{
D3DDevice->SetMaterial( &Meshes.Materials );
D3DDevice->SetTexture( 0, Meshes.Textures );
Meshes.Mesh->DrawSubset( i );
}
D3DDevice->SetTransform( D3DTS_WORLD, &WorldMatrix);
}
Maybe there is a better way to position the meshes.. or is it the drawsubset that steals the fps ??