Commit baa95efb authored by Jan Möbius's avatar Jan Möbius

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 19538920
......@@ -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_;
};
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