You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB

;;;; render.lisp
(in-package :break)
(defstruct-g pos-col
(posiiton :vec3 :accessor pos)
(color :vec4 :accessor col))
(defun-g vert ((vert pos-col) &uniform (to-view :mat4) (to-world :mat4))
(values (* to-view
(* to-world
(v! (pos vert) 1.0)))
(col vert)))
(defun-g frag ((color :vec4))
color)
(defpipeline-g render ()
(vert pos-col)
(frag :vec4))
(defun make-square-e-stream (x y color)
(let* ((verts (make-gpu-array `((,(v! x y 0) ,color)
(,(v! 0 y 0) ,color)
(,(v! 0 0 0) ,color)
(,(v! x 0 0) ,color))
:element-type 'pos-col :dimensions 4))
(indices (make-gpu-array '(0 1 2 0 2 3)
:dimensions 6 :element-type :unsigned-short)))
(make-buffer-stream verts :index-array indices)))
(defun viewport-internal-size (viewport)
(let* ((viewport-width (viewport-resolution-x viewport))
(viewport-height (viewport-resolution-y viewport))
(internal-width (aref *internal-size* 0))
(internal-height (aref *internal-size* 1))
(viewport-aspect-ratio (/ viewport-width viewport-height)))
(if (> viewport-aspect-ratio (/ internal-width internal-height))
(v! (* internal-height viewport-aspect-ratio)
internal-height)
(v! internal-width
(/ internal-width viewport-aspect-ratio)))))
(defun update-matrix (window-size)
(let* ((window-width (aref window-size 0))
(window-height (aref window-size 1))
(internal-width (aref *internal-size* 0))
(internal-height (aref *internal-size* 1))
(window-aspect-ratio (reduce #'/ window-size))
(new-size (if (> window-aspect-ratio (/ internal-width internal-height))
(v! (* internal-height window-aspect-ratio)
internal-height) ; wider, preserve height
(v! internal-width
(/ internal-width window-aspect-ratio)))))
;; (format t "Matrix arguments: ~a ~a.~%" (aref new-size 0) (aref new-size 1))
(rtg-math.projection:orthographic
(aref new-size 0) (aref new-size 1)
1.0 100.0)))