blob: 99a56ef2f79678aa605be1eb850eb5001d7e0ccb [file] [log] [blame]
Brian Pauled113da2009-09-22 11:03:43 -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 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.
26 *
27 * Brian Paul
28 * 22 Sep 2009
29 */
30
31#include <string.h>
32#include "glmain.h"
33#include "common.h"
34
35int WinWidth = 100, WinHeight = 100;
36
37static GLuint VBO;
38
39static GLuint FBO[2], Tex[2];
40
41static const GLsizei TexSize = 512;
42
43static const GLboolean DrawPoint = GL_TRUE;
44
45struct vertex
46{
47 GLfloat x, y, s, t;
48};
49
50static const struct vertex vertices[1] = {
51 { 0.0, 0.0, 0.5, 0.5 },
52};
53
54#define VOFFSET(F) ((void *) offsetof(struct vertex, F))
55
56
57/** Called from test harness/main */
58void
59PerfInit(void)
60{
61 const GLenum filter = GL_LINEAR;
62 GLenum stat;
63 int i;
64
65 if (!PerfExtensionSupported("GL_EXT_framebuffer_object")) {
66 perf_printf("fboswitch: GL_EXT_framebuffer_object not supported\n");
67 exit(0);
68 }
69
70 /* setup VBO */
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);
75
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);
80
81 glGenFramebuffersEXT(2, FBO);
82 glGenTextures(2, Tex);
83
84 for (i = 0; i < 2; i++) {
85 /* setup texture */
86 glBindTexture(GL_TEXTURE_2D, Tex[i]);
87 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
88 TexSize, TexSize, 0,
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);
92
93
94 /* setup fbo */
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");
102 exit(1);
103 }
104
105 /* clear the FBO */
106 glClear(GL_COLOR_BUFFER_BIT);
107 }
108}
109
110
111static void
112FBOBind(unsigned count)
113{
114 unsigned i;
115 for (i = 1; i < count; i++) {
116 const GLuint dst = i & 1;
117 const GLuint src = 1 - dst;
118
119 /* bind src texture */
120 glBindTexture(GL_TEXTURE_2D, Tex[src]);
121
122 /* bind dst fbo */
123 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO[dst]);
124 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
125
126 /* draw something */
127 if (DrawPoint)
128 glDrawArrays(GL_POINTS, 0, 1);
129 }
130 glFinish();
131}
132
133
134/** Called from test harness/main */
135void
136PerfNextRound(void)
137{
138}
139
140
141/** Called from test harness/main */
142void
143PerfDraw(void)
144{
145 double rate;
146
147 rate = PerfMeasureRate(FBOBind);
148 perf_printf(" FBO Binding: %1.f binds/sec\n", rate);
149
150 exit(0);
151}