Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# Texture.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * テクスチャ実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "LampBasic.h"
    00026 #include "Graphics/Texture/Texture.h"
    00027 #include "Graphics/Texture/TextureManager.h"
    00028 #include "Graphics/Material/Material.h"
    00029 #include "Graphics/Picture/Picture.h"
    00030
    00031 namespace Lamp{
    00032
    00033 // アドレスモード文字列テーブル
    00034 const String Texture::addressModeStringTable[] = {
    00035     "Wrap",
    00036     "Clamp",
    00037     "Mirror",
    00038 };
    00039
    00040 //------------------------------------------------------------------------------
    00041 // コンストラクタ
    00042 Texture::Texture(const String& name, Scene* scene) :
    00043     SceneObject(name, scene){
    00044 }
    00045 //------------------------------------------------------------------------------
    00046 // デストラクタ
    00047 Texture::~Texture(){
    00048 }
    00049 //------------------------------------------------------------------------------
    00050 // テクスチャの値コピー
    00051 void Texture::copyTextureValue(Texture* destination, u_int copyMask) const{
    00052     int pictureCount = getPictureCount();
    00053     for(int i = 0; i < pictureCount; i++){
    00054         if((copyMask & copyPicture) == 0){
    00055             // ピクチャを共有する
    00056             destination->addPicture(getPicture(i));
    00057         }else{
    00058             // ピクチャをコピーする
    00059             destination->addPicture(getPicture(i)->copy());
    00060         }
    00061     }
    00062 }
    00063 //------------------------------------------------------------------------------
    00064 // 再帰的破棄
    00065 int Texture::recursiveDestroy(Texture* texture){
    00066     Assert(texture != NULL);
    00067     int result = 0;
    00068     // ピクチャの破棄
    00069     int pictureCount = texture->getPictureCount();
    00070     for(int i = pictureCount - 1; i >= 0; i--){
    00071         Picture* picture = texture->getPicture(i);
    00072         texture->removePicture(picture);
    00073         result += Picture::destroy(picture);
    00074     }
    00075     // 引数の破棄
    00076     TextureManager* manager = texture->getScene()->getTextureManager();
    00077     if(manager->destroy(texture) == 0){ result++; }
    00078     return result;
    00079 }
    00080 //------------------------------------------------------------------------------
    00081 // ステート変更フラグを立てる
    00082 void Texture::stateChanged(){
    00083     int parentCount = getParentCount();
    00084     for(int i = 0; i < parentCount; i++){
    00085         getParent(i)->stateChanged();
    00086     }
    00087 }
    00088 //------------------------------------------------------------------------------
    00089 // アドレスモードから文字列への変換
    00090 const String& Texture::addressModeToString(AddressMode addressMode){
    00091     Assert(addressMode >= 0);
    00092     Assert(addressMode < addressModeMax);
    00093     return addressModeStringTable[addressMode];
    00094 }
    00095 //------------------------------------------------------------------------------
    00096 // 文字列からアドレスモードへの変換
    00097 Texture::AddressMode Texture::addressModeFromString(
    00098     const String& addressModeString){
    00099     for(int i = 0; i < addressModeMax; i++){
    00100         if(addressModeStringTable[i].equals(addressModeString)){
    00101             return AddressMode(i);
    00102         }
    00103     }
    00104     ErrorOut("Texture::addressModeFromString() " + addressModeString);
    00105     return addressModeMax;
    00106 }
    00107 //------------------------------------------------------------------------------
    00108 // ピクチャリファレンスの追加
    00109 void Texture::addPictureReference(Picture* picture){
    00110     picture->addReference(this);
    00111 }
    00112 //------------------------------------------------------------------------------
    00113 // ピクチャリファレンスの削除
    00114 void Texture::removePictureReference(Picture* picture){
    00115     picture->removeReference(this);
    00116 }
    00117 //------------------------------------------------------------------------------
    00118 } // End of namespace Lamp
    00119 //------------------------------------------------------------------------------