From 23a61ca92630d226cb6740ec50eb50eba377a6e4 Mon Sep 17 00:00:00 2001 From: Amr Essam Date: Mon, 4 Sep 2023 14:56:30 +0300 Subject: [PATCH] QmlDesigner: Add syntax highlighter data for shader tags Task-number: QDS-10499 Change-Id: Idbf99f1a86055085c53adaaed15af6058e39b39c Reviewed-by: Mahmoud Badri --- src/plugins/qmldesigner/CMakeLists.txt | 1 + .../effectmaker/effectmakermodel.cpp | 13 +- .../components/effectmaker/effectmakermodel.h | 4 +- .../effectmaker/syntaxhighlighterdata.cpp | 190 ++++++++++++++++++ .../effectmaker/syntaxhighlighterdata.h | 22 ++ 5 files changed, 221 insertions(+), 9 deletions(-) create mode 100644 src/plugins/qmldesigner/components/effectmaker/syntaxhighlighterdata.cpp create mode 100644 src/plugins/qmldesigner/components/effectmaker/syntaxhighlighterdata.h diff --git a/src/plugins/qmldesigner/CMakeLists.txt b/src/plugins/qmldesigner/CMakeLists.txt index cd80c894ea6..d3f6cd599f3 100644 --- a/src/plugins/qmldesigner/CMakeLists.txt +++ b/src/plugins/qmldesigner/CMakeLists.txt @@ -724,6 +724,7 @@ extend_qtc_plugin(QmlDesigner effectutils.cpp effectutils.h effectmakercontextobject.cpp effectmakercontextobject.h shaderfeatures.cpp shaderfeatures.h + syntaxhighlighterdata.cpp syntaxhighlighterdata.h ) extend_qtc_plugin(QmlDesigner diff --git a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp index 15ab784982f..176678f328f 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp +++ b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp @@ -255,13 +255,6 @@ QString EffectMakerModel::valueAsVariable(const Uniform &uniform) } } -const QString EffectMakerModel::getDefineProperties() -{ - // TODO - - return QString(); -} - const QString EffectMakerModel::getConstVariables() { const QList uniforms = allUniforms(); @@ -278,6 +271,12 @@ const QString EffectMakerModel::getConstVariables() return s; } +const QString EffectMakerModel::getDefineProperties() +{ + // TODO + return QString(); +} + int EffectMakerModel::getTagIndex(const QStringList &code, const QString &tag) { Q_UNUSED(code) diff --git a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.h b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.h index 824cfaa0470..1d00c6dda71 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.h +++ b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.h @@ -80,12 +80,12 @@ private: QString detectErrorMessage(const QString &errorMessage); EffectError effectError() const; - void setEffectError(const QString &errorMessage, int type, int lineNumber); + void setEffectError(const QString &errorMessage, int type = -1, int lineNumber = -1); void resetEffectError(int type); QString valueAsVariable(const Uniform &uniform); - const QString getDefineProperties(); const QString getConstVariables(); + const QString getDefineProperties(); int getTagIndex(const QStringList &code, const QString &tag); QString processVertexRootLine(const QString &line); QString processFragmentRootLine(const QString &line); diff --git a/src/plugins/qmldesigner/components/effectmaker/syntaxhighlighterdata.cpp b/src/plugins/qmldesigner/components/effectmaker/syntaxhighlighterdata.cpp new file mode 100644 index 00000000000..47020ed0b0f --- /dev/null +++ b/src/plugins/qmldesigner/components/effectmaker/syntaxhighlighterdata.cpp @@ -0,0 +1,190 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "syntaxhighlighterdata.h" + +namespace QmlDesigner { + +static constexpr QByteArrayView shader_arg_names[] { + { "gl_Position" }, + { "qt_MultiTexCoord0" }, + { "qt_Vertex" }, + { "qt_Matrix" }, + { "qt_Opacity" }, + { "vertCoord" }, + { "fragCoord" }, + { "texCoord" }, + { "fragColor" }, + { "iMouse" }, + { "iResolution" }, + { "iTime" }, + { "iFrame" }, + { "iSource" }, + { "iSourceBlur1" }, + { "iSourceBlur2" }, + { "iSourceBlur3" }, + { "iSourceBlur4" }, + { "iSourceBlur5" }, + { "iSourceBlur6" } +}; + +static constexpr QByteArrayView shader_tag_names[] { + { "@main" }, + { "@nodes" }, + { "@mesh" }, + { "@blursources" }, + { "@requires" } +}; + +// From https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.40.pdf +// Not including functions only available with compatibility profile +static constexpr QByteArrayView shader_function_names[] { + { "radians()" }, + { "degrees()" }, + { "sin()" }, + { "cos()" }, + { "tan()" }, + { "asin()" }, + { "acos()" }, + { "atan()" }, + { "sinh()" }, + { "cosh()" }, + { "tanh()" }, + { "asinh()" }, + { "acosh()" }, + { "atanh()" }, + { "pow()" }, + { "exp()" }, + { "log()" }, + { "exp2()" }, + { "log2()" }, + { "sqrt()" }, + { "inversesqrt()" }, + { "abs()" }, + { "sign()" }, + { "floor()" }, + { "trunc()" }, + { "round()" }, + { "roundEven()" }, + { "ceil()" }, + { "fract()" }, + { "mod()" }, + { "modf()" }, + { "min()" }, + { "max()" }, + { "clamp()" }, + { "mix()" }, + { "step()" }, + { "smoothstep()" }, + { "isnan()" }, + { "isinf()" }, + { "floatBitsToInt()" }, + { "intBitsToFloat()" }, + { "fma()" }, + { "frexp()" }, + { "ldexp()" }, + { "packUnorm2x16()" }, + { "packSnorm2x16()" }, + { "packUnorm4x8()" }, + { "packSnorm4x8()" }, + { "unpackUnorm2x16()" }, + { "unpackSnorm2x16()" }, + { "unpackUnorm4x8()" }, + { "unpackSnorm4x8()" }, + //{ "packDouble2x32()" }, // Not supported in HLSL + //{ "unpackDouble2x32()" }, + { "packHalf2x16()" }, + { "unpackHalf2x16()" }, + { "length()" }, + { "distance()" }, + { "dot()" }, + { "cross()" }, + { "normalize()" }, + { "faceforward()" }, + { "reflect()" }, + { "refract()" }, + { "matrixCompMult()" }, + { "outerProduct()" }, + { "transpose()" }, + { "determinant()" }, + { "inverse()" }, + { "lessThan()" }, + { "lessThanEqual()" }, + { "greaterThan()" }, + { "greaterThanEqual()" }, + { "equal()" }, + { "notEqual()" }, + { "any()" }, + { "all()" }, + { "not()" }, + //{ "uaddCarry()" }, // Extended arithmetic is only available from ESSL 310 + //{ "usubBorrow()" }, + //{ "umulExtended()" }, + //{ "imulExtended()" }, + { "bitfieldExtract()" }, + { "bitfieldInsert()" }, + { "bitfieldReverse()" }, + { "bitCount()" }, + { "findLSB()" }, + { "findMSB()" }, + { "textureSize()" }, + //{ "textureQueryLod()" }, // ImageQueryLod is only supported on MSL 2.2 and up. + //{ "textureQueryLevels()" }, // textureQueryLevels not supported in ES profile. + { "texture()" }, + { "textureProj()" }, + { "textureLod()" }, + { "textureOffset()" }, + { "texelFetch()" }, + { "texelFetchOffset()" }, + { "textureProjOffset()" }, + { "textureLodOffset()" }, + { "textureProjLod()" }, + { "textureProjLodOffset()" }, + { "textureGrad()" }, + { "textureGradOffset()" }, + { "textureProjGrad()" }, + { "textureProjGradOffset()" }, + //{ "textureGather()" }, // textureGather requires ESSL 310. + //{ "textureGatherOffset()" }, + //{ "textureGatherOffsets()" }, + //{ "atomicCounterIncrement()" }, // 'atomic counter types' : not allowed when using GLSL for Vulkan + //{ "atomicCounterDecrement()" }, + //{ "atomicCounter()" }, + //{ "atomicAdd()" }, // HLSL: interlocked targets must be groupshared or UAV elements + //{ "atomicMin()" }, + //{ "atomicMax()" }, + //{ "atomicAnd()" }, + //{ "atomicOr()" }, + //{ "atomicXor()" }, + //{ "atomicExchange()" }, + //{ "atomicCompSwap()" }, + { "dFdx()" }, + { "dFdy()" }, + { "fwidth()" } + //{ "interpolateAtCentroid()" }, // Pull-model interpolation requires MSL 2.3. + //{ "interpolateAtSample()" }, + //{ "interpolateAtOffset()" } +}; + +SyntaxHighlighterData::SyntaxHighlighterData() +{ +} + + +QList SyntaxHighlighterData::reservedArgumentNames() +{ + return { std::begin(shader_arg_names), std::end(shader_arg_names) }; +} + +QList SyntaxHighlighterData::reservedTagNames() +{ + return { std::begin(shader_tag_names), std::end(shader_tag_names) }; +} + +QList SyntaxHighlighterData::reservedFunctionNames() +{ + return { std::begin(shader_function_names), std::end(shader_function_names) }; +} + +} // namespace QmlDesigner + diff --git a/src/plugins/qmldesigner/components/effectmaker/syntaxhighlighterdata.h b/src/plugins/qmldesigner/components/effectmaker/syntaxhighlighterdata.h new file mode 100644 index 00000000000..6342ea094aa --- /dev/null +++ b/src/plugins/qmldesigner/components/effectmaker/syntaxhighlighterdata.h @@ -0,0 +1,22 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#pragma once + +#include +#include + +namespace QmlDesigner { + +class SyntaxHighlighterData +{ +public: + SyntaxHighlighterData(); + + static QList reservedArgumentNames(); + static QList reservedTagNames(); + static QList reservedFunctionNames(); +}; + +} // namespace QmlDesigner +