00001 /* 00002 * This source file is part of KEOS (Free 3D Engine) 00003 * For the latest info, see http://www.keosengine.org/ 00004 * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org 00005 * 00006 * This program is free software; you can redistribute it and/or modify it under 00007 * the terms of the GNU Lesser General Public License as published by the Free Software 00008 * Foundation; either version 2 of the License, or (at your option) any later 00009 * version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but WITHOUT 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License along with 00016 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00017 * Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00018 * http://www.gnu.org/copyleft/lesser.txt. 00019 * 00020 */ 00021 #include "KeosMaterial.h" 00022 #include "KeosLogger.h" 00023 #include "KeosRoot.h" 00024 #include "KeosRenderSystem.h" 00025 #include "KeosUtil.h" 00026 00027 namespace Keos 00028 { 00029 //======================================================================= 00030 // CMaterial implementation 00031 //======================================================================= 00032 00033 //----------------------------------------------------------------------- 00034 CMaterial::CMaterial() 00035 { 00036 m_strName = "#Unnamed#"; 00037 m_DiffuseColor = CColor::White; 00038 } 00039 00040 //----------------------------------------------------------------------- 00041 CMaterial::CMaterial(const String& strTexture) 00042 { 00043 m_strName = "#Unnamed#"; 00044 m_DiffuseColor = CColor::White; 00045 00046 CreateTexture(strTexture); 00047 } 00048 00049 //----------------------------------------------------------------------- 00050 CMaterial::~CMaterial() 00051 { 00052 std::for_each(m_Textures.begin(), m_Textures.end(), Delete()); 00053 } 00054 00055 //----------------------------------------------------------------------- 00056 bool CMaterial::CreateTexture(const String& strTexture, ushort nLayer) 00057 { 00058 if (nLayer >= 00059 CRoot::Instance().GetRenderSystem()->GetCapabilities()->GetNumTextureUnits()) 00060 { 00061 ILogger::Log("RenderSystem has not enough texture units to create this texture : %s !", strTexture.c_str()); 00062 return false; 00063 } 00064 00065 CTexture* pTexture = new CTexture(); 00066 try 00067 { 00068 pTexture->CreateFromFile(strTexture, PXF_A8R8G8B8); 00069 if (nLayer >= m_Textures.size()) 00070 m_Textures.resize(nLayer + 1); 00071 KEOS_DELETE(m_Textures[nLayer]); 00072 m_Textures[nLayer] = pTexture; 00073 } 00074 catch (const CLoadingFailed&) 00075 { 00076 KEOS_DELETE(pTexture); 00077 return false; 00078 } 00079 return true; 00080 } 00081 00082 //----------------------------------------------------------------------- 00083 bool CMaterial::CreateTexture(const CImage& Image, ushort nLayer) 00084 { 00085 if (nLayer >= 00086 CRoot::Instance().GetRenderSystem()->GetCapabilities()->GetNumTextureUnits()) 00087 { 00088 ILogger::Log("RenderSystem has not enough texture units to create this texture !"); 00089 return false; 00090 } 00091 00092 CTexture* pTexture = new CTexture(); 00093 pTexture->CreateFromImage(Image, Image.GetFormat()); 00094 if (nLayer >= m_Textures.size()) 00095 m_Textures.resize(nLayer + 1); 00096 KEOS_DELETE(m_Textures[nLayer]); 00097 m_Textures[nLayer] = pTexture; 00098 00099 return true; 00100 } 00101 00102 } // namespace Keos
1.5.1-p1