OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GLShadersManager Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLShadersManager.hpp>

Collaboration diagram for Slic3r::GLShadersManager:

Public Member Functions

std::pair< bool, std::string > init ()
void shutdown ()
GLShaderProgram * get_shader (const std::string &shader_name)
GLShaderProgram * get_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 ( )
136{
137 GLint id = 0;
139 if (id == 0)
140 return nullptr;
141
142 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; });
143 return (it != m_shaders.end()) ? it->get() : nullptr;
144}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
std::vector< std::unique_ptr< GLShaderProgram > > m_shaders
Definition GLShadersManager.hpp:15
#define GL_CURRENT_PROGRAM
Definition gl.h:508
int GLint
Definition gl.h:2062
#define glGetIntegerv
Definition gl.h:3873

References GL_CURRENT_PROGRAM, glGetIntegerv, glsafe, and m_shaders.

◆ get_shader()

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

References m_shaders.

◆ init()

std::pair< bool, std::string > Slic3r::GLShadersManager::init ( )
23{
24 std::string error;
25
26 auto append_shader = [this, &error](const std::string& name, const GLShaderProgram::ShaderFilenames& filenames,
27 const std::initializer_list<std::string_view> &defines = {}) {
28 m_shaders.push_back(std::make_unique<GLShaderProgram>());
29 if (!m_shaders.back()->init_from_files(name, filenames, defines)) {
30 error += name + "\n";
31 // if any error happens while initializating the shader, we remove it from the list
32 m_shaders.pop_back();
33 return false;
34 }
35 return true;
36 };
37
38 assert(m_shaders.empty());
39
40 bool valid = true;
41
42#if SLIC3R_OPENGL_ES
43 const std::string prefix = "ES/";
44 // used to render wireframed triangles
45 valid &= append_shader("wireframe", { prefix + "wireframe.vs", prefix + "wireframe.fs" });
46#else
47 const std::string prefix = GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 1) ? "140/" : "110/";
48#endif // SLIC3R_OPENGL_ES
49 // imgui shader
50 valid &= append_shader("imgui", { prefix + "imgui.vs", prefix + "imgui.fs" });
51 // basic shader, used to render all what was previously rendered using the immediate mode
52 valid &= append_shader("flat", { prefix + "flat.vs", prefix + "flat.fs" });
53 // basic shader with plane clipping, used to render volumes in picking pass
54 valid &= append_shader("flat_clip", { prefix + "flat_clip.vs", prefix + "flat_clip.fs" });
55 // basic shader for textures, used to render textures
56 valid &= append_shader("flat_texture", { prefix + "flat_texture.vs", prefix + "flat_texture.fs" });
57 // used to apply post-processing antialiasing in screen space
58 valid &= append_shader("fxaa", { prefix + "fxaa.vs", prefix + "fxaa.fs" });
59 // used to apply screen-space ambient occlusion in post process
60 valid &= append_shader("ssao", { prefix + "ssao.vs", prefix + "ssao.fs" });
61 // used to render 3D scene background
62 valid &= append_shader("background", { prefix + "background.vs", prefix + "background.fs" });
63#if SLIC3R_OPENGL_ES
64 // used to render dashed lines
65 valid &= append_shader("dashed_lines", { prefix + "dashed_lines.vs", prefix + "dashed_lines.fs" });
66#else
67 if (GUI::OpenGLManager::get_gl_info().is_core_profile())
68 // used to render thick and/or dashed lines
69 valid &= append_shader("dashed_thick_lines", { prefix + "dashed_thick_lines.vs", prefix + "dashed_thick_lines.fs", prefix + "dashed_thick_lines.gs" });
70#endif // SLIC3R_OPENGL_ES
71 // used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview
72 valid &= append_shader("gouraud_light", { prefix + "gouraud_light.vs", prefix + "gouraud_light.fs" });
73 //used to render thumbnail
74 valid &= append_shader("thumbnail", { prefix + "thumbnail.vs", prefix + "thumbnail.fs"});
75 // used to render printbed
76 valid &= append_shader("printbed", { prefix + "printbed.vs", prefix + "printbed.fs" });
77#if !SLIC3R_OPENGL_ES
78 // used to cast the object shadow map onto the build plate (realistic view)
79 valid &= append_shader("printbed_shadow", { prefix + "printbed_shadow.vs", prefix + "printbed_shadow.fs" });
80#endif // !SLIC3R_OPENGL_ES
81 valid &= append_shader("hotbed", {prefix + "hotbed.vs", prefix + "hotbed.fs"});
82 // used to render options in gcode preview
83 if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) {
84 valid &= append_shader("gouraud_light_instanced", { prefix + "gouraud_light_instanced.vs", prefix + "gouraud_light_instanced.fs" });
85 }
86
87 // used to render objects in 3d editor
88 valid &= append_shader("gouraud", { prefix + "gouraud.vs", prefix + "gouraud.fs" }
89#if ENABLE_ENVIRONMENT_MAP
90 , { "ENABLE_ENVIRONMENT_MAP"sv }
91#endif // ENABLE_ENVIRONMENT_MAP
92 );
93 // used to render objects in 3d editor with phong shading
94 valid &= append_shader("phong", { prefix + "phong.vs", prefix + "phong.fs" }
95#if ENABLE_ENVIRONMENT_MAP
96 , { "ENABLE_ENVIRONMENT_MAP"sv }
97#endif // ENABLE_ENVIRONMENT_MAP
98 );
99 // used to render objects as translucent, edge weighted surfaces in the X-Ray view
100 valid &= append_shader("xray", { prefix + "xray.vs", prefix + "xray.fs" });
101 // used to render variable layers heights in 3d editor
102 valid &= append_shader("variable_layer_height", { prefix + "variable_layer_height.vs", prefix + "variable_layer_height.fs" });
103 // used to render highlight contour around selected triangles inside the multi-material gizmo
104 valid &= append_shader("mm_contour", { prefix + "mm_contour.vs", prefix + "mm_contour.fs" });
105 // Used to render painted triangles inside the multi-material gizmo. Triangle normals are computed inside fragment shader.
106 // For Apple's on Arm CPU computed triangle normals inside fragment shader using dFdx and dFdy has the opposite direction.
107 // Because of this, objects had darker colors inside the multi-material gizmo.
108 // Based on https://stackoverflow.com/a/66206648, the similar behavior was also spotted on some other devices with Arm CPU.
109 // Since macOS 12 (Monterey), this issue with the opposite direction on Apple's Arm CPU seems to be fixed, and computed
110 // triangle normals inside fragment shader have the right direction.
111 if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12)
112 valid &= append_shader("mm_gouraud", { prefix + "mm_gouraud.vs", prefix + "mm_gouraud.fs" }, { "FLIP_TRIANGLE_NORMALS"sv });
113 else
114 valid &= append_shader("mm_gouraud", { prefix + "mm_gouraud.vs", prefix + "mm_gouraud.fs" });
115 // Fast shaded preview for the texture displacement gizmo (see libslic3r/TextureDisplacement.hpp).
116 valid &= append_shader("texture_displacement_shaded", { prefix + "texture_displacement_shaded.vs", prefix + "texture_displacement_shaded.fs" });
117 // UV-check overlay for the same gizmo: a procedural checker or a distortion heatmap over the
118 // painted patch, to sanity-check the unwrap.
119 valid &= append_shader("texture_displacement_uvcheck", { prefix + "texture_displacement_uvcheck.vs", prefix + "texture_displacement_uvcheck.fs" });
120
121 return { valid, error };
122}
std::array< std::string, static_cast< size_t >(EShaderType::Count)> ShaderFilenames
Definition GLShader.hpp:33
static const GLInfo & get_gl_info()
Definition OpenGLManager.hpp:106
@ OSXOnArm
Definition Platform.hpp:30
PlatformFlavor platform_flavor()
Definition Platform.cpp:108

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

Here is the call graph for this function:

◆ shutdown()

void Slic3r::GLShadersManager::shutdown ( )
125{
126 m_shaders.clear();
127}

References m_shaders.

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: