WIP - port to Mali EGL
[mesa-demos/mali.git] / src / perf / fbobind.c
blobfb52a93a2f67b1901d154f1e248f877aa573daec
1 /*
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.
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.
27 * Brian Paul
28 * 22 Sep 2009
31 #include <string.h>
32 #include "glmain.h"
33 #include "common.h"
35 int WinWidth = 100, WinHeight = 100;
37 static GLuint VBO;
39 static GLuint FBO[2], Tex[2];
41 static const GLsizei TexSize = 512;
43 static const GLboolean DrawPoint = GL_TRUE;
45 struct vertex
47 GLfloat x, y, s, t;
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 */
58 void
59 PerfInit(void)
61 const GLenum filter = GL_LINEAR;
62 GLenum stat;
63 int i;
65 if (!PerfExtensionSupported("GL_EXT_framebuffer_object")) {
66 perf_printf("fboswitch: GL_EXT_framebuffer_object not supported\n");
67 exit(0);
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);
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++) {
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);
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);
105 /* clear the FBO */
106 glClear(GL_COLOR_BUFFER_BIT);
109 glEnable(GL_TEXTURE_2D);
113 static void
114 FBOBind(unsigned count)
116 unsigned i;
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]);
124 /* bind dst fbo */
125 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO[dst]);
126 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
128 /* draw something */
129 if (DrawPoint)
130 glDrawArrays(GL_POINTS, 0, 1);
132 glFinish();
136 /** Called from test harness/main */
137 void
138 PerfNextRound(void)
143 /** Called from test harness/main */
144 void
145 PerfDraw(void)
147 double rate;
149 rate = PerfMeasureRate(FBOBind);
150 perf_printf(" FBO Binding: %1.f binds/sec\n", rate);
152 exit(0);