From e117f04fabde000f4c0aae7cc1a82c58da1ba4c3 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Wed, 1 Dec 2010 15:44:50 +1000 Subject: [PATCH] Show different icons for GLSL variable categories Attributes, uniforms, varyings, and constants are shown with a distinguished icon that is different from regular variables. --- src/libs/glsl/glslengine.cpp | 3 +- src/libs/glsl/glslengine.h | 2 +- src/libs/glsl/glslsemantic.cpp | 6 +++- src/libs/glsl/glslsymbols.cpp | 1 + src/libs/glsl/glslsymbols.h | 4 +++ src/plugins/glsleditor/glslcodecompletion.cpp | 26 +++++++++++++++--- src/plugins/glsleditor/glslcodecompletion.h | 4 +++ src/plugins/glsleditor/glsleditor.qrc | 4 +++ src/plugins/glsleditor/images/attribute.png | Bin 0 -> 583 bytes src/plugins/glsleditor/images/const.png | Bin 0 -> 478 bytes src/plugins/glsleditor/images/uniform.png | Bin 0 -> 583 bytes src/plugins/glsleditor/images/varying.png | Bin 0 -> 585 bytes 12 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 src/plugins/glsleditor/images/attribute.png create mode 100644 src/plugins/glsleditor/images/const.png create mode 100644 src/plugins/glsleditor/images/uniform.png create mode 100644 src/plugins/glsleditor/images/varying.png diff --git a/src/libs/glsl/glslengine.cpp b/src/libs/glsl/glslengine.cpp index 73938e947e..2b6ec6e039 100644 --- a/src/libs/glsl/glslengine.cpp +++ b/src/libs/glsl/glslengine.cpp @@ -266,11 +266,12 @@ Argument *Engine::newArgument(Function *function, const QString &name, const Typ return a; } -Variable *Engine::newVariable(Scope *scope, const QString &name, const Type *type) +Variable *Engine::newVariable(Scope *scope, const QString &name, const Type *type, int qualifiers) { Variable *var = new Variable(scope); var->setName(name); var->setType(type); + var->setQualifiers(qualifiers); _symbols.append(var); return var; } diff --git a/src/libs/glsl/glslengine.h b/src/libs/glsl/glslengine.h index ab73debf9e..2d668ba37f 100644 --- a/src/libs/glsl/glslengine.h +++ b/src/libs/glsl/glslengine.h @@ -120,7 +120,7 @@ public: Block *newBlock(Scope *scope = 0); Function *newFunction(Scope *scope = 0); Argument *newArgument(Function *function, const QString &name, const Type *type); - Variable *newVariable(Scope *scope, const QString &name, const Type *type); + Variable *newVariable(Scope *scope, const QString &name, const Type *type, int qualifiers = 0); MemoryPool *pool(); diff --git a/src/libs/glsl/glslsemantic.cpp b/src/libs/glsl/glslsemantic.cpp index 29760e2eec..ac07911ea5 100644 --- a/src/libs/glsl/glslsemantic.cpp +++ b/src/libs/glsl/glslsemantic.cpp @@ -751,7 +751,11 @@ bool Semantic::visit(VariableDeclarationAST *ast) const Type *ty = type(ast->type); ExprResult initializer = expression(ast->initializer); if (ast->name) { - Variable *var = _engine->newVariable(_scope, *ast->name, ty); + QualifiedTypeAST *qtype = ast->type->asQualifiedType(); + int qualifiers = 0; + if (qtype) + qualifiers = qtype->qualifiers; + Variable *var = _engine->newVariable(_scope, *ast->name, ty, qualifiers); _scope->add(var); } return false; diff --git a/src/libs/glsl/glslsymbols.cpp b/src/libs/glsl/glslsymbols.cpp index e4ede5f6c5..2160862917 100644 --- a/src/libs/glsl/glslsymbols.cpp +++ b/src/libs/glsl/glslsymbols.cpp @@ -78,6 +78,7 @@ Symbol *Block::find(const QString &name) const Variable::Variable(Scope *scope) : Symbol(scope) , _type(0) + , _qualifiers(0) { } diff --git a/src/libs/glsl/glslsymbols.h b/src/libs/glsl/glslsymbols.h index 6506c62fa7..bf610dd3a2 100644 --- a/src/libs/glsl/glslsymbols.h +++ b/src/libs/glsl/glslsymbols.h @@ -59,10 +59,14 @@ public: virtual const Type *type() const; void setType(const Type *type); + int qualifiers() const { return _qualifiers; } + void setQualifiers(int qualifiers) { _qualifiers = qualifiers; } + virtual Variable *asVariable() { return this; } private: const Type *_type; + int _qualifiers; }; class GLSL_EXPORT Block: public Scope diff --git a/src/plugins/glsleditor/glslcodecompletion.cpp b/src/plugins/glsleditor/glslcodecompletion.cpp index ff89180275..042f4c8a77 100644 --- a/src/plugins/glsleditor/glslcodecompletion.cpp +++ b/src/plugins/glsleditor/glslcodecompletion.cpp @@ -492,6 +492,10 @@ CodeCompletion::CodeCompletion(QObject *parent) m_varIcon(":/glsleditor/images/var.png"), m_functionIcon(":/glsleditor/images/func.png"), m_typeIcon(":/glsleditor/images/type.png"), + m_constIcon(":/glsleditor/images/const.png"), + m_attributeIcon(":/glsleditor/images/attribute.png"), + m_uniformIcon(":/glsleditor/images/uniform.png"), + m_varyingIcon(":/glsleditor/images/varying.png"), m_otherIcon(":/glsleditor/images/other.png") { const QIcon keywordIcon(QLatin1String(":/glsleditor/images/keyword.png")); @@ -678,14 +682,28 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor) foreach (GLSL::Symbol *s, members) { TextEditor::CompletionItem item(this); - if (s->asVariable() || s->asArgument()) + GLSL::Variable *var = s->asVariable(); + if (var) { + int storageType = var->qualifiers() & GLSL::QualifiedTypeAST::StorageMask; + if (storageType == GLSL::QualifiedTypeAST::Attribute) + item.icon = m_attributeIcon; + else if (storageType == GLSL::QualifiedTypeAST::Uniform) + item.icon = m_uniformIcon; + else if (storageType == GLSL::QualifiedTypeAST::Varying) + item.icon = m_varyingIcon; + else if (storageType == GLSL::QualifiedTypeAST::Const) + item.icon = m_constIcon; + else + item.icon = m_varIcon; + } else if (s->asArgument()) { item.icon = m_varIcon; - else if (s->asFunction() || s->asOverloadSet()) + } else if (s->asFunction() || s->asOverloadSet()) { item.icon = m_functionIcon; - else if (s->asStruct()) + } else if (s->asStruct()) { item.icon = m_typeIcon; - else + } else { item.icon = m_otherIcon; + } item.text = s->name(); if (specialMembers.contains(item.text)) item.order = SpecialMemberOrder; diff --git a/src/plugins/glsleditor/glslcodecompletion.h b/src/plugins/glsleditor/glslcodecompletion.h index f8110bcffc..7eb3796e46 100644 --- a/src/plugins/glsleditor/glslcodecompletion.h +++ b/src/plugins/glsleditor/glslcodecompletion.h @@ -110,6 +110,10 @@ private: QIcon m_varIcon; QIcon m_functionIcon; QIcon m_typeIcon; + QIcon m_constIcon; + QIcon m_attributeIcon; + QIcon m_uniformIcon; + QIcon m_varyingIcon; QIcon m_otherIcon; }; diff --git a/src/plugins/glsleditor/glsleditor.qrc b/src/plugins/glsleditor/glsleditor.qrc index 4003791125..3455048e00 100644 --- a/src/plugins/glsleditor/glsleditor.qrc +++ b/src/plugins/glsleditor/glsleditor.qrc @@ -6,6 +6,10 @@ images/var.png images/func.png images/type.png + images/const.png + images/attribute.png + images/uniform.png + images/varying.png images/other.png diff --git a/src/plugins/glsleditor/images/attribute.png b/src/plugins/glsleditor/images/attribute.png new file mode 100644 index 0000000000000000000000000000000000000000..94f20ac42ac8b268d0d962e9e0ab86b1a518ae00 GIT binary patch literal 583 zcmV-N0=WH&P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ign) z1tuW;Mt+I_00GBIL_t(I%cau4Yg1tq#_{iaa|2g2tys8$=q8GTCLiGRj$JxAT2N3bk%T5xqBcUbP11Ys`{O3LuR|pyF-Z%a^?g6j zfpd;%ciQ|q+@qwR>#XfT!boczVPv)Sjbo=m3FVj1wa z8_>n~W*-SJ?Q!$L)yb6GAL48Wm#YOL9dcyKD@m8g-C~#eiSKH z3jA8D(cEZKT&M;%VZt5N`R55j*$&b zWpS;GyLXWGoczp zp^Gl+6bg#7V=CCeDU=Lu;?NKxPMrkpCdDDp-P!77!NtkN&8bBboC;|kzx^*wjBPrU z9vqi@efP+J0%Huzkd#*HN5bt`s0-w`q$z`XbC;1Hh7mI^gM{mvrAnE&d@MFeqF^rl z=sTD&*QZAy@YYMJA zaoBria#8%i$=(nc{*9nomX)yvmdG^MYBgZ=1i0Sp27prvY3M_i4a8*JC`Ol3Rmz8dHB9h%&GZcquw6SJAk4n%ynJjs3>FSD3Uy70m&`B z!5qh7wrw*WpYD`8;K-imVO!VHFa>-un<}jeCVqrg{Q4rZP*cW|_(ERVHEp!*C| zDmduMc!P|4fJTh>F$2J>bAWQWoV3>O_faa95}gCgJEoSVX$u`tS`n5#=U)K^0GRmy Up4egnY5)KL07*qoM6N<$g7BW!SpWb4 literal 0 HcmV?d00001 diff --git a/src/plugins/glsleditor/images/uniform.png b/src/plugins/glsleditor/images/uniform.png new file mode 100644 index 0000000000000000000000000000000000000000..c6452fc8c6ffe14c756a9423241df93ce34d361b GIT binary patch literal 583 zcmV-N0=WH&P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ign) z1t$#Gg(D~c00GBIL_t(I%casyYZFlv#_|81Ok_mUf`tU)(wCJ`5Zwt<3KrceMse4T znol5#_!ZoVd+EZZF07j_Q?X#JMp`sPTH-8%=}a<{`!dPQxDY}TleXa5-urtFoO49n zkNKan0g5M2AM|I=v7Bm>#>bf&5Ve2Kdgi zlE^w)9^ZX3n-%s*h;#93E6at2dkf;-%T;6`k)gzBgH{@244(1W*#9_!2LW-~KQVuGUaY-ZLraa4`fqoo zF-Fsh_Sy74{ey?Mkk1OcR=QBi2_cYDp_NAU6zyJ{&)()lJif-fE$rG-aVeLkDXJ%F z_u6dvTT}6*JIH6SYL`x3&Y8sU)&FuJo_0w23|1{A%_O7;;=vHdstL>_q{YK9z#o(4 V51>&N1p)v7002ovPDHLkV1i;o3Hty5 literal 0 HcmV?d00001 diff --git a/src/plugins/glsleditor/images/varying.png b/src/plugins/glsleditor/images/varying.png new file mode 100644 index 0000000000000000000000000000000000000000..c2551c002577c415d539876c0c1e690319ca74d6 GIT binary patch literal 585 zcmV-P0=E5$P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ign) z1t=b)q)x8@00GHKL_t(I%cau2Yg17e$MNsExiJw<3oYD097P=z1kp)Bq~Hr~3I>s) zb`iU|2_pUrZsI72U>64mJ9X27f?A0rt--#i8A98<+?(@~?y$<&Za);?mp@SY@r~7D4!>SSDT&dVKsEtlK*k+}uTI|=iwkpX ztQ81?I!ZRsT4A)NQdhkDyeXrILqN&x#&@Qt(wDB>6|Y}D#`h~|rBF(uWP@h2N!8aZ zE^T#iXAhDICpVKllRkIxhM0f#6xr~RGQb#(RtjSbmAc`5Zo3C}0@|V7cl_j8vGC?O zT1&K&Xsysnp^ag?*5qTp@(=Ewg6F!Tn7w=~C4@jJ`RDt(MJ;IYsW2G#kI{2uqIltS zCS|Qf{>4kn)uDLM9(ayJ@zl|YlxanLSs9IoEt2Or6s;v@?P%O-V&5qPW7d+{2?P8F X)U6L$N{A!V00000NkvXXu0mjfor(r2 literal 0 HcmV?d00001 -- GitLab