diff options
author | Colin Okay <colin@cicadas.surf> | 2022-06-29 11:54:24 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-06-29 11:54:24 -0500 |
commit | 82f71b0d13788b1cff9a24c5b652effd11631523 (patch) | |
tree | f0ec127b2f10f46029983ee95b6c72ef29bc504c /src/gl/shader.lisp | |
parent | 4d1ee56c96ce254134b692f0e3b3271c87a42b54 (diff) |
[refactor] [structure] modularized project file structure
Diffstat (limited to 'src/gl/shader.lisp')
-rw-r--r-- | src/gl/shader.lisp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/gl/shader.lisp b/src/gl/shader.lisp new file mode 100644 index 0000000..4bba7b8 --- /dev/null +++ b/src/gl/shader.lisp @@ -0,0 +1,42 @@ +;;;; shader.lisp + +(in-package #:wheelwork) + +(defun shader-by-type (type) + (case type + (:vertex :vertex-shader) + (:geometry :geometry-shader) + (:fragment :fragment-shader))) + +(defun gl-shader (type stage) + (let ((shader (gl:create-shader type))) + (gl:shader-source shader (varjo:glsl-code stage)) + (gl:compile-shader shader) + (unless (gl:get-shader shader :compile-status) + (error "failed to compile ~a shader:~%~a~%" + type (gl:get-shader-info-log shader))) + shader)) + +(defun create-shader (&rest sources) + (let* ((stages + (varjo:rolling-translate + (mapcar (lambda (source) + (destructuring-bind (type inputs uniforms code) source + (varjo:make-stage type inputs uniforms '(:330) code))) + sources))) + (shaders + (loop + :for stage :in stages + :for source :in sources + :collect (gl-shader (shader-by-type (car source)) + stage))) + (program (gl:create-program))) + (dolist (shader shaders) (gl:attach-shader program shader)) + (gl:link-program program) + (unless (gl:get-program program :link-status) + (error "failed to link program: ~%~a~%" + (gl:get-program-info-log program))) + (dolist (shader shaders) + (gl:detach-shader program shader) + (gl:delete-shader shader)) + program)) |