wh-engine/wh-engine/render/drawable.lisp

42 lines
1.2 KiB
Common Lisp

;;;; wh-engine/render/drawable.lisp
(in-package wh-engine)
(defclass drawable (component)
()
(:documentation "Base class for components that draw graphics."))
(defmethod start :after ((this drawable))
; Register
(pushnew (make-weak-pointer this) *world-drawables*))
(defmethod destroy :before ((this drawable))
; Unregister
(setf *world-drawables* (delete this *world-drawables* :key #'weak-pointer-value)))
(defmethod culling-box ((this drawable))
"The local-space bounding box used for culling."
(cons (vec2 0 0) (vec2 0 0)))
(defmethod draw ((this drawable) view)
"Draw this object."
nil)
(defclass drawable-test (drawable)
((colour :documentation "Colour of the test quad."
:accessor colour
:type vec4
:initarg :colour
:initform (vec4 1.0 0.0 1.0 1.0)))
(:documentation "Basic drawable test."))
(defmethod culling-box ((this drawable-test))
(cons (vec2 -0.5 -0.5) (vec2 0.5 0.5)))
(defmethod draw ((this drawable-test) view)
(gl:color (vx4 [this colour]) (vy4 [this colour]) (vz4 [this colour]) (vw4 [this colour]))
(gl:with-primitives :quads
(gl:vertex -0.5 -0.5 0.0 1.0)
(gl:vertex 0.5 -0.5 0.0 1.0)
(gl:vertex 0.5 0.5 0.0 1.0)
(gl:vertex -0.5 0.5 0.0 1.0)))