diff options
Diffstat (limited to 'src/interactive')
-rw-r--r-- | src/interactive/image.lisp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/interactive/image.lisp b/src/interactive/image.lisp index 1b3a817..644c06e 100644 --- a/src/interactive/image.lisp +++ b/src/interactive/image.lisp @@ -6,18 +6,9 @@ "Cached for later cleanup.") (defvar *image-vao* nil) -(defvar *image-count* 0 - "Used by finalizers to determin if the shader should be destroyed.") - -(defun image-finalizer () - "executed after a image has been reclaimed by gc. decrements image -count and destroys shader-program if necessary." - (decf *image-count*) - (unless (plusp *image-count*) - )) - (defclass/std image (unit interactive) - ((texture :ri :std (error "A image requires a texture.")))) + ((texture :ri :std (error "A image requires a texture.")) + (alpha :std 1.0))) (defun make-shared-image-gpu-objects () (unless *image-shader-program* @@ -31,8 +22,10 @@ count and destroys shader-program if necessary." vert))) ;color '(:fragment ((tc :vec2)) - ((tex :sampler-2d)) + ((tex :sampler-2d) + (alpha :float)) ((let ((frag (vari:texture tex tc))) + (setf (aref frag 3) (vari:clamp 0 (* alpha (aref frag 3)) 1)) (if (< (aref frag 3) 0.01) (vari:discard) frag)))))) @@ -77,7 +70,7 @@ count and destroys shader-program if necessary." (make-shared-image-gpu-objects))) (defmethod render ((image image)) - (with-slots (texture) image + (with-slots (texture alpha) image (gl:active-texture 0) (gl:bind-texture :texture-2d (texture-id texture)) (gl:use-program *image-shader-program*) @@ -85,6 +78,10 @@ count and destroys shader-program if necessary." *image-shader-program* (gl:get-uniform-location *image-shader-program* "TRANSFORM") (projected-matrix image)) + (gl:program-uniformf + *image-shader-program* + (gl:get-uniform-location *image-shader-program* "ALPHA") + alpha) (gl:bind-vertex-array *image-vao*) (gl:draw-arrays :triangles 0 6) (gl:bind-vertex-array 0))) |