[shaderz] r35 committed - * Set the material on the preview widget when we select the material f...

1 view
Skip to first unread message

sha...@googlecode.com

unread,
Sep 30, 2010, 12:11:13 PM9/30/10
to shade...@googlegroups.com
Revision: 35
Author: vijay.michaeljoseph
Date: Thu Sep 30 09:10:19 2010
Log: * Set the material on the preview widget when we select the material
from file
* Added dedicated space for showing material information
* Fixed a possible memory leak with all view windows.

Todos:
* The material preview widgets are not maintained as squares when the
material editor is created and space distributed between the child widgets.
Need to enforce them to stay as squares.

http://code.google.com/p/shaderz/source/detail?r=35

Modified:
/trunk/include/qt/qtmainwindow.h
/trunk/include/qt/qtmaterialeditor.h
/trunk/include/qt/qtmaterialpreview.h
/trunk/include/qt/qtshaderzviewwidget.h
/trunk/shaderz.xcodeproj/vijayjoseph.pbxuser
/trunk/src/qt/qtmainwindow.cpp
/trunk/src/qt/qtmaterialeditor.cpp
/trunk/src/qt/qtmaterialpreview.cpp
/trunk/src/qt/qtshaderzviewwidget.cpp

=======================================
--- /trunk/include/qt/qtmainwindow.h Sun Sep 26 11:43:10 2010
+++ /trunk/include/qt/qtmainwindow.h Thu Sep 30 09:10:19 2010
@@ -31,7 +31,6 @@

public slots:
void OnClickedBrowse();
- void OnClickedShaderInfo();
virtual void onShowMaterialEditor();

protected:
=======================================
--- /trunk/include/qt/qtmaterialeditor.h Wed Sep 29 08:37:00 2010
+++ /trunk/include/qt/qtmaterialeditor.h Thu Sep 30 09:10:19 2010
@@ -39,6 +39,7 @@
protected:
QGroupBox* m_pMaterialPreviewContainer;
std::vector<qtMaterialPreview*> m_vMaterialPreviewInstances;
+ QGroupBox* m_pMaterialInfoContainer;

static int m_PreviewWidgetMinSize;
static int m_PreviewWidgetSpacing;
=======================================
--- /trunk/include/qt/qtmaterialpreview.h Wed Sep 29 08:37:00 2010
+++ /trunk/include/qt/qtmaterialpreview.h Thu Sep 30 09:10:19 2010
@@ -53,7 +53,7 @@
protected:
virtual void drawSelectionBox(void);
virtual void loadScene(std::string);
- virtual void setShader(shMaterial* shader);
+ virtual void setPreviewMaterial(shMaterial* shader);

protected: // events
virtual void mousePressEvent ( QMouseEvent * e );
@@ -61,9 +61,9 @@
virtual void paintGL();

protected:
- bool m_bIsSelected;
- shMaterial* m_pMaterial;
- qtMaterialInfoWidget* m_pMaterialInfoWidget;
+ bool m_bIsSelected;
+ osg::ref_ptr<shMaterial> m_pMaterial;
+ qtMaterialInfoWidget* m_pMaterialInfoWidget;

// actions
QAction* m_pCreateMaterialFromFile;
=======================================
--- /trunk/include/qt/qtshaderzviewwidget.h Sat Sep 11 19:27:35 2010
+++ /trunk/include/qt/qtshaderzviewwidget.h Thu Sep 30 09:10:19 2010
@@ -17,6 +17,7 @@
WindowFlags f = 0,
std::string sSceneFilePath = "" // the path of the scene data to
be displayed in the view window
);
+ virtual ~qtShaderzViewWidget();

virtual void loadScene(std::string sModelFilePath);
virtual void resizeGL(int w, int h);
=======================================
--- /trunk/shaderz.xcodeproj/vijayjoseph.pbxuser Wed Sep 29 08:37:00 2010
+++ /trunk/shaderz.xcodeproj/vijayjoseph.pbxuser Thu Sep 30 09:10:19 2010
@@ -388,30 +388,30 @@
PBXFileDataSource_Warnings_ColumnID,
);
};
- PBXPerProjectTemplateStateSaveDate = 307457533;
- PBXWorkspaceStateSaveDate = 307457533;
+ PBXPerProjectTemplateStateSaveDate = 307550600;
+ PBXWorkspaceStateSaveDate = 307550600;
};
perUserProjectItems = {
- 496A8D9C1253768E00CEDA03 /* PBXBookmark */ = 496A8D9C1253768E00CEDA03
/* PBXBookmark */;
- 496A8DA41253790A00CEDA03 /* PBXBookmark */ = 496A8DA41253790A00CEDA03
/* PBXBookmark */;
- 496A8DAB1253798400CEDA03 /* PBXBookmark */ = 496A8DAB1253798400CEDA03
/* PBXBookmark */;
- 496A8DC6125393B000CEDA03 /* PBXTextBookmark */ =
496A8DC6125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DC7125393B000CEDA03 /* PBXTextBookmark */ =
496A8DC7125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DC8125393B000CEDA03 /* PBXTextBookmark */ =
496A8DC8125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DC9125393B000CEDA03 /* PBXTextBookmark */ =
496A8DC9125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DCC125393B000CEDA03 /* PBXTextBookmark */ =
496A8DCC125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DCD125393B000CEDA03 /* PBXTextBookmark */ =
496A8DCD125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DCE125393B000CEDA03 /* PBXTextBookmark */ =
496A8DCE125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DCF125393B000CEDA03 /* PBXTextBookmark */ =
496A8DCF125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DD2125393B000CEDA03 /* PBXTextBookmark */ =
496A8DD2125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DD3125393B000CEDA03 /* PBXTextBookmark */ =
496A8DD3125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DD6125393B000CEDA03 /* PBXTextBookmark */ =
496A8DD6125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DD7125393B000CEDA03 /* PBXTextBookmark */ =
496A8DD7125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DDA125393B000CEDA03 /* PBXTextBookmark */ =
496A8DDA125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DDD125393B000CEDA03 /* PBXTextBookmark */ =
496A8DDD125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DE0125393B000CEDA03 /* PBXTextBookmark */ =
496A8DE0125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DE3125393B000CEDA03 /* PBXTextBookmark */ =
496A8DE3125393B000CEDA03 /* PBXTextBookmark */;
- 496A8DE4125393B000CEDA03 /* PBXTextBookmark */ =
496A8DE4125393B000CEDA03 /* PBXTextBookmark */;
+ 496A8D9C1253768E00CEDA03 = 496A8D9C1253768E00CEDA03 /* PBXBookmark */;
+ 496A8DA41253790A00CEDA03 = 496A8DA41253790A00CEDA03 /* PBXBookmark */;
+ 496A8DAB1253798400CEDA03 = 496A8DAB1253798400CEDA03 /* PBXBookmark */;
+ 496A8DC6125393B000CEDA03 = 496A8DC6125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DC7125393B000CEDA03 = 496A8DC7125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DC8125393B000CEDA03 = 496A8DC8125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DC9125393B000CEDA03 = 496A8DC9125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DCC125393B000CEDA03 = 496A8DCC125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DCD125393B000CEDA03 = 496A8DCD125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DCE125393B000CEDA03 = 496A8DCE125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DCF125393B000CEDA03 = 496A8DCF125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DD2125393B000CEDA03 = 496A8DD2125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DD3125393B000CEDA03 = 496A8DD3125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DD6125393B000CEDA03 = 496A8DD6125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DD7125393B000CEDA03 = 496A8DD7125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DDA125393B000CEDA03 = 496A8DDA125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DDD125393B000CEDA03 = 496A8DDD125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DE0125393B000CEDA03 = 496A8DE0125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DE3125393B000CEDA03 = 496A8DE3125393B000CEDA03 /* PBXTextBookmark
*/;
+ 496A8DE4125393B000CEDA03 = 496A8DE4125393B000CEDA03 /* PBXTextBookmark
*/;
};
sourceControlManager = 49C7DC6A1232ABF100E24C8D /* Source Control */;
userBuildSettings = {
=======================================
--- /trunk/src/qt/qtmainwindow.cpp Sun Sep 26 11:43:10 2010
+++ /trunk/src/qt/qtmainwindow.cpp Thu Sep 30 09:10:19 2010
@@ -49,16 +49,6 @@
connect( browseButton, SIGNAL(clicked()), this, SLOT(OnClickedBrowse())
);
vLayout->addWidget(browseButton);
vLayout->addSpacing(10);
-
- // add the shader load button
- QPushButton* shaderInfoBtn = new QPushButton("ShaderInfo", this);
- connect( shaderInfoBtn, SIGNAL(clicked()), this,
SLOT(OnClickedShaderInfo()) );
- vLayout->addWidget(shaderInfoBtn);
-
- // add the material widget
- m_pTestMaterial = new shMaterial();
- mMaterialInfoWidget = new qtMaterialInfoWidget(this, m_pTestMaterial);
- vLayout->addWidget(mMaterialInfoWidget);
}
hLayout->addItem(vLayout);

@@ -96,31 +86,6 @@
{
LOG<<"Clicked browse button. Put your code changes here.\n";
}
-
-void qtMainWindow::OnClickedShaderInfo()
-{
- LOG<<"Clicked shader info button.\n";
-
-
m_pTestMaterial->loadMaterialFromFile("/Users/vijayjoseph/projects/shaderz/data/osgnvcg1.cg");
- mMaterialInfoWidget->populateMaterialParams();
-
- // set some parameters
- m_pTestMaterial->addVectorParameter("LightVec")->set(osg::Vec4(0, 0, 1,
0));
-
m_pTestMaterial->addStateMatrixParameter("ModelViewProj")->set(osgNV::StateMatrixParameterValue::MODELVIEW_PROJECTION);
-
m_pTestMaterial->addStateMatrixParameter("ModelViewIT")->set(osgNV::StateMatrixParameterValue::MODELVIEW,
osgNV::StateMatrixParameterValue::INVERSE_TRANSPOSE);
-
- // set the shader
- osg::Node* viewRoot = m_pViewWidget->getRoot();
- osg::StateSet* ss = viewRoot ? viewRoot->getOrCreateStateSet() : 0;
- if( ss )
- {
- ss->setAttributeAndModes(m_pTestMaterial);
- }
- else
- {
- LOG<<"Failed to set shader on model. Check to see if OSG_FILE_PATH is
set and the default model is located at that location.\n";
- }
-}

void qtMainWindow::onShowMaterialEditor()
{
=======================================
--- /trunk/src/qt/qtmaterialeditor.cpp Wed Sep 29 08:37:00 2010
+++ /trunk/src/qt/qtmaterialeditor.cpp Thu Sep 30 09:10:19 2010
@@ -51,6 +51,18 @@
}
m_pMaterialPreviewContainer->setLayout(initialLayout);

+ // create the material info container
+ m_pMaterialInfoContainer = new QGroupBox("Material Info", this);
+ m_pMaterialInfoContainer->setMinimumSize( 400, 300 );
+ m_pMaterialInfoContainer->setMaximumSize( 400, 300 );
+ if( !m_pMaterialInfoContainer->layout() )
+ {
+ QVBoxLayout* infoContainerLayout = new QVBoxLayout;
+ m_pMaterialInfoContainer->setLayout(infoContainerLayout);
+ infoContainerLayout->setContentsMargins( 0, 0, 0, 0 );
+ }
+ vLayout->addWidget(m_pMaterialInfoContainer);
+
// set the new layout
if( layout() )
{
@@ -115,5 +127,13 @@
{
LOG<<"Material was created ...\n";
QWidget* materialInfoWidget =
dynamic_cast<QWidget*>(InPreviewWidget->getMaterialInfoWidget());
- layout()->addWidget( materialInfoWidget );
-}
+ QLayout* containerLayout = m_pMaterialInfoContainer->layout();
+ if( containerLayout )
+ {
+ // remove all prev widgets
+ while( containerLayout->count() > 0 ) containerLayout->removeWidget(
containerLayout->itemAt(0)->widget() );
+
+ // add the new widget
+ containerLayout->addWidget( materialInfoWidget );
+ }
+}
=======================================
--- /trunk/src/qt/qtmaterialpreview.cpp Wed Sep 29 08:37:00 2010
+++ /trunk/src/qt/qtmaterialpreview.cpp Thu Sep 30 09:10:19 2010
@@ -48,10 +48,6 @@
qtMaterialPreview::~qtMaterialPreview()
{
// delete material
- if( m_pMaterial )
- {
- delete m_pMaterial;
- }
m_pMaterial = 0;

// delete material info widget
@@ -129,7 +125,7 @@
}
}

-void qtMaterialPreview::setShader(shMaterial* InMaterial)
+void qtMaterialPreview::setPreviewMaterial(shMaterial* InMaterial)
{
if( !m_pRoot )
{
@@ -137,7 +133,6 @@
return;
}

- LOG<<"Setting shader...\n";
osg::StateSet* ss = m_pRoot->getOrCreateStateSet();
ss->setAttributeAndModes(InMaterial);
}
@@ -154,7 +149,14 @@
QString materialFile = QFileDialog::getOpenFileName( this, "Material
File", SHADERZ_DATA_PATH );
if( materialFile != "" && m_pMaterial)
{
+ // create the material and apply it
m_pMaterial->loadMaterialFromFile( materialFile.toLatin1().data() );
+ m_pMaterial->addVectorParameter("LightVec")->set(osg::Vec4(0, 0, 1, 0));
+
m_pMaterial->addStateMatrixParameter("ModelViewProj")->set(osgNV::StateMatrixParameterValue::MODELVIEW_PROJECTION);
+
m_pMaterial->addStateMatrixParameter("ModelViewIT")->set(osgNV::StateMatrixParameterValue::MODELVIEW,
osgNV::StateMatrixParameterValue::INVERSE_TRANSPOSE);
+ setPreviewMaterial(m_pMaterial);
+
+ // send a signal to material editor so that the new material params can
be shown
m_pMaterialInfoWidget->populateMaterialParams();
emit materialCreated(this);
}
=======================================
--- /trunk/src/qt/qtshaderzviewwidget.cpp Sat Sep 11 19:27:35 2010
+++ /trunk/src/qt/qtshaderzviewwidget.cpp Thu Sep 30 09:10:19 2010
@@ -16,6 +16,12 @@
loadScene(sSceneFilePath);
}
}
+
+qtShaderzViewWidget::~qtShaderzViewWidget()
+{
+ // release reference; auto ptr will take care of deleting if required
+ m_pRoot = 0;
+}

void qtShaderzViewWidget::loadScene(std::string sModelFilePath)
{

Reply all
Reply to author
Forward
0 new messages