blob: 4b7d6ad155b73b0cba0f113c3aa4c9dd61599ea3 [file] [log] [blame]
Brian Paulc9ddd6f2009-09-24 19:36:37 -06001/*
2 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22/**
23 * Measure glGenerateMipmap() speed.
24 *
25 * Brian Paul
26 * 24 Sep 2009
27 */
28
29#include <string.h>
30#include "glmain.h"
31#include "common.h"
32
33
34int WinWidth = 100, WinHeight = 100;
35
36static GLboolean DrawPoint = GL_TRUE;
37static GLuint VBO;
38static GLuint TexObj = 0;
39static GLint BaseLevel, MaxLevel;
40
41struct vertex
42{
43 GLfloat x, y, s, t;
44};
45
46static const struct vertex vertices[1] = {
47 { 0.0, 0.0, 0.5, 0.5 },
48};
49
50#define VOFFSET(F) ((void *) offsetof(struct vertex, F))
51
52/** Called from test harness/main */
53void
54PerfInit(void)
55{
56 /* setup VBO w/ vertex data */
57 glGenBuffersARB(1, &VBO);
58 glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
59 glBufferDataARB(GL_ARRAY_BUFFER_ARB,
60 sizeof(vertices), vertices, GL_STATIC_DRAW_ARB);
61 glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(x));
62 glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex), VOFFSET(s));
63 glEnableClientState(GL_VERTEX_ARRAY);
64 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
65
66 glGenTextures(1, &TexObj);
67 glBindTexture(GL_TEXTURE_2D, TexObj);
68 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
69 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
70 glEnable(GL_TEXTURE_2D);
71}
72
73
74static void
75GenMipmap(unsigned count)
76{
77 unsigned i;
78 for (i = 0; i < count; i++) {
79 GLubyte texel[4];
80 texel[0] = texel[1] = texel[2] = texel[3] = i & 0xff;
81 /* dirty the base image */
82 glTexSubImage2D(GL_TEXTURE_2D, BaseLevel,
83 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, texel);
84 glGenerateMipmap(GL_TEXTURE_2D);
85 if (DrawPoint)
86 glDrawArrays(GL_POINTS, 0, 1);
87 }
88 glFinish();
89}
90
91
92/** Called from test harness/main */
93void
94PerfNextRound(void)
95{
96}
97
98
99/** Called from test harness/main */
100void
101PerfDraw(void)
102{
103 const GLint NumLevels = 12;
104 const GLint TexWidth = 2048, TexHeight = 2048;
105 GLubyte *img;
106 double rate;
107
108 /* Make 2K x 2K texture */
109 img = (GLubyte *) malloc(TexWidth * TexHeight * 4);
110 memset(img, 128, TexWidth * TexHeight * 4);
111 glTexImage2D(GL_TEXTURE_2D, 0,
112 GL_RGBA, TexWidth, TexHeight, 0,
113 GL_RGBA, GL_UNSIGNED_BYTE, img);
114 free(img);
115
116 perf_printf("Texture level[0] size: %d x %d, %d levels\n",
117 TexWidth, TexHeight, NumLevels);
118
119 /* loop over base levels 0, 2, 4 */
120 for (BaseLevel = 0; BaseLevel <= 4; BaseLevel += 2) {
121
122 /* loop over max level */
123 for (MaxLevel = NumLevels; MaxLevel > BaseLevel; MaxLevel--) {
124
125 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel);
126 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel);
127
128 rate = PerfMeasureRate(GenMipmap);
129
130 perf_printf(" glGenerateMipmap(levels %d..%d): %.2f gens/sec\n",
131 BaseLevel + 1, MaxLevel, rate);
132 }
133 }
134
135 exit(0);
136}