anchor.diff:               (3 9)
                (4 11)
                (otherwise (+ count 12))))))
  +      (error "draw-mode-group-id: ~a is not a draw-mode" x)))
  +
  +(defn draw-mode-symbol-group-id ((x symbol)) (unsigned-byte 8)
  +  (declare (optimize (speed 3) (safety 1) (debug 0) (compilation-speed 0)))
  +  (or (case x
  +        (:triangles 9)
  +        (:points 0)
  +        (:lines 4)
  +        (:triangle-strip 6)
  +        (:triangle-fan 8)
  +        (:line-strip 1)
  +        (:line-loop 3)
  +        (:lines-adjacency 5)
  +        (:line-strip-adjacency 2)
  +        (:triangle-strip-adjacency 7)
  +        (:triangles-adjacency 10)
  +        (:quads 11)
  +        (:patches (error "Patches can not be used without a length")))
         (error "draw-mode-group-id: ~a is not a draw-mode" x)))
   
   (defn primitive-keyword-to-enum-val ((kwd symbol)) (signed-byte 32)
  
positive.code:                            (foreign-type-size index-type)
                             0)
       :managed managed
       :%primitive primitive
       :primitive-group-id prim-group-id
       :draw-mode-val enum-val
       :patch-length patch-length
  
negative.code:   (patch-length 0 :type (unsigned-byte 8))
    (managed nil :type boolean))
  
  (defn buffer-stream-primitive ((stream buffer-stream)) t
    ;; a slow function, should be used sparingly
    (declare (profile t))
    (let ((prim (buffer-stream-%primitive stream)))
      (if (eq prim :patches)
          (list prim (buffer-stream-patch-length stream))
          prim)))
  
  (defn (setf buffer-stream-primitive) ((primitive (or symbol list))
                                        (stream buffer-stream))
      (or symbol list)
    (declare (optimize (speed 3) (safety 1) (debug 1)
                       (compilation-speed 0))
             (profile t))
    (if (keywordp primitive)
        (unless (eq primitive (buffer-stream-%primitive stream))
          (assert (not (or (eq :patches primitive) (eq :patches primitive))))
          (setf (buffer-stream-%primitive stream) primitive)
          (setf (buffer-stream-primitive-group-id stream)
                (draw-mode-symbol-group-id primitive))
          (setf (buffer-stream-draw-mode-val stream)
                (primitive-keyword-to-enum-val primitive)))
        (set-patch-stream-primitive stream primitive))
    primitive)
  
  (defun2 set-patch-stream-primitive (stream primitive)
    (let* ((prim (varjo.internals:primitive-name-to-instance primitive))
           (group-id (draw-mode-group-id prim))
           (enum-kwd (varjo::lisp-name prim))
           (enum-val (primitive-keyword-to-enum-val enum-kwd))
           (patch-length (primitive-vert-length prim)))
      (setf (buffer-stream-%primitive stream) enum-kwd
            (buffer-stream-primitive-group-id stream) group-id
            (buffer-stream-draw-mode-val stream) enum-val
            (buffer-stream-patch-length stream) patch-length)))
  
  (defn primitive-vert-length ((prim varjo.internals:primitive))
      (unsigned-byte 8)
  