diff options
author | Colin Okay <colin@cicadas.surf> | 2022-07-19 06:45:16 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-07-19 06:45:16 -0500 |
commit | 3c1df8b7807f772887dc3d85725059c4dbe75cca (patch) | |
tree | 9a02be7dff5b9e3e10c13b4f08f5fb487aca0d2c /src/interactive/bitmap.lisp | |
parent | 3e5fb0e5ceb14475164b2a97187c0164ad465cc3 (diff) |
[rename] bitmap/image
Diffstat (limited to 'src/interactive/bitmap.lisp')
-rw-r--r-- | src/interactive/bitmap.lisp | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/interactive/bitmap.lisp b/src/interactive/bitmap.lisp deleted file mode 100644 index 96d8e07..0000000 --- a/src/interactive/bitmap.lisp +++ /dev/null @@ -1,86 +0,0 @@ -;;;; bitmap.lisp - -(in-package #:wheelwork) - -(defvar *bitmap-shader-program* nil - "Cached for later cleanup.") -(defvar *bitmap-vao* nil) - -(defvar *bitmap-count* 0 - "Used by finalizers to determin if the shader should be destroyed.") - -(defun bitmap-finalizer () - "executed after a bitmap has been reclaimed by gc. decrements bitmap -count and destroys shader-program if necessary." - (decf *bitmap-count*) - (unless (plusp *bitmap-count*) - (when *bitmap-vao* - (gl:delete-vertex-arrays (list *bitmap-vao*)) - (setf *bitmap-vao* nil)) - (when *bitmap-shader-program* - (gl:delete-program *bitmap-shader-program*) - (setf *bitmap-shader-program* nil)))) - -(defclass/std bitmap (affine interactive) - ((texture :ri :std (error "A bitmap requires a texture.")))) - -(defmethod initialize-instance :after ((bitmap bitmap) &key) - (incf *bitmap-count*) - (trivial-garbage:finalize bitmap #'bitmap-finalizer) - (with-slots (base-width base-height texture) bitmap - (setf base-height (texture-height texture) - base-width (texture-width texture)) - (unless *bitmap-shader-program* - (setf *bitmap-shader-program* - (create-shader - '(:vertex - ((vert :vec2)) - ((transform :mat4)) - ((values - (* transform (vari:vec4 vert 0.0 1.0)) - vert))) ;color - '(:fragment - ((tc :vec2)) - ((tex :sampler-2d)) - ((let ((frag (vari:texture tex tc))) - (if (< (aref frag 3) 0.01) - (vari:discard) - frag)))))) - (gl:program-uniformi - *bitmap-shader-program* - (gl:get-uniform-location *bitmap-shader-program* "TEX") - 0)) - (unless *bitmap-vao* - (setf *bitmap-vao* (gl:gen-vertex-array)) - (gl:bind-vertex-array *bitmap-vao*) - (let ((vbo (gl:gen-buffer))) - (with-gl-array (verts :float - 0.0 1.0 - 1.0 0.0 - 0.0 0.0 - - 0.0 1.0 - 1.0 1.0 - 1.0 0.0 ) - (gl:bind-buffer :array-buffer vbo) - (gl:buffer-data :array-buffer :static-draw verts))) - (gl:enable-vertex-attrib-array 0) - (gl:vertex-attrib-pointer 0 2 :float 0 (* +float-size+ 2) 0) - (gl:bind-buffer :array-buffer 0) - (gl:bind-vertex-array 0)))) - -(defmethod cleanup ((bitmap bitmap)) - (bitmap-finalizer)) - -(defmethod render ((bitmap bitmap)) - (with-slots (texture) bitmap - (gl:active-texture 0) - (gl:bind-texture :texture-2d (texture-id texture)) - (gl:use-program *bitmap-shader-program*) - (gl:program-uniform-matrix-4fv - *bitmap-shader-program* - (gl:get-uniform-location *bitmap-shader-program* "TRANSFORM") - (projected-matrix bitmap)) - (gl:bind-vertex-array *bitmap-vao*) - (gl:draw-arrays :triangles 0 6) - (gl:bind-vertex-array 0))) |