Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# KeosShader.cpp

Go to the documentation of this file.

    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 "KeosShader.h"
    00022 #include "KeosRenderSystem.h"
    00023 #include "KeosResourceManager.h"
    00024 #include "KeosMediaManager.h"
    00025 #include "KeosLogger.h"
    00026
    00027 namespace Keos
    00028 {
    00029
    00030         //=======================================================================
    00031     // CShader implementation
    00032     //=======================================================================
    00033
    00034     //-----------------------------------------------------------------------
    00035         void CShader::LoadFromFile(const String& strFilename)
    00036         {
    00037                 m_Shader = CResourceManager::Instance().Get<IShaderBase>(strFilename);
    00038
    00039                 if (!m_Shader)
    00040                 {
    00041                         // Create shader
    00042                         m_Shader = CMediaManager::Instance().LoadMediaFromFile<IShaderBase>(strFilename);
    00043
    00044                         // Addition in the resources
    00045                         CResourceManager::Instance().Add(strFilename, m_Shader);
    00046                 }
    00047         }
    00048
    00049         //-----------------------------------------------------------------------
    00050         void CShader::Unload()
    00051         {
    00052                 m_Shader = NULL;
    00053         }
    00054
    00055         //-----------------------------------------------------------------------
    00056         const IShaderBase* CShader::GetShader() const
    00057         {
    00058                 return m_Shader;
    00059         }
    00060
    00061         //-----------------------------------------------------------------------
    00062         void CShader::SetParameter(const String& strName, float fValue)
    00063         {
    00064                 float Data[] = {fValue, 0.0f, 0.0f, 0.0f};
    00065                 m_Shader->SetParameter(strName, Data);
    00066         }
    00067
    00068         //-----------------------------------------------------------------------
    00069         void CShader::SetParameter(const String& strName, const TVector2F& Value)
    00070         {
    00071                 float Data[] = {Value.x, Value.y, 0.0f, 0.0f};
    00072                 m_Shader->SetParameter(strName, Data);
    00073         }
    00074
    00075         //-----------------------------------------------------------------------
    00076         void CShader::SetParameter(const String& strName, const TVector3F& Value)
    00077         {
    00078                 float Data[] = {Value.x, Value.y, Value.z, 0.0f};
    00079                 m_Shader->SetParameter(strName, Data);
    00080         }
    00081
    00082         //-----------------------------------------------------------------------
    00083         void CShader::SetParameter(const String& strName, const TVector4F& Value)
    00084         {
    00085                 float Data[] = {Value.x, Value.y, Value.z, Value.w};
    00086                 m_Shader->SetParameter(strName, Data);
    00087         }
    00088
    00089         //-----------------------------------------------------------------------
    00090         void CShader::SetParameter(const String& strName, const CMatrix4& Value)
    00091         {
    00092                 m_Shader->SetParameter(strName, Value);
    00093         }
    00094
    00095         //-----------------------------------------------------------------------
    00096         void CShader::SetParameter(const String& strName, const CColor& Value)
    00097         {
    00098                 float Data[4];
    00099                 Value.ToFloat(Data);
    00100                 m_Shader->SetParameter(strName, Data);
    00101         }
    00102
    00103 } // namespace Keos