132001f49Smrg/** 232001f49Smrg * Measure fill rates for basic shading/texturing modes. 332001f49Smrg * 432001f49Smrg * Brian Paul 532001f49Smrg * 1 April 2008 632001f49Smrg */ 732001f49Smrg 832001f49Smrg 932001f49Smrg#include <stdio.h> 1032001f49Smrg#include <stdlib.h> 1132001f49Smrg#include <math.h> 1232001f49Smrg#include <GL/glew.h> 1332001f49Smrg#include "glut_wrap.h" 1432001f49Smrg#include "readtex.h" 1532001f49Smrg 1632001f49Smrg#define TEXTURE_1_FILE DEMOS_DATA_DIR "tile.rgb" 1732001f49Smrg#define TEXTURE_2_FILE DEMOS_DATA_DIR "reflect.rgb" 1832001f49Smrg 1932001f49Smrgstatic int Win; 2032001f49Smrgstatic int Width = 1010, Height = 1010; 2132001f49Smrgstatic GLuint Textures[2]; 2232001f49Smrg 2332001f49Smrg 2432001f49Smrg/** 2532001f49Smrg * Draw quad 10 pixels shorter, narrower than window size. 2632001f49Smrg */ 2732001f49Smrgstatic void 2832001f49SmrgDrawQuad(void) 2932001f49Smrg{ 3032001f49Smrg glBegin(GL_POLYGON); 3132001f49Smrg 3232001f49Smrg glColor3f(1.0, 0.5, 0.5); 3332001f49Smrg glMultiTexCoord2f(GL_TEXTURE0, 0, 0); 3432001f49Smrg glMultiTexCoord2f(GL_TEXTURE1, 0, 0); 3532001f49Smrg glVertex2f(5, 5); 3632001f49Smrg 3732001f49Smrg glColor3f(0.5, 1.0, 0.5); 3832001f49Smrg glMultiTexCoord2f(GL_TEXTURE0, 1, 0); 3932001f49Smrg glMultiTexCoord2f(GL_TEXTURE1, 1, 0); 4032001f49Smrg glVertex2f(Width - 5, 5); 4132001f49Smrg 4232001f49Smrg glColor3f(0.5, 0.5, 1.0); 4332001f49Smrg glMultiTexCoord2f(GL_TEXTURE0, 1, 1); 4432001f49Smrg glMultiTexCoord2f(GL_TEXTURE1, 1, 1); 4532001f49Smrg glVertex2f(Width - 5, Height - 5); 4632001f49Smrg 4732001f49Smrg glColor3f(1.0, 0.5, 1.0); 4832001f49Smrg glMultiTexCoord2f(GL_TEXTURE0, 0, 1); 4932001f49Smrg glMultiTexCoord2f(GL_TEXTURE1, 0, 1); 5032001f49Smrg glVertex2f(5, Height - 5); 5132001f49Smrg 5232001f49Smrg glEnd(); 5332001f49Smrg} 5432001f49Smrg 5532001f49Smrg 5632001f49Smrg/** 5732001f49Smrg * Compute rate for drawing large quad with given shading/texture state. 5832001f49Smrg */ 5932001f49Smrgstatic void 6032001f49SmrgRunTest(GLenum shading, GLuint numTextures, GLenum texFilter) 6132001f49Smrg{ 6232001f49Smrg const GLdouble minPeriod = 2.0; 6332001f49Smrg GLdouble t0, t1; 6432001f49Smrg GLdouble pixels, rate; 6532001f49Smrg GLint i, iters; 6632001f49Smrg 6732001f49Smrg glActiveTexture(GL_TEXTURE0); 6832001f49Smrg if (numTextures > 0) { 6932001f49Smrg glBindTexture(GL_TEXTURE_2D, Textures[0]); 7032001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texFilter); 7132001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texFilter); 7232001f49Smrg glEnable(GL_TEXTURE_2D); 7332001f49Smrg } 7432001f49Smrg else { 7532001f49Smrg glDisable(GL_TEXTURE_2D); 7632001f49Smrg } 7732001f49Smrg 7832001f49Smrg glActiveTexture(GL_TEXTURE1); 7932001f49Smrg if (numTextures > 1) { 8032001f49Smrg glBindTexture(GL_TEXTURE_2D, Textures[1]); 8132001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texFilter); 8232001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texFilter); 8332001f49Smrg glEnable(GL_TEXTURE_2D); 8432001f49Smrg } 8532001f49Smrg else { 8632001f49Smrg glDisable(GL_TEXTURE_2D); 8732001f49Smrg } 8832001f49Smrg 8932001f49Smrg glShadeModel(shading); 9032001f49Smrg 9132001f49Smrg 9232001f49Smrg glFinish(); 9332001f49Smrg 9432001f49Smrg iters = 1; 9532001f49Smrg do { 9632001f49Smrg iters *= 4; 9732001f49Smrg t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001; 9832001f49Smrg for (i = 0; i < iters; i++) { 9932001f49Smrg DrawQuad(); 10032001f49Smrg } 10132001f49Smrg glFinish(); 10232001f49Smrg t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001; 10332001f49Smrg } while (t1 - t0 < minPeriod); 10432001f49Smrg 10532001f49Smrg glutSwapBuffers(); 10632001f49Smrg 10732001f49Smrg pixels = (double) iters * (Width - 10) * (Height - 10); 10832001f49Smrg rate = pixels / (t1 - t0); 10932001f49Smrg rate /= 1000000.0; /* megapixels/second */ 11032001f49Smrg 11132001f49Smrg printf("%s ", shading == GL_FLAT ? "GL_FLAT" : "GL_SMOOTH"); 11232001f49Smrg printf("Textures=%u ", numTextures); 11332001f49Smrg printf("Filter=%s: ", texFilter == GL_LINEAR ? "GL_LINEAR" : "GL_NEAREST"); 11432001f49Smrg printf("%g MPixels/sec\n", rate); 11532001f49Smrg} 11632001f49Smrg 11732001f49Smrg 11832001f49Smrgstatic void 11932001f49SmrgDraw(void) 12032001f49Smrg{ 12132001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 12232001f49Smrg 12332001f49Smrg RunTest(GL_FLAT, 0, GL_NEAREST); 12432001f49Smrg RunTest(GL_SMOOTH, 0, GL_NEAREST); 12532001f49Smrg RunTest(GL_SMOOTH, 1, GL_NEAREST); 12632001f49Smrg RunTest(GL_SMOOTH, 1, GL_LINEAR); 12732001f49Smrg RunTest(GL_SMOOTH, 2, GL_NEAREST); 12832001f49Smrg RunTest(GL_SMOOTH, 2, GL_LINEAR); 12932001f49Smrg 13032001f49Smrg glutSwapBuffers(); 13132001f49Smrg} 13232001f49Smrg 13332001f49Smrg 13432001f49Smrgstatic void 13532001f49SmrgReshape(int width, int height) 13632001f49Smrg{ 13732001f49Smrg glViewport(0, 0, width, height); 13832001f49Smrg glMatrixMode(GL_PROJECTION); 13932001f49Smrg glLoadIdentity(); 14032001f49Smrg glOrtho(0, width, 0, height, -1, 1); 14132001f49Smrg glMatrixMode(GL_MODELVIEW); 14232001f49Smrg glLoadIdentity(); 14332001f49Smrg Width = width; 14432001f49Smrg Height = height; 14532001f49Smrg} 14632001f49Smrg 14732001f49Smrg 14832001f49Smrgstatic void 14932001f49SmrgKey(unsigned char key, int x, int y) 15032001f49Smrg{ 15132001f49Smrg (void) x; 15232001f49Smrg (void) y; 15332001f49Smrg switch (key) { 15432001f49Smrg case 27: 15532001f49Smrg glutDestroyWindow(Win); 15632001f49Smrg exit(0); 15732001f49Smrg break; 15832001f49Smrg } 15932001f49Smrg glutPostRedisplay(); 16032001f49Smrg} 16132001f49Smrg 16232001f49Smrg 16332001f49Smrgstatic void 16432001f49SmrgInit(void) 16532001f49Smrg{ 16632001f49Smrg printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); 16732001f49Smrg 16832001f49Smrg glGenTextures(2, Textures); 16932001f49Smrg 17032001f49Smrg glBindTexture(GL_TEXTURE_2D, Textures[0]); 17132001f49Smrg glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 17232001f49Smrg 17332001f49Smrg if (!LoadRGBMipmaps(TEXTURE_1_FILE, GL_RGB)) { 17432001f49Smrg printf("Error: couldn't load texture image\n"); 17532001f49Smrg exit(1); 17632001f49Smrg } 17732001f49Smrg 17832001f49Smrg glBindTexture(GL_TEXTURE_2D, Textures[1]); 17932001f49Smrg glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 18032001f49Smrg 18132001f49Smrg if (!LoadRGBMipmaps(TEXTURE_2_FILE, GL_RGB)) { 18232001f49Smrg printf("Error: couldn't load texture image\n"); 18332001f49Smrg exit(1); 18432001f49Smrg } 18532001f49Smrg 18632001f49Smrg} 18732001f49Smrg 18832001f49Smrg 18932001f49Smrgint 19032001f49Smrgmain(int argc, char *argv[]) 19132001f49Smrg{ 19232001f49Smrg glutInit(&argc, argv); 19332001f49Smrg glutInitWindowPosition(0, 0); 19432001f49Smrg glutInitWindowSize(Width, Height); 19532001f49Smrg glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 19632001f49Smrg Win = glutCreateWindow(argv[0]); 19732001f49Smrg glewInit(); 19832001f49Smrg glutReshapeFunc(Reshape); 19932001f49Smrg glutKeyboardFunc(Key); 20032001f49Smrg glutDisplayFunc(Draw); 20132001f49Smrg Init(); 20232001f49Smrg glutMainLoop(); 20332001f49Smrg return 0; 20432001f49Smrg} 205