Re: [PyOpenGL-Users] VBO help and performance
Brought to you by:
mcfletch
From: Ian M. <geo...@gm...> - 2010-05-02 16:18:28
|
On Sun, May 2, 2010 at 12:31 AM, Wakefield, Robert <rjw...@en...>wrote: > I finally managed to get things working with the VBOs (big thanks to Ian > Mallett for the tip on the VBO class), but I have one question left. I > noticed in the pyOpenGL spec that glVertexPointer (and the others) are > deprecated and scheduled to be removed in the newer OpenGL versions. I doubt it. Do you mean glVertex*f, glNormal*f, etc.? 'Cause those are scheduled to be deprecated . . . in fact they have in OpenGL 3. Ditto for display lists. > Is the only replacement using a GLSL shader? Shaders are how the geometry is drawn, not how it is defined. > If not, what's the other option. > Vertex arrays and VBOs will be the only way to draw geometry. My advice on the whole thing: don't worry about it. It will be a very long time before anything is not supported. > I found a helpful example in the mail archive here: > http://blog.gmane.org/gmane.comp.python.opengl.user/month=20090801 using > that (also see vboattrib.py by clicking on '17 comments' for Josh Davis; > you'll have to rename the bin file to .py), but I'm not really sure how to > apply this to simple tiling. What is the quickest way to set vloc/tloc so > OpenGL know that these are the vertices/textures respectively so the code > below works? > > # main body of drawVBO in the draw loop > vbo.bind() > glVertexAttribPointer(vloc, 2, GL_FLOAT, False, 0, vbo) # vertex > location, start of VBO > glVertexAttribPointer(tloc, 2, GL_FLOAT, False, 0, vbo + (len(vbo)/2*4)) > #texture location, halfway through VBO > glEnableVertexAttribArray(vloc) > glEnableVertexAttribArray(tloc) > glDrawArrays(GL_TRIANGLES, 0, len(vbo)/2) > glDisableVertexAttribArray(vloc) > glDisableVertexAttribArray(tloc) > vbo.unbind() > > For reference, the working code I use with vertex pointers is below. My > earlier problem was apparently doing the glBufferData call wrong, and in > case this helps anyone else the VBO class is a helpful way to outsource the > job. By the way, does interleaving data offer a good performance gain over > a linear VBO (list of verts, then colors, then textures)? > Probably. Might not be too significant right now. I'd worry about optimizing it later. From experience, it's only when you have several hundred VBOs that you're binding/unbinding that it becomes a problem. > > # in the initialization; vbo3 is passed to drawVBO later. > dat = verts[:] + textures[:] # a flat list works fine > vbo3 = VBO(numpy.asarray(dat, 'f'), GL_STATIC_DRAW, GL_ARRAY_BUFFER) > > def drawVBO(texid, vbo): > glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) > glBindTexture( GL_TEXTURE_2D, texid) > > vbo.bind() > glEnableClientState(GL_VERTEX_ARRAY) > glEnableClientState(GL_TEXTURE_COORD_ARRAY) > glVertexPointer(2, GL_FLOAT, 0, vbo) > glTexCoordPointer(2, GL_FLOAT, 0, vbo + (len(vbo)/2*4)) # the *4 > accounts for sizeof(float) > glDrawArrays(GL_TRIANGLES, 0, len(vbo)/2) > glDisableClientState(GL_TEXTURE_COORD_ARRAY) > glDisableClientState(GL_VERTEX_ARRAY) > vbo.unbind() > > glFlush() > glFinish() > ''' I'm using pygame, so I pygame put it all on the screen; GLUT can do > the same ''' > pygame.display.flip() > Ian |