Gabriel Pariat
3 years ago
5 changed files with 103 additions and 46 deletions
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
#version 330 core |
||||
out vec4 FragColor; |
||||
|
||||
in vec3 ourColor; |
||||
|
||||
void main() |
||||
{ |
||||
FragColor = vec4(ourColor, 1.0); |
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
(defpackage #:shader |
||||
(:shadow #:load) |
||||
(:use #:cl) |
||||
(:export #:load #:use #:set-bool #:set-int #:set-float)) |
||||
|
||||
(in-package :shader) |
||||
|
||||
(defclass shader () |
||||
((program :accessor shader-program :initarg :program))) |
||||
|
||||
(defun read-shader-file (path) |
||||
(with-open-file (stream path) |
||||
(apply #'concatenate |
||||
'string |
||||
(loop for line = (read-line stream nil nil) |
||||
while line |
||||
nconc (list line (string #\Newline)))))) |
||||
|
||||
(defun load (vertex-shader-path fragment-shader-path) |
||||
(let ((vertex-shader-file (read-shader-file vertex-shader-path)) |
||||
(fragment-shader-file (read-shader-file fragment-shader-path)) |
||||
(vertex-shader (gl:create-shader :vertex-shader)) |
||||
(fragment-shader (gl:create-shader :fragment-shader)) |
||||
(program (gl:create-program))) |
||||
(gl:shader-source vertex-shader vertex-shader-file) |
||||
(gl:compile-shader vertex-shader) |
||||
(gl:shader-source fragment-shader fragment-shader-file) |
||||
(gl:compile-shader fragment-shader) |
||||
(format t "~&Vertex shader info log: ~%~a" (gl:get-shader-info-log vertex-shader)) |
||||
(format t "~&Fragment shader info log: ~%~a" (gl:get-shader-info-log fragment-shader)) |
||||
(gl:attach-shader program vertex-shader) |
||||
(gl:attach-shader program fragment-shader) |
||||
(gl:link-program program) |
||||
(gl:delete-shader vertex-shader) |
||||
(gl:delete-shader fragment-shader) |
||||
(make-instance 'shader :program program))) |
||||
|
||||
(defmethod use ((self shader)) |
||||
(gl:use-program (shader-program self))) |
||||
|
||||
(defmacro define-set-uniform (name f) |
||||
`(defmethod ,name ((self shader) name value) |
||||
(,f (gl:get-uniform-location (shader-program self) name) value))) |
||||
|
||||
(define-set-uniform set-bool gl:uniformi) |
||||
(define-set-uniform set-int gl:uniformi) |
||||
(define-set-uniform set-float gl:uniformf) |
Loading…
Reference in new issue