[PYTHON MATRIX-SIG] Speed of opengl

Michael McLay mclay@eeel.nist.gov
Tue, 23 Jul 1996 14:01:42 GMT


Is openglmodule-0.33.c the most current version of the opengl module?
There were a couple other modules available so I wasn't sure.

I modified the glu, glut and opengl modules so the prefixes are no
longer necessary.  They seemed redundent and C'ish.  I also had to
patch up the example fog.py and movelight.py demonstration programs in
order to get them to work.  For movelight.py this involved changing:

  glut.MouseFunc(movelight)
  glut.MotionFunc(motion)
  glut.ReshapeFunc(reshape)
  glut.DisplayFunc(display)

to 

  glut.SetMouseFuncCallback(movelight)
  glut.MouseFunc()
  glut.SetMotionFuncCallback(motion)  
  glut.MotionFunc()
  glut.SetReshapeFuncCallback(reshape)
  glut.ReshapeFunc()
  glut.SetDisplayFuncCallback(display)
  glut.DisplayFunc()
  glut.DisplayFunc(display)


The performance of the python OpenGL module on a Linux system isn't
meeting my design objectives and I was wondering if I'm doing
something wrong or if it's just slow software.  The system uses
Mesa-1.2.8 on a Pentium 90 system with #9GXE 64Pro graphics card.
When I run the the Mesa samples/speed test for the configuration the
results are: 

	antialiasing: off
	depthtest: off
	fog: off
	lighting: off
	shading: flat
	texturing: off
	Points per second: 112360
	Lines per second: 53763.4
	Triangles per second: 15408.3
	Rects per second: 10172.9

This is pretty slow compared to an SGI.  I can live with it in the
application but I'd like the drawing rate to be about 4x this speed.    
I may even break down and buy a Acellerated-X OpenGL server for the
PC, but that would be a last resort.

The performance seems to drop below an acceptable speed when I use it
with Python.  Here's a test that draws 500 random length lines.  

  import Ranf
  rlines = (Ranf.random_sample(3000) -.5)*4
  t = time.time()
  Lines(rlines)
  tr = time.time() - t




1000 random lines takes 0.173418 seconds (5766.412600 lines/second

1000 random lines takes 0.041487 seconds (24103.948646 lines/second

There seems to be a great difference in speed if the line length
becomes very small.   

I did some more testing including a comparison with the Mesa
sample/speed.c test.  


The C version draws 100 lines in a glBegin ... glEnd loop and then
repeat this loop 1000 times.  

    for (i = 0; i < repeatCount; i++) {
	v1[0] = 10;
	v1[1] = 10;
	v1[2] = 10;
	v2[0] = 20;
	v2[1] = 20;
	v2[2] = 10;
	glBegin(GL_LINES);
	    for (j = 0; j < loopCount; j++) {
		glVertex2fv(v1);
		glVertex2fv(v2);
	    }
	glEnd();

The results of this test reports:

	Lines per second: 44052.9


I wrote a Python based test that approximates this number of line
draws.  

  small = N.array([0.,.0,0.,10.0,10.0,10.0])
  for i in range(13):
      small = small.concat(small)

  size = len(small)/6
  t = time.time()
  Lines(small)
  tr = time.time() - t
  print "speed line test takes %f seconds (%f lines/second)" %( tr, size/tr)

It results plotted about 8192 lines inside the Lines() command.  The
report printed 

  in reshape 600 300
  speed line test takes 1.377772 seconds (5945.831500 lines/second)
  1000 random lines takes 0.104659 seconds (9554.843538 lines/second

This test uses the same size window as the test script.  The viewport
is closer to the objects being drawn so the lines appear longer.

The Python based version draw at a rate of ~6000 l/s compared to the C
version was drawing at 44k l/s.  The difference is difficult to
uderstand.  It looks like all the time should be spent inside the
gl_Lines loop, so why isn't performance better.  Did I miss something
in my test? 

Michael

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================