Implemented the functionality of the Render Passes widget.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 30f8c9f9e1
commit 02e61b1e1b

@ -77,10 +77,14 @@ namespace NL3D
void addPass( const SRenderPass &pass );
void removePass( const std::string &name );
void renamePass( const std::string &from, const std::string &to );
void movePassUp( const std::string &name );
void movePassDown( const std::string &name );
SRenderPass* getPass( const std::string &name );
private:
std::vector< SRenderPass > passes;
std::vector< SRenderPass* > passes;
};
}

@ -32,6 +32,9 @@ namespace NL3D
if( !f.isReading() )
{
uint32 n = properties.size();
f.serial( n );
std::vector< SDynMaterialProp >::iterator itr = properties.begin();
while( itr != properties.end() )
{
@ -41,9 +44,15 @@ namespace NL3D
}
else
{
SDynMaterialProp prop;
prop.serial( f );
properties.push_back( prop );
uint32 n;
f.serial( n );
for( uint32 i = 0; i < n; i++ )
{
SDynMaterialProp prop;
prop.serial( f );
properties.push_back( prop );
}
}
}
@ -104,6 +113,13 @@ namespace NL3D
CDynMaterial::~CDynMaterial()
{
std::vector< SRenderPass* >::iterator itr = passes.begin();
while( itr != passes.end() )
{
delete *itr;
++itr;
}
passes.clear();
}
void CDynMaterial::serial( NLMISC::IStream &f )
@ -112,18 +128,27 @@ namespace NL3D
if( !f.isReading() )
{
std::vector< SRenderPass >::iterator itr = passes.begin();
uint32 n = passes.size();
f.serial( n );
std::vector< SRenderPass* >::iterator itr = passes.begin();
while( itr != passes.end() )
{
itr->serial( f );
(*itr)->serial( f );
++itr;
}
}
else
{
SRenderPass pass;
pass.serial( f );
passes.push_back( pass );
uint32 n;
f.serial( n );
for( uint32 i = 0; i < n; n++ )
{
SRenderPass *pass = new SRenderPass();
pass->serial( f );
passes.push_back( pass );
}
}
}
@ -133,10 +158,10 @@ namespace NL3D
std::string name;
pass.getName( name );
std::vector< SRenderPass >::iterator itr = passes.begin();
std::vector< SRenderPass* >::iterator itr = passes.begin();
while( itr != passes.end() )
{
itr->getName( n );
(*itr)->getName( n );
if( n == name )
break;
++itr;
@ -144,32 +169,97 @@ namespace NL3D
if( itr != passes.end() )
return;
passes.push_back( pass );
SRenderPass *p = new SRenderPass();
*p = pass;
passes.push_back( p );
}
void CDynMaterial::removePass( const std::string &name )
{
std::string n;
std::vector< SRenderPass >::iterator itr = passes.begin();
std::vector< SRenderPass* >::iterator itr = passes.begin();
while( itr != passes.end() )
{
itr->getName( n );
(*itr)->getName( n );
if( n == name )
break;
++itr;
}
if( itr != passes.end() )
{
delete *itr;
passes.erase( itr );
}
}
void CDynMaterial::renamePass( const std::string &from, const std::string &to )
{
std::string n;
std::vector< SRenderPass* >::iterator itr = passes.begin();
while( itr != passes.end() )
{
(*itr)->getName( n );
if( n == from )
break;
++itr;
}
if( itr != passes.end() )
(*itr)->setName( to );
}
void CDynMaterial::movePassUp( const std::string &name )
{
std::string n;
uint32 i = 0;
for( i = 0; i < passes.size(); i++ )
{
passes[ i ]->getName( n );
if( n == name )
break;
}
if( i >= passes.size() )
return;
if( i == 0 )
return;
SRenderPass *temp = passes[ i ];
passes[ i ] = passes[ i - 1 ];
passes[ i - 1 ] = temp;
}
void CDynMaterial::movePassDown( const std::string &name )
{
std::string n;
uint32 i = 0;
for( i = 0; i < passes.size(); i++ )
{
passes[ i ]->getName( n );
if( n == name )
break;
}
if( i >= passes.size() )
return;
if( i == ( passes.size() - 1 ) )
return;
SRenderPass *temp = passes[ i ];
passes[ i ] = passes[ i + 1 ];
passes[ i + 1 ] = temp;
}
SRenderPass* CDynMaterial::getPass( const std::string &name )
{
std::string n;
std::vector< SRenderPass >::iterator itr = passes.begin();
std::vector< SRenderPass* >::iterator itr = passes.begin();
while( itr != passes.end() )
{
itr->getName( n );
(*itr)->getName( n );
if( n == name )
break;
++itr;
@ -177,7 +267,7 @@ namespace NL3D
if( itr == passes.end() )
return NULL;
else
return &( *itr );
return *itr;
}
}

@ -38,9 +38,11 @@ namespace MaterialEditor
QMainWindow(parent)
{
m_ui.setupUi(this);
nl3dIface = new Nel3DInterface();
nl3dIface = new CNel3DInterface();
shaderWidget = new ShaderWidget();
passesWidget = new RenderPassesWidget();
passesWidget->setNel3dIface( nl3dIface );
createMenus();
createDockWidgets();
}

@ -24,7 +24,7 @@ namespace MaterialEditor
class ShaderWidget;
class RenderPassesWidget;
class Nel3DInterface;
class CNel3DInterface;
class MaterialEditorWindow: public QMainWindow
{
@ -46,7 +46,7 @@ private:
void createMenus();
void createDockWidgets();
Nel3DInterface *nl3dIface;
CNel3DInterface *nl3dIface;
ShaderWidget *shaderWidget;
RenderPassesWidget *passesWidget;

@ -22,16 +22,47 @@
namespace MaterialEditor
{
Nel3DInterface::Nel3DInterface()
void CNelMaterialProxy::addPass( const char *name )
{
NL3D::SRenderPass pass;
pass.setName( name );
material->addPass( pass );
}
void CNelMaterialProxy::removePass( const char *name )
{
material->removePass( name );
}
void CNelMaterialProxy::movePassUp( const char *name )
{
material->movePassUp( name );
}
void CNelMaterialProxy::movePassDown( const char *name )
{
material->movePassDown( name );
}
void CNelMaterialProxy::renamePass( const char *from, const char *to )
{
material->renamePass( from, to );
}
CNel3DInterface::CNel3DInterface()
{
mat = new NL3D::CDynMaterial();
}
Nel3DInterface::~Nel3DInterface()
CNel3DInterface::~CNel3DInterface()
{
}
bool Nel3DInterface::loadMaterial( const char *fname )
bool CNel3DInterface::loadMaterial( const char *fname )
{
NLMISC::CIFile file;
if( !file.open( fname, true ) )
@ -48,7 +79,7 @@ namespace MaterialEditor
return true;
}
bool Nel3DInterface::saveMaterial( const char *fname )
bool CNel3DInterface::saveMaterial( const char *fname )
{
NLMISC::COFile file;
if( !file.open( fname, false, true ) )
@ -65,10 +96,15 @@ namespace MaterialEditor
return true;
}
void Nel3DInterface::newMaterial()
void CNel3DInterface::newMaterial()
{
delete mat;
mat = new NL3D::CDynMaterial();
}
CNelMaterialProxy CNel3DInterface::getMaterial()
{
return CNelMaterialProxy( mat );
}
}

@ -25,17 +25,40 @@ namespace NL3D
namespace MaterialEditor
{
class CNelMaterialProxy
{
public:
CNelMaterialProxy( NL3D::CDynMaterial *mat )
{
material = mat;
}
~CNelMaterialProxy(){}
void addPass( const char *name );
void removePass( const char *name );
void movePassUp( const char *name );
void movePassDown( const char *name );
void renamePass( const char *from, const char *to );
private:
NL3D::CDynMaterial *material;
};
/// Proxy class for Nel3D, so the material editor and Nel3D can interface
class Nel3DInterface
class CNel3DInterface
{
public:
Nel3DInterface();
~Nel3DInterface();
CNel3DInterface();
~CNel3DInterface();
bool loadMaterial( const char *fname );
bool saveMaterial( const char *fname );
void newMaterial();
CNelMaterialProxy getMaterial();
private:
NL3D::CDynMaterial *mat;
};

@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "render_passes.h"
#include "nel3d_interface.h"
#include <QInputDialog>
#include <QMessageBox>
@ -25,6 +26,7 @@ namespace MaterialEditor
{
setupUi( this );
setupConnections();
nl3dIface = NULL;
}
RenderPassesWidget::~RenderPassesWidget()
@ -104,7 +106,9 @@ namespace MaterialEditor
}
listWidget->addItem( label );
Q_EMIT passAdded( label );
CNelMaterialProxy material = nl3dIface->getMaterial();
material.addPass( label.toUtf8().data() );
}
void RenderPassesWidget::onRemoveClicked()
@ -118,7 +122,8 @@ namespace MaterialEditor
pass = item->text();
delete item;
Q_EMIT passRemoved( pass );
CNelMaterialProxy material = nl3dIface->getMaterial();
material.removePass( pass.toUtf8().data() );
}
void RenderPassesWidget::onEditClicked()
@ -141,8 +146,9 @@ namespace MaterialEditor
return;
item->setText( to );
Q_EMIT passRenamed( from, to );
CNelMaterialProxy material = nl3dIface->getMaterial();
material.renamePass( from.toUtf8().data(), to.toUtf8().data() );
}
void RenderPassesWidget::onUpClicked()
@ -161,7 +167,8 @@ namespace MaterialEditor
QString s = item->text();
Q_EMIT passPushedUp( s );
CNelMaterialProxy material = nl3dIface->getMaterial();
material.movePassUp( s.toUtf8().data() );
}
void RenderPassesWidget::onDownClicked()
@ -179,8 +186,9 @@ namespace MaterialEditor
listWidget->setCurrentRow( row + 1 );
QString s = item->text();
Q_EMIT passPushedDown( s );
CNelMaterialProxy material = nl3dIface->getMaterial();
material.movePassDown( s.toUtf8().data() );
}
}

@ -22,6 +22,8 @@
namespace MaterialEditor
{
class CNel3DInterface;
class RenderPassesWidget : public QWidget, public Ui::RenderPassesWidget
{
Q_OBJECT
@ -31,18 +33,13 @@ namespace MaterialEditor
void fillList( const QStringList &list );
void getList( QStringList &list );
void clear();
Q_SIGNALS:
void okClicked();
void passAdded( const QString &pass );
void passRemoved( const QString &pass );
void passRenamed( const QString &from, const QString &to );
void passPushedUp( const QString &pass );
void passPushedDown( const QString &pass );
void setNel3dIface( CNel3DInterface *iface ){ nl3dIface = iface; }
private:
void setupConnections();
CNel3DInterface *nl3dIface;
private Q_SLOTS:
void onOKClicked();
void onAddClicked();

Loading…
Cancel
Save