aboutsummaryrefslogtreecommitdiff
path: root/plugins/language_glsl.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/language_glsl.lua')
-rw-r--r--plugins/language_glsl.lua484
1 files changed, 484 insertions, 0 deletions
diff --git a/plugins/language_glsl.lua b/plugins/language_glsl.lua
new file mode 100644
index 0000000..f8983d4
--- /dev/null
+++ b/plugins/language_glsl.lua
@@ -0,0 +1,484 @@
+
+local style = require "core.style"
+local common = require "core.common"
+
+style.syntax["forbiddenbuiltin"] = { common.color "#ee0000" }
+style.syntax["builtin"] = { common.color "#77eecc" }
+local syntax = require "core.syntax"
+
+syntax.add {
+ files = { "%.glsl$", "%.frag$", "%.vert$", },
+ comment = "//",
+ patterns = {
+ { pattern = "//.-\n", type = "comment" },
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+ { pattern = { "#", "[^\\]\n" }, type = "comment" },
+ { pattern = { '"', '"', '\\' }, type = "string" },
+ { pattern = { "'", "'", '\\' }, type = "string" },
+ { pattern = "-?0x%x+", type = "number" },
+ { pattern = "-?%d+[%d%.eE]*f?", type = "number" },
+ { pattern = "-?%.?%d+f?", type = "number" },
+ { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
+
+ { pattern = "int[1-9]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "int1[0-6]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "int[1-9]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "int1[0-6]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "int[1-4]", type = "forbiddenbuiltin" },
+
+ { pattern = "uint[1-9]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "uint1[0-6]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "uint[1-9]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "uint1[0-6]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "uint[1-4]", type = "forbiddenbuiltin" },
+
+ { pattern = "dword[1-9]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "dword1[0-6]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "dword[1-9]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "dword1[0-6]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "dword[1-4]", type = "forbiddenbuiltin" },
+
+ { pattern = "half[1-9]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "half1[0-6]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "half[1-9]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "half1[0-6]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "half[1-4]", type = "forbiddenbuiltin" },
+
+ { pattern = "float[1-9]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "float1[0-6]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "float[1-9]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "float1[0-6]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "float[1-4]", type = "forbiddenbuiltin" },
+
+ { pattern = "double[1-9]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "double1[0-6]x[1-9]", type = "forbiddenbuiltin" },
+ { pattern = "double[1-9]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "double1[0-6]x1[0-6]", type = "forbiddenbuiltin" },
+ { pattern = "double[1-4]", type = "forbiddenbuiltin" },
+
+ { pattern = "ivec[2-4]", type = "keyword2" },
+ { pattern = "bvec[2-4]", type = "keyword2" },
+ { pattern = "uvec[2-4]", type = "keyword2" },
+ { pattern = "vec[2-4]", type = "keyword2" },
+ { pattern = "dmat[2-4]x[2-4]", type = "keyword2" },
+ { pattern = "dmat[2-4]", type = "keyword2" },
+ { pattern = "mat[2-4]x[2-4]", type = "keyword2" },
+ { pattern = "mat[2-4]", type = "keyword2" },
+
+ { pattern = "[%a_][%w_]*%f[(]", type = "function" },
+ { pattern = "[%a_][%w_]*", type = "symbol" },
+ },
+ symbols = {
+ --https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf
+ --The symbols are added here in the order they appear in the spec
+ ["if"] = "keyword",
+ ["else"] = "keyword",
+ ["do"] = "keyword",
+ ["while"] = "keyword",
+ ["for"] = "keyword",
+ ["break"] = "keyword",
+ ["continue"] = "keyword",
+ ["return"] = "keyword",
+ ["const"] = "keyword",
+ ["switch"] = "keyword",
+ ["case"] = "keyword",
+ ["default"] = "keyword",
+ ["const"] = "keyword",
+ ["void"] = "keyword",
+ ["bool"] = "keyword2",
+ ["int"] = "keyword2",
+ ["uint"] = "keyword2",
+ ["float"] = "keyword2",
+ ["double"] = "keyword2",
+ ["true"] = "literal",
+ ["false"] = "literal",
+ ["NULL"] = "literal",
+
+ ["attribute"] = "keyword",
+ ["varying"] = "keyword",
+ ["uniform"] = "keyword",
+ ["buffer"] = "keyword",
+ ["shared"] = "keyword",
+ ["layout"] = "keyword",
+ ["centroid"] = "keyword",
+ ["flat"] = "keyword",
+ ["smooth"] = "keyword",
+ ["noperspective"]= "keyword",
+ ["patch"] = "keyword",
+ ["sample"] = "keyword",
+ ["in"] = "keyword",
+ ["out"] = "keyword",
+ ["inout"] = "keyword",
+ ["invariant"] = "keyword",
+ ["precise"] = "keyword",
+ ["lowp"] = "keyword",
+ ["mediump"] = "keyword",
+ ["highp"] = "keyword",
+ ["precision"] = "keyword",
+ ["struct"] = "keyword",
+ ["subroutine"] = "keyword",
+
+ ["coherent"] = "keyword",
+ ["volatile"] = "keyword",
+ ["readonly"] = "keyword",
+ ["writeonly"] = "keyword",
+
+ ["sampler1D"] = "keyword2",
+ ["sampler2D"] = "keyword2",
+ ["sampler3D"] = "keyword2",
+ ["samplerCube"] = "keyword2",
+ ["sampler1DShadow"] = "keyword2",
+ ["sampler2DShadow"] = "keyword2",
+ ["samplerCubeShadow"] = "keyword2",
+ ["sampler1DArray"] = "keyword2",
+ ["sampler2DArray"] = "keyword2",
+ ["samplerCubeArray"] = "keyword2",
+ ["sampler1DArrayShadow"] = "keyword2",
+ ["sampler2DArrayShadow"] = "keyword2",
+ ["samplerCubeArrayShadow"]= "keyword2",
+ ["isampler1D"] = "keyword2",
+ ["isampler2D"] = "keyword2",
+ ["isampler3D"] = "keyword2",
+ ["isamplerCube"] = "keyword2",
+ ["sampler2DMS"] = "keyword2",
+ ["isampler2DMS"] = "keyword2",
+ ["usampler2DMS"] = "keyword2",
+ ["sampler2DMSArray"] = "keyword2",
+ ["isampler2DMSArray"] = "keyword2",
+ ["usampler2DMSArray"] = "keyword2",
+ ["isampler1DArray"] = "keyword2",
+ ["isampler2DArray"] = "keyword2",
+ ["usampler1D"] = "keyword2",
+ ["usampler2D"] = "keyword2",
+ ["usampler3D"] = "keyword2",
+ ["usamplerCube"] = "keyword2",
+ ["usampler1DArray"] = "keyword2",
+ ["usampler2DArray"] = "keyword2",
+ ["sampler2DRect"] = "keyword2",
+ ["sampler2DRectShadow"] = "keyword2",
+ ["isampler2DRect"] = "keyword2",
+ ["usampler2DRect"] = "keyword2",
+ ["samplerBuffer"] = "keyword2",
+ ["isamplerBuffer"] = "keyword2",
+ ["usamplerBuffer"] = "keyword2",
+
+ ["image1D"] = "keyword2",
+ ["iimage1D"] = "keyword2",
+ ["uimage1D"] = "keyword2",
+ ["image1DArray"] = "keyword2",
+ ["iimage1DArray"] = "keyword2",
+ ["uimage1DArray"] = "keyword2",
+ ["image2D"] = "keyword2",
+ ["iimage2D"] = "keyword2",
+ ["uimage2D"] = "keyword2",
+ ["image2DArray"] = "keyword2",
+ ["iimage2DArray"] = "keyword2",
+ ["uimage2DArray"] = "keyword2",
+ ["image2DRect"] = "keyword2",
+ ["iimage2DRect"] = "keyword2",
+ ["uimage2DRect"] = "keyword2",
+ ["image2DMS"] = "keyword2",
+ ["iimage2DMS"] = "keyword2",
+ ["uimage2DMS"] = "keyword2",
+ ["image2DMSArray"] = "keyword2",
+ ["iimage2DMSArray"]= "keyword2",
+ ["uimage2DMSArray"]= "keyword2",
+ ["image3D"] = "keyword2",
+ ["iimage3D"] = "keyword2",
+ ["uimage3D"] = "keyword2",
+ ["imageCube"] = "keyword2",
+ ["iimageCube"] = "keyword2",
+ ["uimageCube"] = "keyword2",
+ ["imageCubeArray"] = "keyword2",
+ ["iimageCubeArray"]= "keyword2",
+ ["uimageCubeArray"]= "keyword2",
+ ["imageBuffer"] = "keyword2",
+ ["iimageBuffer"] = "keyword2",
+ ["uimageBuffer"] = "keyword2",
+
+ ["atomic_uint"] = "keyword2",
+
+ ["radians"] = "builtin",
+ ["degrees"] = "builtin",
+ ["sin"] = "builtin",
+ ["cos"] = "builtin",
+ ["tan"] = "builtin",
+ ["asin"] = "builtin",
+ ["acos"] = "builtin",
+ ["atan"] = "builtin",
+ ["sinh"] = "builtin",
+ ["cosh"] = "builtin",
+ ["tanh"] = "builtin",
+ ["asinh"] = "builtin",
+ ["acosh"] = "builtin",
+ ["pow"] = "builtin",
+ ["exp"] = "builtin",
+ ["exp2"] = "builtin",
+ ["log2"] = "builtin",
+ ["sqrt"] = "builtin",
+ ["inversesqrt"] = "forbiddenbuiltin",
+ ["abs"] = "builtin",
+ ["sign"] = "builtin",
+ ["floor"] = "builtin",
+ ["trunc"] = "builtin",
+ ["round"] = "builtin",
+ ["roundEven"] = "builtin",
+ ["ceil"] = "builtin",
+ ["fract"] = "builtin",
+ ["mod"] = "builtin",
+ ["modf"] = "builtin",
+ ["min"] = "builtin",
+ ["max"] = "builtin",
+ ["clamp"] = "builtin",
+ ["mix"] = "builtin",
+ ["step"] = "builtin",
+ ["smoothstep"] = "builtin",
+ ["isnan"] = "builtin",
+ ["isinf"] = "builtin",
+ ["floatBitsToInt"] = "builtin",
+ ["floatBitsToUint"] = "builtin",
+ ["intBitsToFloat"] = "builtin",
+ ["uintBitsToFloat"] = "builtin",
+ ["fma"] = "builtin",
+ ["frexp"] = "builtin",
+ ["ldexp"] = "builtin",
+ ["packUnorm2x16"] = "builtin",
+ ["packSnorm2x16"] = "builtin",
+ ["packUnorm4x8"] = "builtin",
+ ["packSnorm4x8"] = "builtin",
+ ["unpackUnorm2x16"] = "builtin",
+ ["unpackSnorm2x16"] = "builtin",
+ ["unpackUnorm4x8"] = "builtin",
+ ["unpackSnorm4x8"] = "builtin",
+ ["packHalf2x16"] = "builtin",
+ ["unpackHalf2x16"] = "builtin",
+ ["packDouble2x32"] = "builtin",
+ ["unpackDouble2x32"] = "builtin",
+ ["length"] = "builtin",
+ ["distance"] = "builtin",
+ ["dot"] = "builtin",
+ ["cross"] = "builtin",
+ ["normalize"] = "builtin",
+ ["ftransform"] = "builtin",
+ ["faceforward"] = "builtin",
+ ["reflect"] = "builtin",
+ ["refract"] = "builtin",
+ ["matrixCompMult"] = "builtin",
+ ["outerProduct"] = "builtin",
+ ["transpose"] = "builtin",
+ ["determinant"] = "builtin",
+ ["inverse"] = "builtin",
+ ["lessThan"] = "builtin",
+ ["lessThanEqual"] = "builtin",
+ ["greaterThan"] = "builtin",
+ ["greaterThanEqual"] = "builtin",
+ ["equal"] = "builtin",
+ ["notEqual"] = "builtin",
+ ["any"] = "builtin",
+ ["all"] = "builtin",
+ ["not"] = "builtin",
+ ["uaddCarry"] = "builtin",
+ ["usubBorrow"] = "builtin",
+ ["umulExtended"] = "builtin",
+ ["imulExtended"] = "builtin",
+ ["bitfieldExtract"] = "builtin",
+ ["bitfieldInsert"] = "builtin",
+ ["bitfieldReverse"] = "builtin",
+ ["bitCount"] = "builtin",
+ ["findLSB"] = "builtin",
+ ["findMSB"] = "builtin",
+ ["textureSize"] = "builtin",
+ ["textureQueryLod"] = "builtin",
+ ["textureQueryLevels"] = "builtin",
+ ["textureSamples"] = "builtin",
+ ["texture"] = "builtin",
+ ["textureProj"] = "builtin",
+ ["textureLod"] = "builtin",
+ ["textureOffset"] = "builtin",
+ ["texelFetch"] = "builtin",
+ ["texelFetchOffset"] = "builtin",
+ ["textureProjOffset"] = "builtin",
+ ["textureLodOffset"] = "builtin",
+ ["textureProjLod"] = "builtin",
+ ["textureProjLodOffset"] = "builtin",
+ ["textureGrad"] = "builtin",
+ ["textureGradOffset"] = "builtin",
+ ["textureProjGrad"] = "builtin",
+ ["textureProjGradOffset"]= "builtin",
+ ["textureGather"] = "builtin",
+ ["textureGatherOffset"] = "builtin",
+ ["textureGatherOffsets"] = "builtin",
+
+ --Atomic Counter Functions
+ ["atomicCounterIncrement"]= "builtin",
+ ["atomicCounterDecrement"]= "builtin",
+ ["atomicCounter"] = "builtin",
+ ["atomicCounterAdd"] = "builtin",
+ ["atomicCounterSubtract"] = "builtin",
+ ["atomicCounterMin"] = "builtin",
+ ["atomicCounterMax"] = "builtin",
+ ["atomicCounterAnd"] = "builtin",
+ ["atomicCounterOr"] = "builtin",
+ ["atomicCounterXor"] = "builtin",
+ ["atomicCounterExchange"] = "builtin",
+ ["atomicCounterCompSwap"] = "builtin",
+ --Atomic Memory Functions
+ ["atomicAdd"] = "builtin",
+ ["atomicMin"] = "builtin",
+ ["atomicMax"] = "builtin",
+ ["atomicAnd"] = "builtin",
+ ["atomicOr"] = "builtin",
+ ["atomicXor"] = "builtin",
+ ["atomicExchange"]= "builtin",
+ ["atomicCompSwap"]= "builtin",
+ --Image Functions
+ ["imageSize"] = "builtin",
+ ["imageSamples"] = "builtin",
+ ["imageLoad"] = "builtin",
+ ["imageStore"] = "builtin",
+ ["imageAtomicAdd"] = "builtin",
+ ["imageAtomicMin"] = "builtin",
+ ["imageAtomicMax"] = "builtin",
+ ["imageAtomicAnd"] = "builtin",
+ ["imageAtomicOr"] = "builtin",
+ ["imageAtomicXor"] = "builtin",
+ ["imageAtomicExchange"]= "builtin",
+ ["imageAtomicCompSwap"]= "builtin",
+ --Geometry Shader Functions
+ ["EmitStreamVertex"] = "builtin",
+ ["EndStreamPrimitive"] = "builtin",
+ ["EmitVertex"] = "builtin",
+ ["EndPrimitive"] = "builtin",
+ --Fragment Processing Functions
+ ["dFdx"] = "builtin",
+ ["dFdy"] = "builtin",
+ ["dFdxFine"] = "builtin",
+ ["dFdyFine"] = "builtin",
+ ["dFdxCoarse"] = "builtin",
+ ["dFdyCoarse"] = "builtin",
+ ["fwidth"] = "builtin",
+ ["fwidthFine"] = "builtin",
+ ["fwidthCoarse"] = "builtin",
+ ["interpolateAtCentroid"]= "builtin",
+ ["interpolateAtSample"] = "builtin",
+ ["interpolateAtOffset"] = "builtin",
+ --Shader Invocation Control Functions
+ ["barrier"] = "builtin",
+ --Shader Memory Control Functions
+ ["memoryBarrier"] = "builtin",
+ ["memoryBarrierAtomicCounter"]= "builtin",
+ ["memoryBarrierBuffer"] = "builtin",
+ ["memoryBarrierShared"] = "builtin",
+ ["memoryBarrierImage"] = "builtin",
+ ["groupMemoryBarrier"] = "builtin",
+ --Subpass-Input Functions
+ ["subpassLoad"] = "builtin",
+ --Shader Invocation Group Functions
+ ["anyInvocation"] = "builtin",
+ ["allInvocations"] = "builtin",
+ ["allInvocationsEqual"]= "builtin",
+
+ --"In addition, when targeting Vulkan, the following keywords also exist:"
+ ["texture1D"] = "builtin",
+ ["texture1DArray"] = "builtin",
+ ["itexture1D"] = "builtin",
+ ["itexture1DArray"] = "builtin",
+ ["utexture1D"] = "builtin",
+ ["utexture1DArray"] = "builtin",
+ ["texture2D"] = "builtin",
+ ["texture2DArray"] = "builtin",
+ ["itexture2D"] = "builtin",
+ ["itexture2DArray"] = "builtin",
+ ["utexture2D"] = "builtin",
+ ["utexture2DArray"] = "builtin",
+ ["texture2DRect"] = "builtin",
+ ["itexture2DRect"] = "builtin",
+ ["utexture2DRect"] = "builtin",
+ ["texture2DMS"] = "builtin",
+ ["itexture2DMS"] = "builtin",
+ ["utexture2DMS"] = "builtin",
+ ["texture2DMSArray"] = "builtin",
+ ["itexture2DMSArray"]= "builtin",
+ ["utexture2DMSArray"]= "builtin",
+ ["texture3D"] = "builtin",
+ ["itexture3D"] = "builtin",
+ ["utexture3D"] = "builtin",
+ ["textureCube"] = "builtin",
+ ["itextureCube"] = "builtin",
+ ["utextureCube"] = "builtin",
+ ["textureCubeArray"] = "builtin",
+ ["itextureCubeArray"]= "builtin",
+ ["utextureCubeArray"]= "builtin",
+ ["textureBuffer"] = "builtin",
+ ["itextureBuffer"] = "builtin",
+ ["utextureBuffer"] = "builtin",
+ ["sampler"] = "keyword2",
+ ["samplerShadow"] = "keyword2",
+ ["subpassInput"] = "keyword2",
+ ["isubpassInput"] = "keyword2",
+ ["usubpassInput"] = "keyword2",
+ ["subpassInputMS"] = "keyword2",
+ ["isubpassInputMS"] = "keyword2",
+ ["usubpassInputMS"] = "keyword2",
+
+ --"The following are the keywords reserved for future use. Using them will result in a compile-time error:"
+ ["common"] = "forbiddenbuiltin",
+ ["partition"] = "forbiddenbuiltin",
+ ["active"] = "forbiddenbuiltin",
+ ["asm"] = "forbiddenbuiltin",
+ ["class"] = "forbiddenbuiltin",
+ ["union"] = "forbiddenbuiltin",
+ ["enum"] = "forbiddenbuiltin",
+ ["typedef"] = "forbiddenbuiltin",
+ ["template"] = "forbiddenbuiltin",
+ ["this"] = "forbiddenbuiltin",
+ ["resource"] = "forbiddenbuiltin",
+ ["goto"] = "forbiddenbuiltin",
+ ["inline"] = "forbiddenbuiltin",
+ ["noinline"] = "forbiddenbuiltin",
+ ["public"] = "forbiddenbuiltin",
+ ["static"] = "forbiddenbuiltin",
+ ["extern"] = "forbiddenbuiltin",
+ ["external"] = "forbiddenbuiltin",
+ ["interface"] = "forbiddenbuiltin",
+ ["long"] = "forbiddenbuiltin",
+ ["short"] = "forbiddenbuiltin",
+ ["half"] = "forbiddenbuiltin",
+ ["fixed"] = "forbiddenbuiltin",
+ ["unsigned"] = "forbiddenbuiltin",
+ ["superp"] = "forbiddenbuiltin",
+ ["input"] = "forbiddenbuiltin",
+ ["output"] = "forbiddenbuiltin",
+ ["hvec2"] = "forbiddenbuiltin",
+ ["hvec3"] = "forbiddenbuiltin",
+ ["hvec4"] = "forbiddenbuiltin",
+ ["fvec2"] = "forbiddenbuiltin",
+ ["fvec3"] = "forbiddenbuiltin",
+ ["fvec4"] = "forbiddenbuiltin",
+ ["filter"] = "forbiddenbuiltin",
+ ["sizeof"] = "forbiddenbuiltin",
+ ["cast"] = "forbiddenbuiltin",
+ ["namespace"] = "forbiddenbuiltin",
+ ["using"] = "forbiddenbuiltin",
+ ["sampler3DRect"]= "forbiddenbuiltin",
+
+ --common symbols in HLSL that don't exist in GLSL
+ ["frac"] = "forbiddenbuiltin",
+ ["lerp"] = "forbiddenbuiltin",
+ ["mul"] = "forbiddenbuiltin",
+ ["min16float"] = "forbiddenbuiltin",
+ ["min10float"] = "forbiddenbuiltin",
+ ["min16int"] = "forbiddenbuiltin",
+ ["min12int"] = "forbiddenbuiltin",
+ ["min16uint"] = "forbiddenbuiltin",
+ ["rsqrt"] = "forbiddenbuiltin",
+ ["ddx"] = "forbiddenbuiltin",
+ ["ddx_coarse"] = "forbiddenbuiltin",
+ ["ddx_fine"] = "forbiddenbuiltin",
+ ["ddy"] = "forbiddenbuiltin",
+ ["ddy_coarse"] = "forbiddenbuiltin",
+ ["ddy_fine"] = "forbiddenbuiltin",
+
+ },
+}
+