vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.41k stars 67 forks source link

Not reinitializing vao #20

Open cbaggers opened 7 years ago

cbaggers commented 7 years ago

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.

gregcman commented 5 years ago

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]

vydd commented 2 years ago

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?

Gleefre commented 1 year ago

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