Removed invalid EGL config attribute
[glmemperf] / fboblittest.cpp
1 /**
2  * OpenGL ES 2.0 memory performance estimator
3  * Copyright (C) 2009 Nokia
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * \author Sami Kyöstilä <sami.kyostila@nokia.com>
20  *
21  * Framebuffer object blit test
22  */
23 #include "fboblittest.h"
24 #include "util.h"
25 #include <sstream>
26
27 FBOBlitTest::FBOBlitTest(GLenum format, GLenum type, int width, int height,
28                          bool rotate, float texW, float texH, bool useDepth):
29     BlitTest(width, height, rotate, texW, texH),
30     m_type(type),
31     m_useDepth(useDepth)
32 {
33     m_format = format;
34     m_type = type;
35 }
36
37 void FBOBlitTest::prepare()
38 {
39     BlitTest::prepare();
40
41     glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_width, m_height, 0, m_format, m_type, NULL);
42     ASSERT_GL();
43
44     glGenRenderbuffers(1, &m_depthbuffer);
45     glBindRenderbuffer(GL_RENDERBUFFER, m_depthbuffer);
46     glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_width, m_height);
47     ASSERT_GL();
48
49     glGenFramebuffers(1, &m_framebuffer);
50     glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
51     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0);
52     if (m_useDepth)
53     {
54         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
55                                   GL_RENDERBUFFER, m_depthbuffer);
56     }
57     ASSERT_GL();
58
59     GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
60     assert(status == GL_FRAMEBUFFER_COMPLETE);
61
62     GLint viewport[4];
63     glGetIntegerv(GL_VIEWPORT, viewport);
64     glViewport(0, 0, m_width, m_height);
65     fillTexture();
66     glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
67
68     glBindFramebuffer(GL_FRAMEBUFFER, 0);
69     glBindRenderbuffer(GL_RENDERBUFFER, 0);
70     ASSERT_GL();
71 }
72
73 void FBOBlitTest::fillTexture()
74 {
75     int i;
76     glEnable(GL_SCISSOR_TEST);
77     for (i = 0; i < m_width; i++)
78     {
79         glScissor(i, 0, 1, m_height);
80         glClearColor(i / (float)m_width, 0.0f, 0.0f, 1.0f);
81         glClear(GL_COLOR_BUFFER_BIT);
82     }
83     glDisable(GL_SCISSOR_TEST);
84 }
85
86 void FBOBlitTest::teardown()
87 {
88     glDeleteFramebuffers(1, &m_framebuffer);
89     glDeleteRenderbuffers(1, &m_depthbuffer);
90     BlitTest::teardown();
91 }
92
93 std::string FBOBlitTest::name() const
94 {
95     std::stringstream s;
96
97     if (m_rotate)
98     {
99         s << "blit_fbo_rot90_";
100     }
101     else
102     {
103         s << "blit_fbo_";
104     }
105
106     s << textureFormatName(m_format, m_type);
107     s << "_" << m_width << "x" << m_height;
108
109     return s.str();
110 }