Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::GLShaderProgram Class Reference

#include <src/slic3r/GUI/GLShader.hpp>

+ Collaboration diagram for Slic3r::GLShaderProgram:

Public Types

enum class  EShaderType {
  Vertex , Fragment , Geometry , TessEvaluation ,
  TessControl , Compute , Count
}
 
typedef std::array< std::string, static_cast< size_t >(EShaderType::Count)> ShaderFilenames
 
typedef std::array< std::string, static_cast< size_t >(EShaderType::Count)> ShaderSources
 

Public Member Functions

 ~GLShaderProgram ()
 
bool init_from_files (const std::string &name, const ShaderFilenames &filenames, const std::initializer_list< std::string_view > &defines={})
 
bool init_from_texts (const std::string &name, const ShaderSources &sources)
 
const std::string & get_name () const
 
unsigned int get_id () const
 
void start_using () const
 
void stop_using () const
 
void set_uniform (const char *name, int value) const
 
void set_uniform (const char *name, bool value) const
 
void set_uniform (const char *name, float value) const
 
void set_uniform (const char *name, double value) const
 
void set_uniform (const char *name, const std::array< int, 2 > &value) const
 
void set_uniform (const char *name, const std::array< int, 3 > &value) const
 
void set_uniform (const char *name, const std::array< int, 4 > &value) const
 
void set_uniform (const char *name, const std::array< float, 2 > &value) const
 
void set_uniform (const char *name, const std::array< float, 3 > &value) const
 
void set_uniform (const char *name, const std::array< float, 4 > &value) const
 
void set_uniform (const char *name, const std::array< double, 4 > &value) const
 
void set_uniform (const char *name, const float *value, size_t size) const
 
void set_uniform (const char *name, const Transform3f &value) const
 
void set_uniform (const char *name, const Transform3d &value) const
 
void set_uniform (const char *name, const Matrix3f &value) const
 
void set_uniform (const char *name, const Matrix3d &value) const
 
void set_uniform (const char *name, const Matrix4f &value) const
 
void set_uniform (const char *name, const Matrix4d &value) const
 
void set_uniform (const char *name, const Vec2f &value) const
 
void set_uniform (const char *name, const Vec2d &value) const
 
void set_uniform (const char *name, const Vec3f &value) const
 
void set_uniform (const char *name, const Vec3d &value) const
 
void set_uniform (const char *name, const ColorRGB &value) const
 
void set_uniform (const char *name, const ColorRGBA &value) const
 
void set_uniform (int id, int value) const
 
void set_uniform (int id, bool value) const
 
void set_uniform (int id, float value) const
 
void set_uniform (int id, double value) const
 
void set_uniform (int id, const std::array< int, 2 > &value) const
 
void set_uniform (int id, const std::array< int, 3 > &value) const
 
void set_uniform (int id, const std::array< int, 4 > &value) const
 
void set_uniform (int id, const std::array< float, 2 > &value) const
 
void set_uniform (int id, const std::array< float, 3 > &value) const
 
void set_uniform (int id, const std::array< float, 4 > &value) const
 
void set_uniform (int id, const std::array< double, 4 > &value) const
 
void set_uniform (int id, const float *value, size_t size) const
 
void set_uniform (int id, const Transform3f &value) const
 
void set_uniform (int id, const Transform3d &value) const
 
void set_uniform (int id, const Matrix3f &value) const
 
void set_uniform (int id, const Matrix3d &value) const
 
void set_uniform (int id, const Matrix4f &value) const
 
void set_uniform (int id, const Matrix4d &value) const
 
void set_uniform (int id, const Vec2f &value) const
 
void set_uniform (int id, const Vec2d &value) const
 
void set_uniform (int id, const Vec3f &value) const
 
void set_uniform (int id, const Vec3d &value) const
 
void set_uniform (int id, const ColorRGB &value) const
 
void set_uniform (int id, const ColorRGBA &value) const
 
int get_attrib_location (const char *name) const
 
int get_uniform_location (const char *name) const
 

Private Attributes

std::string m_name
 
unsigned int m_id { 0 }
 
std::vector< std::pair< std::string, int > > m_attrib_location_cache
 
std::vector< std::pair< std::string, int > > m_uniform_location_cache
 

Detailed Description

Member Typedef Documentation

◆ ShaderFilenames

typedef std::array<std::string, static_cast<size_t>(EShaderType::Count)> Slic3r::GLShaderProgram::ShaderFilenames

◆ ShaderSources

typedef std::array<std::string, static_cast<size_t>(EShaderType::Count)> Slic3r::GLShaderProgram::ShaderSources

Member Enumeration Documentation

◆ EShaderType

Constructor & Destructor Documentation

◆ ~GLShaderProgram()

Slic3r::GLShaderProgram::~GLShaderProgram ( )
18{
19 if (m_id > 0)
20 glsafe(::glDeleteProgram(m_id));
21}
#define glsafe(cmd)
Definition 3DScene.hpp:25
unsigned int m_id
Definition GLShader.hpp:34

References glsafe, and m_id.

Member Function Documentation

◆ get_attrib_location()

int Slic3r::GLShaderProgram::get_attrib_location ( const char *  name) const
353{
354 assert(m_id > 0);
355
356 if (m_id <= 0)
357 // Shader program not loaded. This should not happen.
358 return -1;
359
360 auto it = std::find_if(m_attrib_location_cache.begin(), m_attrib_location_cache.end(), [name](const auto& p) { return p.first == name; });
361 if (it != m_attrib_location_cache.end())
362 // Attrib ID cached.
363 return it->second;
364
365 int id = ::glGetAttribLocation(m_id, name);
366 const_cast<GLShaderProgram*>(this)->m_attrib_location_cache.push_back({ name, id });
367 return id;
368}
std::vector< std::pair< std::string, int > > m_attrib_location_cache
Definition GLShader.hpp:35

References m_attrib_location_cache, and m_id.

Referenced by Slic3r::GUI::GLModel::render(), Slic3r::GUI::GLMmSegmentationGizmo3DScene::render(), Slic3r::GUI::ImGuiWrapper::render_draw_data(), Slic3r::GUI::GLModel::render_instanced(), and Slic3r::GUI::GCodeViewer::render_toolpaths().

+ Here is the caller graph for this function:

◆ get_id()

unsigned int Slic3r::GLShaderProgram::get_id ( ) const
inline
45{ return m_id; }

References m_id.

◆ get_name()

const std::string & Slic3r::GLShaderProgram::get_name ( ) const
inline
44{ return m_name; }
std::string m_name
Definition GLShader.hpp:33

References m_name.

Referenced by Slic3r::GUI::GLModel::render_instanced().

+ Here is the caller graph for this function:

◆ get_uniform_location()

int Slic3r::GLShaderProgram::get_uniform_location ( const char *  name) const
371{
372 assert(m_id > 0);
373
374 if (m_id <= 0)
375 // Shader program not loaded. This should not happen.
376 return -1;
377
378 auto it = std::find_if(m_uniform_location_cache.begin(), m_uniform_location_cache.end(), [name](const auto &p) { return p.first == name; });
379 if (it != m_uniform_location_cache.end())
380 // Uniform ID cached.
381 return it->second;
382
383 int id = ::glGetUniformLocation(m_id, name);
384 const_cast<GLShaderProgram*>(this)->m_uniform_location_cache.push_back({ name, id });
385 return id;
386}
std::vector< std::pair< std::string, int > > m_uniform_location_cache
Definition GLShader.hpp:36

Referenced by Slic3r::GUI::GCodeViewer::render_toolpaths(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), and set_uniform().

+ Here is the caller graph for this function:

◆ init_from_files()

bool Slic3r::GLShaderProgram::init_from_files ( const std::string &  name,
const ShaderFilenames filenames,
const std::initializer_list< std::string_view > &  defines = {} 
)
24{
25 // Load a shader program from file, prepend defs block.
26 auto load_from_file = [](const std::string& filename, const std::string &defs) {
27 std::string path = resources_dir() + "/shaders/" + filename;
28 boost::nowide::ifstream s(path, boost::nowide::ifstream::binary);
29 if (!s.good()) {
30 BOOST_LOG_TRIVIAL(error) << "Couldn't open file: '" << path << "'";
31 return std::string();
32 }
33
34 s.seekg(0, s.end);
35 int file_length = static_cast<int>(s.tellg());
36 s.seekg(0, s.beg);
37 std::string source(defs.size() + file_length, '\0');
38 memcpy(source.data(), defs.c_str(), defs.size());
39 s.read(source.data() + defs.size(), file_length);
40 if (!s.good()) {
41 BOOST_LOG_TRIVIAL(error) << "Error while loading file: '" << path << "'";
42 return std::string();
43 }
44 s.close();
45
46 if (! defs.empty()) {
47 // Extract the version and flip the order of "defines" and version in the source block.
48 size_t idx = source.find("\n", defs.size());
49 if (idx != std::string::npos && strncmp(source.c_str() + defs.size(), "#version", 8) == 0) {
50 // Swap the version line with the defines.
51 size_t len = idx - defs.size() + 1;
52 memmove(source.data(), source.c_str() + defs.size(), len);
53 memcpy(source.data() + len, defs.c_str(), defs.size());
54 }
55 }
56
57 return source;
58 };
59
60 // Create a block of C "defines" from list of symbols.
61 std::string defines_program;
62 for (std::string_view def : defines)
63 // Our shaders are stored with "\r\n", thus replicate the same here for consistency. Likely "\n" would suffice,
64 // but we don't know all the OpenGL shader compilers around.
65 defines_program += format("#define %s\r\n", def);
66
67 ShaderSources sources = {};
68 for (size_t i = 0; i < static_cast<size_t>(EShaderType::Count); ++i) {
69 sources[i] = filenames[i].empty() ? std::string() : load_from_file(filenames[i], defines_program);
70 }
71
72 bool valid = !sources[static_cast<size_t>(EShaderType::Vertex)].empty() && !sources[static_cast<size_t>(EShaderType::Fragment)].empty() && sources[static_cast<size_t>(EShaderType::Compute)].empty();
73 valid |= !sources[static_cast<size_t>(EShaderType::Compute)].empty() && sources[static_cast<size_t>(EShaderType::Vertex)].empty() && sources[static_cast<size_t>(EShaderType::Fragment)].empty() &&
74 sources[static_cast<size_t>(EShaderType::Geometry)].empty() && sources[static_cast<size_t>(EShaderType::TessEvaluation)].empty() && sources[static_cast<size_t>(EShaderType::TessControl)].empty();
75
76 return valid ? init_from_texts(name, sources) : false;
77}
std::array< std::string, static_cast< size_t >(EShaderType::Count)> ShaderSources
Definition GLShader.hpp:30
bool init_from_texts(const std::string &name, const ShaderSources &sources)
Definition GLShader.cpp:79
const std::string & resources_dir()
Definition utils.cpp:167
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:44
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:229
static char error[256]
Definition tga.cpp:50

References Compute, Count, Slic3r::empty(), error, Slic3r::format(), Fragment, Geometry, init_from_texts(), Slic3r::resources_dir(), TessControl, TessEvaluation, and Vertex.

+ Here is the call graph for this function:

◆ init_from_texts()

bool Slic3r::GLShaderProgram::init_from_texts ( const std::string &  name,
const ShaderSources sources 
)
80{
81 auto shader_type_as_string = [](EShaderType type) {
82 switch (type)
83 {
84 case EShaderType::Vertex: { return "vertex"; }
85 case EShaderType::Fragment: { return "fragment"; }
86 case EShaderType::Geometry: { return "geometry"; }
87 case EShaderType::TessEvaluation: { return "tesselation evaluation"; }
88 case EShaderType::TessControl: { return "tesselation control"; }
89 case EShaderType::Compute: { return "compute"; }
90 default: { return "unknown"; }
91 }
92 };
93
94 auto create_shader = [](EShaderType type) {
95 GLuint id = 0;
96 switch (type)
97 {
98 case EShaderType::Vertex: { id = ::glCreateShader(GL_VERTEX_SHADER); glcheck(); break; }
99 case EShaderType::Fragment: { id = ::glCreateShader(GL_FRAGMENT_SHADER); glcheck(); break; }
100 case EShaderType::Geometry: { id = ::glCreateShader(GL_GEOMETRY_SHADER); glcheck(); break; }
101 case EShaderType::TessEvaluation: { id = ::glCreateShader(GL_TESS_EVALUATION_SHADER); glcheck(); break; }
102 case EShaderType::TessControl: { id = ::glCreateShader(GL_TESS_CONTROL_SHADER); glcheck(); break; }
103 case EShaderType::Compute: { id = ::glCreateShader(GL_COMPUTE_SHADER); glcheck(); break; }
104 default: { break; }
105 }
106
107 return (id == 0) ? std::make_pair(false, GLuint(0)) : std::make_pair(true, id);
108 };
109
110 auto release_shaders = [](const std::array<GLuint, static_cast<size_t>(EShaderType::Count)>& shader_ids) {
111 for (size_t i = 0; i < static_cast<size_t>(EShaderType::Count); ++i) {
112 if (shader_ids[i] > 0)
113 glsafe(::glDeleteShader(shader_ids[i]));
114 }
115 };
116
117 assert(m_id == 0);
118
119 m_name = name;
120
121 std::array<GLuint, static_cast<size_t>(EShaderType::Count)> shader_ids = { 0 };
122
123 for (size_t i = 0; i < static_cast<size_t>(EShaderType::Count); ++i) {
124 const std::string& source = sources[i];
125 if (!source.empty()) {
126 EShaderType type = static_cast<EShaderType>(i);
127 auto [result, id] = create_shader(type);
128 if (result)
129 shader_ids[i] = id;
130 else {
131 BOOST_LOG_TRIVIAL(error) << "glCreateShader() failed for " << shader_type_as_string(type) << " shader of shader program '" << name << "'";
132
133 // release shaders
134 release_shaders(shader_ids);
135 return false;
136 }
137
138 const char* source_ptr = source.c_str();
139 glsafe(::glShaderSource(id, 1, &source_ptr, nullptr));
140 glsafe(::glCompileShader(id));
141 GLint params;
142 glsafe(::glGetShaderiv(id, GL_COMPILE_STATUS, &params));
143 if (params == GL_FALSE) {
144 // Compilation failed.
145 glsafe(::glGetShaderiv(id, GL_INFO_LOG_LENGTH, &params));
146 std::vector<char> msg(params);
147 glsafe(::glGetShaderInfoLog(id, params, &params, msg.data()));
148 BOOST_LOG_TRIVIAL(error) << "Unable to compile " << shader_type_as_string(type) << " shader of shader program '" << name << "':\n" << msg.data();
149
150 // release shaders
151 release_shaders(shader_ids);
152 return false;
153 }
154 }
155 }
156
157 m_id = ::glCreateProgram();
158 glcheck();
159 if (m_id == 0) {
160 BOOST_LOG_TRIVIAL(error) << "glCreateProgram() failed for shader program '" << name << "'";
161
162 // release shaders
163 release_shaders(shader_ids);
164 return false;
165 }
166
167 for (size_t i = 0; i < static_cast<size_t>(EShaderType::Count); ++i) {
168 if (shader_ids[i] > 0)
169 glsafe(::glAttachShader(m_id, shader_ids[i]));
170 }
171
172 glsafe(::glLinkProgram(m_id));
173 GLint params;
174 glsafe(::glGetProgramiv(m_id, GL_LINK_STATUS, &params));
175 if (params == GL_FALSE) {
176 // Linking failed.
177 glsafe(::glGetProgramiv(m_id, GL_INFO_LOG_LENGTH, &params));
178 std::vector<char> msg(params);
179 glsafe(::glGetProgramInfoLog(m_id, params, &params, msg.data()));
180 BOOST_LOG_TRIVIAL(error) << "Unable to link shader program '" << name << "':\n" << msg.data();
181
182 // release shaders
183 release_shaders(shader_ids);
184
185 // release shader program
186 glsafe(::glDeleteProgram(m_id));
187 m_id = 0;
188
189 return false;
190 }
191
192 // release shaders, they are no more needed
193 release_shaders(shader_ids);
194
195 return true;
196}
#define glcheck()
Definition 3DScene.hpp:26
EShaderType
Definition GLShader.hpp:19
int GLint
Definition glu-libtess.h:58
unsigned int GLuint
Definition glu-libtess.h:62
#define GL_FALSE
Definition glu-libtess.h:71
STL namespace.

References Compute, Count, error, Fragment, Geometry, GL_FALSE, glcheck, glsafe, m_id, m_name, TessControl, TessEvaluation, and Vertex.

Referenced by init_from_files().

+ Here is the caller graph for this function:

◆ set_uniform() [1/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
bool  value 
) const
inline
51{ set_uniform(get_uniform_location(name), value); }
void set_uniform(const char *name, int value) const
Definition GLShader.hpp:50
int get_uniform_location(const char *name) const
Definition GLShader.cpp:370

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [2/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const ColorRGB value 
) const
inline
72{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [3/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const ColorRGBA value 
) const
inline
73{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [4/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const float *  value,
size_t  size 
) const
inline
61{ set_uniform(get_uniform_location(name), value, size); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [5/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Matrix3d value 
) const
inline
65{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [6/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Matrix3f value 
) const
inline
64{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [7/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Matrix4d value 
) const
inline
67{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [8/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Matrix4f value 
) const
inline
66{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [9/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const std::array< double, 4 > &  value 
) const
inline
60{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [10/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const std::array< float, 2 > &  value 
) const
inline
57{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [11/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const std::array< float, 3 > &  value 
) const
inline
58{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [12/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const std::array< float, 4 > &  value 
) const
inline
59{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [13/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const std::array< int, 2 > &  value 
) const
inline
54{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [14/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const std::array< int, 3 > &  value 
) const
inline
55{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [15/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const std::array< int, 4 > &  value 
) const
inline
56{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [16/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Transform3d value 
) const
inline
63{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [17/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Transform3f value 
) const
inline
62{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [18/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Vec2d value 
) const
inline
69{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [19/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Vec2f value 
) const
inline
68{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [20/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Vec3d value 
) const
inline
71{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [21/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
const Vec3f value 
) const
inline
70{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [22/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
double  value 
) const
inline
53{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [23/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
float  value 
) const
inline
52{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by set_uniform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_uniform() [24/48]

void Slic3r::GLShaderProgram::set_uniform ( const char *  name,
int  value 
) const
inline
50{ set_uniform(get_uniform_location(name), value); }

References get_uniform_location(), and set_uniform().

Referenced by Slic3r::GUI::GLCanvas3D::_render_background(), Slic3r::GUI::GLCanvas3D::_render_sla_slices(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), Slic3r::GUI::GLCanvas3D::_render_volumes_for_picking(), Slic3r::GUI::GLGizmoFlatten::on_render(), Slic3r::GUI::GLGizmoMeasure::on_render(), Slic3r::GUI::GLGizmoMove3D::on_render(), Slic3r::GUI::GLGizmoRotate::on_render(), Slic3r::GUI::GLGizmoScale3D::on_render(), Slic3r::GLVolume::SinkingContours::render(), Slic3r::GLVolume::NonManifoldEdges::render(), Slic3r::GUI::GCodeViewer::COG::render(), Slic3r::GUI::GCodeViewer::SequentialView::Marker::render(), Slic3r::GUI::GLCanvas3D::SequentialPrintClearance::render(), Slic3r::GUI::GLSelectionRectangle::render(), Slic3r::GUI::GLModel::render(), Slic3r::GUI::CoordAxes::render(), Slic3r::GLVolumeCollection::render(), Slic3r::GUI::GLGizmoBase::Grabber::render(), Slic3r::GUI::GLCanvas3D::LayersEditing::render_active_object_annotations(), Slic3r::GUI::Selection::render_bounding_box(), Slic3r::GUI::MeshClipper::render_contour(), Slic3r::GUI::Bed3D::render_contour(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_circle(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_sphere(), Slic3r::GUI::MeshClipper::render_cut(), Slic3r::GUI::GLGizmoCut3D::render_cut_plane(), Slic3r::GUI::Bed3D::render_default(), Slic3r::GUI::GLGizmoMeasure::render_dimensioning(), Slic3r::GUI::ImGuiWrapper::render_draw_data(), Slic3r::GUI::GLGizmoBase::render_grabbers(), Slic3r::GUI::GLModel::render_instanced(), Slic3r::GUI::GLGizmoCut3D::render_line(), Slic3r::GUI::Bed3D::render_model(), Slic3r::GUI::GLGizmoCut3D::render_model(), Slic3r::GUI::GLGizmoHollow::render_points(), Slic3r::GUI::GLGizmoSlaSupports::render_points(), Slic3r::GUI::GLCanvas3D::LayersEditing::render_profile(), Slic3r::GUI::GLGizmoCut3D::render_rotation_snapping(), Slic3r::GUI::Selection::render_sidebar_hints(), Slic3r::GUI::Selection::render_sidebar_layers_hints(), Slic3r::GUI::Selection::render_sidebar_position_hints(), Slic3r::GUI::Selection::render_sidebar_rotation_hints(), Slic3r::GUI::Selection::render_sidebar_scale_hints(), Slic3r::GUI::GLTexture::render_sub_texture(), Slic3r::GUI::Bed3D::render_texture(), Slic3r::GUI::GCodeViewer::render_toolpaths(), Slic3r::GUI::GLGizmoSlaBase::render_volumes(), Slic3r::GUI::GLCanvas3D::LayersEditing::render_volumes(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), set_uniform(), and set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [25/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
bool  value 
) const
216{
217 set_uniform(id, value ? 1 : 0);
218}

References set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [26/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const ColorRGB value 
) const
343{
344 set_uniform(id, value.data(), 3);
345}

References Slic3r::ColorRGB::data(), and set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [27/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const ColorRGBA value 
) const
348{
349 set_uniform(id, value.data(), 4);
350}

References Slic3r::ColorRGBA::data(), and set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [28/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const float *  value,
size_t  size 
) const
274{
275 if (id >= 0) {
276 if (size == 1)
277 set_uniform(id, value[0]);
278 else if (size == 2)
279 glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value)));
280 else if (size == 3)
281 glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value)));
282 else if (size == 4)
283 glsafe(::glUniform4fv(id, 1, static_cast<const GLfloat*>(value)));
284 }
285}
float GLfloat
Definition glu-libtess.h:63

References glsafe, and set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [29/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Matrix3d value 
) const
305{
306 set_uniform(id, (Matrix3f)value.cast<float>());
307}
Eigen::Matrix< float, 3, 3, Eigen::DontAlign > Matrix3f
Definition Point.hpp:70

References set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [30/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Matrix3f value 
) const
299{
300 if (id >= 0)
301 glsafe(::glUniformMatrix3fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.data())));
302}

References Eigen::PlainObjectBase< Derived >::data(), GL_FALSE, and glsafe.

+ Here is the call graph for this function:

◆ set_uniform() [31/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Matrix4d value 
) const
316{
317 set_uniform(id, (Matrix4f)value.cast<float>());
318}
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > Matrix4f
Definition Point.hpp:72

References set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [32/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Matrix4f value 
) const

◆ set_uniform() [33/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const std::array< double, 4 > &  value 
) const
268{
269 const std::array<float, 4> f_value = { float(value[0]), float(value[1]), float(value[2]), float(value[3]) };
270 set_uniform(id, f_value);
271}

References set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [34/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const std::array< float, 2 > &  value 
) const
250{
251 if (id >= 0)
252 glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value.data())));
253}

References glsafe.

◆ set_uniform() [35/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const std::array< float, 3 > &  value 
) const
256{
257 if (id >= 0)
258 glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value.data())));
259}

References glsafe.

◆ set_uniform() [36/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const std::array< float, 4 > &  value 
) const
262{
263 if (id >= 0)
264 glsafe(::glUniform4fv(id, 1, static_cast<const GLfloat*>(value.data())));
265}

References glsafe.

◆ set_uniform() [37/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const std::array< int, 2 > &  value 
) const
232{
233 if (id >= 0)
234 glsafe(::glUniform2iv(id, 1, static_cast<const GLint*>(value.data())));
235}

References glsafe.

◆ set_uniform() [38/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const std::array< int, 3 > &  value 
) const
238{
239 if (id >= 0)
240 glsafe(::glUniform3iv(id, 1, static_cast<const GLint*>(value.data())));
241}

References glsafe.

◆ set_uniform() [39/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const std::array< int, 4 > &  value 
) const
244{
245 if (id >= 0)
246 glsafe(::glUniform4iv(id, 1, static_cast<const GLint*>(value.data())));
247}

References glsafe.

◆ set_uniform() [40/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Transform3d value 
) const
294{
295 set_uniform(id, value.cast<float>());
296}

References Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::cast(), and set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [41/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Transform3f value 
) const
288{
289 if (id >= 0)
290 glsafe(::glUniformMatrix4fv(id, 1, GL_FALSE, static_cast<const GLfloat*>(value.matrix().data())));
291}

References Eigen::PlainObjectBase< Derived >::data(), GL_FALSE, glsafe, and Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::matrix().

+ Here is the call graph for this function:

◆ set_uniform() [42/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Vec2d value 
) const
327{
328 set_uniform(id, static_cast<Vec2f>(value.cast<float>()));
329}
Eigen::Matrix< float, 2, 1, Eigen::DontAlign > Vec2f
Definition Point.hpp:48

References set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [43/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Vec2f value 
) const
321{
322 if (id >= 0)
323 glsafe(::glUniform2fv(id, 1, static_cast<const GLfloat*>(value.data())));
324}

References Eigen::PlainObjectBase< Derived >::data(), and glsafe.

+ Here is the call graph for this function:

◆ set_uniform() [44/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Vec3d value 
) const
338{
339 set_uniform(id, static_cast<Vec3f>(value.cast<float>()));
340}
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:49

References set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [45/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
const Vec3f value 
) const
332{
333 if (id >= 0)
334 glsafe(::glUniform3fv(id, 1, static_cast<const GLfloat*>(value.data())));
335}

References Eigen::PlainObjectBase< Derived >::data(), and glsafe.

+ Here is the call graph for this function:

◆ set_uniform() [46/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
double  value 
) const
227{
228 set_uniform(id, static_cast<float>(value));
229}

References set_uniform().

+ Here is the call graph for this function:

◆ set_uniform() [47/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
float  value 
) const
221{
222 if (id >= 0)
223 glsafe(::glUniform1f(id, value));
224}

References glsafe.

◆ set_uniform() [48/48]

void Slic3r::GLShaderProgram::set_uniform ( int  id,
int  value 
) const
210{
211 if (id >= 0)
212 glsafe(::glUniform1i(id, value));
213}

References glsafe.

◆ start_using()

void Slic3r::GLShaderProgram::start_using ( ) const
199{
200 assert(m_id > 0);
201 glsafe(::glUseProgram(m_id));
202}

References glsafe, and m_id.

Referenced by Slic3r::GUI::GLCanvas3D::_render_background(), Slic3r::GUI::GLCanvas3D::_render_objects(), Slic3r::GUI::GLCanvas3D::_render_sla_slices(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), Slic3r::GUI::GLCanvas3D::_render_volumes_for_picking(), Slic3r::GUI::GLGizmoFlatten::on_render(), Slic3r::GUI::GLGizmoMeasure::on_render(), Slic3r::GUI::GLGizmoMove3D::on_render(), Slic3r::GUI::GLGizmoRotate::on_render(), Slic3r::GUI::GLGizmoScale3D::on_render(), Slic3r::GUI::GCodeViewer::COG::render(), Slic3r::GUI::GCodeViewer::SequentialView::Marker::render(), Slic3r::GUI::GLCanvas3D::SequentialPrintClearance::render(), Slic3r::GUI::GLSelectionRectangle::render(), Slic3r::GUI::CoordAxes::render(), Slic3r::GLVolumeCollection::render(), Slic3r::GUI::GLCanvas3D::LayersEditing::render_active_object_annotations(), Slic3r::GUI::Selection::render_bounding_box(), Slic3r::GUI::MeshClipper::render_contour(), Slic3r::GUI::Bed3D::render_contour(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_circle(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_sphere(), Slic3r::GUI::MeshClipper::render_cut(), Slic3r::GUI::GLGizmoCut3D::render_cut_plane(), Slic3r::GUI::Bed3D::render_default(), Slic3r::GUI::GLGizmoMeasure::render_dimensioning(), Slic3r::GUI::ImGuiWrapper::render_draw_data(), Slic3r::GUI::GLGizmoBase::render_grabbers(), Slic3r::GUI::GLGizmoCut3D::render_line(), Slic3r::GUI::Bed3D::render_model(), Slic3r::GUI::GLGizmoCut3D::render_model(), Slic3r::GUI::GLGizmoHollow::render_points(), Slic3r::GUI::GLGizmoSlaSupports::render_points(), Slic3r::GUI::GLCanvas3D::LayersEditing::render_profile(), Slic3r::GUI::GLGizmoCut3D::render_rotation_snapping(), Slic3r::GUI::GCodeViewer::render_shells(), Slic3r::GUI::Selection::render_sidebar_hints(), Slic3r::GUI::GLTexture::render_sub_texture(), Slic3r::GUI::Bed3D::render_texture(), Slic3r::GUI::GCodeViewer::render_toolpaths(), Slic3r::GUI::GLGizmoSlaBase::render_volumes(), and Slic3r::GUI::GLCanvas3D::LayersEditing::render_volumes().

+ Here is the caller graph for this function:

◆ stop_using()

void Slic3r::GLShaderProgram::stop_using ( ) const
205{
206 glsafe(::glUseProgram(0));
207}

References glsafe.

Referenced by Slic3r::GUI::GLCanvas3D::_render_background(), Slic3r::GUI::GLCanvas3D::_render_objects(), Slic3r::GUI::GLCanvas3D::_render_sla_slices(), Slic3r::GUI::GLCanvas3D::_render_thumbnail_internal(), Slic3r::GUI::GLCanvas3D::_render_volumes_for_picking(), Slic3r::GUI::GLGizmoFlatten::on_render(), Slic3r::GUI::GLGizmoMeasure::on_render(), Slic3r::GUI::GLGizmoMove3D::on_render(), Slic3r::GUI::GLGizmoRotate::on_render(), Slic3r::GUI::GLGizmoScale3D::on_render(), Slic3r::GUI::GCodeViewer::COG::render(), Slic3r::GUI::GCodeViewer::SequentialView::Marker::render(), Slic3r::GUI::GLCanvas3D::SequentialPrintClearance::render(), Slic3r::GUI::GLSelectionRectangle::render(), Slic3r::GUI::CoordAxes::render(), Slic3r::GLVolumeCollection::render(), Slic3r::GUI::GLCanvas3D::LayersEditing::render_active_object_annotations(), Slic3r::GUI::Selection::render_bounding_box(), Slic3r::GUI::MeshClipper::render_contour(), Slic3r::GUI::Bed3D::render_contour(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_circle(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_sphere(), Slic3r::GUI::MeshClipper::render_cut(), Slic3r::GUI::GLGizmoCut3D::render_cut_plane(), Slic3r::GUI::Bed3D::render_default(), Slic3r::GUI::GLGizmoMeasure::render_dimensioning(), Slic3r::GUI::ImGuiWrapper::render_draw_data(), Slic3r::GUI::GLGizmoBase::render_grabbers(), Slic3r::GUI::GLGizmoCut3D::render_line(), Slic3r::GUI::Bed3D::render_model(), Slic3r::GUI::GLGizmoCut3D::render_model(), Slic3r::GUI::GLGizmoHollow::render_points(), Slic3r::GUI::GLGizmoSlaSupports::render_points(), Slic3r::GUI::GLCanvas3D::LayersEditing::render_profile(), Slic3r::GUI::GLGizmoCut3D::render_rotation_snapping(), Slic3r::GUI::GCodeViewer::render_shells(), Slic3r::GUI::Selection::render_sidebar_hints(), Slic3r::GUI::GLTexture::render_sub_texture(), Slic3r::GUI::Bed3D::render_texture(), Slic3r::GUI::GCodeViewer::render_toolpaths(), Slic3r::GUI::GLGizmoSlaBase::render_volumes(), and Slic3r::GUI::GLCanvas3D::LayersEditing::render_volumes().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_attrib_location_cache

std::vector<std::pair<std::string, int> > Slic3r::GLShaderProgram::m_attrib_location_cache
private

Referenced by get_attrib_location().

◆ m_id

unsigned int Slic3r::GLShaderProgram::m_id { 0 }
private

◆ m_name

std::string Slic3r::GLShaderProgram::m_name
private

Referenced by get_name(), and init_from_texts().

◆ m_uniform_location_cache

std::vector<std::pair<std::string, int> > Slic3r::GLShaderProgram::m_uniform_location_cache
private

The documentation for this class was generated from the following files: