Skip to content

Commit

Permalink
Add internal clear-texture that lets you clear to any gray shade
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed May 29, 2024
1 parent 75f17a1 commit d7f633e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions resources/texture.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@
(defmethod deactivate ((source texture))
(gl:bind-texture (target source) 0))

(defmethod clear ((texture texture))
(defun clear-texture (texture &optional (pixel 0))
#-elide-context-current-checks
(check-context-current)
(gl-extension-case
(:gl-arb-clear-texture
(let ((size (pixel-data-stride (pixel-type texture) (pixel-format texture))))
(cffi:with-foreign-object (fill :uint8 size)
(static-vectors:fill-foreign-memory fill size 0)
(static-vectors:fill-foreign-memory fill size pixel)
(%gl:clear-tex-image (gl-name texture) 0
(pixel-format texture)
(pixel-type texture)
Expand All @@ -341,7 +341,7 @@
(let ((size (* (width texture) (or (height texture) 1) (or (depth texture) 1)
(pixel-data-stride (pixel-type texture) (pixel-format texture)))))
(cffi:with-foreign-object (fill :uint8 size)
(static-vectors:fill-foreign-memory fill size 0)
(static-vectors:fill-foreign-memory fill size pixel)
(gl:bind-texture (target texture) (gl-name texture))
(ecase (target texture)
(:texture-1d
Expand All @@ -351,6 +351,9 @@
((:texture-3d :texture-2d-array)
(%gl:tex-sub-image-3d (target texture) 0 0 0 0 (width texture) (height texture) (depth texture) (pixel-format texture) (pixel-type texture) fill))))))))

(defmethod clear ((texture texture))
(clear-texture texture))

;;;; Texture spec wrangling
;; The idea of this is that, in order to maximise sharing of texture resources
;; between independent parts, we need to join (in the lattice sense) two texture
Expand Down

0 comments on commit d7f633e

Please sign in to comment.