00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 }
00119