Browse files

Stencil buffer support

  • Loading branch information...
Shinmera committed Aug 15, 2017
1 parent 8a6a500 commit 057bcf0ad6d2d4ac475f5dfaf6a4cd569fa38393
Showing with 11 additions and 6 deletions.
  1. +4 −1 display.lisp
  2. +1 −1 effects.lisp
  3. +2 −1 pipeline.lisp
  4. +4 −3 shader-pass.lisp
@@ -35,6 +35,9 @@
(reset-matrix (view-matrix))
(reset-matrix (projection-matrix))
(reset-attributes (attribute-table))
(gl:stencil-mask #xFF)
(gl:clear-stencil #x00)
(gl:stencil-op :keep :keep :keep)
(gl:depth-mask T)
(gl:depth-func :lequal)
(gl:blend-func :src-alpha :one-minus-src-alpha)
@@ -56,7 +59,7 @@
(with-context (context :reentrant T)
(let ((c (clear-color target)))
(gl:clear-color (vx c) (vy c) (vz c) (if (vec4-p c) (vw c) 0.0)))
(gl:clear :color-buffer :depth-buffer)
(gl:clear :color-buffer :depth-buffer :stencil-buffer)
(swap-buffers context))))
@@ -11,7 +11,7 @@
(define-shader-pass render-pass (per-object-pass)
((color :port-type output :attachment :color-attachment0)
(depth :port-type output :attachment :depth-attachment)))
(depth :port-type output :attachment :depth-stencil-attachment)))
(define-shader-pass msaa-pass (render-pass multisampled-per-object-pass)
@@ -132,7 +132,8 @@
(loop for pass across (passes pipeline)
for fbo = (framebuffer pass)
do (gl:bind-framebuffer :framebuffer (resource fbo))
(gl:clear :color-buffer :depth-buffer)
;; FIXME: Figure out which to clear depending on framebuffer attachments
(gl:clear :color-buffer :depth-buffer :stencil-buffer)
(paint-with pass source)))
(defmethod register-object-for-pass ((pipeline pipeline) object)
@@ -189,20 +189,21 @@
(defmethod load progn ((pass multisampled-pass))
(let ((fbo (make-asset 'framebuffer-bundle
`((:attachment :color-attachment0 :bits ,(samples pass) :target :texture-2d-multisample)
(:attachment :depth-attachment :bits ,(samples pass) :target :texture-2d-multisample))
(:attachment :depth-stencil-attachment :bits ,(samples pass) :target :texture-2d-multisample))
:width (width *context*) :height (height *context*))))
(load fbo)
(setf (multisample-fbo pass) fbo)))
(defmethod paint-with :around ((pass multisampled-pass) target)
(let ((original-framebuffer (resource (framebuffer pass))))
(gl:bind-framebuffer :framebuffer (resource (multisample-fbo pass)))
(gl:clear :color-buffer :depth-buffer)
(gl:clear :color-buffer :depth-buffer :stencil-buffer)
(gl:bind-framebuffer :draw-framebuffer original-framebuffer)
(%gl:blit-framebuffer 0 0 (width target) (height target) 0 0 (width target) (height target)
(logior (cffi:foreign-bitfield-value '%gl::ClearBufferMask :color-buffer)
(cffi:foreign-bitfield-value '%gl::ClearBufferMask :depth-buffer))
(cffi:foreign-bitfield-value '%gl::ClearBufferMask :depth-buffer)
(cffi:foreign-bitfield-value '%gl::ClearBufferMask :stencil-buffer))
(cffi:foreign-enum-value '%gl:enum :nearest))
(gl:bind-framebuffer :framebuffer original-framebuffer)))

0 comments on commit 057bcf0

Please sign in to comment.