-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.lisp
More file actions
144 lines (101 loc) · 4.62 KB
/
common.lisp
File metadata and controls
144 lines (101 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
;; common.lisp
;;
;; Copyright (c) 2022 Jeremiah LaRocco <jeremiah_larocco@fastmail.com>
(in-package #:simple-gl)
(deftype point () 'vec3)
(deftype normal () 'vec3)
(deftype color () 'vec4)
(defun deg2rad (deg)
(declare (optimize (speed 3) (space 0) (safety 0) (debug 0))
(type #.3d-vectors::*float-type* deg))
(* deg
(/ pi 180)))
(defun rad2deg (rad)
(declare (optimize (speed 3) (space 0) (safety 0) (debug 0)))
(/ rad
(/ pi 180)))
(defgeneric use-uniform (uniform program)
(:documentation "Pass the uniform's value into the OpenGL program."))
(defgeneric get-value (uniform)
(:documentation "Set a generic's value and optionally type."))
(defgeneric set-value (uniform new-value &optional new-type)
(:documentation "Set a generic's value and optionally type."))
(defgeneric reset-view-safe (viewer)
(:documentation "Reset view to its initial conditions."))
(defgeneric use-style (style)
(:documentation "Apply style settings."))
(defgeneric rebuild-style (object)
(:documentation "Rebuild a style."))
(defgeneric needs-rebuild (object)
(:documentation "Returns non-nil, usually a list of things that need updating."))
(defgeneric fill-texture (obj))
(defgeneric initialize (object &key)
(:documentation "Initialize an OpenGL object. Default implementation calls the initialize-* methods."))
(defgeneric initialize-shaders (object &key)
(:documentation "Initialize the shaders associated with an OpenGL object."))
(defgeneric initialize-buffers (object &key)
(:documentation "Initialize the buffers associated with an OpenGL object."))
(defgeneric initialize-uniforms (object &key)
(:documentation "Initialize the uniforms associated with an OpenGL object."))
(defgeneric initialize-textures (object &key)
(:documentation "Initialize the textures associated with object."))
(defgeneric render (object)
(:documentation "Render an OpenGL object."))
(defgeneric bind (object)
(:documentation "Bind buffers, textures, etc. for an object."))
(defgeneric reload (object)
(:documentation "Copy new data for object to OpenGL."))
(defgeneric update (object elapsed-seconds)
(:documentation "Called on an object before rendering, to update for the next animation frame. Returns nil or an update-result"))
(defclass update-result ()
()
(:documentation "The result of an update. After an update (perform-main-thread-update update-result) is called in the OpenGL thread."))
(defgeneric perform-main-thread-update (update-result)
(:documentation "Run the part of the update that needs to run in the OpenGL thread."))
(defclass style-rebuilder (update-result)
((styles :initarg :styles))
(:documentation "An update-result who's GL thread action is to rebuild the object's shaders."))
(defclass buffer-reloader (update-result)
((buffers :initarg :buffers))
(:documentation "An update-result who's GL thread action is to reload the object."))
(defclass obj-initializer (update-result)
((obj :initarg :obj))
(:documentation "An update-result who's GL thread action is to initialize the object."))
(defmethod perform-main-thread-update ((result buffer-reloader))
(with-slots (buffers) result
(dolist (buf (ensure-list buffers))
(reload buf))))
(defmethod perform-main-thread-update ((result style-rebuilder))
(with-slots (styles) result
(dolist (sty styles)
(rebuild-style sty))))
(defmethod perform-main-thread-update ((result obj-initializer))
(with-slots (obj) result
(initialize obj)))
(defgeneric cleanup (object)
(:documentation "Cleanup any OpenGL resources owned by obj."))
(defgeneric initialized-p (object)
(:documentation "Returns nil if object is not initialized, non-nil otherwise."))
(defgeneric build-style (object)
(:documentation "Bind the correct VAO and build object's shader programs."))
(defgeneric clone (object)
(:documentation "Create an identical but different object."))
(defun show-slots (white-space object slots)
"Print the specified slots of object, one per line, indenting with white-space on each line.~
Use 'nil' slot name to print an empty line to separate values."
(dolist (slot slots)
(cond ((null slot)
(format t "~%"))
(t
(format t "~a~a: ~a~%" white-space slot (slot-value object slot))))))
(defgeneric show-info (object &key indent)
(:documentation "Show OpenGL information for an object."))
(defun indent-whitespace (n)
(make-string (* 2 n) :initial-element #\space))
#+spacenav
(defgeneric handle-3d-mouse-event (object event)
(:documentation "Handle a spacenav 3D mouse event."))
#+spacenav
(defmethod handle-3d-mouse-event ((object t) (event t))
(declare (ignorable object event))
nil)