Added some Shader related classes. They are not yet complete.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 6d79a2cf6f
commit a71e4bc3ed

@ -57,6 +57,7 @@ namespace NL3D
bool changeProperty( const std::string &name, const SDynMaterialProp &prop ); bool changeProperty( const std::string &name, const SDynMaterialProp &prop );
void setName( const std::string &n ){ name = n; } void setName( const std::string &n ){ name = n; }
void getName( std::string &n ) const { n = name; } void getName( std::string &n ) const { n = name; }
void getShaderRef( std::string &s ) const{ s = shaderRef; }
void serial( NLMISC::IStream &f ); void serial( NLMISC::IStream &f );
uint32 count(){ return properties.size(); } uint32 count(){ return properties.size(); }
@ -65,6 +66,7 @@ namespace NL3D
private: private:
std::vector< SDynMaterialProp > properties; std::vector< SDynMaterialProp > properties;
std::string shaderRef;
std::string name; std::string name;
}; };

@ -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

@ -157,6 +157,12 @@ SOURCE_GROUP(Driver FILES
../../include/nel/3d/scene_group.h ../../include/nel/3d/scene_group.h
shader.cpp shader.cpp
../../include/nel/3d/shader.h ../../include/nel/3d/shader.h
shader_loader.cpp
../../include/nel/3d/shader_loader.h
shader_manager.cpp
../../include/nel/3d/shader_manager.h
shader_program.cpp
../../include/nel/3d/shader_program.h
texture.cpp texture.cpp
../../include/nel/3d/texture.h ../../include/nel/3d/texture.h
vertex_buffer.cpp vertex_buffer.cpp

@ -49,6 +49,10 @@ namespace NL3D
f.serial( name ); f.serial( name );
f.xmlPop(); f.xmlPop();
f.xmlPush( "shader" );
f.serial( shaderRef );
f.xmlPop();
f.xmlPush( "properties" ); f.xmlPush( "properties" );
if( !f.isReading() ) if( !f.isReading() )

@ -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 );
}
}

@ -41,7 +41,6 @@ namespace MaterialEditor
{ {
connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) ); connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) );
connect( newButton, SIGNAL( clicked( bool ) ), this, SLOT( onNewClicked() ) );
connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) );
connect( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditClicked() ) ); connect( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditClicked() ) );
@ -75,19 +74,25 @@ namespace MaterialEditor
); );
} }
void ShaderWidget::onNewClicked() void ShaderWidget::onAddClicked()
{ {
bool ok = false;
QString def;
QString name = QString name =
QInputDialog::getText( QInputDialog::getText(
this,
tr( "New shader" ),
tr( "Enter the new shader's name" )
);
if( name.isEmpty() )
{
QMessageBox::critical(
this, this,
tr( "Shader name" ), tr( "New shader" ),
tr( "New shader's name?" ), tr( "You must enter a name for the new shader" ),
QLineEdit::Normal, QMessageBox::Ok
def,
&ok
); );
return;
}
if( nameExists( name ) ) if( nameExists( name ) )
{ {
@ -95,55 +100,21 @@ namespace MaterialEditor
return; return;
} }
QString fname = QFileDialog::getSaveFileName( QString fn =
this, QFileDialog::getSaveFileName(
tr( "New shader's path" ), this,
"/", tr( "Shader filename" ),
tr( "Shader files ( *.nelshader )" ) tr( "/" ),
); tr( "Nel shader files ( *.nelshdr )" )
);
shaderEditorWidget->reset();
shaderEditorWidget->setName( name );
QString sname;
do{
ok = true;
shaderEditorWidget->exec();
shaderEditorWidget->getName( sname );
if( sname != name )
{
if( nameExists( sname ) )
{
ok = false;
nameExistsMessage();
}
}
}while( !ok );
QString descr; if( fn.isEmpty() )
shaderEditorWidget->getDescription( descr ); return;
QTreeWidgetItem *item = new QTreeWidgetItem(); QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText( 0, sname ); item->setText( 0, name );
item->setText( 1, descr ); item->setText( 1, fn );
item->setText( 2, fname );
shaderListWidget->addTopLevelItem( item ); shaderListWidget->addTopLevelItem( item );
shaderListWidget->sortItems( 0, Qt::AscendingOrder );
// save it
}
void ShaderWidget::onAddClicked()
{
QString fn =
QFileDialog::getOpenFileName(
this,
tr( "Load shader" ),
"/",
tr( "Shader files ( *.nelshader )" )
);
} }
@ -173,11 +144,9 @@ namespace MaterialEditor
return; return;
QString name = item->text( 0 ); QString name = item->text( 0 );
QString description = item->text( 1 );
shaderEditorWidget->reset(); shaderEditorWidget->reset();
shaderEditorWidget->setName( name ); shaderEditorWidget->setName( name );
shaderEditorWidget->setDescription( description );
QString sname; QString sname;
bool ok; bool ok;
@ -197,9 +166,7 @@ namespace MaterialEditor
}while( !ok ); }while( !ok );
shaderEditorWidget->getDescription( description );
item->setText( 0, sname ); item->setText( 0, sname );
item->setText( 1, description );
// save // save

@ -41,7 +41,6 @@ namespace MaterialEditor
private Q_SLOTS: private Q_SLOTS:
void onOKClicked(); void onOKClicked();
void onNewClicked();
void onAddClicked(); void onAddClicked();
void onRemoveClicked(); void onRemoveClicked();
void onEditClicked(); void onEditClicked();

@ -9,26 +9,28 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>698</width> <width>502</width>
<height>304</height> <height>467</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Shaders</string> <string>Shaders</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="5" colspan="2"> <item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Shaders</string>
</property>
</widget>
</item>
<item row="1" column="0" rowspan="4" colspan="2">
<widget class="QTreeWidget" name="shaderListWidget"> <widget class="QTreeWidget" name="shaderListWidget">
<column> <column>
<property name="text"> <property name="text">
<string>Name</string> <string>Name</string>
</property> </property>
</column> </column>
<column>
<property name="text">
<string>Description</string>
</property>
</column>
<column> <column>
<property name="text"> <property name="text">
<string>Path</string> <string>Path</string>
@ -36,19 +38,6 @@
</column> </column>
</widget> </widget>
</item> </item>
<item row="0" column="2">
<widget class="QPushButton" name="newButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>New</string>
</property>
</widget>
</item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QPushButton" name="addButton"> <widget class="QPushButton" name="addButton">
<property name="sizePolicy"> <property name="sizePolicy">
@ -82,7 +71,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="2"> <item row="4" column="2" rowspan="3">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -95,7 +84,17 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="5" column="0"> <item row="5" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QPlainTextEdit" name="description"/>
</item>
<item row="7" column="0">
<widget class="QPushButton" name="okButton"> <widget class="QPushButton" name="okButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -108,7 +107,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="7" column="1" colspan="2">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>

Loading…
Cancel
Save