2
* Copyright © 2011 Linaro Limited
4
* This file is part of glcompbench.
6
* glcompbench is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* glcompbench is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with glcompbench. If not, see <http://www.gnu.org/licenses/>.
20
* Alexandros Frantzis <alexandros.frantzis@linaro.org>
21
* Jesse Barker <jesse.barker@linaro.org>
24
#include "composite-test.h"
31
const string CompositeTest::model_view_matrix_name_("modelview");
32
const string CompositeTest::projection_matrix_name_("projection");
33
const string CompositeTest::texture0_name_("Texture0");
34
const string CompositeTest::texcoord_name_("texcoord");
35
const string CompositeTest::position_name_("position");
38
* Gets the number of window that are visible.
40
* @param window_list the window list to search in
42
* @return the number of visible windows
45
num_visible_windows(std::list<CompositeWindow *> &window_list)
49
for(std::list<CompositeWindow*>::iterator iter = window_list.begin();
50
iter != window_list.end(); iter++)
52
if ((*iter)->get_texture())
62
// Initialize shader sources from input files
63
string vsFilename(GLCOMPBENCH_DATA_PATH"/composite-vertex-shader");
64
if (!gotSource(vsFilename, vertex_shader_))
66
cerr << "Failed to get vertex shader source for logo" << endl;
69
string fsFilename(GLCOMPBENCH_DATA_PATH"/composite-fragment-shader");
70
if (!gotSource(fsFilename, fragment_shader_))
72
cerr << "Failed to get fragment shader source for logo" << endl;
77
if (!program_.valid())
79
cerr << "No valid program for compositing (reason: ";
80
cerr << program_.errorMessage() << ")" << endl;
83
program_.addShader(GL_VERTEX_SHADER, vertex_shader_);
84
if (!program_.valid())
86
cerr << "Failed to add vertex shader to compositing program (reason: ";
87
cerr << program_.errorMessage() << ")" << endl;
90
program_.addShader(GL_FRAGMENT_SHADER, fragment_shader_);
91
if (!program_.valid())
93
cerr << "Failed to add fragment shader to compositing program (reason: ";
94
cerr << program_.errorMessage() << ")" << endl;
98
if (!program_.ready())
100
cerr << "Failed to build compositing program (reason: ";
101
cerr << program_.errorMessage() << ")" << endl;
104
vertexIndex_ = program_.getAttribIndex(position_name_);
105
texcoordIndex_ = program_.getAttribIndex(texcoord_name_);
109
* Prepares the test for a test run.
112
CompositeTest::prepare_for_run()
116
program_.loadUniformScalar(texUnit, texture0_name_);
118
glClearColor(0.1, 0.1, 0.3, 1.0);
121
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
125
CompositeTest::reshape(int width, int height)
127
float ar = static_cast<float>(width) / static_cast<float>(height);
129
/* Update the projection matrix */
130
projection_matrix.loadIdentity();
131
projection_matrix.perspective(22.6, ar, 5.0, 60.0);
133
/* Update the modelview matrix */
134
model_view_matrix.loadIdentity();
135
model_view_matrix.translate(0.0, 0.0, -10.0);
137
/* Set the viewport */
138
glViewport(0, 0, width, height);
142
CompositeTest::draw(std::list<CompositeWindow *> &window_list)
144
const GLfloat verts[4][3] = {
150
const GLfloat texcoords[4][2] = {
157
glActiveTexture(GL_TEXTURE0);
158
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
160
/* Set up the position of the attributes in the vertex array */
161
glVertexAttribPointer(vertexIndex_, 3, GL_FLOAT, GL_FALSE, 0, verts);
162
glVertexAttribPointer(texcoordIndex_, 2, GL_FLOAT, GL_FALSE, 0, texcoords);
164
/* Enable the attributes */
165
glEnableVertexAttribArray(vertexIndex_);
166
glEnableVertexAttribArray(texcoordIndex_);
168
program_.loadUniformMatrix(projection_matrix.getCurrent(),
169
projection_matrix_name_);
171
/* Find out how many windows are visible and calculate the angular step */
172
GLuint visible_windows(num_visible_windows(window_list));
173
GLfloat angular_step(2 * M_PI / visible_windows);
175
/* Draw the windows in a circle using the calculated angular step */
177
for(std::list<CompositeWindow*>::iterator iter = window_list.begin();
178
iter != window_list.end(); ++iter)
180
CompositeWindow *comp_win = *iter;
181
GLuint tex = comp_win->get_texture();
183
model_view_matrix.push();
184
model_view_matrix.translate(cos(angular_step * i),
185
sin(angular_step * i), 0);
187
/* Load shader ModelView uniform */
188
program_.loadUniformMatrix(model_view_matrix.getCurrent(),
189
model_view_matrix_name_);
191
Log::debug("Drawing Win: 0x%x Tex: 0x%x\n",
192
comp_win->get_xwindow(), comp_win->get_texture());
194
glBindTexture(GL_TEXTURE_2D, tex);
195
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
196
model_view_matrix.pop();
201
/* Disable the attributes */
202
glDisableVertexAttribArray(vertexIndex_);
203
glDisableVertexAttribArray(texcoordIndex_);
207
CompositeTest::cleanup()