/*---------------------------------------------------------------------------* Project: NintendoWare File: lyt_TextureContainer.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision: 27719 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include namespace nw { namespace lyt { TextureRefLink::TextureRefLink() { m_Name[0] = '\0'; } TextureRefLink::~TextureRefLink() { GLuint texName = m_TexInfo.GetTextureObject(); if (texName != m_TexInfo.INVALID) { glDeleteTextures(1, &texName); } } void TextureRefLink::Set( const char* name, const TextureInfo& texInfo) { NW_NULL_ASSERT(name); // TODO: バイナリコンバータでファイル名の長さをチェックする。 ut::strcpy(m_Name, sizeof(m_Name), name); m_TexInfo = texInfo; } TextureContainer::~TextureContainer() { this->Finalize(); } void TextureContainer::Finalize() { while (!this->empty()) { TextureRefLink* pLink = &this->front(); this->erase(pLink); Layout::DeleteObj(pLink); } } const TextureInfo TextureContainer::FindTextureByName(const char* name) { for (Iterator it = this->GetBeginIter(); it != this->GetEndIter(); ++it) { if (0 == std::strcmp(name, it->GetResourceName())) { return it->GetTextureInfo(); } } return TextureInfo(); } const TextureInfo TextureContainer::FindTextureByKey(TextureKey key) { NW_NULL_ASSERT(key); TextureRefLink* pLink = (TextureRefLink*)(key); for (Iterator it = this->GetBeginIter(); it != this->GetEndIter(); ++it) { if (&(*it) == pLink) { return it->GetTextureInfo(); } } return TextureInfo(); } TextureKey TextureContainer::RegistTexture(const char* name, const TextureInfo& textureInfo) { NW_ASSERT(name); TextureRefLink* pLink = Layout::NewObj(); if (pLink == NULL) { return NULL; } pLink->Set(name, textureInfo); this->push_back(pLink); return (TextureKey) pLink; } void TextureContainer::UnregistTexture(TextureKey key) { NW_NULL_ASSERT(key); TextureRefLink* pLink = (TextureRefLink*)(key); this->erase(pLink); Layout::DeleteObj(pLink); } } // namespace nw::lyt } // namespace nw