2
// Copyright (c) 2010-2012 Linaro Limited
4
// All rights reserved. This program and the accompanying materials
5
// are made available under the terms of the MIT License which accompanies
6
// this distribution, and is available at
7
// http://www.opensource.org/licenses/mit-license.php
10
// Alexandros Frantzis <alexandros.frantzis@linaro.org>
11
// Jesse Barker <jesse.barker@linaro.org>
20
* Helper class for loading and manipulating shader sources.
31
ShaderSource(ShaderType type = ShaderTypeUnknown) :
32
precision_has_been_set_(false), type_(type) {}
33
ShaderSource(const std::string &filename, ShaderType type = ShaderTypeUnknown) :
34
precision_has_been_set_(false), type_(type) { append_file(filename); }
36
void append(const std::string &str);
37
void append_file(const std::string &filename);
39
void replace(const std::string &remove, const std::string &insert);
40
void replace_with_file(const std::string &remove, const std::string &filename);
42
void add(const std::string &str, const std::string &function = "");
44
void add_const(const std::string &name, float f,
45
const std::string &function = "");
46
void add_const(const std::string &name, std::vector<float> &f,
47
const std::string &function = "");
48
void add_const(const std::string &name, const LibMatrix::vec2 &v,
49
const std::string &function = "");
50
void add_const(const std::string &name, const LibMatrix::vec3 &v,
51
const std::string &function = "");
52
void add_const(const std::string &name, const LibMatrix::vec4 &v,
53
const std::string &function = "");
54
void add_const(const std::string &name, const LibMatrix::mat3 &m,
55
const std::string &function = "");
57
void add_array(const std::string &name, std::vector<float> &array,
58
const std::string &init_function,
59
const std::string &decl_function = "");
73
Precision(PrecisionValue int_p, PrecisionValue float_p,
74
PrecisionValue sampler2d_p, PrecisionValue samplercube_p);
75
Precision(const std::string& list);
77
PrecisionValue int_precision;
78
PrecisionValue float_precision;
79
PrecisionValue sampler2d_precision;
80
PrecisionValue samplercube_precision;
83
void precision(const Precision& precision);
84
const Precision& precision();
86
static void default_precision(const Precision& precision,
87
ShaderType type = ShaderTypeUnknown);
88
static const Precision& default_precision(ShaderType type);
91
void add_global(const std::string &str);
92
void add_local(const std::string &str, const std::string &function);
93
bool load_file(const std::string& filename, std::string& str);
94
void emit_precision(std::stringstream& ss, ShaderSource::PrecisionValue val,
95
const std::string& type_str);
97
std::stringstream source_;
99
bool precision_has_been_set_;
102
static std::vector<Precision> default_precision_;