sketch icon indicating copy to clipboard operation
sketch copied to clipboard

Not reinitializing vao

Open cbaggers opened this issue 8 years ago • 3 comments

In the guide here http://onrendering.blogspot.no/2011/10/buffer-object-streaming-in-opengl.html it shows that after orphaning the buffer you need to reset your vao. In sketch currently it is only rebound.

instead something like this should be added to glkit

(defun reinit-vao (vao)
  (with-slots ((vao-type type) id vbos vertex-count) vao
    (with-slots (groups) vao-type
      (loop for group across groups
         as vbo-offset = 0 then (+ vbo-offset vbo-count)
         as vbo-count = (vao-vbo-count group)
         as vbo-subset = (make-array vbo-count :displaced-to vbos
                                     :displaced-index-offset vbo-offset)
         as attr-offset = 0 then (+ attr-offset attr-count)
         as attr-count = (vao-attr-count group)
         do (loop for i from 0 below (vao-attr-count group)
               do (%gl:enable-vertex-attrib-array (+ i attr-offset)))
           (vao-set-pointers group attr-offset vertex-count vbo-subset)))))

and this be called from start-draw, as in:

(defun start-draw ()
  (%gl:bind-buffer :array-buffer 1)
  (%gl:buffer-data :array-buffer *buffer-size* (cffi:null-pointer) :stream-draw)
  (setf (env-buffer-position *env*) 0)
  (kit.gl.vao:vao-bind (env-vao *env*))
  (kit.gl.vao::reinit-vao (env-vao *env*)))

This has been working but I think only because there is only one vao.

cbaggers avatar May 22 '17 23:05 cbaggers

not sure if this is related but (%gl:bind-buffer :array-buffer 1) only works because there is a single VBO for the entire time, named 1

(let ((the-vbo (aref (slot-value (env-vao *env*) 'kit.gl.vao::vbos) 0)))
    (%gl:bind-buffer :array-buffer the-vbo))

modified version of sketch supporting multiple overlapping defsketches, using pure common lisp zpb-ttf, vecto, opticl and glfw rather sdl2-ttf, sdl2-image, and sdl2, which means the user can just do (ql:quickload :sketch) and not have to install anything [for most platforms]

gregcman avatar Apr 08 '19 22:04 gregcman

Hey @gregcman ! I wanted to look at your linked example, but it appears to be removed from github. Is it available on a branch somewhere?

vydd avatar Nov 06 '22 17:11 vydd

I think it can be found here: https://github.com/gregcman/sucle/tree/1e95ca02beabc624f9f6c89308217de4229d7817/application/subsystems/sketch-sucle

Gleefre avatar Oct 21 '23 23:10 Gleefre