Thread: [PyOpenGL-Users] size limit of vertex array?
Brought to you by:
mcfletch
From: Roland E. <r.e...@gm...> - 2010-07-13 14:36:19
|
Hello, I would like to know if there is supposed to be a limit in the number of elements in a list given to glVertexPointer()? I am using a vertex array to create a plane composed of small squares, after some experiment, it seems the vertex array cannot contains more than 64 squares whatever the size of the squares. I have not tried to optimize the number of vertices I need to draw the plane, so for each square there is 4 vertices in the array. Thus the total number of elements in the list considered by opengl is 64 * 4 * 3, even if there is more than 64 squares defined in the array. I know there is surely better way to draw such object, but this is not what I was interested in. I am currently playing with lighting and I wanted to study how to handle normal vectors, and how the color of the material is affected by the light and the normals. Regards, Roland. |
From: Ian M. <geo...@gm...> - 2010-07-13 14:39:54
|
Hi, The bounds of a vertex array or VBO object should ultimately be constrained by the amount of RAM and video memory you have. I've personally used vertex arrays of larger size than 64*4*3, so something's wrong. What specifically goes wrong when you add more? Can we see some code? Ian |
From: Roland E. <r.e...@gm...> - 2010-07-13 16:07:22
|
Ian, Here is the code to create the list of vertices: self.vertices = [] self.normals = [] self.nbrindices = 0 unit = 1.0 y = 0.0 rows = 8 columns = 8 z_center_delta = unit * (float(rows) / 2.0) x_center_delta = unit * (float(columns) / 2.0) for i in range(rows): delta_z = (unit * float(i)) - z_center_delta for j in range(columns): delta_x = (unit * float(j)) - x_center_delta self.vertices += [0.0 + delta_x, y, 0.0 + delta_z, 0.0 + delta_x, y, unit + delta_z, unit + delta_x, y, unit + delta_z, unit + delta_x, y, 0.0 + delta_z] self.normals += [0.0, +1.0, 0.0, 0.0, +1.0, 0.0, 0.0, +1.0, 0.0, 0.0, +1.0, 0.0] self.nbrindices = len(self.vertices) / 3 self.indices = range(self.nbrindices) In addition to creating the squares, the code try also to center the plane on the origin. Next is the code used for the rendering: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glVertexPointer(3, GL_FLOAT, 0, self.vertices) # Specify the vertex list to be used to draw the object glNormalPointer(GL_FLOAT, 0, self.normals) # Specify the normals list to be used to draw the object glDrawElements(GL_QUADS, self.nbrindices, GL_UNSIGNED_BYTE, self.indices) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_NORMAL_ARRAY) Thanks for the help, Roland. Le 07/13/10 16:39, Ian Mallett a écrit : > Hi, > > The bounds of a vertex array or VBO object should ultimately be > constrained by the amount of RAM and video memory you have. I've > personally used vertex arrays of larger size than 64*4*3, so > something's wrong. > > What specifically goes wrong when you add more? Can we see some code? > > Ian |
From: Ian M. <geo...@gm...> - 2010-07-13 16:22:57
|
My recommendation: use glDrawArrays(...). #Init: self.vertices = [] self.normals = [] self.nbrindices = 0 unit = 1.0 y = 0.0 rows = 2 columns = 8 z_center_delta = unit * (float(rows) / 2.0) x_center_delta = unit * (float(columns) / 2.0) for i in range(rows): delta_z = (unit * float(i)) - z_center_delta for j in range(columns): delta_x = (unit * float(j)) - x_center_delta self.vertices += [[0.0 + delta_x, y, 0.0 + delta_z], [0.0 + delta_x, y, unit + delta_z], [unit + delta_x, y, unit + delta_z], [unit + delta_x, y, 0.0 + delta_z]] self.normals += [[0.0, +1.0, 0.0], [0.0, +1.0, 0.0], [0.0, +1.0, 0.0], [0.0, +1.0, 0.0]] #Draw: glPolygonMode(GL_FRONT_AND_BACK,GL_LINE) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glVertexPointer(3, GL_FLOAT, 0, self.vertices) # Specify the vertex list to be used to draw the object glNormalPointer(GL_FLOAT, 0, self.normals) # Specify the normals list to be used to draw the object glDrawArrays(GL_QUADS,0,len(self.vertices)) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_NORMAL_ARRAY) Ian |
From: Alejandro S. <as...@gm...> - 2010-07-13 21:49:03
|
Hi Roland, I completely agree with Ian on this one. glDrawArrays seems more appropriate for the way you are composing your arrays. IMO, this should not be setting any constraints on how many vertices you can supply to the GL tough. How much RAM does your video card have? Alejandro.- On Tue, Jul 13, 2010 at 1:22 PM, Ian Mallett <geo...@gm...> wrote: > My recommendation: use glDrawArrays(...). > > #Init: > > self.vertices = [] > self.normals = [] > self.nbrindices = 0 > unit = 1.0 > y = 0.0 > rows = 2 > columns = 8 > z_center_delta = unit * (float(rows) / 2.0) > x_center_delta = unit * (float(columns) / 2.0) > for i in range(rows): > delta_z = (unit * float(i)) - z_center_delta > for j in range(columns): > delta_x = (unit * float(j)) - x_center_delta > self.vertices += [[0.0 + delta_x, y, 0.0 + delta_z], > [0.0 + delta_x, y, unit + delta_z], > [unit + delta_x, y, unit + delta_z], > [unit + delta_x, y, 0.0 + delta_z]] > self.normals += [[0.0, +1.0, 0.0], > [0.0, +1.0, 0.0], > [0.0, +1.0, 0.0], > [0.0, +1.0, 0.0]] > > #Draw: > glPolygonMode(GL_FRONT_AND_BACK,GL_LINE) > > > glEnableClientState(GL_VERTEX_ARRAY) > glEnableClientState(GL_NORMAL_ARRAY) > > glVertexPointer(3, GL_FLOAT, 0, self.vertices) # Specify the vertex list to > be used to draw the object > glNormalPointer(GL_FLOAT, 0, self.normals) # Specify the normals list to be > used to draw the object > > glDrawArrays(GL_QUADS,0,len(self.vertices)) > > > glDisableClientState(GL_VERTEX_ARRAY) > glDisableClientState(GL_NORMAL_ARRAY) > > Ian > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > -- Alejandro Segovia Azapian Director, Algorithmia: Visualization & Acceleration http://web.algorithmia.net |
From: Roland E. <r.e...@gm...> - 2010-07-14 09:50:20
|
Hi, With glDrawArrays it works, I had anyway to change the example from: glDrawArrays(GL_QUADS,0,len(self.vertices)) To: glDrawArrays(GL_QUADS,0,len(self.vertices) / 3) Thanks, Roland. Le 07/13/10 23:48, Alejandro Segovia a écrit : > Hi Roland, > > I completely agree with Ian on this one. glDrawArrays seems more > appropriate for the way you are composing your arrays. IMO, this > should not be setting any constraints on how many vertices you can > supply to the GL tough. > > How much RAM does your video card have? > > Alejandro.- > > On Tue, Jul 13, 2010 at 1:22 PM, Ian Mallett <geo...@gm... > <mailto:geo...@gm...>> wrote: > > My recommendation: use glDrawArrays(...). > > #Init: > > self.vertices = [] > self.normals = [] > self.nbrindices = 0 > unit = 1.0 > y = 0.0 > rows = 2 > columns = 8 > z_center_delta = unit * (float(rows) / 2.0) > x_center_delta = unit * (float(columns) / 2.0) > for i in range(rows): > delta_z = (unit * float(i)) - z_center_delta > for j in range(columns): > delta_x = (unit * float(j)) - x_center_delta > self.vertices += [[0.0 + delta_x, y, 0.0 + delta_z], > [0.0 + delta_x, y, unit + delta_z], > [unit + delta_x, y, unit + delta_z], > [unit + delta_x, y, 0.0 + delta_z]] > self.normals += [[0.0, +1.0, 0.0], > [0.0, +1.0, 0.0], > [0.0, +1.0, 0.0], > [0.0, +1.0, 0.0]] > > #Draw: > glPolygonMode(GL_FRONT_AND_BACK,GL_LINE) > > > glEnableClientState(GL_VERTEX_ARRAY) > glEnableClientState(GL_NORMAL_ARRAY) > > glVertexPointer(3, GL_FLOAT, 0, self.vertices) # Specify the > vertex list to be used to draw the object > glNormalPointer(GL_FLOAT, 0, self.normals) # Specify the normals > list to be used to draw the object > > glDrawArrays(GL_QUADS,0,len(self.vertices)) > > > glDisableClientState(GL_VERTEX_ARRAY) > glDisableClientState(GL_NORMAL_ARRAY) > > Ian > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first <http://sprint.com/first> -- > http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > <mailto:PyO...@li...> > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > -- > Alejandro Segovia Azapian > Director, Algorithmia: Visualization & Acceleration > http://web.algorithmia.net |
From: Roland E. <r.e...@gm...> - 2010-07-14 12:28:20
|
Hi, Its me again still playing with vertex array. Using the code showed previously, I have tried to display a plane of 60 rows and 44 columns. With lighting disabled, no material properties defined and no normals provided, the rendering of such plane is performed at 10 FPS. In addition, one of the core of the CPU is used at 100% by python what ever the size of the plane or the number of "objects" rendered. Is it normal that python uses so much CPU? Does 60 * 44 * 4, hence, 10560 vertices such big for an interactive application or should I use other techniques (VBO maybe) to render such amount of vertices or less vertices for such object? (I know that it depends, mainly, on what I want to do with the plane) When using glGetString() to get information on the hardware here are the information I got: NVIDIA Corporation GeForce 8800 GTX/PCI/SSE2 3.2.0 NVIDIA 190.42 So it seems that the program is using the graphics card at some point. The CPU of the machine is an AMD 64 X2 DualCore 5200+. Thanks for any advise, Roland Le 07/14/10 11:49, Roland Everaert a écrit : > Hi, > > With glDrawArrays it works, I had anyway to change the example from: > > glDrawArrays(GL_QUADS,0,len(self.vertices)) > > To: > > glDrawArrays(GL_QUADS,0,len(self.vertices) / 3) > > > Thanks, > > > Roland. > > Le 07/13/10 23:48, Alejandro Segovia a écrit : >> Hi Roland, >> >> I completely agree with Ian on this one. glDrawArrays seems more >> appropriate for the way you are composing your arrays. IMO, this >> should not be setting any constraints on how many vertices you can >> supply to the GL tough. >> >> How much RAM does your video card have? >> >> Alejandro.- >> >> On Tue, Jul 13, 2010 at 1:22 PM, Ian Mallett <geo...@gm... >> <mailto:geo...@gm...>> wrote: >> >> My recommendation: use glDrawArrays(...). >> >> #Init: >> >> self.vertices = [] >> self.normals = [] >> self.nbrindices = 0 >> unit = 1.0 >> y = 0.0 >> rows = 2 >> columns = 8 >> z_center_delta = unit * (float(rows) / 2.0) >> x_center_delta = unit * (float(columns) / 2.0) >> for i in range(rows): >> delta_z = (unit * float(i)) - z_center_delta >> for j in range(columns): >> delta_x = (unit * float(j)) - x_center_delta >> self.vertices += [[0.0 + delta_x, y, 0.0 + delta_z], >> [0.0 + delta_x, y, unit + delta_z], >> [unit + delta_x, y, unit + delta_z], >> [unit + delta_x, y, 0.0 + delta_z]] >> self.normals += [[0.0, +1.0, 0.0], >> [0.0, +1.0, 0.0], >> [0.0, +1.0, 0.0], >> [0.0, +1.0, 0.0]] >> >> #Draw: >> glPolygonMode(GL_FRONT_AND_BACK,GL_LINE) >> >> >> glEnableClientState(GL_VERTEX_ARRAY) >> glEnableClientState(GL_NORMAL_ARRAY) >> >> glVertexPointer(3, GL_FLOAT, 0, self.vertices) # Specify the >> vertex list to be used to draw the object >> glNormalPointer(GL_FLOAT, 0, self.normals) # Specify the normals >> list to be used to draw the object >> >> glDrawArrays(GL_QUADS,0,len(self.vertices)) >> >> >> glDisableClientState(GL_VERTEX_ARRAY) >> glDisableClientState(GL_NORMAL_ARRAY) >> >> Ian >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by Sprint >> What will you do first with EVO, the first 4G phone? >> Visit sprint.com/first <http://sprint.com/first> -- >> http://p.sf.net/sfu/sprint-com-first >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> <mailto:PyO...@li...> >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >> >> >> >> >> -- >> Alejandro Segovia Azapian >> Director, Algorithmia: Visualization & Acceleration >> http://web.algorithmia.net |
From: Roland E. <r.e...@gm...> - 2010-07-14 16:56:32
|
Concenring the high CPU usage after some thought and a test, it is mainly due to the while loop in which the OpenGL code run. Roland. Le 07/14/10 14:19, Roland Everaert a écrit : > Hi, > > Its me again still playing with vertex array. > > Using the code showed previously, I have tried to display a plane of > 60 rows and 44 columns. With lighting disabled, no material properties > defined and no normals provided, the rendering of such plane is > performed at 10 FPS. > > In addition, one of the core of the CPU is used at 100% by python what > ever the size of the plane or the number of "objects" rendered. > > Is it normal that python uses so much CPU? > > Does 60 * 44 * 4, hence, 10560 vertices such big for an interactive > application or should I use other techniques (VBO maybe) to render > such amount of vertices or less vertices for such object? (I know that > it depends, mainly, on what I want to do with the plane) > > When using glGetString() to get information on the hardware here are > the information I got: > > NVIDIA Corporation > GeForce 8800 GTX/PCI/SSE2 > 3.2.0 NVIDIA 190.42 > > So it seems that the program is using the graphics card at some point. > > The CPU of the machine is an AMD 64 X2 DualCore 5200+. > > > > Thanks for any advise, > > > Roland > > > > Le 07/14/10 11:49, Roland Everaert a écrit : >> Hi, >> >> With glDrawArrays it works, I had anyway to change the example from: >> >> glDrawArrays(GL_QUADS,0,len(self.vertices)) >> >> To: >> >> glDrawArrays(GL_QUADS,0,len(self.vertices) / 3) >> >> >> Thanks, >> >> >> Roland. >> >> Le 07/13/10 23:48, Alejandro Segovia a écrit : >>> Hi Roland, >>> >>> I completely agree with Ian on this one. glDrawArrays seems more >>> appropriate for the way you are composing your arrays. IMO, this >>> should not be setting any constraints on how many vertices you can >>> supply to the GL tough. >>> >>> How much RAM does your video card have? >>> >>> Alejandro.- >>> >>> On Tue, Jul 13, 2010 at 1:22 PM, Ian Mallett <geo...@gm... >>> <mailto:geo...@gm...>> wrote: >>> >>> My recommendation: use glDrawArrays(...). >>> >>> #Init: >>> >>> self.vertices = [] >>> self.normals = [] >>> self.nbrindices = 0 >>> unit = 1.0 >>> y = 0.0 >>> rows = 2 >>> columns = 8 >>> z_center_delta = unit * (float(rows) / 2.0) >>> x_center_delta = unit * (float(columns) / 2.0) >>> for i in range(rows): >>> delta_z = (unit * float(i)) - z_center_delta >>> for j in range(columns): >>> delta_x = (unit * float(j)) - x_center_delta >>> self.vertices += [[0.0 + delta_x, y, 0.0 + delta_z], >>> [0.0 + delta_x, y, unit + delta_z], >>> [unit + delta_x, y, unit + delta_z], >>> [unit + delta_x, y, 0.0 + delta_z]] >>> self.normals += [[0.0, +1.0, 0.0], >>> [0.0, +1.0, 0.0], >>> [0.0, +1.0, 0.0], >>> [0.0, +1.0, 0.0]] >>> >>> #Draw: >>> glPolygonMode(GL_FRONT_AND_BACK,GL_LINE) >>> >>> >>> glEnableClientState(GL_VERTEX_ARRAY) >>> glEnableClientState(GL_NORMAL_ARRAY) >>> >>> glVertexPointer(3, GL_FLOAT, 0, self.vertices) # Specify the >>> vertex list to be used to draw the object >>> glNormalPointer(GL_FLOAT, 0, self.normals) # Specify the normals >>> list to be used to draw the object >>> >>> glDrawArrays(GL_QUADS,0,len(self.vertices)) >>> >>> >>> glDisableClientState(GL_VERTEX_ARRAY) >>> glDisableClientState(GL_NORMAL_ARRAY) >>> >>> Ian >>> >>> ------------------------------------------------------------------------------ >>> This SF.net email is sponsored by Sprint >>> What will you do first with EVO, the first 4G phone? >>> Visit sprint.com/first <http://sprint.com/first> -- >>> http://p.sf.net/sfu/sprint-com-first >>> _______________________________________________ >>> PyOpenGL Homepage >>> http://pyopengl.sourceforge.net >>> _______________________________________________ >>> PyOpenGL-Users mailing list >>> PyO...@li... >>> <mailto:PyO...@li...> >>> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >>> >>> >>> >>> >>> -- >>> Alejandro Segovia Azapian >>> Director, Algorithmia: Visualization & Acceleration >>> http://web.algorithmia.net |
From: Ian M. <geo...@gm...> - 2010-07-14 18:35:11
|
Hi, Your problem is that vertex arrays are, by nature, slow. Imagine trying to specify your plane via glVertex3f and glNormal3f calls. If you're familiar with these, you know that they're fairly slow. This is because ALL of the geometry and normal data for the entire object must be passed over the graphics bus to the graphics card each frame. Not speedy. Vertex arrays act similarly. The gl_____Pointer commands, when used like this, pass all the data over the graphics bus. Again, = slow. Two solutions: display lists or VBOs. VBOs are newer, and therefore are recommended. They're also more complicated. I recommend PyOpenGL's built-in VBO class, available with "from OpenGL.arrays import vbo". Display lists are notably simpler, but they're technically deprecated (though I predict they won't be removed for at least another 15 years) and not as flexible (most notably, they can't be dynamically updated). Google should provide you with implementation specific for each. Ian |