VertexBuffer and binding to Program

67 views
Skip to first unread message

rob.mc...@noaa.gov

unread,
Mar 17, 2015, 1:46:04 PM3/17/15
to vi...@googlegroups.com
I'm a noob vispy user, using gloo to convert my old style immediate mode stuff into shaders.

Is it efficient to bind different sets of VertexBuffers to a single program to draw multiple objects? I've got a bunch of objects that can be individually edited, but want them displayed in the same window. E.g., something like:

        self.program = Program(vertex_src, fragment_src)
        self.program.bind(object1.vertices)
        self.program.draw('triangles', object1.faces)
        self.program.bind(object2.vertices)
        self.program.draw('triangles', object2.faces)

Should I make separate programs even though they will use the exact same code? I'm just wondering if the call to bind causes an upload to the graphics card every time? My noob thought is that a VertexBuffer data is resident on the card if possible and won't be removed if unbound, but shaders still make my head spin.

Thanks,

Rob

Nicolas P. Rougier

unread,
Mar 17, 2015, 2:00:28 PM3/17/15
to vi...@googlegroups.com

If your triangles share the same shader code you need only one draw call, but you need to organize your data:

Two buffer/call solution (yours)

object 1: vertices = [P0, ..., Pn], faces = [0,1,2, 1,2,3,.... p]
object 2: vertices = [Q0, ..., Qm], faces = [0,1,2, 1,2,3,.... q]

One buffer/call solution:

vertices = [P0, ..., Pn, Q0, ..., Qm]
faces = [0,1,2, 1,2,3,.... p, p+0, p+1, ...., p+q]

Nicolas
> --
> You received this message because you are subscribed to the Google Groups "vispy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vispy+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Rob McMullen - NOAA Affiliate

unread,
Mar 17, 2015, 2:31:03 PM3/17/15
to vi...@googlegroups.com
I think I'm kind of required to use multiple buffer calls because of the different colors/line styles of the objects? I guess I left too much stuff out for brevity -- more like:

        self.program.bind(object1.vertices)
        self.program['u_color'] = object1.color
        self.program.draw('triangles', object1.faces)
        self.program.bind(object2.vertices)
        self.program['u_color'] = object2.color
        self.program.draw('triangles', object2.faces)

I suppose I could rewrite a shader to incorporate a line style as a uniform object? Er, no, a varying value to be interspersed with the index buffer data?  Hmmm, I'm probably using old-style thinking. But there are thousands of lines in each object and each object will have a uniform color.

This app is an editor, so objects will be turned on/off, and within objects points can be added/deleted/moved so I had been thinking to try to keep it modular with multiple vertex buffers because the cost of recreating a single combined vertex buffer is higher than multiple draws?

Thanks,

Rob





Nicolas P. Rougier

unread,
Mar 17, 2015, 5:19:23 PM3/17/15
to vi...@googlegroups.com


You can also have color as vertex attributes or you will need the collection system that should be implemented by next week (hopefully) during the sprint (collection is a dynamic sized buffer with local/shared/global properties).
Reply all
Reply to author
Forward
0 new messages