Re: [PyOpenGL-Users] Pyopengl - slow performance using
Brought to you by:
mcfletch
From: Alejandro S. <as...@gm...> - 2011-01-13 11:52:35
|
Hello Pedro, On Jan 13, 2011, at 9:29 AM, pm...@gm... wrote: > Hi all, > > I am developing an application using pyopenGL to read data from a shape file and to draw it in 2D using openGl. However, the performance is really bad; it takes up to 20 seconds to draw the map. I am using Ubuntu and nVidia NVS 3100M. > > The shape file being read has the following characteristics: > > - 50 000 entries containing the description roads segments; each road segment has the associated geometry (set of (x,y) points ) > - +/- 350 000 points in total > > > A simplified version of the code is shown bellow: > > a) to get data from shapefile (using pyshapelib) and store it in a list of lists of tuples (python): > ... > self.shp = [] > self.extents = [] > self.array = [] > ... > self.shp = shapelib.ShapeFile(filename) > for i in range(self.shp.info()[0]): > lineVert = self.shp.read_object(i).vertices() > tempArray = [] > for j in lineVert[0]: > tempArray.append([j[0],j[1]]) > self.array.append(tempArray) > > b) to draw the data using pyopenGL: > ... > glEnableClientState(GL_VERTEX_ARRAY) > # obtained from the shapefile(array element) > arrayList = self.map.getArrayList() > if len(arrayList) > 0: > for objMap in arrayList: > self.drawPolyline(objMap) > > def drawPolyline(self,inArray): > #glColor(1.0, 0.0, 0.0) > glVertexPointerf(inArray) > glDrawArrays(GL_LINE_STRIP, 0, len(inArray)) > > - Do you have any hints how to improve the performance dramatically and make it usable? I tried several options but none worked out. For instance I tried to replace python list with numpy arrays but the performance was not significantly changed. I find it puzzling that you didn't notice any speedup at all after doing this. Python lists are just linked lists, which means they are probably not consecutive in memory, but rather, they have to be converted to an array at each call to drawArrays. Are you 100% certain you were converting from a python list to a numpy array just once and not at every frame? The other thing I noticed is that you are making several calls to drawArrays. This might be required by your app's logic, but if data is actually static, I would consider making just one big array and supplying all the data at once to OpenGL. Finally, I would also consider using VBOs to prevent copying vertex data from main memory to the GPU several times over (specially if your data is static). > > - Do I need execute the OpenGL code in C? Altough I could do this, I still need to use python as scripting language due to other dependencies of the implementation. I don't think so, as long as you avoid doing a lot of calculations using python and you using deprecated features, you should be fine. Please consider revising the usage of numpy arrays. Good luck! Alejandro.- > > Thank you in advance for your help! > > Best Regards, > > Pedro > > -- > Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir > belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de > > ------------------------------------------------------------------------------ > Protect Your Site and Customers from Malware Attacks > Learn about various malware tactics and how to avoid them. Understand > malware threats, the impact they can have on your business, and how you > can protect your company and customers by using code signing. > http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |