使用Visual Studio SDK制作GLSL词法着色插件

使用Visual Studio SDK制作GLSL词法着色插件


我们在Visual Studio上开发OpenGL ES项目时,避免不了写Shader。这时在vs里直接编辑shader就会显得很方便。但是vs默认是不支持GLSL的语法着色的,我们只好自己动手创造。最简单的实现自定义语法着色的方法就是创建一个VSIX插件包,我们只需要安装Visual Studio SDK,使用内置的模版就可以构建一个插件项目。

1. 安装Visual Studio SDK 


http://www.microsoft.com/en-us/download/details.aspx?id=40758下载最新的Visual Studio 2013 SDK。

双击安装,一路next即可。

安装完毕后我们可以在新建项目->模版->C#中看到“扩展性”这一条目,这些就是开发插件用的模版了。

2. 创建插件项目


新建项目,在扩展性标签中,选择Editor Classifier模版,命名为ShaderEditor,点击确定。

Visual Studio为我们生成了如下几个文件。

ShaderEditorFormat.cs文件的默认代码如下: 

复制代码
 1     [Export(typeof(EditorFormatDefinition))]
 2     [ClassificationType(ClassificationTypeNames = "ShaderEditor")]
 3     [Name("ShaderEditor")]
 4     [UserVisible(true)] //this should be visible to the end user
 5     [Order(Before = Priority.Default)] //set the priority to be after the default classifiers
 6     internal sealed class ShaderEditorFormat : ClassificationFormatDefinition {
 7         /// <summary>
 8         /// Defines the visual format for the "ShaderEditor" classification type
 9         /// </summary>
10         public ShaderEditorFormat() {
11             this.DisplayName = "ShaderEditor"; //human readable version of the name
12             this.BackgroundColor = Colors.BlueViolet;
13             this.TextDecorations = System.Windows.TextDecorations.Underline;
14         }
15     }
复制代码

 

这段代码定义了一个名为"ShaderEditor"的着色类型,编译工程并运行,我们可以在Visual Studio实验实例的工具->选项->字体和颜色中找到一个名为"ShaderEditor"的条目。同时我们会发现所有文本文件的颜色都变成了Colors.BlueViolet并带上了下划线修改this.DisplayName = "ShaderEditor"的内容,可以改变在字体和颜色中显示的名字。下面的格式设置可以任意修改成喜欢的样式,但要注意在这里的格式只是插件首次安装时的默认设置,这些条目和其它着色选项一样,都可以被用户任意更改。

3. 创建GLSL的着色类型
 

我们已经了解了如何将着色类型添加到Visual Studio,现在修改ShaderEditorFormat.cs,添加我们的着色类型。
复制代码
 1     [Export(typeof(EditorFormatDefinition))]
 2     [ClassificationType(ClassificationTypeNames = "GLSLText")]
 3     [Name("GLSLText")]
 4     [UserVisible(true)]
 5     [Order(Before = Priority.Default)]
 6     internal sealed class GLSLTextFormatDefinition : ClassificationFormatDefinition {
 7         public GLSLTextFormatDefinition() {
 8             this.DisplayName = "GLSL文本";
 9             this.ForegroundColor = Colors.Brown;
10         }
11     }
12 
13     [Export(typeof(EditorFormatDefinition))]
14     [ClassificationType(ClassificationTypeNames = "GLSLIdentifier")]
15     [Name("GLSLIdentifier")]
16     [UserVisible(true)]
17     [Order(Before = Priority.Default)]
18     internal sealed class GLSLIdentifierFormatDefinition : ClassificationFormatDefinition {
19         public GLSLIdentifierFormatDefinition() {
20             this.DisplayName = "GLSL标识符";
21             this.ForegroundColor = Colors.Brown;
22         }
23     }
24 
25     [Export(typeof(EditorFormatDefinition))]
26     [ClassificationType(ClassificationTypeNames = "GLSLComment")]
27     [Name("GLSLComment")]
28     [UserVisible(true)]
29     [Order(Before = Priority.Default)]
30     internal sealed class GLSLCommentFormatDefinition : ClassificationFormatDefinition {
31         public GLSLCommentFormatDefinition() {
32             
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值