1 #ifndef slic3r_GLShader_hpp_
2 #define slic3r_GLShader_hpp_
3 
4 #include <array>
5 #include <string>
6 #include <string_view>
7 
8 #include "libslic3r/Point.hpp"
9 
10 namespace Slic3r {
11 
12 class GLShaderProgram
13 {
14 public:
15     enum class EShaderType
16     {
17         Vertex,
18         Fragment,
19         Geometry,
20         TessEvaluation,
21         TessControl,
22         Compute,
23         Count
24     };
25 
26     typedef std::array<std::string, static_cast<size_t>(EShaderType::Count)> ShaderFilenames;
27     typedef std::array<std::string, static_cast<size_t>(EShaderType::Count)> ShaderSources;
28 
29 private:
30     std::string m_name;
31     unsigned int m_id{ 0 };
32 
33 public:
34     ~GLShaderProgram();
35 
36     bool init_from_files(const std::string& name, const ShaderFilenames& filenames, const std::initializer_list<std::string_view> &defines = {});
37     bool init_from_texts(const std::string& name, const ShaderSources& sources);
38 
get_name() const39     const std::string& get_name() const { return m_name; }
get_id() const40     unsigned int get_id() const { return m_id; }
41 
42     void start_using() const;
43     void stop_using() const;
44 
45     bool set_uniform(const char* name, int value) const;
46     bool set_uniform(const char* name, bool value) const;
47     bool set_uniform(const char* name, float value) const;
48     bool set_uniform(const char* name, double value) const;
49     bool set_uniform(const char* name, const std::array<int, 2>& value) const;
50     bool set_uniform(const char* name, const std::array<int, 3>& value) const;
51     bool set_uniform(const char* name, const std::array<int, 4>& value) const;
52     bool set_uniform(const char* name, const std::array<float, 2>& value) const;
53     bool set_uniform(const char* name, const std::array<float, 3>& value) const;
54     bool set_uniform(const char* name, const std::array<float, 4>& value) const;
55     bool set_uniform(const char* name, const float* value, size_t size) const;
56     bool set_uniform(const char* name, const Transform3f& value) const;
57     bool set_uniform(const char* name, const Transform3d& value) const;
58     bool set_uniform(const char* name, const Matrix3f& value) const;
59     bool set_uniform(const char* name, const Vec3f& value) const;
60     bool set_uniform(const char* name, const Vec3d& value) const;
61 
62     // returns -1 if not found
63     int get_attrib_location(const char* name) const;
64     // returns -1 if not found
65     int get_uniform_location(const char* name) const;
66 };
67 
68 } // namespace Slic3r
69 
70 #endif /* slic3r_GLShader_hpp_ */
71