MCPcopy Create free account
hub / github.com/assimp/assimp / DisplayMemoryConsumption

Function DisplayMemoryConsumption

tools/assimp_view/MessageProc.cpp:612–724  ·  view source on GitHub ↗

------------------------------------------------------------------------------- Display memory statistics -------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

610// Display memory statistics
611//-------------------------------------------------------------------------------
612void DisplayMemoryConsumption() {
613 // first get the memory consumption for the aiScene
614 if (! g_pcAsset ||!g_pcAsset->pcScene) {
615 MessageBox(g_hDlg,"No asset is loaded. Can you guess how much memory I need to store nothing?",
616 "Memory consumption",MB_OK);
617 return;
618 }
619 unsigned int iScene = sizeof(aiScene);
620 for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) {
621 iScene += sizeof(aiMesh);
622 if (g_pcAsset->pcScene->mMeshes[i]->HasPositions())
623 iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
624
625 if (g_pcAsset->pcScene->mMeshes[i]->HasNormals())
626 iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
627
628 if (g_pcAsset->pcScene->mMeshes[i]->HasTangentsAndBitangents())
629 iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices * 2;
630
631 for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a) {
632 if (g_pcAsset->pcScene->mMeshes[i]->HasVertexColors(a)) {
633 iScene += sizeof(aiColor4D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
634 } else {
635 break;
636 }
637 }
638 for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) {
639 if (g_pcAsset->pcScene->mMeshes[i]->HasTextureCoords(a))
640 iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
641 else break;
642 }
643 if (g_pcAsset->pcScene->mMeshes[i]->HasBones()) {
644 for (unsigned int p = 0; p < g_pcAsset->pcScene->mMeshes[i]->mNumBones;++p) {
645 iScene += sizeof(aiBone);
646 iScene += g_pcAsset->pcScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight);
647 }
648 }
649 iScene += (sizeof(aiFace) + 3 * sizeof(unsigned int))*g_pcAsset->pcScene->mMeshes[i]->mNumFaces;
650 }
651 // add all embedded textures
652 for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumTextures;++i) {
653 const aiTexture* pc = g_pcAsset->pcScene->mTextures[i];
654 if (0 != pc->mHeight) {
655 iScene += 4 * pc->mHeight * pc->mWidth;
656 } else {
657 iScene += pc->mWidth;
658 }
659 }
660 // add 30k for each material ... a string has 4k for example
661 iScene += g_pcAsset->pcScene->mNumMaterials * 30 * 1024;
662
663 // now get the memory consumption required by D3D, first all textures
664 unsigned int iTexture = 0;
665 for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) {
666 AssetHelper::MeshHelper* pc = g_pcAsset->apcMeshes[i];
667
668 AddTextureMem(pc->piDiffuseTexture,iTexture);
669 AddTextureMem(pc->piSpecularTexture,iTexture);

Callers 1

MessageProcFunction · 0.85

Calls 7

AddTextureMemFunction · 0.85
HasBonesMethod · 0.80
HasPositionsMethod · 0.45
HasNormalsMethod · 0.45
HasVertexColorsMethod · 0.45
HasTextureCoordsMethod · 0.45

Tested by

no test coverage detected