Added some Shader related classes. They are not yet complete.
--HG-- branch : gsoc2013-dfighterhg/feature/gsoc2013-dfighter
parent
6d79a2cf6f
commit
a71e4bc3ed
@ -0,0 +1,44 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef SHADER_LOADER_H
|
||||
#define SHADER_LOADER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
class CShaderManager;
|
||||
|
||||
class CShaderLoader
|
||||
{
|
||||
public:
|
||||
CShaderLoader();
|
||||
~CShaderLoader();
|
||||
void setManager( CShaderManager *mgr ){ manager = mgr; }
|
||||
void loadShaders( const std::string &directory );
|
||||
|
||||
private:
|
||||
void loadShader( const std::string &file );
|
||||
|
||||
CShaderManager *manager;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,48 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef SHADER_MANAGER_H
|
||||
#define SHADER_MANAGER_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
class CShaderProgram;
|
||||
class IShaderVisitor;
|
||||
|
||||
class CShaderManager
|
||||
{
|
||||
public:
|
||||
CShaderManager();
|
||||
~CShaderManager();
|
||||
void clear();
|
||||
void getShaderList( std::vector< std::string > &v );
|
||||
void addShader( CShaderProgram *program );
|
||||
void changeShader( const std::string &name, CShaderProgram *program );
|
||||
void visitShaders( IShaderVisitor *visitor );
|
||||
void visitShader( const std::string &name, IShaderVisitor *visitor );
|
||||
|
||||
private:
|
||||
std::tr1::unordered_map< std::string, CShaderProgram* > programs;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,71 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef SHADER_PROGRAM_H
|
||||
#define SHADER_PROGRAM_H
|
||||
|
||||
#include "nel/misc/stream.h"
|
||||
#include <string>
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
class CShaderProgram : public NLMISC::IStreamable
|
||||
{
|
||||
public:
|
||||
CShaderProgram();
|
||||
|
||||
~CShaderProgram();
|
||||
|
||||
std::string getClassName(){ return "CShaderProgram"; }
|
||||
|
||||
void serial( NLMISC::IStream &f );
|
||||
|
||||
void getName( std::string &n ) const{ n = name; }
|
||||
void getDescription( std::string &d ) const{ d = description; }
|
||||
void getVP( std::string &vp ) const{ vp = vertexProgram; }
|
||||
void getFP( std::string &fp ) const{ fp = fragmentProgram; }
|
||||
|
||||
void setName( const std::string &n ){ name = n; }
|
||||
void setDescription( const std::string &d ){ description = d; }
|
||||
void setVP( std::string &vp ){ vertexProgram = vp; }
|
||||
void setFP( std::string &fp ){ fragmentProgram = fp; }
|
||||
|
||||
uint32 getVPId() const{ return vpId; }
|
||||
uint32 getFPId() const{ return fpId; }
|
||||
uint32 getPId() const{ return pId; }
|
||||
|
||||
void setVPId( uint32 id ){ vpId = id; }
|
||||
void setFPId( uint32 id ){ fpId = id;}
|
||||
void setPid( uint32 id ){ pId = id; }
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::string vertexProgram;
|
||||
std::string fragmentProgram;
|
||||
|
||||
|
||||
uint32 vpId;
|
||||
uint32 fpId;
|
||||
uint32 pId;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -0,0 +1,50 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef SHADER_SAVER_H
|
||||
#define SHADER_SAVER_H
|
||||
|
||||
#include "nel/3d/shader_visitor.h"
|
||||
#include <string>
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
class CShaderProgram;
|
||||
class CShaderManager;
|
||||
|
||||
class CShaderSaver : public IShaderVisitor
|
||||
{
|
||||
public:
|
||||
CShaderSaver();
|
||||
~CShaderSaver();
|
||||
|
||||
void setManager( CShaderManager *mgr ){ manager = mgr; }
|
||||
|
||||
void visit( CShaderProgram *program );
|
||||
|
||||
void saveShaders( const std::string &directory );
|
||||
void saveShader( const std::string &directory, const std::string &name );
|
||||
|
||||
private:
|
||||
CShaderManager *manager;
|
||||
std::string outputDir;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef SHADER_VISITOR_H
|
||||
#define SHADER_VISITOR_H
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
class CShaderProgram;
|
||||
|
||||
class IShaderVisitor
|
||||
{
|
||||
public:
|
||||
IShaderVisitor(){}
|
||||
~IShaderVisitor(){}
|
||||
|
||||
virtual void visit( CShaderProgram *program ) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -0,0 +1,73 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "nel/3d/shader_loader.h"
|
||||
#include "nel/3d/shader_manager.h"
|
||||
#include "nel/3d/shader_program.h"
|
||||
#include "nel/misc/file.h"
|
||||
#include "nel/misc/path.h"
|
||||
#include "nel/misc/i_xml.h"
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
CShaderLoader::CShaderLoader()
|
||||
{
|
||||
}
|
||||
|
||||
CShaderLoader::~CShaderLoader()
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderLoader::loadShaders( const std::string &directory )
|
||||
{
|
||||
if( manager == NULL )
|
||||
return;
|
||||
|
||||
std::vector< std::string > files;
|
||||
|
||||
NLMISC::CPath::getPathContent( directory, true, false, true, files );
|
||||
|
||||
std::vector< std::string >::iterator itr = files.begin();
|
||||
while( itr != files.end() )
|
||||
{
|
||||
if( NLMISC::CFile::getExtension( *itr ) == ".nelshdr" )
|
||||
{
|
||||
loadShader( *itr );
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void CShaderLoader::loadShader( const std::string &file )
|
||||
{
|
||||
NLMISC::CIFile f;
|
||||
if( !f.open( file, true ) )
|
||||
return;
|
||||
|
||||
NLMISC::CIXml xml;
|
||||
if( !xml.init( f ) )
|
||||
return;
|
||||
|
||||
CShaderProgram *p = new CShaderProgram();
|
||||
p->serial( xml );
|
||||
manager->addShader( p );
|
||||
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,118 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "nel/3d/shader_manager.h"
|
||||
#include "nel/3d/shader_program.h"
|
||||
#include "nel/3d/shader_visitor.h"
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
CShaderManager::CShaderManager()
|
||||
{
|
||||
}
|
||||
|
||||
CShaderManager::~CShaderManager()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void CShaderManager::clear()
|
||||
{
|
||||
std::tr1::unordered_map< std::string, CShaderProgram* >::iterator itr = programs.begin();
|
||||
while( itr != programs.end() )
|
||||
{
|
||||
delete itr->second;
|
||||
++itr;
|
||||
}
|
||||
programs.clear();
|
||||
}
|
||||
|
||||
void CShaderManager::getShaderList( std::vector< std::string > &v )
|
||||
{
|
||||
v.clear();
|
||||
|
||||
std::string n;
|
||||
std::tr1::unordered_map< std::string, CShaderProgram* >::iterator itr = programs.begin();
|
||||
while( itr != programs.end() )
|
||||
{
|
||||
itr->second->getName( n );
|
||||
v.push_back( n );
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void CShaderManager::addShader( CShaderProgram *program )
|
||||
{
|
||||
std::string n;
|
||||
program->getName( n );
|
||||
|
||||
std::tr1::unordered_map< std::string, CShaderProgram* >::iterator itr
|
||||
= programs.find( n );
|
||||
if( itr != programs.end() )
|
||||
return;
|
||||
|
||||
programs[ n ] = program;
|
||||
}
|
||||
|
||||
void CShaderManager::changeShader( const std::string &name, CShaderProgram *program )
|
||||
{
|
||||
std::tr1::unordered_map< std::string, CShaderProgram* >::iterator itr
|
||||
= programs.find( name );
|
||||
if( itr == programs.end() )
|
||||
return;
|
||||
|
||||
CShaderProgram *p = itr->second;
|
||||
|
||||
std::string s;
|
||||
|
||||
program->getName( s );
|
||||
p->setName( s );
|
||||
|
||||
program->getDescription( s );
|
||||
p->setDescription( s );
|
||||
|
||||
program->getVP( s );
|
||||
p->setVP( s );
|
||||
|
||||
program->getFP( s );
|
||||
p->setFP( s );
|
||||
|
||||
}
|
||||
|
||||
void CShaderManager::visitShaders( IShaderVisitor *visitor )
|
||||
{
|
||||
std::tr1::unordered_map< std::string, CShaderProgram* >::iterator itr = programs.begin();
|
||||
while( itr != programs.end() )
|
||||
{
|
||||
visitor->visit( itr->second );
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void CShaderManager::visitShader( const std::string &name, IShaderVisitor *visitor )
|
||||
{
|
||||
std::tr1::unordered_map< std::string, CShaderProgram* >::iterator itr =
|
||||
programs.find( name );
|
||||
if( itr == programs.end() )
|
||||
return;
|
||||
|
||||
visitor->visit( itr->second );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,58 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "nel/3d/shader_program.h"
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
CShaderProgram::CShaderProgram()
|
||||
{
|
||||
vpId = 0;
|
||||
fpId = 0;
|
||||
}
|
||||
|
||||
CShaderProgram::~CShaderProgram()
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderProgram::serial( NLMISC::IStream &f )
|
||||
{
|
||||
f.xmlPush( "ShaderProgram" );
|
||||
|
||||
int version = f.serialVersion( 1 );
|
||||
|
||||
f.xmlPush( "Name" );
|
||||
f.serial( name );
|
||||
f.xmlPop();
|
||||
|
||||
f.xmlPush( "Description" );
|
||||
f.serial( description );
|
||||
f.xmlPop();
|
||||
|
||||
f.xmlPush( "VertexProgram" );
|
||||
f.serial( vertexProgram );
|
||||
f.xmlPop();
|
||||
|
||||
f.xmlPush( "FragmentProgram" );
|
||||
f.serial( fragmentProgram );
|
||||
f.xmlPop();
|
||||
|
||||
f.xmlPop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,71 @@
|
||||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "nel/3d/shader_saver.h"
|
||||
#include "nel/3d/shader_manager.h"
|
||||
#include "nel/3d/shader_program.h"
|
||||
#include "nel/misc/file.h"
|
||||
#include "nel/misc/o_xml.h"
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
CShaderSaver::CShaderSaver()
|
||||
{
|
||||
manager = NULL;
|
||||
}
|
||||
|
||||
CShaderSaver::~CShaderSaver()
|
||||
{
|
||||
}
|
||||
|
||||
void CShaderSaver::visit( CShaderProgram *program )
|
||||
{
|
||||
std::string fn;
|
||||
program->getName( fn );
|
||||
fn += ".nlshdr";
|
||||
|
||||
fn = outputDir + fn;
|
||||
|
||||
NLMISC::COFile of;
|
||||
if( !of.open( fn, false, true ) )
|
||||
return;
|
||||
|
||||
NLMISC::COXml xml;
|
||||
if( !xml.init( &of ) )
|
||||
return;
|
||||
|
||||
program->serial( xml );
|
||||
|
||||
xml.flush();
|
||||
of.close();
|
||||
|
||||
}
|
||||
|
||||
void CShaderSaver::saveShaders( const std::string &directory )
|
||||
{
|
||||
outputDir = directory;
|
||||
manager->visitShaders( this );
|
||||
}
|
||||
|
||||
void CShaderSaver::saveShader( const std::string &directory, const std::string &name )
|
||||
{
|
||||
outputDir = directory;
|
||||
manager->visitShader( name, this );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue