2
* Copyright © 2010-2011 Linaro Limited
4
* This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
6
* glmark2 is free software: you can redistribute it and/or modify it under the
7
* terms of the GNU General Public License as published by the Free Software
8
* Foundation, either version 3 of the License, or (at your option) any later
11
* glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
* You should have received a copy of the GNU General Public License along with
17
* glmark2. If not, see <http://www.gnu.org/licenses/>.
20
* Alexandros Frantzis (glmark2)
30
static const std::string shader_file_base(GLMARK_DATA_PATH"/shaders/function");
32
static const std::string vtx_file(shader_file_base + ".vert");
33
static const std::string frg_file(shader_file_base + ".frag");
34
static const std::string call_file(shader_file_base + "-call.all");
35
static const std::string step_low_file(shader_file_base + "-step-low.all");
36
static const std::string step_medium_file(shader_file_base + "-step-medium.all");
38
SceneFunction::SceneFunction(Canvas &pCanvas) :
39
SceneGrid(pCanvas, "function")
41
mOptions["fragment-steps"] = Scene::Option("fragment-steps", "1",
42
"The number of computational steps in the fragment shader");
43
mOptions["fragment-function"] = Scene::Option("fragment-function", "true",
44
"Whether each computational step includes a function call");
45
mOptions["vertex-steps"] = Scene::Option("vertex-steps", "1",
46
"The number of computational steps in the vertex shader");
47
mOptions["vertex-function"] = Scene::Option("vertex-function", "true",
48
"Whether each computational step includes an if-else clause");
49
mOptions["vertex-complexity"] = Scene::Option("vertex-complexity", "low",
50
"The complexity of each computational step in the vertex shader");
51
mOptions["fragment-complexity"] = Scene::Option("fragment-complexity", "low",
52
"The complexity of each computational step in the fragment shader");
55
SceneFunction::~SceneFunction()
60
replace_string(std::string &str, const std::string &remove, const std::string &insert)
62
std::string::size_type pos = 0;
64
while ((pos = str.find(remove, pos)) != std::string::npos) {
65
str.replace(pos, remove.size(), insert);
73
get_vertex_shader_source(int steps, bool function, std::string &complexity)
75
std::string vtx_string, step_low_string, step_medium_string, call_string;
77
if (!gotSource(vtx_file, vtx_string) ||
78
!gotSource(step_low_file, step_low_string) ||
79
!gotSource(step_medium_file, step_medium_string) ||
80
!gotSource(call_file, call_string))
85
std::stringstream ss_main;
86
std::string process_string;
88
if (complexity == "low")
89
process_string = step_low_string;
90
else if (complexity == "medium")
91
process_string = step_medium_string;
93
for (int i = 0; i < steps; i++) {
95
ss_main << call_string;
97
ss_main << process_string;
100
replace_string(vtx_string, "$PROCESS$", function ? process_string : "");
101
replace_string(vtx_string, "$MAIN$", ss_main.str());
107
get_fragment_shader_source(int steps, bool function, std::string &complexity)
109
std::string frg_string, step_low_string, step_medium_string, call_string;
111
if (!gotSource(frg_file, frg_string) ||
112
!gotSource(step_low_file, step_low_string) ||
113
!gotSource(step_medium_file, step_medium_string) ||
114
!gotSource(call_file, call_string))
119
std::stringstream ss_main;
120
std::string process_string;
122
if (complexity == "low")
123
process_string = step_low_string;
124
else if (complexity == "medium")
125
process_string = step_medium_string;
127
for (int i = 0; i < steps; i++) {
129
ss_main << call_string;
131
ss_main << process_string;
134
replace_string(frg_string, "$PROCESS$", function ? process_string : "");
135
replace_string(frg_string, "$MAIN$", ss_main.str());
140
void SceneFunction::setup()
145
bool vtx_function = mOptions["vertex-function"].value == "true";
146
bool frg_function = mOptions["fragment-function"].value == "true";
147
std::string vtx_complexity = mOptions["vertex-complexity"].value;
148
std::string frg_complexity = mOptions["fragment-complexity"].value;
152
std::stringstream ss;
154
ss << mOptions["vertex-steps"].value;
157
ss << mOptions["fragment-steps"].value;
161
std::string vtx_shader(get_vertex_shader_source(vtx_steps, vtx_function,
163
std::string frg_shader(get_fragment_shader_source(frg_steps, frg_function,
166
if (!Scene::load_shaders_from_strings(mProgram, vtx_shader, frg_shader))
171
std::vector<GLint> attrib_locations;
172
attrib_locations.push_back(mProgram.getAttribIndex("position"));
173
mMesh.set_attrib_locations(attrib_locations);
176
mStartTime = Scene::get_timestamp_us() / 1000000.0;
177
mLastUpdateTime = mStartTime;