Show shader.cpp syntax highlighted
/***************************************************************************
shader.cpp - Pipeline shaders
-------------------
begin : Mon May 05 2003
copyright : (C) 2003 by Reality Rift Studios
email : mattias@realityrift.com
last modify date : Wen Jul 12 2006
last modify : GLSL manager
l.m. copyright : (C) 2004-2006 by Arcadia Design s.r.l.
email : Dario Deledda (penguindark [at] hotmail.com)
***************************************************************************
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the NeoEngine, NeoDevOpenGL, shader.cpp
The Initial Developer of the Original Code is Mattias Jansson.
Portions created by Mattias Jansson are Copyright (C) 2003
Reality Rift Studios. All Rights Reserved.
Contributors: Cody Russell (cody [at] jhu.edu)
***************************************************************************/
#include "shader.h"
#include "program-glsl.h"
#include <neoengine/logstream.h>
using namespace std;
using namespace NeoEngine;
namespace NeoOGL
{
ShaderTable Shader::s_kPSTable;
NeoEngine::ShaderPtr Device::CreateShader( NeoEngine::ShaderPtr in ){
if (in){
if ( in->GetType() == Shader::GLSLPROGRAM ){
NeoOGL::ProgramGLSL* pShd = new ProgramGLSL( this, Shader::GLSLPROGRAM ,(in->GetName()+"_cpy"), m_pkShaderPool, m_pkFileManager );
void *p=static_cast<void*>( &(*in));
NeoOGL::ProgramGLSL* ptr= static_cast<NeoOGL::ProgramGLSL*>(p);
*pShd=*(ptr);
pShd->m_kParams.Clear();
pShd->m_vpkParams.clear();
pShd->m_vpkUpdatedParams.clear();
std::vector< NeoEngine::ShaderParam* >::const_iterator iter=ptr->m_vpkParams.begin();
std::vector< NeoEngine::ShaderParam* >::const_iterator end=ptr->m_vpkParams.end();
while (iter != end){
ShaderParam *pkParam = new ShaderParam;
*pkParam=*(*iter);
pShd->m_kParams.Insert( pkParam->m_sName, pkParam );
pShd->m_vpkParams.push_back( pkParam );
iter++;
}
return pShd;
}
else
neolog << LogLevel( ERROR ) << "*** Unable to duplicate shader: Unknown type [" << in->GetType() << "]" << endl;
}
return 0;
}
NeoEngine::ShaderPtr Device::CreateShader( NeoEngine::Shader::SHADERTYPE eType, const std::string &rstrName )
{
Shader::SHADERTARGET tgt=Shader::s_eVSTarget;
if( eType == Shader::GLSLPROGRAM )
{
NeoEngine::ShaderPtr pShd=this->GetShader(Shader::GLSLPROGRAM,rstrName);
if (pShd){
return pShd;
}else{
pShd = new ProgramGLSL( this, Shader::GLSLPROGRAM ,rstrName, m_pkShaderPool, m_pkFileManager );
return pShd;
}
}
else
neolog << LogLevel( ERROR ) << "*** Unable to create shader: Unknown type [" << eType << "]" << endl;
return 0;
}
NeoEngine::ShaderPtr Device::GetShader( NeoEngine::Shader::SHADERTYPE eType, const std::string &rstrName )
{
return ( ( eType == Shader::GLSLPROGRAM ) ? (Shader::s_kPSTable.Find( rstrName )) : 0);
}
Shader::Shader( Device *pkDevice, SHADERTYPE eType, const std::string &rstrName,
NeoEngine::ShaderPool *pkShaderPool, NeoEngine::FileManager *pkFileManager ) :
NeoEngine::Shader( eType, rstrName, pkShaderPool, pkFileManager ),
m_pkDevice( pkDevice ),
m_bIsCompiled( false )
{
}
Shader::~Shader()
{
if( GetType() == Shader::GLSLPROGRAM )
Shader::s_kPSTable.Delete( m_strName, this );
if( m_pkDevice->m_pkProgramShader == this )
m_pkDevice->m_pkProgramShader = 0;
}
void Shader::SetName( const HashString &rstrName )
{
if( rstrName == GetName() )
return;
if( m_bIsCompiled )
{
ShaderTable &rkTable = Shader::s_kPSTable ;
rkTable.Delete( m_strName, this );
m_strName = rstrName;
rkTable.Insert( m_strName, this );
}
else
m_strName = rstrName;
}
};
See more files for this project here