2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-10 14:01:09 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-11-10 14:01:09 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-10 14:01:09 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-11-10 14:01:09 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
#include "glsleditorplugin.h"
|
|
|
|
|
#include "glsleditor.h"
|
|
|
|
|
#include "glsleditorconstants.h"
|
|
|
|
|
#include "glsleditorfactory.h"
|
2010-11-24 13:27:53 +10:00
|
|
|
#include "glslfilewizard.h"
|
2010-11-26 11:17:30 +01:00
|
|
|
#include "glslhoverhandler.h"
|
2011-04-15 16:19:23 +02:00
|
|
|
#include "glslcompletionassist.h"
|
2014-06-26 00:27:27 +02:00
|
|
|
#include "glslhighlighter.h"
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-11-10 14:01:09 +01:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <projectexplorer/taskhub.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2014-06-26 00:27:27 +02:00
|
|
|
#include <texteditor/highlighterfactory.h>
|
2010-11-10 14:01:09 +01:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
|
|
|
|
#include <texteditor/textfilewizard.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2010-11-26 15:00:46 +01:00
|
|
|
#include <glsl/glslengine.h>
|
|
|
|
|
#include <glsl/glslparser.h>
|
|
|
|
|
#include <glsl/glsllexer.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtPlugin>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QAction>
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2012-12-30 20:11:28 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
|
|
|
|
namespace GLSLEditor {
|
|
|
|
|
namespace Internal {
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2013-09-10 18:27:42 +02:00
|
|
|
class GLSLEditorPluginPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
GLSLEditorPluginPrivate() :
|
|
|
|
|
m_editor(0),
|
|
|
|
|
m_glsl_120_frag(0),
|
|
|
|
|
m_glsl_120_vert(0),
|
|
|
|
|
m_glsl_120_common(0),
|
|
|
|
|
m_glsl_es_100_frag(0),
|
|
|
|
|
m_glsl_es_100_vert(0),
|
|
|
|
|
m_glsl_es_100_common(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
~GLSLEditorPluginPrivate()
|
|
|
|
|
{
|
|
|
|
|
delete m_glsl_120_frag;
|
|
|
|
|
delete m_glsl_120_vert;
|
|
|
|
|
delete m_glsl_120_common;
|
|
|
|
|
delete m_glsl_es_100_frag;
|
|
|
|
|
delete m_glsl_es_100_vert;
|
|
|
|
|
delete m_glsl_es_100_common;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GLSLEditorFactory *m_editor;
|
|
|
|
|
QPointer<TextEditor::ITextEditor> m_currentTextEditable;
|
|
|
|
|
|
|
|
|
|
GLSLEditorPlugin::InitFile *m_glsl_120_frag;
|
|
|
|
|
GLSLEditorPlugin::InitFile *m_glsl_120_vert;
|
|
|
|
|
GLSLEditorPlugin::InitFile *m_glsl_120_common;
|
|
|
|
|
GLSLEditorPlugin::InitFile *m_glsl_es_100_frag;
|
|
|
|
|
GLSLEditorPlugin::InitFile *m_glsl_es_100_vert;
|
|
|
|
|
GLSLEditorPlugin::InitFile *m_glsl_es_100_common;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GLSLEditorPluginPrivate *dd = 0;
|
|
|
|
|
static GLSLEditorPlugin *m_instance = 0;
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2010-11-26 15:00:46 +01:00
|
|
|
GLSLEditorPlugin::InitFile::~InitFile()
|
|
|
|
|
{
|
|
|
|
|
delete engine;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:27:42 +02:00
|
|
|
GLSLEditorPlugin::GLSLEditorPlugin()
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
|
|
|
|
m_instance = this;
|
2013-09-10 18:27:42 +02:00
|
|
|
dd = new GLSLEditorPluginPrivate;
|
2010-11-10 14:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GLSLEditorPlugin::~GLSLEditorPlugin()
|
|
|
|
|
{
|
2013-09-10 18:27:42 +02:00
|
|
|
removeObject(dd->m_editor);
|
|
|
|
|
delete dd;
|
2010-11-10 14:01:09 +01:00
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2013-08-30 16:38:57 +02:00
|
|
|
if (!MimeDatabase::addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage))
|
2010-11-10 14:01:09 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// m_modelManager = new ModelManager(this);
|
|
|
|
|
// addAutoReleasedObject(m_modelManager);
|
|
|
|
|
|
2010-11-26 11:17:30 +01:00
|
|
|
addAutoReleasedObject(new GLSLHoverHandler(this));
|
|
|
|
|
|
2013-09-10 18:27:42 +02:00
|
|
|
dd->m_editor = new GLSLEditorFactory(this);
|
|
|
|
|
addObject(dd->m_editor);
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
addAutoReleasedObject(new GLSLCompletionAssistProvider);
|
2010-11-12 17:11:20 +01:00
|
|
|
|
2012-12-30 20:11:28 +01:00
|
|
|
ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT);
|
|
|
|
|
ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL));
|
|
|
|
|
glslToolsMenu->setOnAllDisabledBehavior(ActionContainer::Hide);
|
2010-11-10 14:01:09 +01:00
|
|
|
QMenu *menu = glslToolsMenu->menu();
|
|
|
|
|
//: GLSL sub-menu in the Tools menu
|
|
|
|
|
menu->setTitle(tr("GLSL"));
|
2012-12-30 20:11:28 +01:00
|
|
|
ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(glslToolsMenu);
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2012-12-30 20:11:28 +01:00
|
|
|
Command *cmd = 0;
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
// Insert marker for "Refactoring" menu:
|
2012-12-30 20:11:28 +01:00
|
|
|
Context globalContext(Core::Constants::C_GLOBAL);
|
|
|
|
|
Command *sep = contextMenu->addSeparator(globalContext);
|
2012-11-26 20:58:49 +02:00
|
|
|
sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT));
|
2012-06-05 14:22:20 +02:00
|
|
|
contextMenu->addSeparator(globalContext);
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2012-12-30 20:11:28 +01:00
|
|
|
cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
2010-11-10 14:01:09 +01:00
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
errorMessage->clear();
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2013-09-12 16:06:33 +02:00
|
|
|
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE);
|
|
|
|
|
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_VERT);
|
|
|
|
|
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_FRAG);
|
|
|
|
|
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_VERT_ES);
|
|
|
|
|
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_FRAG_ES);
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2014-05-02 17:38:42 +02:00
|
|
|
IWizardFactory *wizard = new GLSLFileWizard(GLSLFileWizard::FragmentShaderES);
|
|
|
|
|
wizard->setWizardKind(IWizardFactory::FileWizard);
|
2013-09-20 15:12:44 +02:00
|
|
|
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
|
|
|
|
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
|
|
|
|
wizard->setDescription
|
2010-11-24 13:27:53 +10:00
|
|
|
(tr("Creates a fragment shader in the OpenGL/ES 2.0 Shading "
|
2011-02-15 16:05:52 +01:00
|
|
|
"Language (GLSL/ES). Fragment shaders generate the final "
|
|
|
|
|
"pixel colors for triangles, points and lines rendered "
|
2010-11-24 13:27:53 +10:00
|
|
|
"with OpenGL."));
|
2013-09-20 15:12:44 +02:00
|
|
|
wizard->setDisplayName(tr("Fragment Shader (OpenGL/ES 2.0)"));
|
|
|
|
|
wizard->setId(QLatin1String("F.GLSL"));
|
|
|
|
|
addAutoReleasedObject(wizard);
|
|
|
|
|
|
|
|
|
|
wizard = new GLSLFileWizard(GLSLFileWizard::VertexShaderES);
|
2014-05-02 17:38:42 +02:00
|
|
|
wizard->setWizardKind(IWizardFactory::FileWizard);
|
2013-09-20 15:12:44 +02:00
|
|
|
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
|
|
|
|
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
|
|
|
|
wizard->setDescription
|
2010-11-24 13:27:53 +10:00
|
|
|
(tr("Creates a vertex shader in the OpenGL/ES 2.0 Shading "
|
2011-02-15 16:05:52 +01:00
|
|
|
"Language (GLSL/ES). Vertex shaders transform the "
|
|
|
|
|
"positions, normals and texture co-ordinates of "
|
|
|
|
|
"triangles, points and lines rendered with OpenGL."));
|
2013-09-20 15:12:44 +02:00
|
|
|
wizard->setDisplayName(tr("Vertex Shader (OpenGL/ES 2.0)"));
|
|
|
|
|
wizard->setId(QLatin1String("G.GLSL"));
|
|
|
|
|
addAutoReleasedObject(wizard);
|
|
|
|
|
|
|
|
|
|
wizard = new GLSLFileWizard(GLSLFileWizard::FragmentShaderDesktop);
|
2014-05-02 17:38:42 +02:00
|
|
|
wizard->setWizardKind(IWizardFactory::FileWizard);
|
2013-09-20 15:12:44 +02:00
|
|
|
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
|
|
|
|
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
|
|
|
|
wizard->setDescription
|
2010-12-01 10:04:56 +10:00
|
|
|
(tr("Creates a fragment shader in the Desktop OpenGL Shading "
|
2011-02-15 16:05:52 +01:00
|
|
|
"Language (GLSL). Fragment shaders generate the final "
|
|
|
|
|
"pixel colors for triangles, points and lines rendered "
|
2010-12-01 10:04:56 +10:00
|
|
|
"with OpenGL."));
|
2013-09-20 15:12:44 +02:00
|
|
|
wizard->setDisplayName(tr("Fragment Shader (Desktop OpenGL)"));
|
|
|
|
|
wizard->setId(QLatin1String("J.GLSL"));
|
|
|
|
|
addAutoReleasedObject(wizard);
|
|
|
|
|
|
|
|
|
|
wizard = new GLSLFileWizard(GLSLFileWizard::VertexShaderDesktop);
|
2014-05-02 17:38:42 +02:00
|
|
|
wizard->setWizardKind(IWizardFactory::FileWizard);
|
2013-09-20 15:12:44 +02:00
|
|
|
wizard->setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
|
|
|
|
wizard->setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
|
|
|
|
wizard->setDescription
|
2010-12-01 10:04:56 +10:00
|
|
|
(tr("Creates a vertex shader in the Desktop OpenGL Shading "
|
2011-02-15 16:05:52 +01:00
|
|
|
"Language (GLSL). Vertex shaders transform the "
|
|
|
|
|
"positions, normals and texture co-ordinates of "
|
|
|
|
|
"triangles, points and lines rendered with OpenGL."));
|
2013-09-20 15:12:44 +02:00
|
|
|
wizard->setDisplayName(tr("Vertex Shader (Desktop OpenGL)"));
|
|
|
|
|
wizard->setId(QLatin1String("K.GLSL"));
|
|
|
|
|
addAutoReleasedObject(wizard);
|
|
|
|
|
|
2014-06-26 00:27:27 +02:00
|
|
|
auto hf = new TextEditor::HighlighterFactory;
|
|
|
|
|
hf->setProductType<Highlighter>();
|
|
|
|
|
hf->setId(GLSLEditor::Constants::C_GLSLEDITOR_ID);
|
|
|
|
|
hf->addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE);
|
|
|
|
|
hf->addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_VERT);
|
|
|
|
|
hf->addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG);
|
|
|
|
|
hf->addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES);
|
|
|
|
|
hf->addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES);
|
|
|
|
|
addAutoReleasedObject(hf);
|
2010-11-24 13:27:53 +10:00
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSLEditorPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag GLSLEditorPlugin::aboutToShutdown()
|
|
|
|
|
{
|
|
|
|
|
// delete GLSL::Icons::instance(); // delete object held by singleton
|
|
|
|
|
return IPlugin::aboutToShutdown();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:27:42 +02:00
|
|
|
static QByteArray glslFile(const QString &fileName)
|
2010-11-26 14:18:50 +01:00
|
|
|
{
|
2012-12-30 20:11:28 +01:00
|
|
|
QFile file(ICore::resourcePath() + QLatin1String("/glsl/") + fileName);
|
2010-11-26 14:18:50 +01:00
|
|
|
if (file.open(QFile::ReadOnly))
|
|
|
|
|
return file.readAll();
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:27:42 +02:00
|
|
|
static void parseGlslFile(const QString &fileName, GLSLEditorPlugin::InitFile *initFile)
|
2010-11-26 15:00:46 +01:00
|
|
|
{
|
2010-11-29 10:09:22 +10:00
|
|
|
// Parse the builtins for any langugage variant so we can use all keywords.
|
2012-05-20 21:15:30 +02:00
|
|
|
const int variant = GLSL::Lexer::Variant_All;
|
2010-11-26 15:00:46 +01:00
|
|
|
|
|
|
|
|
const QByteArray code = glslFile(fileName);
|
|
|
|
|
initFile->engine = new GLSL::Engine();
|
|
|
|
|
GLSL::Parser parser(initFile->engine, code.constData(), code.size(), variant);
|
|
|
|
|
initFile->ast = parser.parse();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:27:42 +02:00
|
|
|
static GLSLEditorPlugin::InitFile *getInitFile(const char *fileName, GLSLEditorPlugin::InitFile **initFile)
|
|
|
|
|
{
|
|
|
|
|
if (*initFile)
|
|
|
|
|
return *initFile;
|
|
|
|
|
*initFile = new GLSLEditorPlugin::InitFile;
|
|
|
|
|
parseGlslFile(QLatin1String(fileName), *initFile);
|
|
|
|
|
return *initFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit(int variant)
|
2010-11-26 14:18:50 +01:00
|
|
|
{
|
2010-12-01 10:04:56 +10:00
|
|
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
2013-09-10 18:27:42 +02:00
|
|
|
return getInitFile("glsl_120.frag", &dd->m_glsl_120_frag);
|
2010-12-01 10:04:56 +10:00
|
|
|
else
|
2013-09-10 18:27:42 +02:00
|
|
|
return getInitFile("glsl_es_100.frag", &dd->m_glsl_es_100_frag);
|
2010-11-26 14:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:27:42 +02:00
|
|
|
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit(int variant)
|
2010-11-26 14:18:50 +01:00
|
|
|
{
|
2010-12-01 10:04:56 +10:00
|
|
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
2013-09-10 18:27:42 +02:00
|
|
|
return getInitFile("glsl_120.vert", &dd->m_glsl_120_vert);
|
2010-12-01 10:04:56 +10:00
|
|
|
else
|
2013-09-10 18:27:42 +02:00
|
|
|
return getInitFile("glsl_es_100.vert", &dd->m_glsl_es_100_vert);
|
2010-11-26 14:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
2013-09-10 18:27:42 +02:00
|
|
|
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit(int variant)
|
2010-11-26 14:18:50 +01:00
|
|
|
{
|
2010-12-01 10:04:56 +10:00
|
|
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
2013-09-10 18:27:42 +02:00
|
|
|
return getInitFile("glsl_120_common.glsl", &dd->m_glsl_120_common);
|
2010-12-01 10:04:56 +10:00
|
|
|
else
|
2013-09-10 18:27:42 +02:00
|
|
|
return getInitFile("glsl_es_100_common.glsl", &dd->m_glsl_es_100_common);
|
2010-11-26 14:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
2012-12-30 20:11:28 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace GLSLEditor
|
|
|
|
|
|
2012-12-31 10:39:47 +01:00
|
|
|
Q_EXPORT_PLUGIN(GLSLEditor::Internal::GLSLEditorPlugin)
|