Question

I have some code that creates a batch using the pyglet library. The whole thing contains about 10 000 quads when fully loaded. Now when I run the script which renders the whole scene (it is a completely static scene), I get 3FPS. The only thing that in the prototype I used for the scene renderer, I would build up the map using some slow and sloppy written python code, which happened to also run at 3FPS for the exact same scene. Since the batches in pyglet are managed using C++, I have this bothering feeling that I am missing something obvious that causes the batch to draw at 3FPS.

This is my scene initialization code:

glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60.0, float(width)/height, .1, 10000.)
glMatrixMode(GL_MODELVIEW)
glClearColor(94.0/255.0, 161.0/255.0, 255.0/255.0, 0.5)
glClearDepth(1.0)
glShadeModel(GL_FLAT)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)  
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

And this is the code that runs each frame to render the scene:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glTranslatef(0, 0, -1*self.mapZoomLevel)
glRotatef(self.mapPitch/5, 1, 0, 0)
glRotatef(self.mapRotation, 0, 0, 1)
glTranslatef(self.mapX, self.mapY, 0)
self.mapPrimitive.batch.draw()
Was it helpful?

Solution

If the scene is static, it should be easily fixed using a display list. Some vendors optimize display lists by converting them to VBO and glMultiDrawElements() internally so some lousy 10k quads should be no problems. And it's like four lines of code.

OTHER TIPS

There is a shortcut for this if you are using CPython. Pypy has supported pyglet for a while (http://pypy.org/compat.html). Switching into Pypy, you can get a performance improvement easily, and there is basically no need to change your code. Hope helpful to you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top