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.
23 * Measure rate of binding/switching between FBO targets.
24 * Create two framebuffer objects for rendering to two textures.
25 * Ping pong between texturing from one and drawing into the other.
35 int WinWidth
= 100, WinHeight
= 100;
39 static GLuint FBO
[2], Tex
[2];
41 static const GLsizei TexSize
= 512;
43 static const GLboolean DrawPoint
= GL_TRUE
;
50 static const struct vertex vertices
[1] = {
51 { 0.0, 0.0, 0.5, 0.5 },
54 #define VOFFSET(F) ((void *) offsetof(struct vertex, F))
57 /** Called from test harness/main */
61 const GLenum filter
= GL_LINEAR
;
65 if (!PerfExtensionSupported("GL_EXT_framebuffer_object")) {
66 perf_printf("fboswitch: GL_EXT_framebuffer_object not supported\n");
71 glGenBuffersARB(1, &VBO
);
72 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, VBO
);
73 glBufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(vertices
),
74 vertices
, GL_STATIC_DRAW_ARB
);
76 glVertexPointer(2, GL_FLOAT
, sizeof(struct vertex
), VOFFSET(x
));
77 glTexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), VOFFSET(s
));
78 glEnableClientState(GL_VERTEX_ARRAY
);
79 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
81 glGenFramebuffersEXT(2, FBO
);
82 glGenTextures(2, Tex
);
84 for (i
= 0; i
< 2; i
++) {
86 glBindTexture(GL_TEXTURE_2D
, Tex
[i
]);
87 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
,
89 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
90 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, filter
);
91 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, filter
);
95 glBindFramebufferEXT(GL_FRAMEBUFFER
, FBO
[i
]);
96 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
97 GL_COLOR_ATTACHMENT0_EXT
,
98 GL_TEXTURE_2D
, Tex
[i
], 0/*level*/);
99 stat
= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT
);
100 if (stat
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
101 perf_printf("fboswitch: Error: incomplete FBO!\n");
106 glClear(GL_COLOR_BUFFER_BIT
);
109 glEnable(GL_TEXTURE_2D
);
114 FBOBind(unsigned count
)
117 for (i
= 1; i
< count
; i
++) {
118 const GLuint dst
= i
& 1;
119 const GLuint src
= 1 - dst
;
121 /* bind src texture */
122 glBindTexture(GL_TEXTURE_2D
, Tex
[src
]);
125 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, FBO
[dst
]);
126 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT
);
130 glDrawArrays(GL_POINTS
, 0, 1);
136 /** Called from test harness/main */
143 /** Called from test harness/main */
149 rate
= PerfMeasureRate(FBOBind
);
150 perf_printf(" FBO Binding: %1.f binds/sec\n", rate
);