Platform_Win32_3D_Texture.cpp
Go to the documentation of this file.00001 //*** Platform_Win32_3D_Texture.cpp *** 00002 00003 #include "Platform_Win32_3D_Texture.h" 00004 #include "Platform_Win32_3D_Technology.h" 00005 #include "Platform_Win32_3D.h" 00006 #include "Image.h" 00007 #include "Debug.h" 00008 #include "Asset.h" 00009 #include "StandardLibrary.h" 00010 00011 //*** Constructor *** 00012 00013 Platform_Win32_3D_Texture::Platform_Win32_3D_Texture(Platform_Win32_3D* win32_3d, const Asset& asset): 00014 win32_3d_(win32_3d), 00015 width_(0), 00016 height_(0), 00017 size_(0), 00018 textureData_(0), 00019 technologyTexture_(0) 00020 { 00021 size_=asset.GetSize(); 00022 textureData_=static_cast<unsigned char*>(Malloc(size_)); 00023 if (asset.Open()) 00024 { 00025 asset.Read(textureData_,size_); 00026 asset.Close(); 00027 } 00028 } 00029 00030 00031 //*** Constructor *** 00032 00033 Platform_Win32_3D_Texture::Platform_Win32_3D_Texture(Platform_Win32_3D* win32_3d, const Image& image): 00034 win32_3d_(win32_3d), 00035 width_(0), 00036 height_(0), 00037 size_(0), 00038 textureData_(0), 00039 technologyTexture_(0) 00040 { 00041 width_=image.GetWidth(); 00042 height_=image.GetHeight(); 00043 textureData_=static_cast<unsigned char*>(Malloc(width_*height_*sizeof(unsigned int))); 00044 for (int y=0; y<height_; y++) 00045 { 00046 for (int x=0; x<width_; x++) 00047 { 00048 (reinterpret_cast<unsigned int*>(textureData_))[x+y*width_]=image.GetPixel(x,y); 00049 } 00050 } 00051 } 00052 00053 00054 //*** Destructor *** 00055 00056 Platform_Win32_3D_Texture::~Platform_Win32_3D_Texture() 00057 { 00058 if (technologyTexture_) 00059 { 00060 delete technologyTexture_; 00061 technologyTexture_=0; 00062 } 00063 00064 Free(textureData_); 00065 00066 win32_3d_->TextureDeleted(this); 00067 } 00068 00069 00070 //*** Reset *** 00071 00072 void Platform_Win32_3D_Texture::Reset(Platform_Win32_3D_Technology* technology) 00073 { 00074 if (technologyTexture_) 00075 { 00076 delete technologyTexture_; 00077 technologyTexture_=0; 00078 } 00079 00080 if (size_>0) 00081 { 00082 technologyTexture_=technology->CreateTexture(textureData_,size_); 00083 } 00084 else 00085 { 00086 technologyTexture_=technology->CreateTexture(width_,height_,textureData_); 00087 } 00088 } 00089 00090 00091 //*** Bind *** 00092 00093 void Platform_Win32_3D_Texture::Bind(int stage) 00094 { 00095 Assert(technologyTexture_,"No technology instance!"); 00096 if (!technologyTexture_) 00097 { 00098 return; 00099 } 00100 00101 technologyTexture_->Bind(stage); 00102 00103 win32_3d_->TextureBound(stage,this); 00104 } 00105 00106 00107 //*** HasAlphaChannel *** 00108 00109 bool Platform_Win32_3D_Texture::HasAlphaChannel() 00110 { 00111 Assert(technologyTexture_,"No technology instance!"); 00112 if (!technologyTexture_) 00113 { 00114 return 0; 00115 } 00116 00117 return technologyTexture_->HasAlphaChannel(); 00118 } 00119 00120 00121 //*** GetWidth *** 00122 00123 int Platform_Win32_3D_Texture::GetWidth() 00124 { 00125 Assert(technologyTexture_,"No technology instance!"); 00126 if (!technologyTexture_) 00127 { 00128 return 0; 00129 } 00130 00131 return technologyTexture_->GetWidth(); 00132 } 00133 00134 00135 //*** GetHeight *** 00136 00137 int Platform_Win32_3D_Texture::GetHeight() 00138 { 00139 Assert(technologyTexture_,"No technology instance!"); 00140 if (!technologyTexture_) 00141 { 00142 return 0; 00143 } 00144 00145 return technologyTexture_->GetHeight(); 00146 } 00147 00148 00149 //*** Lock *** 00150 00151 void Platform_Win32_3D_Texture::Lock() 00152 { 00153 Assert(technologyTexture_,"No technology instance!"); 00154 if (!technologyTexture_) 00155 { 00156 return; 00157 } 00158 00159 technologyTexture_->Lock(); 00160 } 00161 00162 00163 //*** Unlock *** 00164 00165 void Platform_Win32_3D_Texture::Unlock() 00166 { 00167 Assert(technologyTexture_,"No technology instance!"); 00168 if (!technologyTexture_) 00169 { 00170 return; 00171 } 00172 00173 technologyTexture_->Unlock(); 00174 } 00175 00176 00177 //*** GetTexelData *** 00178 00179 unsigned char* Platform_Win32_3D_Texture::GetTexelData() 00180 { 00181 Assert(technologyTexture_,"No technology instance!"); 00182 if (!technologyTexture_) 00183 { 00184 return 0; 00185 } 00186 00187 return technologyTexture_->GetTexelData(); 00188 } 00189 00190 00191 //*** GetPitch *** 00192 00193 int Platform_Win32_3D_Texture::GetPitch() 00194 { 00195 Assert(technologyTexture_,"No technology instance!"); 00196 if (!technologyTexture_) 00197 { 00198 return 0; 00199 } 00200 00201 return technologyTexture_->GetPitch(); 00202 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
