forked from qt-creator/qt-creator
GlslEditor: Move shader file setup to GlslEditor
Change-Id: I2e8b3bc222ce0e0cfb79a96d90319e9cba44bac0 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -8,7 +8,7 @@ add_qtc_plugin(GLSLEditor
|
|||||||
glsleditor.cpp glsleditor.h
|
glsleditor.cpp glsleditor.h
|
||||||
glsleditor.qrc
|
glsleditor.qrc
|
||||||
glsleditorconstants.h
|
glsleditorconstants.h
|
||||||
glsleditorplugin.cpp glsleditorplugin.h
|
glsleditorplugin.cpp
|
||||||
glsleditortr.h
|
glsleditortr.h
|
||||||
glslhighlighter.cpp glslhighlighter.h
|
glslhighlighter.cpp glslhighlighter.h
|
||||||
glslindenter.cpp glslindenter.h
|
glslindenter.cpp glslindenter.h
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "glslcompletionassist.h"
|
#include "glslcompletionassist.h"
|
||||||
#include "glsleditorconstants.h"
|
|
||||||
#include "glsleditorplugin.h"
|
|
||||||
|
|
||||||
#include <glsl/glslengine.h>
|
#include <glsl/glslengine.h>
|
||||||
#include <glsl/glsllexer.h>
|
#include <glsl/glsllexer.h>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "glsleditor.h"
|
#include "glsleditor.h"
|
||||||
#include "glsleditorconstants.h"
|
#include "glsleditorconstants.h"
|
||||||
#include "glsleditorplugin.h"
|
|
||||||
#include "glslhighlighter.h"
|
#include "glslhighlighter.h"
|
||||||
#include "glslautocompleter.h"
|
#include "glslautocompleter.h"
|
||||||
#include "glslcompletionassist.h"
|
#include "glslcompletionassist.h"
|
||||||
@@ -105,6 +104,93 @@ enum {
|
|||||||
UPDATE_DOCUMENT_DEFAULT_INTERVAL = 150
|
UPDATE_DOCUMENT_DEFAULT_INTERVAL = 150
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class InitFile final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit InitFile(const QString &fileName) : m_fileName(fileName) {}
|
||||||
|
|
||||||
|
~InitFile() { delete m_engine; }
|
||||||
|
|
||||||
|
GLSL::Engine *engine() const
|
||||||
|
{
|
||||||
|
if (!m_engine)
|
||||||
|
initialize();
|
||||||
|
return m_engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLSL::TranslationUnitAST *ast() const
|
||||||
|
{
|
||||||
|
if (!m_ast)
|
||||||
|
initialize();
|
||||||
|
return m_ast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initialize() const
|
||||||
|
{
|
||||||
|
// Parse the builtins for any language variant so we can use all keywords.
|
||||||
|
const int variant = GLSL::Lexer::Variant_All;
|
||||||
|
|
||||||
|
QByteArray code;
|
||||||
|
QFile file(Core::ICore::resourcePath("glsl").pathAppended(m_fileName).toString());
|
||||||
|
if (file.open(QFile::ReadOnly))
|
||||||
|
code = file.readAll();
|
||||||
|
|
||||||
|
m_engine = new GLSL::Engine();
|
||||||
|
GLSL::Parser parser(m_engine, code.constData(), code.size(), variant);
|
||||||
|
m_ast = parser.parse();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString m_fileName;
|
||||||
|
mutable GLSL::Engine *m_engine = nullptr;
|
||||||
|
mutable GLSL::TranslationUnitAST *m_ast = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const InitFile *fragmentShaderInit(int variant)
|
||||||
|
{
|
||||||
|
static InitFile glsl_es_100_frag{"glsl_es_100.frag"};
|
||||||
|
static InitFile glsl_120_frag{"glsl_120.frag"};
|
||||||
|
static InitFile glsl_330_frag{"glsl_330.frag"};
|
||||||
|
|
||||||
|
if (variant & GLSL::Lexer::Variant_GLSL_400)
|
||||||
|
return &glsl_330_frag;
|
||||||
|
|
||||||
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
||||||
|
return &glsl_120_frag;
|
||||||
|
|
||||||
|
return &glsl_es_100_frag;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const InitFile *vertexShaderInit(int variant)
|
||||||
|
{
|
||||||
|
static InitFile glsl_es_100_vert{"glsl_es_100.vert"};
|
||||||
|
static InitFile glsl_120_vert{"glsl_120.vert"};
|
||||||
|
static InitFile glsl_330_vert{"glsl_330.vert"};
|
||||||
|
|
||||||
|
if (variant & GLSL::Lexer::Variant_GLSL_400)
|
||||||
|
return &glsl_330_vert;
|
||||||
|
|
||||||
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
||||||
|
return &glsl_120_vert;
|
||||||
|
|
||||||
|
return &glsl_es_100_vert;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const InitFile *shaderInit(int variant)
|
||||||
|
{
|
||||||
|
static InitFile glsl_es_100_common{"glsl_es_100_common.glsl"};
|
||||||
|
static InitFile glsl_120_common{"glsl_120_common.glsl"};
|
||||||
|
static InitFile glsl_330_common{"glsl_330_common.glsl"};
|
||||||
|
|
||||||
|
if (variant & GLSL::Lexer::Variant_GLSL_400)
|
||||||
|
return &glsl_330_common;
|
||||||
|
|
||||||
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
||||||
|
return &glsl_120_common;
|
||||||
|
|
||||||
|
return &glsl_es_100_common;
|
||||||
|
}
|
||||||
|
|
||||||
class CreateRanges: protected Visitor
|
class CreateRanges: protected Visitor
|
||||||
{
|
{
|
||||||
QTextDocument *textDocument;
|
QTextDocument *textDocument;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ QtcPlugin {
|
|||||||
"glsleditor.qrc",
|
"glsleditor.qrc",
|
||||||
"glsleditorconstants.h",
|
"glsleditorconstants.h",
|
||||||
"glsleditorplugin.cpp",
|
"glsleditorplugin.cpp",
|
||||||
"glsleditorplugin.h",
|
|
||||||
"glsleditortr.h",
|
"glsleditortr.h",
|
||||||
"glslhighlighter.cpp",
|
"glslhighlighter.cpp",
|
||||||
"glslhighlighter.h",
|
"glslhighlighter.h",
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "glsleditorplugin.h"
|
|
||||||
|
|
||||||
#include "glslcompletionassist.h"
|
#include "glslcompletionassist.h"
|
||||||
#include "glsleditor.h"
|
#include "glsleditor.h"
|
||||||
#include "glsleditorconstants.h"
|
#include "glsleditorconstants.h"
|
||||||
#include "glsleditortr.h"
|
#include "glsleditortr.h"
|
||||||
|
|
||||||
#include <glsl/glslengine.h>
|
|
||||||
#include <glsl/glslparser.h>
|
|
||||||
#include <glsl/glsllexer.h>
|
|
||||||
|
|
||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/actionmanager/command.h>
|
#include <coreplugin/actionmanager/command.h>
|
||||||
@@ -41,89 +35,6 @@ public:
|
|||||||
|
|
||||||
static GlslEditorPluginPrivate *dd = nullptr;
|
static GlslEditorPluginPrivate *dd = nullptr;
|
||||||
|
|
||||||
InitFile::InitFile(const QString &fileName)
|
|
||||||
: m_fileName(fileName)
|
|
||||||
{}
|
|
||||||
|
|
||||||
InitFile::~InitFile()
|
|
||||||
{
|
|
||||||
delete m_engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitFile::initialize() const
|
|
||||||
{
|
|
||||||
// Parse the builtins for any language variant so we can use all keywords.
|
|
||||||
const int variant = GLSL::Lexer::Variant_All;
|
|
||||||
|
|
||||||
QByteArray code;
|
|
||||||
QFile file(ICore::resourcePath("glsl").pathAppended(m_fileName).toString());
|
|
||||||
if (file.open(QFile::ReadOnly))
|
|
||||||
code = file.readAll();
|
|
||||||
|
|
||||||
m_engine = new GLSL::Engine();
|
|
||||||
GLSL::Parser parser(m_engine, code.constData(), code.size(), variant);
|
|
||||||
m_ast = parser.parse();
|
|
||||||
}
|
|
||||||
|
|
||||||
GLSL::TranslationUnitAST *InitFile::ast() const
|
|
||||||
{
|
|
||||||
if (!m_ast)
|
|
||||||
initialize();
|
|
||||||
return m_ast;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLSL::Engine *InitFile::engine() const
|
|
||||||
{
|
|
||||||
if (!m_engine)
|
|
||||||
initialize();
|
|
||||||
return m_engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
const InitFile *fragmentShaderInit(int variant)
|
|
||||||
{
|
|
||||||
static InitFile glsl_es_100_frag{"glsl_es_100.frag"};
|
|
||||||
static InitFile glsl_120_frag{"glsl_120.frag"};
|
|
||||||
static InitFile glsl_330_frag{"glsl_330.frag"};
|
|
||||||
|
|
||||||
if (variant & GLSL::Lexer::Variant_GLSL_400)
|
|
||||||
return &glsl_330_frag;
|
|
||||||
|
|
||||||
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
|
||||||
return &glsl_120_frag;
|
|
||||||
|
|
||||||
return &glsl_es_100_frag;
|
|
||||||
}
|
|
||||||
|
|
||||||
const InitFile *vertexShaderInit(int variant)
|
|
||||||
{
|
|
||||||
static InitFile glsl_es_100_vert{"glsl_es_100.vert"};
|
|
||||||
static InitFile glsl_120_vert{"glsl_120.vert"};
|
|
||||||
static InitFile glsl_330_vert{"glsl_330.vert"};
|
|
||||||
|
|
||||||
if (variant & GLSL::Lexer::Variant_GLSL_400)
|
|
||||||
return &glsl_330_vert;
|
|
||||||
|
|
||||||
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
|
||||||
return &glsl_120_vert;
|
|
||||||
|
|
||||||
return &glsl_es_100_vert;
|
|
||||||
}
|
|
||||||
|
|
||||||
const InitFile *shaderInit(int variant)
|
|
||||||
{
|
|
||||||
static InitFile glsl_es_100_common{"glsl_es_100_common.glsl"};
|
|
||||||
static InitFile glsl_120_common{"glsl_120_common.glsl"};
|
|
||||||
static InitFile glsl_330_common{"glsl_330_common.glsl"};
|
|
||||||
|
|
||||||
if (variant & GLSL::Lexer::Variant_GLSL_400)
|
|
||||||
return &glsl_330_common;
|
|
||||||
|
|
||||||
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
|
||||||
return &glsl_120_common;
|
|
||||||
|
|
||||||
return &glsl_es_100_common;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GlslEditorPlugin final : public ExtensionSystem::IPlugin
|
class GlslEditorPlugin final : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include <glsl/glsl.h>
|
|
||||||
|
|
||||||
namespace GlslEditor::Internal {
|
|
||||||
|
|
||||||
class InitFile
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit InitFile(const QString &m_fileName);
|
|
||||||
~InitFile();
|
|
||||||
|
|
||||||
GLSL::Engine *engine() const;
|
|
||||||
GLSL::TranslationUnitAST *ast() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initialize() const;
|
|
||||||
|
|
||||||
QString m_fileName;
|
|
||||||
mutable GLSL::Engine *m_engine = nullptr;
|
|
||||||
mutable GLSL::TranslationUnitAST *m_ast = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
const InitFile *fragmentShaderInit(int variant);
|
|
||||||
const InitFile *vertexShaderInit(int variant);
|
|
||||||
const InitFile *shaderInit(int variant);
|
|
||||||
|
|
||||||
} // GlslEditor
|
|
||||||
Reference in New Issue
Block a user