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
* Helper class for loading and manipulating shader sources.
41
ShaderSource(ShaderType type = ShaderTypeUnknown) :
42
precision_has_been_set_(false), type_(type) {}
43
ShaderSource(const std::string &filename, ShaderType type = ShaderTypeUnknown) :
44
precision_has_been_set_(false), type_(type) { append_file(filename); }
46
void append(const std::string &str);
47
void append_file(const std::string &filename);
49
void replace(const std::string &remove, const std::string &insert);
50
void replace_with_file(const std::string &remove, const std::string &filename);
52
void add(const std::string &str, const std::string &function = "");
54
void add_const(const std::string &name, float f,
55
const std::string &function = "");
56
void add_const(const std::string &name, std::vector<float> &f,
57
const std::string &function = "");
58
void add_const(const std::string &name, const LibMatrix::vec3 &v,
59
const std::string &function = "");
60
void add_const(const std::string &name, const LibMatrix::vec4 &v,
61
const std::string &function = "");
62
void add_const(const std::string &name, const LibMatrix::mat3 &m,
63
const std::string &function = "");
65
void add_array(const std::string &name, std::vector<float> &array,
66
const std::string &init_function,
67
const std::string &decl_function = "");
76
PrecisionValueDefault,
81
Precision(PrecisionValue int_p, PrecisionValue float_p,
82
PrecisionValue sampler2d_p, PrecisionValue samplercube_p);
83
Precision(const std::string& list);
85
PrecisionValue int_precision;
86
PrecisionValue float_precision;
87
PrecisionValue sampler2d_precision;
88
PrecisionValue samplercube_precision;
91
void precision(const Precision& precision);
92
const Precision& precision();
94
static void default_precision(const Precision& precision,
95
ShaderType type = ShaderTypeUnknown);
96
static const Precision& default_precision(ShaderType type);
99
void add_global(const std::string &str);
100
void add_local(const std::string &str, const std::string &function);
101
bool load_file(const std::string& filename, std::string& str);
102
void emit_precision(std::stringstream& ss, ShaderSource::PrecisionValue val,
103
const std::string& type_str);
105
std::stringstream source_;
106
Precision precision_;
107
bool precision_has_been_set_;
110
static std::vector<Precision> default_precision_;