~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to progs/tests/api_speed.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * (C) Copyright IBM Corporation 2002
3
 
 * All Rights Reserved.
4
 
 *
5
 
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 
 * copy of this software and associated documentation files (the "Software"),
7
 
 * to deal in the Software without restriction, including without limitation
8
 
 * on the rights to use, copy, modify, merge, publish, distribute, sub
9
 
 * license, and/or sell copies of the Software, and to permit persons to whom
10
 
 * the Software is furnished to do so, subject to the following conditions:
11
 
 *
12
 
 * The above copyright notice and this permission notice (including the next
13
 
 * paragraph) shall be included in all copies or substantial portions of the
14
 
 * Software.
15
 
 *
16
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19
 
 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20
 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
 
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23
 
 */
24
 
 
25
 
/**
26
 
 * \file api_speed.c
27
 
 * Simple test to measure the overhead of making GL calls.
28
 
 * 
29
 
 * The main purpose of this test is to measure the difference in calling
30
 
 * overhead of different dispatch methods.  Since it uses asm/timex.h to
31
 
 * access the Pentium's cycle counters, it will probably only compile on
32
 
 * Linux (though most architectures have a get_cycles function in timex.h).
33
 
 * That is why it isn't in the default Makefile.
34
 
 * 
35
 
 * \author Ian Romanick <idr@us.ibm.com>
36
 
 */
37
 
 
38
 
#include <stdio.h>
39
 
#include <stdlib.h>
40
 
#define GL_GLEXT_PROTOTYPES
41
 
#include <GL/gl.h>
42
 
#include <GL/glext.h>
43
 
#include <GL/glut.h>
44
 
 
45
 
#define inline __inline__
46
 
#include <asm/timex.h>
47
 
 
48
 
static float Width = 400;
49
 
static float Height = 400;
50
 
static unsigned count = 1000000;
51
 
 
52
 
 
53
 
static void Idle( void )
54
 
{
55
 
   glutPostRedisplay();
56
 
}
57
 
 
58
 
#define DO_FUNC(f,p) \
59
 
   do { \
60
 
      t0 = get_cycles(); \
61
 
      for ( i = 0 ; i < count ; i++ ) { \
62
 
         f p ; \
63
 
      } \
64
 
      t1 = get_cycles(); \
65
 
      printf("%u calls to % 20s required %llu cycles.\n", count, # f, t1 - t0); \
66
 
   } while( 0 )
67
 
 
68
 
/**
69
 
 * Main display function.  This is the place to add more API calls.
70
 
 */
71
 
static void Display( void )
72
 
{
73
 
   int i;
74
 
   const float v[3] = { 1.0, 0.0, 0.0 };
75
 
   cycles_t t0;
76
 
   cycles_t t1;
77
 
 
78
 
   glBegin(GL_TRIANGLE_STRIP);
79
 
 
80
 
   DO_FUNC( glColor3fv, (v) );
81
 
   DO_FUNC( glNormal3fv, (v) );
82
 
   DO_FUNC( glTexCoord2fv, (v) );
83
 
   DO_FUNC( glTexCoord3fv, (v) );
84
 
   DO_FUNC( glMultiTexCoord2fv, (GL_TEXTURE0, v) );
85
 
   DO_FUNC( glMultiTexCoord2f, (GL_TEXTURE0, 0.0, 0.0) );
86
 
   DO_FUNC( glFogCoordfvEXT, (v) );
87
 
   DO_FUNC( glFogCoordfEXT, (0.5) );
88
 
 
89
 
   glEnd();
90
 
 
91
 
   exit(0);
92
 
}
93
 
 
94
 
 
95
 
static void Reshape( int width, int height )
96
 
{
97
 
   Width = width;
98
 
   Height = height;
99
 
   glViewport( 0, 0, width, height );
100
 
   glMatrixMode( GL_PROJECTION );
101
 
   glLoadIdentity();
102
 
   glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
103
 
   glMatrixMode( GL_MODELVIEW );
104
 
   glLoadIdentity();
105
 
}
106
 
 
107
 
 
108
 
static void Key( unsigned char key, int x, int y )
109
 
{
110
 
   (void) x;
111
 
   (void) y;
112
 
   switch (key) {
113
 
      case 27:
114
 
         exit(0);
115
 
         break;
116
 
   }
117
 
   glutPostRedisplay();
118
 
}
119
 
 
120
 
 
121
 
int main( int argc, char *argv[] )
122
 
{
123
 
   glutInit( &argc, argv );
124
 
   glutInitWindowSize( (int) Width, (int) Height );
125
 
   glutInitWindowPosition( 0, 0 );
126
 
 
127
 
   glutInitDisplayMode( GLUT_RGB );
128
 
 
129
 
   glutCreateWindow( argv[0] );
130
 
 
131
 
   if ( argc > 1 ) {
132
 
      count = strtoul( argv[1], NULL, 0 );
133
 
      if ( count == 0 ) {
134
 
         fprintf( stderr, "Usage: %s [iterations]\n", argv[0] );
135
 
         exit(1);
136
 
      }
137
 
   }
138
 
 
139
 
   glutReshapeFunc( Reshape );
140
 
   glutKeyboardFunc( Key );
141
 
   glutDisplayFunc( Display );
142
 
   glutIdleFunc( Idle );
143
 
 
144
 
   glutMainLoop();
145
 
   return 0;
146
 
}