diff --git a/display.lisp b/display.lisp index 6f62b91f..1adac7db 100644 --- a/display.lisp +++ b/display.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) (call-next-method) (swap-buffers context)))) diff --git a/effects.lisp b/effects.lisp index 35533db1..0214359d 100644 --- a/effects.lisp +++ b/effects.lisp @@ -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) ()) diff --git a/pipeline.lisp b/pipeline.lisp index 79ba12cf..902d693e 100644 --- a/pipeline.lisp +++ b/pipeline.lisp @@ -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) diff --git a/shader-pass.lisp b/shader-pass.lisp index f4733303..98c09a71 100644 --- a/shader-pass.lisp +++ b/shader-pass.lisp @@ -189,7 +189,7 @@ (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))) @@ -197,12 +197,13 @@ (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) (call-next-method) (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)))