2 * OpenGL ES 2.0 memory performance estimator
3 * Copyright (C) 2009 Nokia
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.
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.
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.
19 * \author Sami Kyöstilä <sami.kyostila@nokia.com>
27 const char *defaultVertSource =
28 "precision mediump float;\n"
29 "attribute vec2 in_position;\n"
30 "attribute vec2 in_texcoord;\n"
31 "varying vec2 texcoord;\n"
35 " gl_Position = vec4(in_position, 0.0, 1.0);\n"
36 " texcoord = in_texcoord;\n"
39 const char *defaultFragSource =
40 "precision mediump float;\n"
41 "varying vec2 texcoord;\n"
42 "uniform sampler2D texture;\n"
46 " gl_FragColor = texture2D(texture, texcoord);\n"
49 BlitTest::BlitTest(int width, int height,
50 bool rotate, float texW, float texH,
51 float quadW, float quadH):
59 m_vertSource(defaultVertSource),
60 m_fragSource(defaultFragSource)
64 BlitTest::BlitTest(GLenum format, GLenum type, int width, int height, const std::string& fileName,
65 bool rotate, float texW, float texH,
66 float quadW, float quadH):
77 m_vertSource(defaultVertSource),
78 m_fragSource(defaultFragSource)
80 if (m_format >= 0x8c00)
86 void BlitTest::teardown()
89 glDisableVertexAttribArray(m_positionAttr);
90 glDisableVertexAttribArray(m_texcoordAttr);
91 glDeleteProgram(m_program);
92 // Disabled until driver segfault is fixed
93 //glDeleteTextures(1, &m_texture);
96 void BlitTest::prepare()
99 if (m_fileName.size())
101 if (m_format >= 0x8c00)
103 loadCompressedTexture(GL_TEXTURE_2D, 0, m_format, m_width, m_height, m_fileName);
107 loadRawTexture(GL_TEXTURE_2D, 0, m_format, m_width, m_height, m_format, m_type, m_fileName);
113 void BlitTest::operator()(int frame)
115 float t = frame / 400.0f;
117 // Disable animation for now, since it interferes with the results due
118 // to lack of wrapping for NPOT textures
121 const GLfloat texcoords[] =
125 m_texW + t, m_texH + t,
129 const GLfloat texcoordsRotated[] =
133 m_texW + t, m_texH + t,
137 const GLfloat vertices[] =
145 glVertexAttribPointer(m_positionAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices);
146 glVertexAttribPointer(m_texcoordAttr, 2, GL_FLOAT, GL_FALSE, 0, m_rotate ? texcoordsRotated : texcoords);
147 glClear(GL_COLOR_BUFFER_BIT);
148 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
151 std::string BlitTest::name() const
157 s << "blit_tex_rot90_";
164 s << textureFormatName(m_format, m_type);
165 s << "_" << m_width << "x" << m_height;
170 void BlitTest::initializeBlitter()
172 m_program = createProgram(m_vertSource, m_fragSource);
173 glUseProgram(m_program);
175 glClearColor(.2, .4, .6, 1.0);
177 m_positionAttr = glGetAttribLocation(m_program, "in_position");
178 m_texcoordAttr = glGetAttribLocation(m_program, "in_texcoord");
179 assert(m_positionAttr >= 0);
180 assert(m_texcoordAttr >= 0);
182 glEnableVertexAttribArray(m_positionAttr);
183 glEnableVertexAttribArray(m_texcoordAttr);
185 m_textureUnif = glGetUniformLocation(m_program, "texture");
186 assert(m_textureUnif >= 0);
187 glUniform1i(m_textureUnif, 0);
189 glGenTextures(1, &m_texture);
190 glBindTexture(GL_TEXTURE_2D, m_texture);
191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
192 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);