Skip to content
Permalink
Browse files

Allow framebuffers and passes with zero attachments.

  • Loading branch information...
Shinmera committed Aug 19, 2019
1 parent 8d2a959 commit 9785dc6eb088b13f5e3e5c7c5f18f768bc2e8eb6
Showing with 45 additions and 20 deletions.
  1. +2 −0 pipeline.lisp
  2. +37 −20 resources/framebuffer.lisp
  3. +6 −0 shader-pass.lisp
@@ -153,6 +153,8 @@
(add-handler pass pipeline))
(setf (framebuffer pass)
(make-instance 'framebuffer
:width (width pass)
:height (height pass)
:attachments (loop for port in (flow:ports pass)
when (typep port 'output)
collect (list (attachment port) (texture port))))))
@@ -7,7 +7,9 @@
(in-package #:org.shirakumo.fraf.trial)

(defclass framebuffer (gl-resource)
((attachments :initarg :attachments :accessor attachments))
((attachments :initarg :attachments :accessor attachments)
(width :initarg :width :initform NIL :accessor width)
(height :initarg :height :initform NIL :accessor height))
(:default-initargs
:attachments (error "ATTACHMENTS required.")))

@@ -30,25 +32,40 @@
(with-cleanup-on-failure (gl:delete-framebuffers (list fbo))
(gl:bind-framebuffer :framebuffer fbo)
(unwind-protect
(dolist (attachment (attachments framebuffer))
(destructuring-bind (attachment texture &key (level 0) layer &allow-other-keys) attachment
(check-framebuffer-attachment attachment)
(check-type texture texture)
(check-allocated texture)
(v:debug :trial.framebuffer "Attaching ~a~@[:~a~] as ~a to ~a."
texture layer attachment framebuffer)
(if layer
(%gl:framebuffer-texture-layer :framebuffer attachment (gl-name texture) level layer)
(%gl:framebuffer-texture :framebuffer attachment (gl-name texture) level))
(let ((completeness (gl:check-framebuffer-status :framebuffer)))
(unless (find completeness '(:framebuffer-complete :framebuffer-complete-oes))
(error "Failed to attach ~a as ~s to ~a: ~s"
texture attachment framebuffer completeness)))))
(cond (color-attachments
(gl:draw-buffers color-attachments))
(T
(gl:draw-buffer :none)
(gl:read-buffer :none)))
(progn
(dolist (attachment (attachments framebuffer))
(destructuring-bind (attachment texture &key (level 0) layer &allow-other-keys) attachment
(check-framebuffer-attachment attachment)
(check-type texture texture)
(check-allocated texture)
(v:debug :trial.framebuffer "Attaching ~a~@[:~a~] as ~a to ~a."
texture layer attachment framebuffer)
(cond ((null (width framebuffer))
(setf (width framebuffer) (width texture)))
((/= (width framebuffer) (width texture))
(error "Cannot attach~% ~a~%to~% ~a~%, as the width is mismatched."
texture framebuffer)))
(cond ((null (height framebuffer))
(setf (height framebuffer) (height texture)))
((/= (height framebuffer) (height texture))
(error "Cannot attach~% ~a~%to~% ~a~%, as the height is mismatched."
texture framebuffer)))
(if layer
(%gl:framebuffer-texture-layer :framebuffer attachment (gl-name texture) level layer)
(%gl:framebuffer-texture :framebuffer attachment (gl-name texture) level))
(let ((completeness (gl:check-framebuffer-status :framebuffer)))
(unless (find completeness '(:framebuffer-complete :framebuffer-complete-oes))
(error "Failed to attach ~a as ~s to ~a: ~s"
texture attachment framebuffer completeness)))))
(cond (color-attachments
(gl:draw-buffers color-attachments))
(T
(gl:draw-buffer :none)
(gl:read-buffer :none)))
(unless (and (width framebuffer) (height framebuffer))
(error "The framebuffer has no attachments and no default width and height set!"))
(%gl:framebuffer-parameter-i :framebuffer :framebuffer-default-width (width framebuffer))
(%gl:framebuffer-parameter-i :framebuffer :framebuffer-default-height (height framebuffer)))
(gl:bind-framebuffer :framebuffer 0)
(setf (data-pointer framebuffer) fbo)))))

@@ -80,10 +80,16 @@

(define-shader-subject shader-pass (flow:static-node)
((framebuffer :initform NIL :accessor framebuffer)
(width :initarg :width :initform NIL :accessor width)
(height :initarg :height :initform NIL :accessor height)
(uniforms :initarg :uniforms :initform () :accessor uniforms))
(:metaclass shader-pass-class)
(:inhibit-shaders (shader-entity :fragment-shader)))

(defmethod (setf framebuffer) :after ((framebuffer framebuffer) (pass shader-pass))
(setf (width pass) (width framebuffer))
(setf (height pass) (height framebuffer)))

(define-class-shader (shader-pass :fragment-shader)
"#version 330 core")

0 comments on commit 9785dc6

Please sign in to comment.
You can’t perform that action at this time.