Commit 8ebb6d0f authored by Marlin Frickenschmidt's avatar Marlin Frickenschmidt

Shaders can now be properly activated and deactivated again in the...

Shaders can now be properly activated and deactivated again in the shaderWidget. Removed a lot of redundant/useless code from ViewControlPlugin shader handling and updated ShaderNode such that shaders may now also be disabled for a given drawMode.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10382 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1b01cc54
......@@ -692,11 +692,15 @@ void ViewControlPlugin::slotShaderClicked( QListWidgetItem * _item ){
PluginFunctions::getObject( lastObjectId_, object );
if ( object && object->shaderNode() ){
if ( object->shaderNode()->vertexShaderName( id ) == vertexFile.toStdString() &&
object->shaderNode()->fragmentShaderName( id ) == fragmentFile.toStdString() )
item->setCheckState( Qt::Checked );
else
item->setCheckState( Qt::Unchecked );
if ( object->shaderNode()->vertexShaderName( id ) == vertexFile.toStdString() &&
object->shaderNode()->fragmentShaderName( id ) == fragmentFile.toStdString() )
item->setCheckState( Qt::Checked );
else
{
//std::cerr << "vertex:" << object->shaderNode()->vertexShaderName( id ) << ", this: " << vertexFile.toStdString() << std::endl;
//std::cerr << "fragment:" << object->shaderNode()->fragmentShaderName( id ) << ", this: " << fragmentFile.toStdString() << std::endl;
item->setCheckState( Qt::Unchecked );
}
}
shaderWidget_->drawModes->addItem(item);
}
......@@ -787,131 +791,126 @@ void ViewControlPlugin::slotSetShader(){
return;
}
//get shader paths
QStringList shadersDirs = OpenFlipper::Options::shaderDir().entryList( QDir::Dirs| QDir::NoDotAndDotDot ,QDir::Name);
QString shaderDir = OpenFlipper::Options::shaderDirStr() + OpenFlipper::Options::dirSeparator();
QString vertexFile = shadersDirs[ shaderWidget_->availableShaders->currentRow() ] +
OpenFlipper::Options::dirSeparator() + shaderWidget_->vertexShader->text();
QString fragmentFile = shadersDirs[ shaderWidget_->availableShaders->currentRow() ] +
OpenFlipper::Options::dirSeparator() + shaderWidget_->fragmentShader->text();
QString pickVertexFile = shadersDirs[ shaderWidget_->availableShaders->currentRow() ] +
OpenFlipper::Options::dirSeparator() + shaderWidget_->pickVertexShader->text();
QString pickFragmentFile = shadersDirs[ shaderWidget_->availableShaders->currentRow() ] +
OpenFlipper::Options::dirSeparator() + shaderWidget_->pickFragmentShader->text();
//get drawmodes
std::vector< QString > mode;
std::vector <QString> mode;
for (int i=0; i < shaderWidget_->drawModes->count(); i++)
if (shaderWidget_->drawModes->item(i)->checkState() == Qt::Checked){
mode.push_back( shaderWidget_->drawModes->item(i)->text() );
{
if (shaderWidget_->drawModes->item(i)->checkState() == Qt::Checked)
{
mode.push_back (shaderWidget_->drawModes->item(i)->text());
setShader(lastObjectId_, descriptionsToDrawMode(mode), shaderList_[index]);
mode.clear();
}
//set the shader
if ( QFile( shaderDir + vertexFile ).exists() && QFile( shaderDir + fragmentFile ).exists() ) {
BaseObjectData* object = 0;
PluginFunctions::getObject( lastObjectId_, object );
if ( object && object->shaderNode() ){
if ( shaderWidget_->pickVertexShader->text() != "" &&
shaderWidget_->pickFragmentShader->text() != "" &&
QFile( shaderDir + pickVertexFile ).exists() &&
QFile( shaderDir + pickFragmentFile ).exists() )
object->shaderNode()->setShader(descriptionsToDrawMode(mode), vertexFile.toStdString() , fragmentFile.toStdString(),
pickVertexFile.toStdString() , pickFragmentFile.toStdString());
else
object->shaderNode()->setShader(descriptionsToDrawMode(mode), vertexFile.toStdString() , fragmentFile.toStdString());
// set uniforms if available
if (shaderList_[index].hasUniforms){
GLSL::PtrProgram shader = object->shaderNode()->getShader( descriptionsToDrawMode(mode) );
if ( shader == 0 ) {
std::cerr << "Error: Unable to get shader for shader mode" << std::endl;
} else {
shader->use();
for (int u=0; u < shaderList_[index].uniforms.count(); u++){
//float uniforms
if (shaderList_[index].uniformTypes[u] == "float" ){
shaderWidget_->uniforms->setCurrentCell(u,0);
float value = shaderWidget_->uniforms->currentItem()->text().toFloat();
shader->setUniform(shaderList_[index].uniforms[u].toUtf8(), value);
} else
//vec3 uniforms
if (shaderList_[index].uniformTypes[u] == "vec3" ){
shaderWidget_->uniforms->setCurrentCell(u,0);
QStringList vecStr = shaderWidget_->uniforms->currentItem()->text().split(",");
if (vecStr.count() == 3){
ACG::Vec3f value( vecStr[0].toFloat(), vecStr[1].toFloat(), vecStr[2].toFloat() );
shader->setUniform(shaderList_[index].uniforms[u].toUtf8(), value);
}
}else
std::cerr << "Error: handling of uniformType '" << shaderList_[index].uniformTypes[u].toStdString() << "' not yet implemented" << std::endl;
}
shader->disable();
}
}
else
{
mode.push_back (shaderWidget_->drawModes->item(i)->text());
disableShader(lastObjectId_, descriptionsToDrawMode(mode), &shaderList_[index] );
mode.clear();
}
}
emit updateView();
}
void ViewControlPlugin::setShader(int _id, QString _drawMode, QString _vertexShader, QString _fragmentShader,
QString _pickVertexShader, QString _pickFragmentShader){
void ViewControlPlugin::disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo* _shader) {
BaseObjectData* object = 0;
PluginFunctions::getObject( _objectId, object );
if (object)
{
if (!_shader)
object->shaderNode()->disableShader( _drawMode );
else
{
std::string shadeDir = _shader->directory.toStdString() + OpenFlipper::Options::dirSeparator().toStdString();
if (object->shaderNode()->vertexShaderName( _drawMode ) == shadeDir + _shader->vertexShader.toStdString() &&
object->shaderNode()->fragmentShaderName( _drawMode ) == shadeDir + _shader->fragmentShader.toStdString() )
object->shaderNode()->disableShader( _drawMode );
}
}
emit updateView();
}
if ( OpenFlipper::Options::nogui() )
return;
void ViewControlPlugin::setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader) {
BaseObjectData* object = 0;
PluginFunctions::getObject( _id, object );
if ( OpenFlipper::Options::nogui() )
return;
std::vector< QString > mode;
mode.push_back( _drawMode );
BaseObjectData* object = 0;
PluginFunctions::getObject( _id, object );
//get shader paths
QFileInfo vertexFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.vertexShader);
QFileInfo fragmentFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.fragmentShader);
QFileInfo pickVertexFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.pickVertexShader);
QFileInfo pickFragmentFile (_shader.name + OpenFlipper::Options::dirSeparator() + _shader.pickFragmentShader);
if ( object && object->shaderNode() ){
if ( object && object->shaderNode()
&& _shader.vertexShader.length() && _shader.fragmentShader.length()) {
QFileInfo vertexFile(_vertexShader);
QFileInfo fragmentFile(_fragmentShader);
if (vertexFile.absolutePath() != fragmentFile.absolutePath()) {
emit log(LOGERR, "Cannot set shader. Currently shader files have to be in the same folder.");
return;
}
if (vertexFile.absolutePath() != fragmentFile.absolutePath()){
emit log(LOGERR, "Cannot set shader. Currently shader files have to be in the same folder.");
return;
if (_shader.pickVertexShader.length() && _shader.pickFragmentShader.length())
{
if (vertexFile.absolutePath() != pickVertexFile.absolutePath() ||
vertexFile.absolutePath() != pickFragmentFile.absolutePath()) {
emit log(LOGERR, "Cannot set picking shader. Currently shader files have to be in the same folder.");
return;
}
object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
object->shaderNode()->setShader(_drawMode,
vertexFile.fileName().toStdString(),
fragmentFile.fileName().toStdString(),
pickVertexFile.fileName().toStdString(),
pickFragmentFile.fileName().toStdString());
}
else
{
object->shaderNode()->setShaderDir( (_shader.directory + OpenFlipper::Options::dirSeparator()).toStdString() );
object->shaderNode()->setShader(_drawMode, vertexFile.fileName().toStdString(), fragmentFile.fileName().toStdString());
}
}
if (_pickVertexShader.length () && _pickFragmentShader.length ())
{
QFileInfo pickVertexFile(_pickVertexShader);
QFileInfo pickFragmentFile(_pickFragmentShader);
if (vertexFile.absolutePath() != pickVertexFile.absolutePath() ||
vertexFile.absolutePath() != pickFragmentFile.absolutePath()){
emit log(LOGERR, "Cannot set shader. Currently shader files have to be in the same folder.");
return;
}
// set uniforms if available
if (_shader.hasUniforms) {
GLSL::PtrProgram shader = object->shaderNode()->getShader( _drawMode );
if ( shader == 0 ) {
std::cerr << "Error: Unable to get shader for shader mode" << std::endl;
} else {
shader->use();
object->shaderNode()->setShaderDir( (vertexFile.absolutePath() + OpenFlipper::Options::dirSeparator()).toStdString() );
for (int u=0; u < _shader.uniforms.count(); u++) {
//float uniforms
if (_shader.uniformTypes[u] == "float" ) {
shaderWidget_->uniforms->setCurrentCell(u,0);
float value = shaderWidget_->uniforms->currentItem()->text().toFloat();
shader->setUniform(_shader.uniforms[u].toUtf8(), value);
} else
//vec3 uniforms
if (_shader.uniformTypes[u] == "vec3" ) {
shaderWidget_->uniforms->setCurrentCell(u,0);
QStringList vecStr = shaderWidget_->uniforms->currentItem()->text().split(",");
if (vecStr.count() == 3) {
ACG::Vec3f value( vecStr[0].toFloat(), vecStr[1].toFloat(), vecStr[2].toFloat() );
shader->setUniform(_shader.uniforms[u].toUtf8(), value);
}
} else
std::cerr << "Error: handling of uniformType '" << _shader.uniformTypes[u].toStdString() << "' not yet implemented" << std::endl;
object->shaderNode()->setShader(listToDrawMode( mode ), vertexFile.fileName().toStdString(),
fragmentFile.fileName().toStdString(),
pickVertexFile.fileName().toStdString(),
pickFragmentFile.fileName().toStdString());
}
else
{
object->shaderNode()->setShaderDir( (vertexFile.absolutePath() + OpenFlipper::Options::dirSeparator()).toStdString() );
}
object->shaderNode()->setShader(listToDrawMode( mode ), vertexFile.fileName().toStdString(),
fragmentFile.fileName().toStdString());
shader->disable();
}
}
}
emit updateView();
emit updateView();
}
void ViewControlPlugin::setShader(int _id, QString _drawMode, QString _name ){
......@@ -934,24 +933,11 @@ void ViewControlPlugin::setShader(int _id, QString _drawMode, QString _name ){
std::cerr << "Error: Shader not found! " << std::endl;
return;
}
BaseObjectData* object = 0;
PluginFunctions::getObject( _id, object );
std::vector< QString > mode;
mode.push_back( _drawMode );
if ( object && object->shaderNode() ){
object->shaderNode()->setShaderDir( (shaderList_[index].directory + OpenFlipper::Options::dirSeparator()).toStdString() );
object->shaderNode()->setShader(listToDrawMode( mode ), shaderList_[index].vertexShader.toStdString(),
shaderList_[index].fragmentShader.toStdString(),
shaderList_[index].pickVertexShader.toStdString(),
shaderList_[index].pickFragmentShader.toStdString());
}
emit updateView();
std::vector <QString> mode;
mode.push_back(_drawMode);
setShader(_id, listToDrawMode(mode), shaderList_[index]);
}
//-----------------------------------------------------------------------------
......
......@@ -182,6 +182,15 @@ class ViewControlPlugin : public QObject, BaseInterface , PickingInterface, Logg
/// Allows to enable/disable visualization of the objects modeling area for meshes
void showModelingAreas( int _id , bool _state );
/** Disable the given shader for a given object and draw mode.
* @param _objectId ID of the object for which to disable the shader
* @param _drawMode _drawMode for which the shader is disabled
* @param _shader Shader which is disabled. If this shader is not currently active for
* the given _drawMode, nothing will be disabled. In order to disable
* all shaders for the given _drawMode, use _shader=0 (default).
*/
void disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo* _shader=0);
/** Sets a shader for the object and the given drawMode( can be a combination of draw modes )
* @param _id Object Id
* @param _drawMode ; seperated list of drawmodes used by the shader
......@@ -190,8 +199,7 @@ class ViewControlPlugin : public QObject, BaseInterface , PickingInterface, Logg
* @param _pickVertexShader File with the picking vertex shader code
* @param _pickFragmentShader File with the picking fragment shader code
*/
void setShader(int _id, QString _drawMode, QString _vertexShader, QString _fragmentShader,
QString _pickVertexShader = "", QString _pickFragmentShader = "");
void setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader);
/** Sets a Shader from the Shader directory of OpenFlipper ( Name of the one given inside the ini file )
*
......@@ -218,7 +226,7 @@ class ViewControlPlugin : public QObject, BaseInterface , PickingInterface, Logg
/// translate Scene
void translate( Vector _vec , int _viewer = PluginFunctions::ALL_VIEWERS );
/// Set the draw mode for a viewer
void setDrawMode(QString _mode, int _viewer = PluginFunctions::ALL_VIEWERS );
......
......@@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
<string>Shader Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="2">
......@@ -42,13 +42,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="setGlobalButton">
<property name="text">
<string>Set shader Globally</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="setShaderButton">
<property name="text">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment