Commit e804a22f authored by Jan Möbius's avatar Jan Möbius
Browse files

Possibility to output shaders to strings in IRenderer

Added syntax highlighting for the render object widget

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16268 383ad7c9-94d9-4d36-a494-682f7c89f535
parent d6f1ad99
......@@ -500,17 +500,60 @@ void IRenderer::dumpRenderObjectsToFile(const char* _fileName, ACG::RenderObject
}
QString IRenderer::dumpCurrentRenderObjectsToString(ACG::RenderObject** _list) {
QString IRenderer::dumpCurrentRenderObjectsToString(ACG::RenderObject** _list, bool _outputShaders ) {
QString objectString;
QTextStream outStrm(&objectString);
for (int i = 0; i < getNumRenderObjects(); ++i)
{
if (_list)
if (_list) {
outStrm << "\n" << _list[i]->toString();
else
if ( _outputShaders ) {
outStrm << "\n";
outStrm << _list[i]->shaderDesc.toString();
ShaderProgGenerator progGen(&(_list[i]->shaderDesc));
outStrm << "\n---------------------vertex-shader--------------------\n\n";
for (int i = 0; i < progGen.getVertexShaderCode().size(); ++i)
outStrm << progGen.getVertexShaderCode()[i] << "\n";
outStrm << "\n---------------------end-vertex-shader--------------------\n\n";
outStrm << "\n---------------------fragment-shader--------------------\n\n";
for (int i = 0; i < progGen.getFragmentShaderCode().size(); ++i)
outStrm << progGen.getFragmentShaderCode()[i] << "\n";
outStrm << "\n---------------------end-fragment-shader--------------------\n\n";
}
} else {
outStrm << "\n" << renderObjects_[i].toString();
if ( _outputShaders ) {
outStrm << "\n";
outStrm << _list[i]->shaderDesc.toString();
ShaderProgGenerator progGen(&(_list[i]->shaderDesc));
outStrm << "\n---------------------vertex-shader--------------------\n\n";
for (int i = 0; i < progGen.getVertexShaderCode().size(); ++i)
outStrm << progGen.getVertexShaderCode()[i] << "\n";
outStrm << "\n---------------------end-vertex-shader--------------------\n\n";
outStrm << "\n---------------------fragment-shader--------------------\n\n";
for (int i = 0; i < progGen.getFragmentShaderCode().size(); ++i)
outStrm << progGen.getFragmentShaderCode()[i] << "\n";
outStrm << "\n---------------------end-fragment-shader--------------------\n\n";
}
}
}
return objectString;
......
......@@ -263,9 +263,11 @@ public:
/** \brief Outputs the current render objects to the string
*
* @return Render object data
* @param _list Pointer to a list of render objects used for output (defaults to unsorted internal list)
* @param _outputShaders Output the shaders used for the objects?
* @return Render object data in a QString
*/
virtual QString dumpCurrentRenderObjectsToString(ACG::RenderObject** _list = 0);
virtual QString dumpCurrentRenderObjectsToString(ACG::RenderObject** _list = 0, bool _outputShaders = false);
//=========================================================================
// Variables
......
......@@ -95,11 +95,15 @@ GLSL::Program* ACG::ShaderCache::getProgram( const ShaderGenDesc* _desc, unsigne
if (_desc->fragmentTemplateFile)
newEntry.strFragmentTemplate = _desc->fragmentTemplateFile;
if (_desc->geometryTemplateFile)
newEntry.strGeometryTemplate = _desc->geometryTemplateFile;
if (_desc->vertexTemplateFile)
newEntry.strVertexTemplate = _desc->vertexTemplateFile;
for (CacheList::iterator it = cache_.begin(); it != cache_.end(); ++it)
{
// If the shaders are equal, we return the cached entry
if (!compareShaderGenDescs(&it->first, &newEntry))
return it->second;
}
......@@ -140,6 +144,8 @@ GLSL::Program* ACG::ShaderCache::getProgram( const ShaderGenDesc* _desc, unsigne
}
#endif
// TODO: Geometry shader handling if supported!
GLSL::FragmentShader* fragShader = new GLSL::FragmentShader();
GLSL::VertexShader* vertShader = new GLSL::VertexShader();
......@@ -188,13 +194,16 @@ int ACG::ShaderCache::compareShaderGenDescs( const CacheEntry* _a, const CacheEn
if (_a->strFragmentTemplate != _b->strFragmentTemplate)
return -1;
if (_a->strGeometryTemplate != _b->strGeometryTemplate)
return -1;
if (_a->strVertexTemplate != _b->strVertexTemplate)
return -1;
if (a->numLights)
return memcmp(a->lightTypes, b->lightTypes, a->numLights * sizeof(ShaderGenLightType));
return 0;
return 0; // false
}
......
......@@ -102,10 +102,12 @@ protected:
// string-pointer in ShaderGenDesc may not be permanent,
// so copy string data here
std::string strVertexTemplate;
std::string strVertexTemplate;
std::string strGeometryTemplate;
std::string strFragmentTemplate;
};
/// \brief Returns true, if the shaders are not equal
int compareShaderGenDescs(const CacheEntry* _a, const CacheEntry* _b);
......
......@@ -87,6 +87,7 @@ struct ShaderGenDesc
// optionally specify shader template file names
const char* vertexTemplateFile;
const char* geometryTemplateFile;
const char* fragmentTemplateFile;
......
......@@ -152,9 +152,10 @@ class RenderInterface {
* The IRenderer class already has a function called dumpCurrentRenderObjectsToString()
* which can be used to implement this function.
*
* @param _outputShaderInfo Output shader code along with the render objects
* @return string of render objects
*/
virtual QString renderObjectsInfo() { return QString("Render object inforation not implemented in this plugin"); };
virtual QString renderObjectsInfo(bool _outputShaderInfo) { return QString("Render object inforation not implemented in this plugin"); };
......
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 12439 $ *
* $LastChangedBy: moebius $ *
* $Date: 2011-09-22 17:55:29 +0200 (Do, 22 Sep 2011) $ *
* *
\*===========================================================================*/
#include <QtGui>
#include "renderObjectHighLighter.hh"
RenderObjectHighlighter::RenderObjectHighlighter(QTextDocument *parent)
: QSyntaxHighlighter(parent)
{
init();
}
RenderObjectHighlighter::RenderObjectHighlighter(QTextEdit *parent)
: QSyntaxHighlighter(parent)
{
init();
}
void RenderObjectHighlighter::init() {
// Set the basic format styles
VertexShaderFormat_.setForeground(Qt::darkGreen);
VertexShaderFormat_.setFontWeight(QFont::Bold);
FragmentShaderFormat_.setForeground(Qt::darkRed);
FragmentShaderFormat_.setFontWeight(QFont::Bold);
vertexShaderStartExpression_ = QRegExp("---------------------vertex-shader--------------------");
vertexShaderEndExpression_ = QRegExp("---------------------end-vertex-shader--------------------");
fragmentShaderStartExpression_ = QRegExp("---------------------fragment-shader--------------------");
fragmentShaderEndExpression_ = QRegExp("---------------------end-fragment-shader--------------------");
update();
// classFormat.setFontWeight(QFont::Bold);
// classFormat.setForeground(Qt::darkMagenta);
// rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
// rule.format = classFormat;
// highlightingRules.append(rule);
//
}
void RenderObjectHighlighter::update() {
highlightingRules_.clear();
// HighlightingRule rule;
//
// // Create Rules for keywords
// foreach (QString pattern, keywordPatterns_) {
// rule.pattern = QRegExp("\\b" + pattern + "\\b" );
// rule.format = keywordFormat_;
// highlightingRules_.append(rule);
// }
}
void RenderObjectHighlighter::highlightBlock(const QString &text)
{
// foreach (HighlightingRule rule, highlightingRules_) {
// QRegExp expression(rule.pattern);
// int index = text.indexOf(expression);
// while (index >= 0) {
// int length = expression.matchedLength();
// setFormat(index, length, rule.format);
// index = text.indexOf(expression, index + length);
// }
// }
// Blockstate -1,0 : nothing
// Blockstate 1 : vertexShader Code
// Blockstate 2 : geometryShader Code
// Blockstate 3 : fragment Shader Code
setCurrentBlockState(0);
// Vertex shader block
int startIndex = 0;
if (previousBlockState() != 1)
startIndex = text.indexOf(vertexShaderStartExpression_);
while (startIndex >= 0) {
int endIndex = text.indexOf(vertexShaderEndExpression_, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(1);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex + vertexShaderEndExpression_.matchedLength();
}
setFormat(startIndex, commentLength, VertexShaderFormat_);
startIndex = text.indexOf(vertexShaderStartExpression_, startIndex + commentLength);
}
// Fragment shader block
startIndex = 0;
if (previousBlockState() != 3)
startIndex = text.indexOf(fragmentShaderStartExpression_);
while (startIndex >= 0) {
int endIndex = text.indexOf(fragmentShaderEndExpression_, startIndex);
int commentLength;
if (endIndex == -1) {
setCurrentBlockState(3);
commentLength = text.length() - startIndex;
} else {
commentLength = endIndex - startIndex + fragmentShaderEndExpression_.matchedLength();
}
setFormat(startIndex, commentLength, FragmentShaderFormat_);
startIndex = text.indexOf(fragmentShaderStartExpression_, startIndex + commentLength);
}
}
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 12438 $ *
* $LastChangedBy: moebius $ *
* $Date: 2011-09-22 17:16:17 +0200 (Do, 22 Sep 2011) $ *
* *
\*===========================================================================*/
#pragma once
#include <QSyntaxHighlighter>
#include <QHash>
#include <QTextCharFormat>
class QTextDocument;
class RenderObjectHighlighter : public QSyntaxHighlighter
{
Q_OBJECT
public:
RenderObjectHighlighter( QTextDocument* parent = 0);
RenderObjectHighlighter( QTextEdit* parent = 0);
/// Updates the highlighter with the current rule set defined in the patterns
void update();
protected:
void highlightBlock(const QString &text);
private:
/// common initializer function called by the constructors
void init();
struct HighlightingRule
{
QRegExp pattern;
QTextCharFormat format;
};
QVector<HighlightingRule> highlightingRules_;
QRegExp vertexShaderStartExpression_;
QRegExp vertexShaderEndExpression_;
QRegExp fragmentShaderStartExpression_;
QRegExp fragmentShaderEndExpression_;
QTextCharFormat VertexShaderFormat_;
QTextCharFormat FragmentShaderFormat_;
};
......@@ -50,7 +50,8 @@
RendererObjectWidget::RendererObjectWidget(QWidget *parent)
: QDialog(parent)
: QDialog(parent),
highlighter_(0)
{
setupUi(this);
......@@ -61,6 +62,7 @@ RendererObjectWidget::RendererObjectWidget(QWidget *parent)
closeButton->setIcon( QIcon(iconPath + "window-close.png"));
highlighter_ = new RenderObjectHighlighter( textBrowser->document() );
}
void RendererObjectWidget::closeEvent(QCloseEvent *event)
......@@ -86,9 +88,9 @@ void RendererObjectWidget::update()
textBrowser->insertPlainText(tr("Version: ") + renderer->version + "\n" );
textBrowser->insertPlainText("\n" );
//TODO: Flag for shader output activate/deactivate
if ( renderManager().activeId(PluginFunctions::activeExaminer()) != 0 )
textBrowser->insertPlainText(renderer->plugin->renderObjectsInfo());
textBrowser->insertPlainText(renderer->plugin->renderObjectsInfo(true));
} else {
textBrowser->setText("Unable to get renderer!");
......
......@@ -44,6 +44,7 @@
#include <QtGui>
#include <OpenFlipper/common/RendererInfo.hh>
#include "renderObjectHighLighter.hh"
class RendererObjectWidget : public QDialog, public Ui::RendererObjectWidget
{
......@@ -62,5 +63,7 @@ class RendererObjectWidget : public QDialog, public Ui::RendererObjectWidget
void update();
RenderObjectHighlighter* highlighter_;
};
......@@ -74,7 +74,7 @@ public:
public slots:
QString version() { return QString("1.0"); };
QString renderObjectsInfo() { return dumpCurrentRenderObjectsToString(&sortedObjects_[0]); };
QString renderObjectsInfo(bool _outputShaderInfo) { return dumpCurrentRenderObjectsToString(&sortedObjects_[0],_outputShaderInfo); };
private slots:
......
......@@ -75,7 +75,7 @@ public:
public slots:
QString version() { return QString("1.0"); };
QString renderObjectsInfo() { return dumpCurrentRenderObjectsToString(&sortedObjects_[0]); };
QString renderObjectsInfo(bool _outputShaderInfo) { return dumpCurrentRenderObjectsToString(&sortedObjects_[0],_outputShaderInfo); };
private slots:
......
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