Skip to content

Commit

Permalink
Stencil buffer support
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Aug 15, 2017
1 parent 8a6a500 commit 057bcf0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion display.lisp
Expand Up @@ -35,6 +35,9 @@
(reset-matrix (view-matrix)) (reset-matrix (view-matrix))
(reset-matrix (projection-matrix)) (reset-matrix (projection-matrix))
(reset-attributes (attribute-table)) (reset-attributes (attribute-table))
(gl:stencil-mask #xFF)
(gl:clear-stencil #x00)
(gl:stencil-op :keep :keep :keep)
(gl:depth-mask T) (gl:depth-mask T)
(gl:depth-func :lequal) (gl:depth-func :lequal)
(gl:blend-func :src-alpha :one-minus-src-alpha) (gl:blend-func :src-alpha :one-minus-src-alpha)
Expand All @@ -56,7 +59,7 @@
(with-context (context :reentrant T) (with-context (context :reentrant T)
(let ((c (clear-color target))) (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 (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)
(call-next-method) (call-next-method)
(swap-buffers context)))) (swap-buffers context))))


Expand Down
2 changes: 1 addition & 1 deletion effects.lisp
Expand Up @@ -11,7 +11,7 @@


(define-shader-pass render-pass (per-object-pass) (define-shader-pass render-pass (per-object-pass)
((color :port-type output :attachment :color-attachment0) ((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) (define-shader-pass msaa-pass (render-pass multisampled-per-object-pass)
()) ())
Expand Down
3 changes: 2 additions & 1 deletion pipeline.lisp
Expand Up @@ -132,7 +132,8 @@
(loop for pass across (passes pipeline) (loop for pass across (passes pipeline)
for fbo = (framebuffer pass) for fbo = (framebuffer pass)
do (gl:bind-framebuffer :framebuffer (resource fbo)) 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))) (paint-with pass source)))


(defmethod register-object-for-pass ((pipeline pipeline) object) (defmethod register-object-for-pass ((pipeline pipeline) object)
Expand Down
7 changes: 4 additions & 3 deletions shader-pass.lisp
Expand Up @@ -189,20 +189,21 @@
(defmethod load progn ((pass multisampled-pass)) (defmethod load progn ((pass multisampled-pass))
(let ((fbo (make-asset 'framebuffer-bundle (let ((fbo (make-asset 'framebuffer-bundle
`((:attachment :color-attachment0 :bits ,(samples pass) :target :texture-2d-multisample) `((: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*)))) :width (width *context*) :height (height *context*))))
(load fbo) (load fbo)
(setf (multisample-fbo pass) fbo))) (setf (multisample-fbo pass) fbo)))


(defmethod paint-with :around ((pass multisampled-pass) target) (defmethod paint-with :around ((pass multisampled-pass) target)
(let ((original-framebuffer (resource (framebuffer pass)))) (let ((original-framebuffer (resource (framebuffer pass))))
(gl:bind-framebuffer :framebuffer (resource (multisample-fbo pass))) (gl:bind-framebuffer :framebuffer (resource (multisample-fbo pass)))
(gl:clear :color-buffer :depth-buffer) (gl:clear :color-buffer :depth-buffer :stencil-buffer)
(call-next-method) (call-next-method)
(gl:bind-framebuffer :draw-framebuffer original-framebuffer) (gl:bind-framebuffer :draw-framebuffer original-framebuffer)
(%gl:blit-framebuffer 0 0 (width target) (height target) 0 0 (width target) (height target) (%gl:blit-framebuffer 0 0 (width target) (height target) 0 0 (width target) (height target)
(logior (cffi:foreign-bitfield-value '%gl::ClearBufferMask :color-buffer) (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)) (cffi:foreign-enum-value '%gl:enum :nearest))
(gl:bind-framebuffer :framebuffer original-framebuffer))) (gl:bind-framebuffer :framebuffer original-framebuffer)))


Expand Down

0 comments on commit 057bcf0

Please sign in to comment.