-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathob-glsl.el
More file actions
39 lines (34 loc) · 1.45 KB
/
ob-glsl.el
File metadata and controls
39 lines (34 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(require 'ob)
(require 'ob-glsl-module)
(defvar org-babel-default-header-args:glsl
'((:results . "file") (:exports . "results"))
"Default arguments to use when evaluating a glsl source block.")
(defun org-babel-expand-body:glsl (body params)
"Expand BODY according to PARAMS, return the expanded body."
(concat
"#version 330 core\n"
"out vec4 fragColor;\n"
"uniform vec2 iResolution;\n"
body))
(defun org-babel-execute:glsl (body params)
"Execute a block of glsl code with org-babel.
This function is called by `org-babel-execute-src-block'."
(let ((out-file (org-babel-process-file-name
(cdr (or (assq :file params)
(error "You need to specify a :file parameter")))
t))
(glsl-code (org-babel-expand-body:glsl body params))
(render-width (cdr (assq :width params)))
(render-height (cdr (assq :height params))))
(if (and (not render-width) render-height)
(setq render-width (* 4 (/ render-height 3))))
(if (and (not render-height) render-width)
(setq render-height (* 3 (/ render-width 4))))
(if (and (not render-width) (not render-height))
(setq render-width 400 render-height 300))
(ob-glsl-run glsl-code render-width render-height out-file)
nil))
(defun org-babel-prep-session:shady (_session _params)
"Return an error because glsl does not support sessions."
(error "glsl does not support sessions"))
(provide 'ob-glsl)