Thread: [PyOpenGL-Users] constructing a VBO containing mixture of floats, ubytes, etc
Brought to you by:
mcfletch
From: Jonathan H. <ta...@ta...> - 2011-02-03 11:49:59
|
Hey, I am using vbo.VBO, constructed using a single array of (position, color, normal) - all floats. This looks like: self.vbo = vbo.VBO( array( list( list(chain(v, c, n)) for v, c, n in zip(verts, colors, normals) ), 'f' ), usage='GL_STATIC_DRAW' ) where verts, colors, normals are each generator expressions containing named tuples of (x, y, z) or (r, g, b), etc. My problem is that I want to try out converting the colors to unsigned bytes instead of floats. When I was using vertex arrays instead of VBOs, using unsigned bytes gave me something like 25% better framerates on my hardware (2004 era laptop with ATI), purely from increased rendering speeds. Does it sound likely that I'll see this sort of improvement on other hardware too? Or should I just stick with using colors as floats throughout? If I do go ahead, I'm not certain how to construct the vbo containing mixed types like this. Is there anything in OpenGL.arrays that might help, or do I need to brush up on my ctypes-fu to construct an array of structs manually? I'm happy that I do understand how to assign the vertex attribute pointers once the vbo is constructed. Jonathan -- Jonathan Hartley Made of meat. http://tartley.com ta...@ta... +44 7737 062 225 twitter/skype: tartley |
From: Nicolas R. <Nic...@in...> - 2011-02-03 13:35:30
|
> If I do go ahead, I'm not certain how to construct the vbo containing > mixed types like this. Is there anything in OpenGL.arrays that might > help, or do I need to brush up on my ctypes-fu to construct an array of > structs manually? Maybe the script below may help you (it needs numpy). Nicolas import sys import ctypes import numpy as np import OpenGL import OpenGL.GL as gl import OpenGL.GLU as glu import OpenGL.GLUT as glut # ----------------------------------------------------------------------------- class VertexAttribute(object): def __init__(self, count, gltype, stride, offset): self.count = count self.gltype = gltype self.stride = stride self.offset = ctypes.c_void_p(offset) # ----------------------------------------------------------------------------- class VertexAttribute_color(VertexAttribute): def __init__(self, count, gltype, stride, offset): assert count in (3, 4), \ 'Color attributes must have count of 3 or 4' VertexAttribute.__init__(self, count, gltype, stride, offset) def enable(self): gl.glColorPointer(self.count, self.gltype, self.stride, self.offset) gl.glEnableClientState(gl.GL_COLOR_ARRAY) # ----------------------------------------------------------------------------- class VertexAttribute_edge_flag(VertexAttribute): def __init__(self, count, gltype, stride, offset): assert count == 1, \ 'Edge flag attribute must have a size of 1' assert gltype in (gl.GL_BYTE, gl.GL_UNSIGNED_BYTE, gl.GL_BOOL), \ 'Edge flag attribute must have boolean type' VertexAttribute.__init__(self, 1, gltype, stride, offset) def enable(self): gl.glEdgeFlagPointer(self.stride, self.offset) gl.glEnableClientState(gl.GL_EDGE_FLAG_ARRAY) # ----------------------------------------------------------------------------- class VertexAttribute_fog_coord(VertexAttribute): def __init__(self, count, gltype, stride, offset): VertexAttribute.__init__(self, count, gltype, stride, offset) def enable(self): gl.glFogCoordPointer(self.count, self.gltype, self.stride, self.offset) gl.glEnableClientState(gl.GL_FOG_COORD_ARRAY) # ----------------------------------------------------------------------------- class VertexAttribute_normal(VertexAttribute): def __init__(self, count, gltype, stride, offset): assert count == 3, \ 'Normal attribute must have a size of 3' assert gltype in (gl.GL_BYTE, gl.GL_SHORT, gl.GL_INT, gl.GL_FLOAT, gl.GL_DOUBLE), \ 'Normal attribute must have signed type' VertexAttribute.__init__(self, 3, gltype, stride, offset) def enable(self): gl.glNormalPointer(self.gltype, self.stride, self.offset) gl.glEnableClientState(gl.GL_NORMAL_ARRAY) # ----------------------------------------------------------------------------- class VertexAttribute_secondary_color(VertexAttribute): def __init__(self, count, gltype, strude, offset): assert count == 3, \ 'Secondary color attribute must have a size of 3' VertexAttribute.__init__(self, 3, gltype, stride, offset) def enable(self): gl.glSecondaryColorPointer(3, self.gltype, self.stride, self.offset) gl.glEnableClientState(gl.GL_SECONDARY_COLOR_ARRAY) # ----------------------------------------------------------------------------- class VertexAttribute_tex_coord(VertexAttribute): def __init__(self, count, gltype, stride, offset): assert gltype in (gl.GL_SHORT, gl.GL_INT, gl.GL_FLOAT, gl.GL_DOUBLE), \ 'Texture coord attribute must have non-byte signed type' VertexAttribute.__init__(self, count, gltype, stride, offset) def enable(self): gl.glTexCoordPointer(self.count, self.gltype, self.stride, self.offset) gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY) # ----------------------------------------------------------------------------- class VertexAttribute_position(VertexAttribute): def __init__(self, count, gltype, stride, offset): assert count > 1, \ 'Vertex attribute must have count of 2, 3 or 4' assert gltype in (gl.GL_SHORT, gl.GL_INT, gl.GL_FLOAT, gl.GL_DOUBLE), \ 'Vertex attribute must have signed type larger than byte' VertexAttribute.__init__(self, count, gltype, stride, offset) def enable(self): gl.glVertexPointer(self.count, self.gltype, self.stride, self.offset) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) # ----------------------------------------------------------------------------- class VertexBufferException(Exception): pass class VertexBuffer(object): def __init__(self, vertices, indices=None): gltypes = { 'float32': gl.GL_FLOAT, 'float' : gl.GL_DOUBLE, 'float64': gl.GL_DOUBLE, 'int8' : gl.GL_BYTE, 'uint8' : gl.GL_UNSIGNED_BYTE, 'int16' : gl.GL_SHORT, 'uint16' : gl.GL_UNSIGNED_SHORT, 'int32' : gl.GL_INT, 'uint32' : gl.GL_UNSIGNED_INT } dtype = vertices.dtype names = dtype.names or [] stride = vertices.itemsize offset = 0 self.attributes = {} if indices is None: indices = np.arange(vertices.size,dtype=np.uint32) for name in names: gtype = str(dtype[name].subdtype[0]) count = reduce(lambda x,y:x*y, dtype[name].shape) if gtype not in gltypes.keys(): raise VertexBufferException gltype = gltypes[gtype] vclass = 'VertexAttribute_%s' % name self.attributes[name[0]] = eval(vclass)(count,gltype,stride,offset) offset += dtype[name].itemsize self.vertices = vertices self.vertices_id = gl.glGenBuffers(1) gl.glBindBuffer( gl.GL_ARRAY_BUFFER, self.vertices_id ) gl.glBufferData( gl.GL_ARRAY_BUFFER, self.vertices, gl.GL_STATIC_DRAW ) gl.glBindBuffer( gl.GL_ARRAY_BUFFER, 0 ) self.indices = indices self.indices_id = gl.glGenBuffers(1) gl.glBindBuffer( gl.GL_ELEMENT_ARRAY_BUFFER, self.indices_id ) gl.glBufferData( gl.GL_ELEMENT_ARRAY_BUFFER, self.indices, gl.GL_STATIC_DRAW ) gl.glBindBuffer( gl.GL_ELEMENT_ARRAY_BUFFER, 0 ) def render(self, mode=gl.GL_QUADS, what='pnctesf'): gl.glPushClientAttrib( gl.GL_CLIENT_VERTEX_ARRAY_BIT ) gl.glBindBuffer( gl.GL_ARRAY_BUFFER, self.vertices_id ) gl.glBindBuffer( gl.GL_ELEMENT_ARRAY_BUFFER, self.indices_id ) for c in self.attributes.keys(): if c in what: self.attributes[c].enable() gl.glDrawElements( gl.GL_QUADS, self.indices.size, gl.GL_UNSIGNED_INT, None) gl.glBindBuffer( gl.GL_ELEMENT_ARRAY_BUFFER, 0 ) gl.glBindBuffer( gl.GL_ARRAY_BUFFER, 0 ) gl.glPopClientAttrib( ) # ----------------------------------------------------------------------------- def on_display(): global cube, theta, phi, frame, time, timebase frame += 1 time = glut.glutGet( glut.GLUT_ELAPSED_TIME ) if (time - timebase > 1000): print frame*1000.0/(time-timebase) timebase = time; frame = 0; gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glPushMatrix() gl.glRotatef(theta, 0,0,1) gl.glRotatef(phi, 0,1,0) gl.glDisable( gl.GL_BLEND ) gl.glEnable( gl.GL_LIGHTING ) gl.glEnable( gl.GL_DEPTH_TEST ) gl.glEnable( gl.GL_POLYGON_OFFSET_FILL ) gl.glPolygonMode( gl.GL_FRONT_AND_BACK, gl.GL_FILL ) cube.render( gl.GL_QUADS, 'pnc' ) gl.glDisable( gl.GL_POLYGON_OFFSET_FILL ) gl.glEnable( gl.GL_BLEND ) gl.glDisable( gl.GL_LIGHTING ) gl.glPolygonMode( gl.GL_FRONT_AND_BACK, gl.GL_LINE ) gl.glDepthMask( gl.GL_FALSE ) gl.glColor( 0.0, 0.0, 0.0, 0.5 ) cube.render( gl.GL_QUADS, 'p' ) gl.glDepthMask( gl.GL_TRUE ) gl.glPopMatrix() glut.glutSwapBuffers() def on_reshape(width, height): gl.glViewport(0, 0, width, height) gl.glMatrixMode( gl.GL_PROJECTION ) gl.glLoadIdentity( ) glu.gluPerspective( 45.0, float(width)/float(height), 2.0, 10.0 ) gl.glMatrixMode( gl.GL_MODELVIEW ) gl.glLoadIdentity( ) gl.glTranslatef( 0.0, 0.0, -5.0 ) def on_keyboard(key, x, y): if key == '\033': sys.exit() def on_timer(value): global theta, phi theta += 0.25 phi += 0.25 glut.glutPostRedisplay() glut.glutTimerFunc(10, on_timer, 0) def on_idle(): global theta, phi theta += 0.25 phi += 0.25 glut.glutPostRedisplay() if __name__ == '__main__': p = ( ( 1, 1, 1), (-1, 1, 1), (-1,-1, 1), ( 1,-1, 1), ( 1,-1,-1), ( 1, 1,-1), (-1, 1,-1), (-1,-1,-1) ) n = ( ( 0, 0, 1), (1, 0, 0), ( 0, 1, 0), (-1, 0, 1), (0,-1, 0), ( 0, 0,-1) ); c = ( ( 1, 1, 1), ( 1, 1, 0), ( 1, 0, 1), ( 0, 1, 1), ( 1, 0, 0), ( 0, 0, 1), ( 0, 1, 0), ( 0, 0, 0) ); vertices = np.array( [ (p[0],n[0],c[0]), (p[1],n[0],c[1]), (p[2],n[0],c[2]), (p[3],n[0],c[3]), (p[0],n[1],c[0]), (p[3],n[1],c[3]), (p[4],n[1],c[4]), (p[5],n[1],c[5]), (p[0],n[2],c[0]), (p[5],n[2],c[5]), (p[6],n[2],c[6]), (p[1],n[2],c[1]), (p[1],n[3],c[1]), (p[6],n[3],c[6]), (p[7],n[3],c[7]), (p[2],n[3],c[2]), (p[7],n[4],c[7]), (p[4],n[4],c[4]), (p[3],n[4],c[3]), (p[2],n[4],c[2]), (p[4],n[5],c[4]), (p[7],n[5],c[7]), (p[6],n[5],c[6]), (p[5],n[5],c[5]) ], dtype = [('position','f4',(3,)), ('normal','f4',3), ('color','f4',3)] ) glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH) glut.glutCreateWindow("Python VBO") glut.glutReshapeWindow(400, 400) glut.glutDisplayFunc(on_display) glut.glutReshapeFunc(on_reshape) glut.glutKeyboardFunc(on_keyboard) glut.glutTimerFunc(10, on_timer, 0) #glut.glutIdleFunc(on_idle) gl.glPolygonOffset( 1, 1 ) gl.glClearColor(1,1,1,1); gl.glEnable( gl.GL_DEPTH_TEST ) gl.glEnable( gl.GL_COLOR_MATERIAL ) gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA ) gl.glEnable( gl.GL_LIGHT0 ) gl.glLight( gl.GL_LIGHT0, gl.GL_DIFFUSE, (1.0,1.0,1.0,1.0) ) gl.glLight( gl.GL_LIGHT0, gl.GL_AMBIENT, (0.1,0.1,0.1,1.0) ) gl.glLight( gl.GL_LIGHT0, gl.GL_SPECULAR, (0.0,0.0,0.0,1.0) ) gl.glLight( gl.GL_LIGHT0, gl.GL_POSITION, (0.0,1.0,2.0,1.0) ) gl.glEnable( gl.GL_LINE_SMOOTH ) theta, phi = 0, 0 frame, time, timebase = 0, 0, 0 cube = VertexBuffer(vertices) glut.glutMainLoop() |
From: Ian M. <geo...@gm...> - 2011-02-03 14:19:45
|
On Thu, Feb 3, 2011 at 4:49 AM, Jonathan Hartley <ta...@ta...>wrote: > My problem is that I want to try out converting the colors to unsigned > bytes instead of floats. When I was using vertex arrays instead of VBOs, > using unsigned bytes gave me something like 25% better framerates on my > hardware (2004 era laptop with ATI), purely from increased rendering > speeds. > > Does it sound likely that I'll see this sort of improvement on other > hardware too? Or should I just stick with using colors as floats > throughout? > Because vertex arrays transfer data across the (fairly slow) graphics bus each frame, I suspect most, if not all of this performance gain is due to passing across ~1/4 of the bits for color. As far as I know, the GPU will convert everything to floating point before rendering (with the only exception being (possibly?) textures). For example, glTranslated(...) is no more accurate than glTranslatef(...), because the matrix stack is ultimately in floating point (and the values of the transformation matrix are truncated before being multiplied in hardware). I'm fairly sure that when drawing, the rasterizer converts everything to floating point, including color. I.e., don't bother. the speed increase you're getting is due to less data transfer to the GPU. With vertex buffer objects, this data transfer nominally happens exactly once (from your usage, GL_STATIC_DRAW, yes, exactly once). If you somehow made an interleaved VBO with different data types, it sounds like you'd gain perhaps a fraction of a second of loading time (not counting the extra computation to make it client-side first), but nothing more. Ian |
From: Stephen H. <sho...@us...> - 2011-02-03 17:49:37
|
I dont think its possible to have 2 different data types in the same array. IF you've been using Numpy, each array has a type like float32, zeros(3 * numVertices + 4 * numVertices , dtype=float32) you could make 2 vbos and bind 2 vertexAttribPointers colorVBO = zeros(4 * numVertices, dtype="whatever is unsigned byte") vertexVBO = zeros(3*numVertices, dtype="float32") On Thu, Feb 3, 2011 at 3:49 AM, Jonathan Hartley <ta...@ta...>wrote: > Hey, > > I am using vbo.VBO, constructed using a single array of (position, > color, normal) - all floats. This looks like: > > self.vbo = vbo.VBO( array( list( > list(chain(v, c, n)) > for v, c, n in zip(verts, colors, normals) > ), > 'f' > ), > usage='GL_STATIC_DRAW' > ) > > where verts, colors, normals are each generator expressions containing > named tuples of (x, y, z) or (r, g, b), etc. > > My problem is that I want to try out converting the colors to unsigned > bytes instead of floats. When I was using vertex arrays instead of VBOs, > using unsigned bytes gave me something like 25% better framerates on my > hardware (2004 era laptop with ATI), purely from increased rendering > speeds. > > Does it sound likely that I'll see this sort of improvement on other > hardware too? Or should I just stick with using colors as floats > throughout? > > If I do go ahead, I'm not certain how to construct the vbo containing > mixed types like this. Is there anything in OpenGL.arrays that might > help, or do I need to brush up on my ctypes-fu to construct an array of > structs manually? > > I'm happy that I do understand how to assign the vertex attribute > pointers once the vbo is constructed. > > Jonathan > > -- > Jonathan Hartley Made of meat. http://tartley.com > ta...@ta... +44 7737 062 225 twitter/skype: tartley > > > > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better > price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > |
From: Nicolas R. <Nic...@in...> - 2011-02-03 18:23:09
|
Yes you can (see numpy record arrays) Z = numpy.zeros(100, dtype = [('position','f4',3)), ('normal','f4',3), ('color','uint8',4)] ) (see example posted previously). Nicolas On Feb 3, 2011, at 6:49 PM, Stephen Hopkins wrote: > I dont think its possible to have 2 different data types in the same array. IF you've been using Numpy, each array has a type like float32, > > zeros(3 * numVertices + 4 * numVertices , dtype=float32) > > you could make 2 vbos and bind 2 vertexAttribPointers > > colorVBO = zeros(4 * numVertices, dtype="whatever is unsigned byte") > vertexVBO = zeros(3*numVertices, dtype="float32") > > On Thu, Feb 3, 2011 at 3:49 AM, Jonathan Hartley <ta...@ta...> wrote: > Hey, > > I am using vbo.VBO, constructed using a single array of (position, > color, normal) - all floats. This looks like: > > self.vbo = vbo.VBO( array( list( > list(chain(v, c, n)) > for v, c, n in zip(verts, colors, normals) > ), > 'f' > ), > usage='GL_STATIC_DRAW' > ) > > where verts, colors, normals are each generator expressions containing > named tuples of (x, y, z) or (r, g, b), etc. > > My problem is that I want to try out converting the colors to unsigned > bytes instead of floats. When I was using vertex arrays instead of VBOs, > using unsigned bytes gave me something like 25% better framerates on my > hardware (2004 era laptop with ATI), purely from increased rendering speeds. > > Does it sound likely that I'll see this sort of improvement on other > hardware too? Or should I just stick with using colors as floats throughout? > > If I do go ahead, I'm not certain how to construct the vbo containing > mixed types like this. Is there anything in OpenGL.arrays that might > help, or do I need to brush up on my ctypes-fu to construct an array of > structs manually? > > I'm happy that I do understand how to assign the vertex attribute > pointers once the vbo is constructed. > > Jonathan > > -- > Jonathan Hartley Made of meat. http://tartley.com > ta...@ta... +44 7737 062 225 twitter/skype: tartley > > > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d_______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |
From: Jonathan H. <ta...@ta...> - 2011-02-03 22:35:13
|
Thanks for all the responses, they are all extremely helpful. It surprised me to hear that a single VBO can't hold different data types. SuperBible tentatively confirms what Steve says. Page 485 (5th ed.): It is also possible to store several different attributes in a single buffer by interleaving them. To do this, call glVertexArrayPointer with the stride param set to the distance (in bytes) between attributes *of the same type. * (Emphasis mine) All of the subsequent examples use VBOs filled exclusively with floats - although sometimes vec4s of float interleaved with vec3s of float. Is that a confirmation, or am I reading too much into it? If I manage to try it out I'll report back how it goes, but I have more urgent fish to fry for today, because , as Ian suggested early on, it probably doesn't reap the performance gain I was hoping for, so I'll stick with colors as floats for now. * *Thanks all round, especially to Nicolas whose code I'm greedily poring over. Jonathan On 03/02/2011 18:23, Nicolas Rougier wrote: > > Yes you can (see numpy record arrays) > > Z = numpy.zeros(100, > dtype = [('position','f4',3)), ('normal','f4',3), > ('color','uint8',4)] ) > > (see example posted previously). > > Nicolas > > > On Feb 3, 2011, at 6:49 PM, Stephen Hopkins wrote: > >> I dont think its possible to have 2 different data types in the same >> array. IF you've been using Numpy, each array has a type like float32, >> >> zeros(3 * numVertices + 4 * numVertices , dtype=float32) >> >> you could make 2 vbos and bind 2 vertexAttribPointers >> >> colorVBO = zeros(4 * numVertices, dtype="whatever is unsigned byte") >> vertexVBO = zeros(3*numVertices, dtype="float32") >> >> On Thu, Feb 3, 2011 at 3:49 AM, Jonathan Hartley <ta...@ta... >> <mailto:ta...@ta...>> wrote: >> >> Hey, >> >> I am using vbo.VBO, constructed using a single array of (position, >> color, normal) - all floats. This looks like: >> >> self.vbo = vbo.VBO( array( list( >> list(chain(v, c, n)) >> for v, c, n in zip(verts, colors, normals) >> ), >> 'f' >> ), >> usage='GL_STATIC_DRAW' >> ) >> >> where verts, colors, normals are each generator expressions >> containing >> named tuples of (x, y, z) or (r, g, b), etc. >> >> My problem is that I want to try out converting the colors to >> unsigned >> bytes instead of floats. When I was using vertex arrays instead >> of VBOs, >> using unsigned bytes gave me something like 25% better framerates >> on my >> hardware (2004 era laptop with ATI), purely from increased >> rendering speeds. >> >> Does it sound likely that I'll see this sort of improvement on other >> hardware too? Or should I just stick with using colors as floats >> throughout? >> >> If I do go ahead, I'm not certain how to construct the vbo containing >> mixed types like this. Is there anything in OpenGL.arrays that might >> help, or do I need to brush up on my ctypes-fu to construct an >> array of >> structs manually? >> >> I'm happy that I do understand how to assign the vertex attribute >> pointers once the vbo is constructed. >> >> Jonathan >> >> -- >> Jonathan Hartley Made of meat. http://tartley.com >> <http://tartley.com/> >> ta...@ta... <mailto:ta...@ta...> +44 7737 062 >> 225 twitter/skype: tartley >> >> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better >> price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> http://p.sf.net/sfu/arcsight-sfd2d >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net <http://pyopengl.sourceforge.net/> >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> <mailto:PyO...@li...> >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better >> price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> http://p.sf.net/sfu/arcsight-sfd2d_______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > > > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users -- Jonathan Hartley Made of meat. http://tartley.com ta...@ta... +44 7737 062 225 twitter/skype: tartley |
From: Stephen H. <sho...@us...> - 2011-02-03 20:38:36
|
And the Z array you posted could be passed as a single vertex attrib pointer? On Thu, Feb 3, 2011 at 10:23 AM, Nicolas Rougier <Nic...@in...>wrote: > > Yes you can (see numpy record arrays) > > Z = numpy.zeros(100, > dtype = [('position','f4',3)), ('normal','f4',3), > ('color','uint8',4)] ) > > (see example posted previously). > > Nicolas > > > On Feb 3, 2011, at 6:49 PM, Stephen Hopkins wrote: > > I dont think its possible to have 2 different data types in the same array. > IF you've been using Numpy, each array has a type like float32, > > zeros(3 * numVertices + 4 * numVertices , dtype=float32) > > you could make 2 vbos and bind 2 vertexAttribPointers > > colorVBO = zeros(4 * numVertices, dtype="whatever is unsigned byte") > vertexVBO = zeros(3*numVertices, dtype="float32") > > On Thu, Feb 3, 2011 at 3:49 AM, Jonathan Hartley <ta...@ta...>wrote: > >> Hey, >> >> I am using vbo.VBO, constructed using a single array of (position, >> color, normal) - all floats. This looks like: >> >> self.vbo = vbo.VBO( array( list( >> list(chain(v, c, n)) >> for v, c, n in zip(verts, colors, normals) >> ), >> 'f' >> ), >> usage='GL_STATIC_DRAW' >> ) >> >> where verts, colors, normals are each generator expressions containing >> named tuples of (x, y, z) or (r, g, b), etc. >> >> My problem is that I want to try out converting the colors to unsigned >> bytes instead of floats. When I was using vertex arrays instead of VBOs, >> using unsigned bytes gave me something like 25% better framerates on my >> hardware (2004 era laptop with ATI), purely from increased rendering >> speeds. >> >> Does it sound likely that I'll see this sort of improvement on other >> hardware too? Or should I just stick with using colors as floats >> throughout? >> >> If I do go ahead, I'm not certain how to construct the vbo containing >> mixed types like this. Is there anything in OpenGL.arrays that might >> help, or do I need to brush up on my ctypes-fu to construct an array of >> structs manually? >> >> I'm happy that I do understand how to assign the vertex attribute >> pointers once the vbo is constructed. >> >> Jonathan >> >> -- >> Jonathan Hartley Made of meat. http://tartley.com >> ta...@ta... +44 7737 062 225 twitter/skype: tartley >> >> >> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better >> price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> http://p.sf.net/sfu/arcsight-sfd2d >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >> > > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better > price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > > http://p.sf.net/sfu/arcsight-sfd2d_______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > ------------------------------------------------------------------------------ > Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! > Finally, a world-class log management solution at an even better > price-free! > Download using promo code Free_Logger_4_Dev2Dev. Offer expires > February 28th, so secure your free ArcSight Logger TODAY! > http://p.sf.net/sfu/arcsight-sfd2d > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > |
From: Stephen H. <sho...@us...> - 2011-02-03 20:47:48
|
hm well I guess theres the stride thing, and the type specifier when you use vertexAttributes. This is off topic, but ts there any way to reply to my own thread. I posted earlier about transformFeedback. I had to update my graphics card drivers from opengl 2.1 to opengl 3.3 and then reinstall pyopengl and it finally worked. Is the documentation for pyopengl going to be updated to include the newer api functons like glBeginTransformFeedback or glGenFrameBuffers? On Thu, Feb 3, 2011 at 12:38 PM, Stephen Hopkins <sho...@us...> wrote: > And the Z array you posted could be passed as a single vertex attrib > pointer? > > > On Thu, Feb 3, 2011 at 10:23 AM, Nicolas Rougier <Nic...@in... > > wrote: > >> >> Yes you can (see numpy record arrays) >> >> Z = numpy.zeros(100, >> dtype = [('position','f4',3)), ('normal','f4',3), >> ('color','uint8',4)] ) >> >> (see example posted previously). >> >> Nicolas >> >> >> On Feb 3, 2011, at 6:49 PM, Stephen Hopkins wrote: >> >> I dont think its possible to have 2 different data types in the same >> array. IF you've been using Numpy, each array has a type like float32, >> >> zeros(3 * numVertices + 4 * numVertices , dtype=float32) >> >> you could make 2 vbos and bind 2 vertexAttribPointers >> >> colorVBO = zeros(4 * numVertices, dtype="whatever is unsigned byte") >> vertexVBO = zeros(3*numVertices, dtype="float32") >> >> On Thu, Feb 3, 2011 at 3:49 AM, Jonathan Hartley <ta...@ta...>wrote: >> >>> Hey, >>> >>> I am using vbo.VBO, constructed using a single array of (position, >>> color, normal) - all floats. This looks like: >>> >>> self.vbo = vbo.VBO( array( list( >>> list(chain(v, c, n)) >>> for v, c, n in zip(verts, colors, normals) >>> ), >>> 'f' >>> ), >>> usage='GL_STATIC_DRAW' >>> ) >>> >>> where verts, colors, normals are each generator expressions containing >>> named tuples of (x, y, z) or (r, g, b), etc. >>> >>> My problem is that I want to try out converting the colors to unsigned >>> bytes instead of floats. When I was using vertex arrays instead of VBOs, >>> using unsigned bytes gave me something like 25% better framerates on my >>> hardware (2004 era laptop with ATI), purely from increased rendering >>> speeds. >>> >>> Does it sound likely that I'll see this sort of improvement on other >>> hardware too? Or should I just stick with using colors as floats >>> throughout? >>> >>> If I do go ahead, I'm not certain how to construct the vbo containing >>> mixed types like this. Is there anything in OpenGL.arrays that might >>> help, or do I need to brush up on my ctypes-fu to construct an array of >>> structs manually? >>> >>> I'm happy that I do understand how to assign the vertex attribute >>> pointers once the vbo is constructed. >>> >>> Jonathan >>> >>> -- >>> Jonathan Hartley Made of meat. http://tartley.com >>> ta...@ta... +44 7737 062 225 twitter/skype: tartley >>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >>> Finally, a world-class log management solution at an even better >>> price-free! >>> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >>> February 28th, so secure your free ArcSight Logger TODAY! >>> http://p.sf.net/sfu/arcsight-sfd2d >>> _______________________________________________ >>> PyOpenGL Homepage >>> http://pyopengl.sourceforge.net >>> _______________________________________________ >>> PyOpenGL-Users mailing list >>> PyO...@li... >>> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >>> >> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better >> price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> >> http://p.sf.net/sfu/arcsight-sfd2d_______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >> >> >> >> >> ------------------------------------------------------------------------------ >> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! >> Finally, a world-class log management solution at an even better >> price-free! >> Download using promo code Free_Logger_4_Dev2Dev. Offer expires >> February 28th, so secure your free ArcSight Logger TODAY! >> http://p.sf.net/sfu/arcsight-sfd2d >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >> >> > |
From: Greg E. <gre...@ca...> - 2011-02-03 21:42:35
|
Stephen Hopkins wrote: > I dont think its possible to have 2 different data types in the same > array. Actually, you can -- numpy lets you have arrays of records, where each record can be made up of fields of different types. -- Greg |
From: Greg E. <gre...@ca...> - 2011-02-04 21:31:53
|
Jonathan Hartley wrote: > It surprised me to hear that a single VBO can't hold different data > types. SuperBible tentatively confirms what Steve says. Page 485 (5th ed.): > > It is also possible to store several different attributes in a > single buffer by interleaving them. To do this, call > glVertexArrayPointer with the stride param set to the distance (in > bytes) between attributes *of the same type.* I think you may be misinterpreting that. By "type" there I don't think it means data type, but rather the "kind" of value, i.e. coordinates, normal, colour, etc. What it's trying to say is that the stride is the distance from one entire record to the next. Not sure about VBOs, but the various predefined formats for interleaved vertex arrays under the old system certainly include some with mixed data types. -- Greg |