From 1f2ff5721e5e303cda075d4055d3baa8034b8610 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 6 Jul 2013 23:12:02 +0200 Subject: [PATCH] Shaders are now loaded/saved/deleted from the disk. --HG-- branch : gsoc2013-dfighter --- code/nel/src/3d/shader_loader.cpp | 2 +- code/nel/src/3d/shader_saver.cpp | 2 +- .../material_editor_window.cpp | 10 +++++++-- .../material_editor/material_editor_window.h | 1 + .../material_editor/nel3d_interface.cpp | 22 +++++++++++++++++++ .../plugins/material_editor/nel3d_interface.h | 4 ++++ .../plugins/material_editor/shader_widget.cpp | 9 ++++++++ 7 files changed, 46 insertions(+), 4 deletions(-) diff --git a/code/nel/src/3d/shader_loader.cpp b/code/nel/src/3d/shader_loader.cpp index ed4fb88fc..a5f59645f 100644 --- a/code/nel/src/3d/shader_loader.cpp +++ b/code/nel/src/3d/shader_loader.cpp @@ -45,7 +45,7 @@ namespace NL3D std::vector< std::string >::iterator itr = files.begin(); while( itr != files.end() ) { - if( NLMISC::CFile::getExtension( *itr ) == ".nelshdr" ) + if( NLMISC::CFile::getExtension( *itr ) == "nlshdr" ) { loadShader( *itr ); } diff --git a/code/nel/src/3d/shader_saver.cpp b/code/nel/src/3d/shader_saver.cpp index a322ca539..17db2e727 100644 --- a/code/nel/src/3d/shader_saver.cpp +++ b/code/nel/src/3d/shader_saver.cpp @@ -38,7 +38,7 @@ namespace NL3D program->getName( fn ); fn += ".nlshdr"; - fn = outputDir + fn; + fn = outputDir + "/" + fn; NLMISC::COFile of; if( !of.open( fn, false, true ) ) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp index ddde7059e..270856804 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp @@ -32,8 +32,7 @@ #include #include #include - -#include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" +#include namespace MaterialEditor { @@ -55,6 +54,8 @@ namespace MaterialEditor createMenus(); createDockWidgets(); + + QTimer::singleShot( 1, this, SLOT( onStartup() ) ); } MaterialEditorWindow::~MaterialEditorWindow() @@ -148,6 +149,11 @@ namespace MaterialEditor { passesWidget->show(); } + + void MaterialEditorWindow::onStartup() + { + nl3dIface->loadShaders(); + } void MaterialEditorWindow::createMenus() { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h index 534f7fca4..fc7522154 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h @@ -42,6 +42,7 @@ private Q_SLOTS: void onSaveMaterialClicked(); void onShadersClicked(); void onPassesClicked(); + void onStartup(); private: void createMenus(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp index 5c83cc1d4..a30e560cc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -18,9 +18,12 @@ #include "nel/3d/dynamic_material.h" #include "nel/3d/shader_manager.h" #include "nel/3d/shader_program.h" +#include "nel/3d/shader_loader.h" +#include "nel/3d/shader_saver.h" #include "nel/misc/i_xml.h" #include "nel/misc/o_xml.h" #include "nel/misc/file.h" +#include "nel/misc/path.h" namespace MaterialEditor { @@ -300,5 +303,24 @@ namespace MaterialEditor { return shaderManager->removeShader( name ); } + + void CNel3DInterface::loadShaders() + { + NL3D::CShaderLoader loader; + loader.setManager( shaderManager ); + loader.loadShaders( "./shaders" ); + } + + void CNel3DInterface::saveShader( const std::string &name ) + { + NL3D::CShaderSaver saver; + saver.setManager( shaderManager ); + saver.saveShader( "./shaders", name ); + } + + void CNel3DInterface::deleteShader( const std::string &name ) + { + NLMISC::CFile::deleteFile( "./shaders/" + name + ".nlshdr" ); + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h index 167381b7b..ae77d31ab 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h @@ -135,6 +135,10 @@ namespace MaterialEditor bool addShader( const SShaderInfo &info ); bool removeShader( const std::string &name ); + void loadShaders(); + void saveShader( const std::string &name ); + void deleteShader( const std::string &name ); + private: NL3D::CDynMaterial *mat; NL3D::CShaderManager *shaderManager; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp index cf30a0abe..264b8cc83 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp @@ -121,6 +121,7 @@ namespace MaterialEditor SShaderInfo info; info.name = name.toUtf8().data(); bool ok = nl3dIface->addShader( info ); + nl3dIface->saveShader( info.name ); if( !ok ) { QMessageBox::critical( @@ -155,7 +156,12 @@ namespace MaterialEditor QListWidgetItem *item = shaderList->takeItem( i ); std::string n = item->text().toUtf8().data(); delete item; + nl3dIface->removeShader( n ); + nl3dIface->deleteShader( n ); + + if( shaderList->count() == 0 ) + description->setPlainText( "" ); } } @@ -214,6 +220,9 @@ namespace MaterialEditor tr( "There was an error while trying to save shader data!" ) ); } + nl3dIface->saveShader( info.name ); + + description->setPlainText( info.description.c_str() ); } void ShaderWidget::onRowChanged( int i )