performance.py :  » Game-2D-3D » PyOpenGL » PyOpenGL-3.0.1 » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » PyOpenGL 
PyOpenGL » PyOpenGL 3.0.1 » tests » performance.py
#! /usr/bin/env python
"""This script is intended to give me an idea of current performance with various drawing strategies"""
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from OpenGL.arrays import vbo
import cProfile, time, os
PROFILER = cProfile.Profile()

import numpy

def dump( ):
    def newfile( base ):
        new = base 
        count = 0
        while os.path.isfile( new ):
            new = '%s-%s%s'%( 
                os.path.splitext(base)[0], 
                count,
                os.path.splitext(base)[1] 
            )
            count += 1
        return new
    PROFILER.dump_stats( newfile( 'performance.profile' ) )


def init_vbo( size = 1000000 ):
    """Create VBO with vertices of count size"""
    a = numpy.zeros( (size,3), dtype='d')
    xes = numpy.arange(-5,5,float(10)/size, dtype='d' )
    a[:len(xes),0] = xes
    a[:len(xes),1] = numpy.sin( xes )
    a[:len(xes),2] = numpy.cos( xes )
    v = a
    v = vbo.VBO( a )
    v.bind()
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnable( GL_LIGHTING )
    glEnable( GL_LIGHT0 )
    glDisable( GL_CULL_FACE )
    glColor3f( 1.0,1.0,1.0)
    glNormal3f( 0.0, 0.0, 1.0 )
    return v 

def draw_with_array( a , count):
    glDrawArrays( GL_TRIANGLES, 0, (count) )
    glFlush()
    glutSwapBuffers()

def init():
    glMatrixMode (GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(40.0, 300/300, 1.0, 20.0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    gluLookAt(
        20,0,0, # eyepoint
        0,0,0, # center-of-view
        0,1,0, # up-vector
    )
    glClearColor( 0,0,.25, 0 )
    glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT )

def display( ):
    init()
    repeat = range(100)
    for count in [(2**i) for i in range(8,19)]:
        v = init_vbo( count )
        def x( ):
            t1 = time.time()
            for i in repeat:
                glVertexPointer(  3, GL_DOUBLE, 0, v )
                draw_with_array( v, count )
            t2 = time.time()
            print 'Count: %s Total Time for %s iterations: %s  MTri/s: %s'%(
                count, len(repeat), t2-t1, (count*len(repeat)/(t2-t1)/1000000)
            )
        PROFILER.runcall( x )
    dump()
    import sys
    sys.exit(1)
    print 'should not get here'

if __name__ == "__main__":
    import sys
    newArgv = glutInit(sys.argv)
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB )
    glutInitWindowSize(250, 250)
    glutInitWindowPosition(100, 100)
    window = glutCreateWindow("hello")
    glutDisplayFunc(display)
    glutMainLoop()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.