2 * Measure fill rates for basic shading/texturing modes.
12 #include <glad/glad.h>
13 #include "glut_wrap.h"
16 #define TEXTURE_1_FILE DEMOS_DATA_DIR "tile.rgb"
17 #define TEXTURE_2_FILE DEMOS_DATA_DIR "reflect.rgb"
20 static int Width
= 1010, Height
= 1010;
21 static GLuint Textures
[2];
25 * Draw quad 10 pixels shorter, narrower than window size.
32 glColor3f(1.0, 0.5, 0.5);
33 glMultiTexCoord2f(GL_TEXTURE0
, 0, 0);
34 glMultiTexCoord2f(GL_TEXTURE1
, 0, 0);
37 glColor3f(0.5, 1.0, 0.5);
38 glMultiTexCoord2f(GL_TEXTURE0
, 1, 0);
39 glMultiTexCoord2f(GL_TEXTURE1
, 1, 0);
40 glVertex2f(Width
- 5, 5);
42 glColor3f(0.5, 0.5, 1.0);
43 glMultiTexCoord2f(GL_TEXTURE0
, 1, 1);
44 glMultiTexCoord2f(GL_TEXTURE1
, 1, 1);
45 glVertex2f(Width
- 5, Height
- 5);
47 glColor3f(1.0, 0.5, 1.0);
48 glMultiTexCoord2f(GL_TEXTURE0
, 0, 1);
49 glMultiTexCoord2f(GL_TEXTURE1
, 0, 1);
50 glVertex2f(5, Height
- 5);
57 * Compute rate for drawing large quad with given shading/texture state.
60 RunTest(GLenum shading
, GLuint numTextures
, GLenum texFilter
)
62 const GLdouble minPeriod
= 2.0;
64 GLdouble pixels
, rate
;
67 glActiveTexture(GL_TEXTURE0
);
68 if (numTextures
> 0) {
69 glBindTexture(GL_TEXTURE_2D
, Textures
[0]);
70 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, texFilter
);
71 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, texFilter
);
72 glEnable(GL_TEXTURE_2D
);
75 glDisable(GL_TEXTURE_2D
);
78 glActiveTexture(GL_TEXTURE1
);
79 if (numTextures
> 1) {
80 glBindTexture(GL_TEXTURE_2D
, Textures
[1]);
81 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, texFilter
);
82 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, texFilter
);
83 glEnable(GL_TEXTURE_2D
);
86 glDisable(GL_TEXTURE_2D
);
89 glShadeModel(shading
);
97 t0
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
98 for (i
= 0; i
< iters
; i
++) {
102 t1
= glutGet(GLUT_ELAPSED_TIME
) * 0.001;
103 } while (t1
- t0
< minPeriod
);
107 pixels
= (double) iters
* (Width
- 10) * (Height
- 10);
108 rate
= pixels
/ (t1
- t0
);
109 rate
/= 1000000.0; /* megapixels/second */
111 printf("%s ", shading
== GL_FLAT
? "GL_FLAT" : "GL_SMOOTH");
112 printf("Textures=%u ", numTextures
);
113 printf("Filter=%s: ", texFilter
== GL_LINEAR
? "GL_LINEAR" : "GL_NEAREST");
114 printf("%g MPixels/sec\n", rate
);
121 glClear(GL_COLOR_BUFFER_BIT
);
123 RunTest(GL_FLAT
, 0, GL_NEAREST
);
124 RunTest(GL_SMOOTH
, 0, GL_NEAREST
);
125 RunTest(GL_SMOOTH
, 1, GL_NEAREST
);
126 RunTest(GL_SMOOTH
, 1, GL_LINEAR
);
127 RunTest(GL_SMOOTH
, 2, GL_NEAREST
);
128 RunTest(GL_SMOOTH
, 2, GL_LINEAR
);
135 Reshape(int width
, int height
)
137 glViewport(0, 0, width
, height
);
138 glMatrixMode(GL_PROJECTION
);
140 glOrtho(0, width
, 0, height
, -1, 1);
141 glMatrixMode(GL_MODELVIEW
);
149 Key(unsigned char key
, int x
, int y
)
155 glutDestroyWindow(Win
);
166 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
168 glGenTextures(2, Textures
);
170 glBindTexture(GL_TEXTURE_2D
, Textures
[0]);
171 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
173 if (!LoadRGBMipmaps(TEXTURE_1_FILE
, GL_RGB
)) {
174 printf("Error: couldn't load texture image\n");
178 glBindTexture(GL_TEXTURE_2D
, Textures
[1]);
179 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
181 if (!LoadRGBMipmaps(TEXTURE_2_FILE
, GL_RGB
)) {
182 printf("Error: couldn't load texture image\n");
190 main(int argc
, char *argv
[])
192 glutInit(&argc
, argv
);
193 glutInitWindowPosition(0, 0);
194 glutInitWindowSize(Width
, Height
);
195 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
196 Win
= glutCreateWindow(argv
[0]);
198 glutReshapeFunc(Reshape
);
199 glutKeyboardFunc(Key
);
200 glutDisplayFunc(Draw
);