File: gl_harness.c

package info (click to toggle)
glut 3.7-14
  • links: PTS
  • area: main
  • in suites: woody
  • size: 12,556 kB
  • ctags: 45,170
  • sloc: ansic: 148,716; makefile: 35,208; ada: 2,062; yacc: 473; fortran: 290; lex: 131; csh: 51; sed: 49; sh: 33
file content (154 lines) | stat: -rw-r--r-- 3,711 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

/* Copyright (c) Mark J. Kilgard, 1996. */

/* This program is freely distributable without licensing fees 
   and is provided without guarantee or warrantee expressed or 
   implied. This program is -not- in the public domain. */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glut.h>

extern testInit(int argc, char **argv, int width, int height);
extern testRender(void);

int testIterationsStep, testDisplayMode, testMinimumTestTime;
float timeEnd, timeStart;
int error;
int renders = 0, damaged = 0;

/* ARGSUSED */
void
report(int value)
{
  float duration;

  duration = (timeEnd - timeStart) / 1000.0;
  printf("Renders/second = %g\n",
    renders / duration);
  printf("  after %d iterations over %g seconds\n",
    renders, duration);
  if (error != GL_NO_ERROR)
    printf("OpenGL errors occurred during test; RESULTS ARE DUBIOUS.\n");
  if (damaged != 1)
    printf("Window disturbed during test; RESULTS ARE DUBIOUS.\n");
  printf("\n");
  exit(damaged != 1);
}

/* ARGSUSED */
void
ensureEventsGotten(int value)
{
  /* Hack.  Creating a new window _ensures_ any outstanding
     expose event from popping the window will be retrieved. */
  glutCreateWindow("dummy");
  glutHideWindow();
  glutTimerFunc(1, report, 0);
}

void
displayDone(void)
{
  if (glutLayerGet(GLUT_NORMAL_DAMAGED))
    damaged++;
}

/* ARGSUSED */
void
done(int value)
{
  glFinish();
  timeEnd = glutGet(GLUT_ELAPSED_TIME);
  error = glGetError();

  /* Pop the window.  If the window was obscured by another
     window during the test, raising the window should generate
     an expose event we want to catch. */
  glutPopWindow();

  /* The test is over so only notice an expose and do not run
     the testRender routine. */
  glutDisplayFunc(displayDone);
  glutTimerFunc(1, ensureEventsGotten, 0);
}

void
display(void)
{
  int i;

  if (glutLayerGet(GLUT_NORMAL_DAMAGED)) {
    damaged++;
    if (damaged == 1) {
      glutTimerFunc(testMinimumTestTime * 1000, done, 0);
      timeStart = glutGet(GLUT_ELAPSED_TIME);
    }
  }
  for (i = 0; i < testIterationsStep; i++) {
    testRender();
    renders++;
  }
  glutPostRedisplay();
}

void
visible(int state)
{
  if (state == GLUT_NOT_VISIBLE)
    damaged++;
}

int
main(int argc, char **argv)
{
  char *newArgv[100];
  int newArgc, i;

  /* Defaults; testInit may override these. */
  testIterationsStep = 5;
  testDisplayMode = GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH;
  testMinimumTestTime = 10;  /* seconds */

  glutInit(&argc, argv);
  newArgc = 1;
  newArgv[0] = argv[0];
  for (i = 1; i < argc; i++) {
    if (!strcmp("-time", argv[i])) {
      i++;
      if (argv[i] == NULL) {
        fprintf(stderr, "%s: -time option needs argument\n", argv[0]);
        exit(1);
      }
      testMinimumTestTime = (int) strtol(argv[i], NULL, 0);
    } else if (!strcmp("-mode", argv[i])) {
      i++;
      if (argv[i] == NULL) {
        fprintf(stderr, "%s: -mode option needs argument\n", argv[0]);
        exit(1);
      }
      testDisplayMode = (int) strtol(argv[i], NULL, 0);
    } else if (!strcmp("-iters", argv[i])) {
      i++;
      if (argv[i] == NULL) {
        fprintf(stderr, "%s: -mode option needs argument\n", argv[0]);
        exit(1);
      }
      testIterationsStep = (int) strtol(argv[i], NULL, 0);
    } else {
      newArgv[newArgc] = argv[i];
      newArgc++;
    }
  }
  newArgv[newArgc] = NULL;

  glutInitDisplayMode(testDisplayMode);
  glutCreateWindow("OpenGL performance test");
  glutDisplayFunc(display);
  glutVisibilityFunc(visible);
  testInit(newArgc, newArgv,
    glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}