cepl icon indicating copy to clipboard operation
cepl copied to clipboard

Potential `make-texture` bug

Open lovrolu opened this issue 6 years ago • 0 comments

The following two forms give different results:

(let* ((arr (make-array
             '(2 2)
             :initial-contents
             (list (list (v!uint 1 2 3 4) (v!uint 1 2 3 4))
                   (list (v!uint 1 2 3 4) (v!uint 1 2 3 4)))))
       (tex (make-texture arr :element-type :rgba8)))
  (pull-g tex))

;;; => ((#(1 0 0 0) #(1 0 0 0)) (#(1 0 0 0) #(1 0 0 0)))
(let* ((arr (make-array
             '(2 2)
             :initial-contents
             (list (list (v!uint8 1 2 3 4) (v!uint8 1 2 3 4))
                   (list (v!uint8 1 2 3 4) (v!uint8 1 2 3 4)))))
       (tex (make-texture arr :element-type :rgba8)))
  (pull-g tex))

;;; => ((#(1 2 3 4) #(1 2 3 4)) (#(1 2 3 4) #(1 2 3 4)))

I'm not completely sure whether this is a bug or not, but I figured I'd still report it just in case.

Notice that the only difference is whether we're using v!uint or v!uint8. If that's not a bug, I'd be glad to hear what's going on (I'm assuming it has to do with how make-texture interprets the individual elements). The docstring says:

    If the :initial-contents is a nested list then you must either:
    
    - specify multiple dimensions and an element-type
    - specify an element-type to be some struct type, then nested lists are then
      used to populate the fields of the foreign structs. For an example of this
      please see this example: https://github.com/cbaggers/cepl.examples/blob/master/examples/triangle.lisp#L30.

Since I haven't specified multiple dimensions, does this mean :rgba8 counts as a struct type? What exactly happens when it tries to interpret a uint vector as a uint8 vector, i.e. how do we get #(1 0 0 0) from #(1 2 3 4)?

Thanks for the awesome project by the way (Varjo is so far the most amazing piece to me :-)). I've used it during my graphics course and it was much fun!

lovrolu avatar Feb 27 '19 16:02 lovrolu