//===========================================================================// // Copyright (C) Microsoft Corporation. All rights reserved. // //===========================================================================// #include "MLRHeaders.hpp" MLRTexturePool *MLRTexturePool::Instance; MLRTexturePool::ClassData* MLRTexturePool::DefaultData = NULL; //############################################################################# //############################ MLRTexture ############################### //############################################################################# //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLRTexturePool::InitializeClass() { Verify(!DefaultData); Verify(gos_GetCurrentHeap() == StaticHeap); DefaultData = new ClassData( MLRTexturePoolClassID, "MidLevelRenderer::MLRTexturePool", RegisteredClass::DefaultData ); Register_Object(DefaultData); MLRTexturePool::Instance = NULL; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLRTexturePool::TerminateClass() { if (MLRTexturePool::Instance) { Unregister_Object(MLRTexturePool::Instance); delete MLRTexturePool::Instance; } Unregister_Object(DefaultData); delete DefaultData; DefaultData = NULL; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRTexturePool::MLRTexturePool(MemoryStream *stream): RegisteredClass(DefaultData) { Verify(gos_GetCurrentHeap() == Heap); unLoadedImages = false; STOP(("Not implemented")); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // void MLRTexturePool::Stop (void) { Verify(gos_GetCurrentHeap() == Heap); int i; for(i=0;itextureNameHashValue == textureNameHashValue ) { yo = 1; } } if(yo == false) { continue; } for(j=first;jinstance == instance) { return textureArray[j]; } } for(j=first;jGetName(); int i, j, textureNameHashValue = textureName.GetHashValue(); for(i=0;itextureNameHashValue == textureNameHashValue ) { Verify(image == textureArray[j]->GetImage()); return textureArray[j]; // STOP(("Image allready in texture pool !")); } } } int newHandle; gos_PushCurrentHeap(Heap); if(firstFreeHandle < lastFreeHandle) { newHandle = (freeHandle[firstFreeHandle&(handleMax-1)])<textureHandle-1] = NULL; storedTextures--; int i, first = (tex->textureHandle-1) & ~(instanceMax-1); for(i=first;i= first+instanceMax) { imagePool->RemoveImage(tex->image); tex->image = NULL; freeHandle[lastFreeHandle&(handleMax-1)] = (tex->textureHandle-1) >> instanceDepth; lastFreeHandle++; } tex->textureHandle = 0; unLoadedImages = true; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // MLRTexture* MLRTexturePool::operator()(const char *tn, int instance) { Check_Object(this); MString textureName = tn; int i, j, textureNameHashValue = textureName.GetHashValue(); for(i=0;itextureNameHashValue == textureNameHashValue ) { if (textureArray[j]->instance == instance ) { return textureArray[j]; } } else { break; } } } } return NULL; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // unsigned MLRTexturePool::LoadImages() { Check_Object(imagePool); if(unLoadedImages == false) { return lastHandle; } // // Statistic timing function // for (unsigned i=0;iGetImage(&hint); if (image && !image->IsLoaded()) { Check_Object(image); if (!imagePool->LoadImage(image, hint)) { STOP(("Cannot load texture: %s!", textureArray[i]->textureName)); } } } } // // End timing function // unLoadedImages = false; return lastHandle; }