Jump to content
  • Advertisement
Sign in to follow this  
kgstation

Questions about loading a great mount of object using x files

This topic is 2480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wonder if it's a correct method of loading multi object(same object,but in different position)
this is code
for( int z = 0; z <= 50; z++)
{
D3DXMATRIX T;
D3DXMatrixTranslation(&T, x, 0.0f, z);
mSandWorld = T;
HR(mFX->SetMatrix(mhLightWVP, &(mSandWorld*mLightVP)));
HR(mFX->SetMatrix(mhWVP, &(mSandWorld*gCamera->viewProj())));
HR(mFX->SetMatrix(mhWorld, &mSandWorld));
for(UINT j = 0; j < mSandMtrls.size(); ++j)
{
HR(mFX->SetValue(mhMtrl, &mSandMtrls[j], sizeof(Mtrl)));

if(mSandTextures[j] != 0)
{
HR(mFX->SetTexture(mhTex, mSandTextures[j]));
}
else
{
HR(mFX->SetTexture(mhTex, mWhiteTex));
}

HR(mFX->CommitChanges());
HR(mSandMesh->DrawSubset(j));
}
}

[color=#000000][font=arial][size=1]It's very inefficiency![/font]
[color=#000000][font=arial][size=1]sorry for my poor english![/font]

Share this post


Link to post
Share on other sites
Advertisement
It's generally best to avoid as many state changes as possible, and rendering in the way you are is the worst possible way to reduce state changes. You may be better putting your 'z' loop around just the DrawSubset call, and setting the matrices just before it. That way you're setting the matrices num_subsets * 50 times, but you only need to change the texture and materials 1/50th as often.

Also remember that D3DXMesh is designed for convenience, not for efficiency - although it's reasonably efficient, if you're having performance issues with it you may be better rolling your own.

Share this post


Link to post
Share on other sites

It's generally best to avoid as many state changes as possible, and rendering in the way you are is the worst possible way to reduce state changes. You may be better putting your 'z' loop around just the DrawSubset call, and setting the matrices just before it. That way you're setting the matrices num_subsets * 50 times, but you only need to change the texture and materials 1/50th as often.

Also remember that D3DXMesh is designed for convenience, not for efficiency - although it's reasonably efficient, if you're having performance issues with it you may be better rolling your own.

Thanks!You are right!
It improved my fps!
By the way,would Z-buffer method works well?I have collect some imformation about Z-buffer method!And I'm intend to add this method to my program.But it seems there are some issue with this method...Is that true?

Share this post


Link to post
Share on other sites
That depends on what you mean by "Z-buffer method". If you mean just enabling a Z-buffer, it's unlikely to improve performance much, it's more that it'll fix any rendering artifacts (Objects in the distance drawing through those in front).

If you have a lot of overlap in your scene, and/or expensive pixel shaders, then you can sometimes gain performance by doing a z-only pase - I.e. render the entire scene with a colour writes disabled, and then render again with them enabled. That way you should only write each pixel once rather than drawing over them with successive draws.
But that only helps if you have expensive pixel shaders and/or a lot of overlap.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!