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

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

+ Collaboration diagram for Slic3r::GLShadersManager:

Public Member Functions

std::pair< bool, std::string > init ()
 
void shutdown ()
 
GLShaderProgramget_shader (const std::string &shader_name)
 
GLShaderProgramget_current_shader ()
 

Private Attributes

std::vector< std::unique_ptr< GLShaderProgram > > m_shaders
 

Detailed Description

Member Function Documentation

◆ get_current_shader()

GLShaderProgram * Slic3r::GLShadersManager::get_current_shader ( )
112{
113 GLint id = 0;
114 glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, &id));
115 if (id == 0)
116 return nullptr;
117
118 auto it = std::find_if(m_shaders.begin(), m_shaders.end(), [id](std::unique_ptr<GLShaderProgram>& p) { return static_cast<GLint>(p->get_id()) == id; });
119 return (it != m_shaders.end()) ? it->get() : nullptr;
120}
#define glsafe(cmd)
Definition 3DScene.hpp:25
std::vector< std::unique_ptr< GLShaderProgram > > m_shaders
Definition GLShadersManager.hpp:14
int GLint
Definition glu-libtess.h:58

References glsafe, and m_shaders.

Referenced by Slic3r::GUI::OpenGLManager::get_current_shader().

+ Here is the caller graph for this function:

◆ get_shader()

GLShaderProgram * Slic3r::GLShadersManager::get_shader ( const std::string &  shader_name)
106{
107 auto it = std::find_if(m_shaders.begin(), m_shaders.end(), [&shader_name](std::unique_ptr<GLShaderProgram>& p) { return p->get_name() == shader_name; });
108 return (it != m_shaders.end()) ? it->get() : nullptr;
109}

References m_shaders.

Referenced by Slic3r::GUI::OpenGLManager::get_shader().

+ Here is the caller graph for this function:

◆ init()

std::pair< bool, std::string > Slic3r::GLShadersManager::init ( )
20{
21 std::string error;
22
23 auto append_shader = [this, &error](const std::string& name, const GLShaderProgram::ShaderFilenames& filenames,
24 const std::initializer_list<std::string_view> &defines = {}) {
25 m_shaders.push_back(std::make_unique<GLShaderProgram>());
26 if (!m_shaders.back()->init_from_files(name, filenames, defines)) {
27 error += name + "\n";
28 // if any error happens while initializating the shader, we remove it from the list
29 m_shaders.pop_back();
30 return false;
31 }
32 return true;
33 };
34
35 assert(m_shaders.empty());
36
37 bool valid = true;
38
39#if ENABLE_OPENGL_ES
40 const std::string prefix = "ES/";
41 // used to render wireframed triangles
42 valid &= append_shader("wireframe", { prefix + "wireframe.vs", prefix + "wireframe.fs" });
43#else
44 const std::string prefix = GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 1) ? "140/" : "110/";
45#endif // ENABLE_OPENGL_ES
46 // imgui shader
47 valid &= append_shader("imgui", { prefix + "imgui.vs", prefix + "imgui.fs" });
48 // basic shader, used to render all what was previously rendered using the immediate mode
49 valid &= append_shader("flat", { prefix + "flat.vs", prefix + "flat.fs" });
50 // basic shader with plane clipping, used to render volumes in picking pass
51 valid &= append_shader("flat_clip", { prefix + "flat_clip.vs", prefix + "flat_clip.fs" });
52 // basic shader for textures, used to render textures
53 valid &= append_shader("flat_texture", { prefix + "flat_texture.vs", prefix + "flat_texture.fs" });
54 // used to render 3D scene background
55 valid &= append_shader("background", { prefix + "background.vs", prefix + "background.fs" });
56#if ENABLE_OPENGL_ES
57 // used to render dashed lines
58 valid &= append_shader("dashed_lines", { prefix + "dashed_lines.vs", prefix + "dashed_lines.fs" });
59#elif ENABLE_GL_CORE_PROFILE
60 if (GUI::OpenGLManager::get_gl_info().is_core_profile())
61 // used to render thick and/or dashed lines
62 valid &= append_shader("dashed_thick_lines", { prefix + "dashed_thick_lines.vs", prefix + "dashed_thick_lines.fs", prefix + "dashed_thick_lines.gs" });
63#endif // ENABLE_OPENGL_ES
64 // used to render toolpaths center of gravity
65 valid &= append_shader("toolpaths_cog", { prefix + "toolpaths_cog.vs", prefix + "toolpaths_cog.fs" });
66 // used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview
67 valid &= append_shader("gouraud_light", { prefix + "gouraud_light.vs", prefix + "gouraud_light.fs" });
68 // extend "gouraud_light" by adding clipping, used in sla gizmos
69 valid &= append_shader("gouraud_light_clip", { prefix + "gouraud_light_clip.vs", prefix + "gouraud_light_clip.fs" });
70 // used to render printbed
71 valid &= append_shader("printbed", { prefix + "printbed.vs", prefix + "printbed.fs" });
72 // used to render options in gcode preview
73 if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) {
74 valid &= append_shader("gouraud_light_instanced", { prefix + "gouraud_light_instanced.vs", prefix + "gouraud_light_instanced.fs" });
75 }
76 // used to render objects in 3d editor
77 valid &= append_shader("gouraud", { prefix + "gouraud.vs", prefix + "gouraud.fs" }
78#if ENABLE_ENVIRONMENT_MAP
79 , { "ENABLE_ENVIRONMENT_MAP"sv }
80#endif // ENABLE_ENVIRONMENT_MAP
81 );
82 // used to render variable layers heights in 3d editor
83 valid &= append_shader("variable_layer_height", { prefix + "variable_layer_height.vs", prefix + "variable_layer_height.fs" });
84 // used to render highlight contour around selected triangles inside the multi-material gizmo
85 valid &= append_shader("mm_contour", { prefix + "mm_contour.vs", prefix + "mm_contour.fs" });
86 // Used to render painted triangles inside the multi-material gizmo. Triangle normals are computed inside fragment shader.
87 // For Apple's on Arm CPU computed triangle normals inside fragment shader using dFdx and dFdy has the opposite direction.
88 // Because of this, objects had darker colors inside the multi-material gizmo.
89 // Based on https://stackoverflow.com/a/66206648, the similar behavior was also spotted on some other devices with Arm CPU.
90 // Since macOS 12 (Monterey), this issue with the opposite direction on Apple's Arm CPU seems to be fixed, and computed
91 // triangle normals inside fragment shader have the right direction.
92 if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12)
93 valid &= append_shader("mm_gouraud", { prefix + "mm_gouraud.vs", prefix + "mm_gouraud.fs" }, { "FLIP_TRIANGLE_NORMALS"sv });
94 else
95 valid &= append_shader("mm_gouraud", { prefix + "mm_gouraud.vs", prefix + "mm_gouraud.fs" });
96
97 return { valid, error };
98}
std::array< std::string, static_cast< size_t >(EShaderType::Count)> ShaderFilenames
Definition GLShader.hpp:29
static const GLInfo & get_gl_info()
Definition OpenGLManager.hpp:141
PlatformFlavor platform_flavor()
Definition Platform.cpp:103
static char error[256]
Definition tga.cpp:50

References error, Slic3r::GUI::OpenGLManager::get_gl_info(), m_shaders, Slic3r::OSXOnArm, and Slic3r::platform_flavor().

Referenced by Slic3r::GUI::OpenGLManager::init_gl().

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

◆ shutdown()

void Slic3r::GLShadersManager::shutdown ( )
101{
102 m_shaders.clear();
103}

References m_shaders.

Referenced by Slic3r::GUI::OpenGLManager::~OpenGLManager().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_shaders

std::vector<std::unique_ptr<GLShaderProgram> > Slic3r::GLShadersManager::m_shaders
private

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