From c53145d0d347b5306a1a6cb547c7ea0d3772778b Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 24 Jun 2022 10:30:14 -0500 Subject: [add] caching projected matrix, passed to shader programs --- wheelwork.lisp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/wheelwork.lisp b/wheelwork.lisp index c9ce939..ccb38cb 100644 --- a/wheelwork.lisp +++ b/wheelwork.lisp @@ -6,7 +6,7 @@ "current application") (defclass/std unit () - ((cached-model :a) + ((cached-model cached-projected-matrix :a) (container :with :a) (width height :with :std 1.0) (rotation x y :with :std 0.0) @@ -16,7 +16,8 @@ (newval class (unit unit) slot) (case (closer-mop:slot-definition-name slot) ((x y width height rotation ) - (setf (cached-model unit) nil)))) + (setf (cached-model unit) nil + (cached-projected-matrix unit) nil)))) (defclass/std container () ((units :with :a)) @@ -288,12 +289,12 @@ necessary." (sdl2:gl-swap-window (application-window app)) (sleep (frame-wait app))) - - - (defgeneric model-matrix (thing) (:documentation "Returns the model matrix")) +(defgeneric projected-matrix (thing) + (:documentation "Returns the raw array of the model matrix after it + has been prjected by the application's projecion matrix")) (defmethod model-matrix ((u unit)) (or (cached-model u) @@ -308,6 +309,12 @@ necessary." (mat:nmscale m (vec:vec (unit-width u) (unit-height u) 1.0)) m)))) +(defmethod projected-matrix ((thing unit)) + (or (cached-projected-matrix thing) + (setf (cached-projected-matrix thing) + (mat:marr (mat:m* (application-projection *application*) + (model-matrix thing)))))) + (defgeneric ensure-loaded (asset) (:documentation "Ensures that the asset is loaded into memory and ready for use. Returns the asset.")) @@ -594,7 +601,9 @@ give focus to whatever was clicked." (gl:program-uniform-matrix-4fv shader (gl:get-uniform-location shader "TRANSFORM") - (mat:marr (mat:m* (application-projection *application*) (model-matrix bitmap)))) + (projected-matrix bitmap) + ;(mat:marr (mat:m* (application-projection *application*) (model-matrix bitmap))) + ) (gl:bind-vertex-array vao) (gl:draw-arrays :triangles 0 6) (gl:bind-vertex-array 0))) -- cgit v1.2.3