~thomas-voss/glmark2/build-for-mir

« back to all changes in this revision

Viewing changes to src/shader-source.h

  • Committer: Package Import Robot
  • Author(s): Alexandros Frantzis
  • Date: 2011-09-22 11:32:17 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: package-import@ubuntu.com-20110922113217-wvok1qgruexari8d
Tags: 2011.09-0ubuntu1
* New upstream release 2011.09.
* debian/control:
  - Start the description of the glmark2-data package with
    a lowercase letter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2010-2011 Linaro Limited
 
3
 *
 
4
 * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
 
5
 *
 
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
 
9
 * version.
 
10
 *
 
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
 
14
 * details.
 
15
 *
 
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/>.
 
18
 *
 
19
 * Authors:
 
20
 *  Alexandros Frantzis (glmark2)
 
21
 */
 
22
 
 
23
#include <string>
 
24
#include <sstream>
 
25
#include <vector>
 
26
#include "vec.h"
 
27
#include "mat.h"
 
28
 
 
29
/** 
 
30
 * Helper class for loading and manipulating shader sources.
 
31
 */
 
32
class ShaderSource
 
33
{
 
34
public:
 
35
    enum ShaderType {
 
36
        ShaderTypeVertex,
 
37
        ShaderTypeFragment,
 
38
        ShaderTypeUnknown
 
39
    };
 
40
 
 
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); }
 
45
 
 
46
    void append(const std::string &str);
 
47
    void append_file(const std::string &filename);
 
48
 
 
49
    void replace(const std::string &remove, const std::string &insert);
 
50
    void replace_with_file(const std::string &remove, const std::string &filename);
 
51
 
 
52
    void add(const std::string &str, const std::string &function = "");
 
53
 
 
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 = "");
 
64
 
 
65
    void add_array(const std::string &name, std::vector<float> &array,
 
66
                   const std::string &init_function,
 
67
                   const std::string &decl_function = "");
 
68
 
 
69
    ShaderType type();
 
70
    std::string str();
 
71
 
 
72
    enum PrecisionValue {
 
73
        PrecisionValueLow,
 
74
        PrecisionValueMedium,
 
75
        PrecisionValueHigh,
 
76
        PrecisionValueDefault,
 
77
    };
 
78
 
 
79
    struct Precision {
 
80
        Precision();
 
81
        Precision(PrecisionValue int_p, PrecisionValue float_p,
 
82
                  PrecisionValue sampler2d_p, PrecisionValue samplercube_p);
 
83
        Precision(const std::string& list);
 
84
 
 
85
        PrecisionValue int_precision;
 
86
        PrecisionValue float_precision;
 
87
        PrecisionValue sampler2d_precision;
 
88
        PrecisionValue samplercube_precision;
 
89
    };
 
90
 
 
91
    void precision(const Precision& precision);
 
92
    const Precision& precision();
 
93
 
 
94
    static void default_precision(const Precision& precision,
 
95
                                  ShaderType type = ShaderTypeUnknown);
 
96
    static const Precision& default_precision(ShaderType type);
 
97
 
 
98
private:
 
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);
 
104
 
 
105
    std::stringstream source_;
 
106
    Precision precision_;
 
107
    bool precision_has_been_set_;
 
108
    ShaderType type_;
 
109
 
 
110
    static std::vector<Precision> default_precision_;
 
111
};