2 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
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.
33 int WinWidth
= 1000, WinHeight
= 1000;
35 static GLuint VBO
, TexObj
;
40 GLfloat x
, y
, s
, t
, r
, g
, b
, a
;
43 #define VOFFSET(F) ((void *) offsetof(struct vertex, F))
45 static const struct vertex vertices
[4] = {
47 { -1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.5 },
48 { 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.5 },
49 { 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.5 },
50 { -1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.5 }
54 static const char *VertexShader
=
57 " gl_Position = ftransform(); \n"
58 " gl_TexCoord[0] = gl_MultiTexCoord0; \n"
59 " gl_FrontColor = gl_Color; \n"
62 /* simple fragment shader */
63 static const char *FragmentShader1
=
64 "uniform sampler2D Tex; \n"
67 " vec4 t = texture2D(Tex, gl_TexCoord[0].xy); \n"
68 " gl_FragColor = vec4(1.0) - t * gl_Color; \n"
72 * A more complex fragment shader (but equivalent to first shader).
73 * A good optimizer should catch some of these no-op operations, but
74 * probably not all of them.
76 static const char *FragmentShader2
=
77 "uniform sampler2D Tex; \n"
81 " vec4 t = texture2D(Tex, gl_TexCoord[0].xy); \n"
82 " t = vec4(1.0) - t * gl_Color; \n"
86 " // no-op negate/swizzle \n"
90 " // no-op inverts \n"
91 " t = vec4(1.0) - t; \n"
92 " t = vec4(1.0) - t; \n"
94 " // no-op min/max \n"
104 " // no-op add/mul \n"
105 " t = (t + t + t + t) * 0.25; \n"
107 " // no-op mul/sub \n"
108 " t = 3.0 * t - 2.0 * t; \n"
110 " // no-op negate/min/max \n"
111 " t = -min(-t, -t); \n"
112 " t = -max(-t, -t); \n"
114 " gl_FragColor = t; \n"
117 static GLuint ShaderProg1
, ShaderProg2
;
121 /** Called from test harness/main */
127 /* setup VBO w/ vertex data */
128 glGenBuffersARB(1, &VBO
);
129 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, VBO
);
130 glBufferDataARB(GL_ARRAY_BUFFER_ARB
,
131 sizeof(vertices
), vertices
, GL_STATIC_DRAW_ARB
);
132 glVertexPointer(2, GL_FLOAT
, sizeof(struct vertex
), VOFFSET(x
));
133 glTexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), VOFFSET(s
));
134 glColorPointer(4, GL_FLOAT
, sizeof(struct vertex
), VOFFSET(r
));
135 glEnableClientState(GL_VERTEX_ARRAY
);
136 glEnableClientState(GL_COLOR_ARRAY
);
139 TexObj
= PerfCheckerTexture(128, 128);
142 ShaderProg1
= PerfShaderProgram(VertexShader
, FragmentShader1
);
143 glUseProgram(ShaderProg1
);
144 u
= glGetUniformLocation(ShaderProg1
, "Tex");
145 glUniform1i(u
, 0); /* texture unit 0 */
147 ShaderProg2
= PerfShaderProgram(VertexShader
, FragmentShader2
);
148 glUseProgram(ShaderProg2
);
149 u
= glGetUniformLocation(ShaderProg2
, "Tex");
150 glUniform1i(u
, 0); /* texture unit 0 */
159 glMatrixMode(GL_PROJECTION
);
161 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
162 glMatrixMode(GL_MODELVIEW
);
169 DrawQuad(unsigned count
)
172 glClear(GL_COLOR_BUFFER_BIT
);
174 for (i
= 0; i
< count
; i
++) {
175 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
177 /* Avoid sending command buffers with huge numbers of fullscreen
178 * quads. Graphics schedulers don't always cope well with
183 glClear(GL_COLOR_BUFFER_BIT
);
198 /** Called from test harness/main */
203 double pixelsPerDraw
= WinWidth
* WinHeight
;
208 rate
= PerfMeasureRate(DrawQuad
) * pixelsPerDraw
;
209 perf_printf(" Simple fill: %s pixels/second\n",
210 PerfHumanFloat(rate
));
214 rate
= PerfMeasureRate(DrawQuad
) * pixelsPerDraw
;
216 perf_printf(" Blended fill: %s pixels/second\n",
217 PerfHumanFloat(rate
));
220 glEnable(GL_TEXTURE_2D
);
221 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
222 rate
= PerfMeasureRate(DrawQuad
) * pixelsPerDraw
;
223 glDisable(GL_TEXTURE_2D
);
224 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
225 perf_printf(" Textured fill: %s pixels/second\n",
226 PerfHumanFloat(rate
));
229 glUseProgram(ShaderProg1
);
230 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
231 rate
= PerfMeasureRate(DrawQuad
) * pixelsPerDraw
;
233 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
234 perf_printf(" Shader1 fill: %s pixels/second\n",
235 PerfHumanFloat(rate
));
238 glUseProgram(ShaderProg2
);
239 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
240 rate
= PerfMeasureRate(DrawQuad
) * pixelsPerDraw
;
242 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
243 perf_printf(" Shader2 fill: %s pixels/second\n",
244 PerfHumanFloat(rate
));