Browse code

Add editor integrations

Robert Cranston authored on 23/12/2021 11:25:37
Showing 1 changed files
... ...
@@ -68,6 +68,54 @@ options:
68 68
     Print the generated code that is passed to the compiler.
69 69
 ```
70 70
 
71
+### Editor integrations
72
+
73
+#### Vim
74
+
75
+Add the following [Vimscript][] to `.vimrc`:
76
+
77
+```vimscript
78
+autocmd FileType glsl
79
+\ set makeprg=glslrun
80
+```
81
+
82
+[`:make`][] (or [`:Dispatch`][]) runs this configured `makeprg`.
83
+
84
+`:copen` opens the quickfix list.
85
+
86
+[Vimscript]: https://en.wikipedia.org/wiki/Vim_(text_editor)#Vim_script
87
+[`:make`]: https://vimhelp.org/quickfix.txt.html#:make
88
+[`:Dispatch`]: https://github.com/tpope/vim-dispatch
89
+
90
+#### Visual Studio Code
91
+
92
+Add the following [JSON][] task to `.vscode/tasks.json`:
93
+
94
+```json
95
+{
96
+    "version": "2.0.0",
97
+    "tasks": [
98
+        {
99
+            "label": "glslrun",
100
+            "type": "process",
101
+            "command": "glslrun",
102
+            "args": [ "${file}" ],
103
+            "problemMatcher": "$gcc"
104
+        }
105
+    ]
106
+}
107
+```
108
+
109
+<kbd>Ctrl</kbd><kbd>P</kbd> opens the Command Palette in which `task glslrun`
110
+can be typed.
111
+
112
+<kbd>Ctrl</kbd><kbd>Shift</kbd><kbd>\`</kbd> opens the terminal output.
113
+
114
+<kbd>Ctrl</kbd><kbd>Shift</kbd><kbd>M</kbd> opens the list of problems.
115
+
116
+[JSON]: https://en.wikipedia.org/wiki/JSON
117
+[launch configuration]: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
118
+
71 119
 ## Dependencies
72 120
 
73 121
 For compiling C++:
... ...
@@ -96,6 +144,12 @@ systems have some version), and are highly likely to be installed by default
96 144
 [`sed`]: https://packages.debian.org/sed
97 145
 [`mawk`]: https://packages.debian.org/mawk
98 146
 
147
+## Example
148
+
149
+```glsl
150
+TODO
151
+```
152
+
99 153
 ## License
100 154
 
101 155
 Licensed under the [ISC License][] unless otherwise noted, see the
Browse code

Add implementation

Robert Cranston authored on 21/12/2021 09:34:56
Showing 1 changed files
... ...
@@ -2,8 +2,44 @@
2 2
 
3 3
 Run [GLSL][] code on the CPU.
4 4
 
5
+Generates a wrapper file including some [C++][] standard library functionality
6
+and [OpenGL Mathematics (GLM)][], compiles it with the systems C++ compiler (by
7
+default [`gcc`][], can be changed by setting the [environment variable][]
8
+`CXX`) and runs the result.
9
+
10
+This, of course, does not *really* run GLSL code on the CPU. For an actual GLSL
11
+compiler (but not to something that can run on the CPU), see [`glslang`][].
12
+
13
+The wapper does the following:
14
+
15
+-   C++ standard library
16
+    -   Brings the `std` namespace into global scope.
17
+    -   `#include`s [`cassert`][] for testing.
18
+    -   `#include`s [`iostream`][] for printing.
19
+-   GLM
20
+    -   Brings the `glm` namespace into global scope.
21
+    -   `#define`s `GLM_FORCE_SWIZZLE` to enable [swizzling][] support.
22
+    -   `#include`s [`glm/gtx/io.hpp`][] to enable [`iostream`][] support.
23
+-   Other
24
+    -   `#define`s `GLSLRUN`.
25
+    -   Defines [built-in variable][]s (like [`gl_Position`][]).
26
+    -   Defines [built-in function][]s (like [`EmitVertex`][]).
27
+
5 28
 [`glslrun`]: https://git.rcrnstn.net/rcrnstn/glslrun
6 29
 [GLSL]: https://en.wikipedia.org/wiki/OpenGL_Shading_Language
30
+[C++]: https://en.wikipedia.org/wiki/C++
31
+[OpenGL Mathematics (GLM)]: https://glm.g-truc.net
32
+[`gcc`]: https://gcc.gnu.org
33
+[environment variable]: https://en.wikipedia.org/wiki/Environment_variable
34
+[`glslang`]: https://github.com/KhronosGroup/glslang
35
+[`cassert`]: https://en.cppreference.com/w/cpp/header/cassert
36
+[`iostream`]: https://en.cppreference.com/w/cpp/header/iostream
37
+[swizzling]: https://en.wikipedia.org/wiki/Swizzling_(computer_graphics)
38
+[`glm/gtx/io.hpp`]: http://glm.g-truc.net/0.9.9/api/a00332.html
39
+[built-in variable]: https://www.khronos.org/opengl/wiki/Built-in_Variable_(GLSL)
40
+[`gl_Position`]: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_Position.xhtml
41
+[built-in function]: https://www.khronos.org/opengl/wiki/Built-in_Function_(GLSL)
42
+[`EmitVertex`]: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/EmitVertex.xhtml
7 43
 
8 44
 ## Usage
9 45
 
... ...
@@ -21,7 +57,8 @@ usage:
21 57
 
22 58
 arguments:
23 59
   <file>
24
-    File containing code to run. Specify - to read from stdin instead.
60
+    File containing code to run. If <file> is omitted or -, to read from
61
+    stdin instead.
25 62
 
26 63
 options:
27 64
   -m, --main
... ...
@@ -33,16 +70,28 @@ options:
33 70
 
34 71
 ## Dependencies
35 72
 
36
-All dependencies are [POSIX][] and are highly likely to be installed by default
73
+For compiling C++:
74
+
75
+-   C++ compiler (e.g. from [`g++`][])
76
+-   C++ standard library (e.g. from [`libstdc++`][])
77
+-   OpenGL Mathematics (GLM) (e.g. from [`libglm-dev`][])
78
+
79
+All other dependencies are [POSIX][] (except `mktemp`, but most Unix-like
80
+systems have some version), and are highly likely to be installed by default
37 81
 (e.g. they all have the [Debian priority][] `required`).
38 82
 
39 83
 -   `sh` (e.g. from [`bash`][] or [`dash`][])
84
+-   `rm`, `cat`, `mktemp` (e.g. from [`coreutils`][])
40 85
 -   `sed` (e.g. from [`sed`][])
41 86
 -   `awk` (e.g. from [`mawk`][])
42 87
 
88
+[`g++`]: https://packages.debian.org/g++
89
+[`libstdc++`]: https://packages.debian.org/libstdc++
90
+[`libglm-dev`]: https://packages.debian.org/libglm-dev
43 91
 [POSIX]: https://en.wikipedia.org/wiki/POSIX
44 92
 [Debian priority]: https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities
45 93
 [`bash`]: https://packages.debian.org/bash
94
+[`coreutils`]: https://packages.debian.org/coreutils
46 95
 [`dash`]: https://packages.debian.org/dash
47 96
 [`sed`]: https://packages.debian.org/sed
48 97
 [`mawk`]: https://packages.debian.org/mawk
Browse code

Add argument parsing

Robert Cranston authored on 21/12/2021 09:19:37
Showing 1 changed files
... ...
@@ -5,6 +5,48 @@ Run [GLSL][] code on the CPU.
5 5
 [`glslrun`]: https://git.rcrnstn.net/rcrnstn/glslrun
6 6
 [GLSL]: https://en.wikipedia.org/wiki/OpenGL_Shading_Language
7 7
 
8
+## Usage
9
+
10
+`glslrun --help`:
11
+
12
+```
13
+glslrun 1.0
14
+
15
+Run GLSL code snippets on the CPU.
16
+
17
+usage:
18
+  glslrun [options] [--] [<file>]
19
+  glslrun -h|--help
20
+  glslrun --version
21
+
22
+arguments:
23
+  <file>
24
+    File containing code to run. Specify - to read from stdin instead.
25
+
26
+options:
27
+  -m, --main
28
+    Generate an enclosing main() function.
29
+
30
+  -p, --print
31
+    Print the generated code that is passed to the compiler.
32
+```
33
+
34
+## Dependencies
35
+
36
+All dependencies are [POSIX][] and are highly likely to be installed by default
37
+(e.g. they all have the [Debian priority][] `required`).
38
+
39
+-   `sh` (e.g. from [`bash`][] or [`dash`][])
40
+-   `sed` (e.g. from [`sed`][])
41
+-   `awk` (e.g. from [`mawk`][])
42
+
43
+[POSIX]: https://en.wikipedia.org/wiki/POSIX
44
+[Debian priority]: https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities
45
+[`bash`]: https://packages.debian.org/bash
46
+[`dash`]: https://packages.debian.org/dash
47
+[`sed`]: https://packages.debian.org/sed
48
+[`mawk`]: https://packages.debian.org/mawk
49
+
8 50
 ## License
9 51
 
10 52
 Licensed under the [ISC License][] unless otherwise noted, see the
Browse code

Add license

Robert Cranston authored on 21/12/2021 08:17:50
Showing 1 changed files
... ...
@@ -4,3 +4,10 @@ Run [GLSL][] code on the CPU.
4 4
 
5 5
 [`glslrun`]: https://git.rcrnstn.net/rcrnstn/glslrun
6 6
 [GLSL]: https://en.wikipedia.org/wiki/OpenGL_Shading_Language
7
+
8
+## License
9
+
10
+Licensed under the [ISC License][] unless otherwise noted, see the
11
+[`LICENSE`](LICENSE) file.
12
+
13
+[ISC License]: https://choosealicense.com/licenses/isc/
Browse code

Add readme

Robert Cranston authored on 21/12/2021 08:16:11
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+# [`glslrun`][]
2
+
3
+Run [GLSL][] code on the CPU.
4
+
5
+[`glslrun`]: https://git.rcrnstn.net/rcrnstn/glslrun
6
+[GLSL]: https://en.wikipedia.org/wiki/OpenGL_Shading_Language