From 028dfb5d9e48ae7764ebf4664b659e2947cffe26 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 6 Dec 2022 12:17:01 +0100 Subject: [PATCH] Tech ENABLE_LEGACY_OPENGL_REMOVAL set as default --- resources/shaders/background.fs | 11 - resources/shaders/background.vs | 9 - resources/shaders/flat.fs | 8 - resources/shaders/flat.vs | 6 - resources/shaders/flat_texture.fs | 10 - resources/shaders/flat_texture.vs | 9 - resources/shaders/gouraud.fs | 79 -- resources/shaders/gouraud.vs | 71 -- resources/shaders/gouraud_light.fs | 12 - resources/shaders/gouraud_light.vs | 38 - resources/shaders/gouraud_light_instanced.fs | 12 - resources/shaders/gouraud_light_instanced.vs | 46 - resources/shaders/mm_contour.fs | 6 - resources/shaders/mm_contour.vs | 11 - resources/shaders/mm_gouraud.fs | 60 - resources/shaders/mm_gouraud.vs | 23 - resources/shaders/printbed.fs | 36 - resources/shaders/printbed.vs | 9 - resources/shaders/toolpaths_cog.fs | 18 - resources/shaders/toolpaths_cog.vs | 40 - resources/shaders/toolpaths_lines.fs | 28 - resources/shaders/toolpaths_lines.vs | 9 - resources/shaders/variable_layer_height.fs | 41 - resources/shaders/variable_layer_height.vs | 52 - src/libslic3r/BuildVolume.hpp | 2 - src/libslic3r/Technologies.hpp | 10 +- src/slic3r/GUI/3DBed.cpp | 386 ------ src/slic3r/GUI/3DBed.hpp | 68 - src/slic3r/GUI/3DScene.cpp | 1127 +---------------- src/slic3r/GUI/3DScene.hpp | 297 +---- src/slic3r/GUI/Camera.cpp | 44 - src/slic3r/GUI/Camera.hpp | 3 - src/slic3r/GUI/CoordAxes.cpp | 29 - src/slic3r/GUI/CoordAxes.hpp | 4 - src/slic3r/GUI/GCodeViewer.cpp | 194 --- src/slic3r/GUI/GCodeViewer.hpp | 17 - src/slic3r/GUI/GLCanvas3D.cpp | 719 +---------- src/slic3r/GUI/GLCanvas3D.hpp | 29 +- src/slic3r/GUI/GLModel.cpp | 706 ----------- src/slic3r/GUI/GLModel.hpp | 75 -- src/slic3r/GUI/GLSelectionRectangle.cpp | 48 - src/slic3r/GUI/GLSelectionRectangle.hpp | 4 - src/slic3r/GUI/GLShadersManager.cpp | 38 - src/slic3r/GUI/GLTexture.cpp | 13 - src/slic3r/GUI/GLToolbar.cpp | 639 ---------- src/slic3r/GUI/GLToolbar.hpp | 16 - src/slic3r/GUI/GalleryDialog.cpp | 5 - src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 66 - src/slic3r/GUI/Gizmos/GLGizmoBase.hpp | 2 - src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 22 - src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp | 30 - src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp | 8 - src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 38 - .../GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 66 - .../GUI/Gizmos/GLGizmoMmuSegmentation.hpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoMove.cpp | 64 - src/slic3r/GUI/Gizmos/GLGizmoMove.hpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp | 295 +---- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp | 66 - src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 166 +-- src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 14 - src/slic3r/GUI/Gizmos/GLGizmoScale.cpp | 102 -- src/slic3r/GUI/Gizmos/GLGizmoScale.hpp | 10 - src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp | 29 - src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 80 +- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 32 - src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 189 --- src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 14 - src/slic3r/GUI/ImGuiWrapper.cpp | 60 - src/slic3r/GUI/MeshUtils.cpp | 32 +- src/slic3r/GUI/MeshUtils.hpp | 14 - src/slic3r/GUI/Selection.cpp | 343 +---- src/slic3r/GUI/Selection.hpp | 11 - src/slic3r/Utils/UndoRedo.cpp | 2 - 74 files changed, 37 insertions(+), 6847 deletions(-) delete mode 100644 resources/shaders/background.fs delete mode 100644 resources/shaders/background.vs delete mode 100644 resources/shaders/flat.fs delete mode 100644 resources/shaders/flat.vs delete mode 100644 resources/shaders/flat_texture.fs delete mode 100644 resources/shaders/flat_texture.vs delete mode 100644 resources/shaders/gouraud.fs delete mode 100644 resources/shaders/gouraud.vs delete mode 100644 resources/shaders/gouraud_light.fs delete mode 100644 resources/shaders/gouraud_light.vs delete mode 100644 resources/shaders/gouraud_light_instanced.fs delete mode 100644 resources/shaders/gouraud_light_instanced.vs delete mode 100644 resources/shaders/mm_contour.fs delete mode 100644 resources/shaders/mm_contour.vs delete mode 100644 resources/shaders/mm_gouraud.fs delete mode 100644 resources/shaders/mm_gouraud.vs delete mode 100644 resources/shaders/printbed.fs delete mode 100644 resources/shaders/printbed.vs delete mode 100644 resources/shaders/toolpaths_cog.fs delete mode 100644 resources/shaders/toolpaths_cog.vs delete mode 100644 resources/shaders/toolpaths_lines.fs delete mode 100644 resources/shaders/toolpaths_lines.vs delete mode 100644 resources/shaders/variable_layer_height.fs delete mode 100644 resources/shaders/variable_layer_height.vs diff --git a/resources/shaders/background.fs b/resources/shaders/background.fs deleted file mode 100644 index b14844089..000000000 --- a/resources/shaders/background.fs +++ /dev/null @@ -1,11 +0,0 @@ -#version 110 - -uniform vec4 top_color; -uniform vec4 bottom_color; - -varying vec2 tex_coord; - -void main() -{ - gl_FragColor = mix(bottom_color, top_color, tex_coord.y); -} diff --git a/resources/shaders/background.vs b/resources/shaders/background.vs deleted file mode 100644 index b7c1d92c0..000000000 --- a/resources/shaders/background.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 110 - -varying vec2 tex_coord; - -void main() -{ - gl_Position = gl_Vertex; - tex_coord = gl_MultiTexCoord0.xy; -} diff --git a/resources/shaders/flat.fs b/resources/shaders/flat.fs deleted file mode 100644 index ab656998d..000000000 --- a/resources/shaders/flat.fs +++ /dev/null @@ -1,8 +0,0 @@ -#version 110 - -uniform vec4 uniform_color; - -void main() -{ - gl_FragColor = uniform_color; -} diff --git a/resources/shaders/flat.vs b/resources/shaders/flat.vs deleted file mode 100644 index d0d3ee42a..000000000 --- a/resources/shaders/flat.vs +++ /dev/null @@ -1,6 +0,0 @@ -#version 110 - -void main() -{ - gl_Position = ftransform(); -} diff --git a/resources/shaders/flat_texture.fs b/resources/shaders/flat_texture.fs deleted file mode 100644 index ffe193b1c..000000000 --- a/resources/shaders/flat_texture.fs +++ /dev/null @@ -1,10 +0,0 @@ -#version 110 - -uniform sampler2D uniform_texture; - -varying vec2 tex_coord; - -void main() -{ - gl_FragColor = texture2D(uniform_texture, tex_coord); -} diff --git a/resources/shaders/flat_texture.vs b/resources/shaders/flat_texture.vs deleted file mode 100644 index 27addc752..000000000 --- a/resources/shaders/flat_texture.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 110 - -varying vec2 tex_coord; - -void main() -{ - gl_Position = ftransform(); - tex_coord = gl_MultiTexCoord0.xy; -} diff --git a/resources/shaders/gouraud.fs b/resources/shaders/gouraud.fs deleted file mode 100644 index 1657fc051..000000000 --- a/resources/shaders/gouraud.fs +++ /dev/null @@ -1,79 +0,0 @@ -#version 110 - -const vec3 ZERO = vec3(0.0, 0.0, 0.0); -const float EPSILON = 0.0001; - -struct PrintVolumeDetection -{ - // 0 = rectangle, 1 = circle, 2 = custom, 3 = invalid - int type; - // type = 0 (rectangle): - // x = min.x, y = min.y, z = max.x, w = max.y - // type = 1 (circle): - // x = center.x, y = center.y, z = radius - vec4 xy_data; - // x = min z, y = max z - vec2 z_data; -}; - -struct SlopeDetection -{ - bool actived; - float normal_z; - mat3 volume_world_normal_matrix; -}; - -uniform vec4 uniform_color; -uniform SlopeDetection slope; - -#ifdef ENABLE_ENVIRONMENT_MAP - uniform sampler2D environment_tex; - uniform bool use_environment_tex; -#endif // ENABLE_ENVIRONMENT_MAP - -varying vec3 clipping_planes_dots; - -// x = diffuse, y = specular; -varying vec2 intensity; - -uniform PrintVolumeDetection print_volume; - -varying vec4 world_pos; -varying float world_normal_z; -varying vec3 eye_normal; - -void main() -{ - if (any(lessThan(clipping_planes_dots, ZERO))) - discard; - vec3 color = uniform_color.rgb; - float alpha = uniform_color.a; - - if (slope.actived && world_normal_z < slope.normal_z - EPSILON) { - color = vec3(0.7, 0.7, 1.0); - alpha = 1.0; - } - - // if the fragment is outside the print volume -> use darker color - vec3 pv_check_min = ZERO; - vec3 pv_check_max = ZERO; - if (print_volume.type == 0) { - // rectangle - pv_check_min = world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, print_volume.z_data.x); - pv_check_max = world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, print_volume.z_data.y); - } - else if (print_volume.type == 1) { - // circle - float delta_radius = print_volume.xy_data.z - distance(world_pos.xy, print_volume.xy_data.xy); - pv_check_min = vec3(delta_radius, 0.0, world_pos.z - print_volume.z_data.x); - pv_check_max = vec3(0.0, 0.0, world_pos.z - print_volume.z_data.y); - } - color = (any(lessThan(pv_check_min, ZERO)) || any(greaterThan(pv_check_max, ZERO))) ? mix(color, ZERO, 0.3333) : color; - -#ifdef ENABLE_ENVIRONMENT_MAP - if (use_environment_tex) - gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, alpha); - else -#endif - gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); -} diff --git a/resources/shaders/gouraud.vs b/resources/shaders/gouraud.vs deleted file mode 100644 index c8b3d7b33..000000000 --- a/resources/shaders/gouraud.vs +++ /dev/null @@ -1,71 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -//#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION) -//#define LIGHT_FRONT_SHININESS 5.0 - -#define INTENSITY_AMBIENT 0.3 - -const vec3 ZERO = vec3(0.0, 0.0, 0.0); - -struct SlopeDetection -{ - bool actived; - float normal_z; - mat3 volume_world_normal_matrix; -}; - -uniform mat4 volume_world_matrix; -uniform SlopeDetection slope; - -// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane. -uniform vec2 z_range; -// Clipping plane - general orientation. Used by the SLA gizmo. -uniform vec4 clipping_plane; - -// x = diffuse, y = specular; -varying vec2 intensity; - -varying vec3 clipping_planes_dots; - -varying vec4 world_pos; -varying float world_normal_z; -varying vec3 eye_normal; - -void main() -{ - // First transform the normal into camera space and normalize the result. - eye_normal = normalize(gl_NormalMatrix * gl_Normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - // Point in homogenous coordinates. - world_pos = volume_world_matrix * gl_Vertex; - - // z component of normal vector in world coordinate used for slope shading - world_normal_z = slope.actived ? (normalize(slope.volume_world_normal_matrix * gl_Normal)).z : 0.0; - - gl_Position = ftransform(); - // Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded. - clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z); -} diff --git a/resources/shaders/gouraud_light.fs b/resources/shaders/gouraud_light.fs deleted file mode 100644 index 970185a00..000000000 --- a/resources/shaders/gouraud_light.fs +++ /dev/null @@ -1,12 +0,0 @@ -#version 110 - -uniform vec4 uniform_color; -uniform float emission_factor; - -// x = tainted, y = specular; -varying vec2 intensity; - -void main() -{ - gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a); -} diff --git a/resources/shaders/gouraud_light.vs b/resources/shaders/gouraud_light.vs deleted file mode 100644 index d4f71938a..000000000 --- a/resources/shaders/gouraud_light.vs +++ /dev/null @@ -1,38 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -// x = tainted, y = specular; -varying vec2 intensity; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(gl_NormalMatrix * gl_Normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - gl_Position = ftransform(); -} diff --git a/resources/shaders/gouraud_light_instanced.fs b/resources/shaders/gouraud_light_instanced.fs deleted file mode 100644 index 970185a00..000000000 --- a/resources/shaders/gouraud_light_instanced.fs +++ /dev/null @@ -1,12 +0,0 @@ -#version 110 - -uniform vec4 uniform_color; -uniform float emission_factor; - -// x = tainted, y = specular; -varying vec2 intensity; - -void main() -{ - gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a); -} diff --git a/resources/shaders/gouraud_light_instanced.vs b/resources/shaders/gouraud_light_instanced.vs deleted file mode 100644 index a42f8e9a4..000000000 --- a/resources/shaders/gouraud_light_instanced.vs +++ /dev/null @@ -1,46 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -// vertex attributes -attribute vec3 v_position; -attribute vec3 v_normal; -// instance attributes -attribute vec3 i_offset; -attribute vec2 i_scales; - -// x = tainted, y = specular; -varying vec2 intensity; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 eye_normal = normalize(gl_NormalMatrix * v_normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec4 world_position = vec4(v_position * vec3(vec2(1.5 * i_scales.x), 1.5 * i_scales.y) + i_offset - vec3(0.0, 0.0, 0.5 * i_scales.y), 1.0); - vec3 eye_position = (gl_ModelViewMatrix * world_position).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - gl_Position = gl_ProjectionMatrix * vec4(eye_position, 1.0); -} diff --git a/resources/shaders/mm_contour.fs b/resources/shaders/mm_contour.fs deleted file mode 100644 index 14c18dcf1..000000000 --- a/resources/shaders/mm_contour.fs +++ /dev/null @@ -1,6 +0,0 @@ -#version 110 - -void main() -{ - gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); -} diff --git a/resources/shaders/mm_contour.vs b/resources/shaders/mm_contour.vs deleted file mode 100644 index 8423362e4..000000000 --- a/resources/shaders/mm_contour.vs +++ /dev/null @@ -1,11 +0,0 @@ -#version 110 - -uniform float offset; - -void main() -{ - // Add small epsilon to z to solve z-fighting between painted triangles and contour lines. - vec4 clip_position = gl_ModelViewProjectionMatrix * gl_Vertex; - clip_position.z -= offset * abs(clip_position.w); - gl_Position = clip_position; -} diff --git a/resources/shaders/mm_gouraud.fs b/resources/shaders/mm_gouraud.fs deleted file mode 100644 index 5932efe59..000000000 --- a/resources/shaders/mm_gouraud.fs +++ /dev/null @@ -1,60 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -const vec3 ZERO = vec3(0.0, 0.0, 0.0); -const float EPSILON = 0.0001; - -uniform vec4 uniform_color; - -varying vec3 clipping_planes_dots; -varying vec4 model_pos; - -uniform bool volume_mirrored; - -void main() -{ - if (any(lessThan(clipping_planes_dots, ZERO))) - discard; - vec3 color = uniform_color.rgb; - float alpha = uniform_color.a; - - vec3 triangle_normal = normalize(cross(dFdx(model_pos.xyz), dFdy(model_pos.xyz))); -#ifdef FLIP_TRIANGLE_NORMALS - triangle_normal = -triangle_normal; -#endif - - if (volume_mirrored) - triangle_normal = -triangle_normal; - - // First transform the normal into camera space and normalize the result. - vec3 eye_normal = normalize(gl_NormalMatrix * triangle_normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(eye_normal, LIGHT_TOP_DIR), 0.0); - - // x = diffuse, y = specular; - vec2 intensity = vec2(0.0, 0.0); - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * model_pos).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha); -} diff --git a/resources/shaders/mm_gouraud.vs b/resources/shaders/mm_gouraud.vs deleted file mode 100644 index 2847c3136..000000000 --- a/resources/shaders/mm_gouraud.vs +++ /dev/null @@ -1,23 +0,0 @@ -#version 110 - -const vec3 ZERO = vec3(0.0, 0.0, 0.0); - -uniform mat4 volume_world_matrix; -// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane. -uniform vec2 z_range; -// Clipping plane - general orientation. Used by the SLA gizmo. -uniform vec4 clipping_plane; - -varying vec3 clipping_planes_dots; -varying vec4 model_pos; - -void main() -{ - model_pos = gl_Vertex; - // Point in homogenous coordinates. - vec4 world_pos = volume_world_matrix * gl_Vertex; - - gl_Position = ftransform(); - // Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded. - clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z); -} diff --git a/resources/shaders/printbed.fs b/resources/shaders/printbed.fs deleted file mode 100644 index e11b293e9..000000000 --- a/resources/shaders/printbed.fs +++ /dev/null @@ -1,36 +0,0 @@ -#version 110 - -const vec3 back_color_dark = vec3(0.235, 0.235, 0.235); -const vec3 back_color_light = vec3(0.365, 0.365, 0.365); - -uniform sampler2D texture; -uniform bool transparent_background; -uniform bool svg_source; - -varying vec2 tex_coord; - -vec4 svg_color() -{ - // takes foreground from texture - vec4 fore_color = texture2D(texture, tex_coord); - - // calculates radial gradient - vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5))))); - - // blends foreground with background - return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0); -} - -vec4 non_svg_color() -{ - // takes foreground from texture - vec4 color = texture2D(texture, tex_coord); - return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a); -} - -void main() -{ - vec4 color = svg_source ? svg_color() : non_svg_color(); - color.a = transparent_background ? color.a * 0.5 : color.a; - gl_FragColor = color; -} \ No newline at end of file diff --git a/resources/shaders/printbed.vs b/resources/shaders/printbed.vs deleted file mode 100644 index 27addc752..000000000 --- a/resources/shaders/printbed.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 110 - -varying vec2 tex_coord; - -void main() -{ - gl_Position = ftransform(); - tex_coord = gl_MultiTexCoord0.xy; -} diff --git a/resources/shaders/toolpaths_cog.fs b/resources/shaders/toolpaths_cog.fs deleted file mode 100644 index f88d79b96..000000000 --- a/resources/shaders/toolpaths_cog.fs +++ /dev/null @@ -1,18 +0,0 @@ -#version 110 - -const vec4 BLACK = vec4(vec3(0.1), 1.0); -const vec4 WHITE = vec4(vec3(1.0), 1.0); - -const float emission_factor = 0.25; - -// x = tainted, y = specular; -varying vec2 intensity; -varying vec3 world_position; -uniform vec3 world_center; - -void main() -{ - vec3 delta = world_position - world_center; - vec4 color = delta.x * delta.y * delta.z > 0.0 ? BLACK : WHITE; - gl_FragColor = vec4(vec3(intensity.y) + color.rgb * (intensity.x + emission_factor), 1.0); -} diff --git a/resources/shaders/toolpaths_cog.vs b/resources/shaders/toolpaths_cog.vs deleted file mode 100644 index c7b1abfdb..000000000 --- a/resources/shaders/toolpaths_cog.vs +++ /dev/null @@ -1,40 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -// normalized values for (1./1.43, 0.2/1.43, 1./1.43) -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) - -#define INTENSITY_AMBIENT 0.3 - -// x = tainted, y = specular; -varying vec2 intensity; -varying vec3 world_position; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(gl_NormalMatrix * gl_Normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular applied). - NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - world_position = gl_Vertex.xyz; - gl_Position = ftransform(); -} diff --git a/resources/shaders/toolpaths_lines.fs b/resources/shaders/toolpaths_lines.fs deleted file mode 100644 index 31151cdc1..000000000 --- a/resources/shaders/toolpaths_lines.fs +++ /dev/null @@ -1,28 +0,0 @@ -#version 110 - -// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0); - -// x = ambient, y = top diffuse, z = front diffuse, w = global -uniform vec4 light_intensity; -uniform vec4 uniform_color; - -varying vec3 eye_normal; - -void main() -{ - vec3 normal = normalize(eye_normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. Take the abs value to light the lines no matter in which direction the normal points. - float NdotL = abs(dot(normal, LIGHT_TOP_DIR)); - - float intensity = light_intensity.x + NdotL * light_intensity.y; - - // Perform the same lighting calculation for the 2nd light source. - NdotL = abs(dot(normal, LIGHT_FRONT_DIR)); - intensity += NdotL * light_intensity.z; - - gl_FragColor = vec4(uniform_color.rgb * light_intensity.w * intensity, uniform_color.a); -} diff --git a/resources/shaders/toolpaths_lines.vs b/resources/shaders/toolpaths_lines.vs deleted file mode 100644 index c008aedc6..000000000 --- a/resources/shaders/toolpaths_lines.vs +++ /dev/null @@ -1,9 +0,0 @@ -#version 110 - -varying vec3 eye_normal; - -void main() -{ - gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; - eye_normal = gl_NormalMatrix * gl_Normal; -} diff --git a/resources/shaders/variable_layer_height.fs b/resources/shaders/variable_layer_height.fs deleted file mode 100644 index 693c1c6a0..000000000 --- a/resources/shaders/variable_layer_height.fs +++ /dev/null @@ -1,41 +0,0 @@ -#version 110 - -#define M_PI 3.1415926535897932384626433832795 - -// 2D texture (1D texture split by the rows) of color along the object Z axis. -uniform sampler2D z_texture; -// Scaling from the Z texture rows coordinate to the normalized texture row coordinate. -uniform float z_to_texture_row; -uniform float z_texture_row_to_normalized; -uniform float z_cursor; -uniform float z_cursor_band_width; - -// x = tainted, y = specular; -varying vec2 intensity; - -varying float object_z; - -void main() -{ - float object_z_row = z_to_texture_row * object_z; - // Index of the row in the texture. - float z_texture_row = floor(object_z_row); - // Normalized coordinate from 0. to 1. - float z_texture_col = object_z_row - z_texture_row; - float z_blend = 0.25 * cos(min(M_PI, abs(M_PI * (object_z - z_cursor) * 1.8 / z_cursor_band_width))) + 0.25; - // Calculate level of detail from the object Z coordinate. - // This makes the slowly sloping surfaces to be shown with high detail (with stripes), - // and the vertical surfaces to be shown with low detail (no stripes) - float z_in_cells = object_z_row * 190.; - // Gradient of Z projected on the screen. - float dx_vtc = dFdx(z_in_cells); - float dy_vtc = dFdy(z_in_cells); - float lod = clamp(0.5 * log2(max(dx_vtc * dx_vtc, dy_vtc * dy_vtc)), 0., 1.); - // Sample the Z texture. Texture coordinates are normalized to <0, 1>. - vec4 color = vec4(0.25, 0.25, 0.25, 1.0); - if (z_texture_row >= 0.0) - color = mix(texture2D(z_texture, vec2(z_texture_col, z_texture_row_to_normalized * (z_texture_row + 0.5 )), -10000.), - texture2D(z_texture, vec2(z_texture_col, z_texture_row_to_normalized * (z_texture_row * 2. + 1.)), 10000.), lod); - // Mix the final color. - gl_FragColor = vec4(vec3(intensity.y), 1.0) + intensity.x * mix(color, vec4(1.0, 1.0, 0.0, 1.0), z_blend); -} diff --git a/resources/shaders/variable_layer_height.vs b/resources/shaders/variable_layer_height.vs deleted file mode 100644 index 0e966b081..000000000 --- a/resources/shaders/variable_layer_height.vs +++ /dev/null @@ -1,52 +0,0 @@ -#version 110 - -#define INTENSITY_CORRECTION 0.6 - -const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); -#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) -#define LIGHT_TOP_SHININESS 20.0 - -const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); -#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) -//#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION) -//#define LIGHT_FRONT_SHININESS 5.0 - -#define INTENSITY_AMBIENT 0.3 - -uniform mat4 volume_world_matrix; -uniform float object_max_z; - -// x = tainted, y = specular; -varying vec2 intensity; - -varying float object_z; - -void main() -{ - // First transform the normal into camera space and normalize the result. - vec3 normal = normalize(gl_NormalMatrix * gl_Normal); - - // Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. - // Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. - float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); - - intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; - vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; - intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); - - // Perform the same lighting calculation for the 2nd light source (no specular) - NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); - - intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; - - // Scaled to widths of the Z texture. - if (object_max_z > 0.0) - // when rendering the overlay - object_z = object_max_z * gl_MultiTexCoord0.y; - else - // when rendering the volumes - object_z = (volume_world_matrix * gl_Vertex).z; - - gl_Position = ftransform(); -} diff --git a/src/libslic3r/BuildVolume.hpp b/src/libslic3r/BuildVolume.hpp index b4ac118ec..6537d2745 100644 --- a/src/libslic3r/BuildVolume.hpp +++ b/src/libslic3r/BuildVolume.hpp @@ -95,10 +95,8 @@ public: bool all_paths_inside_vertices_and_normals_interleaved(const std::vector& paths, const Eigen::AlignedBox& bbox, bool ignore_bottom = true) const; -#if ENABLE_LEGACY_OPENGL_REMOVAL const std::pair, std::vector>& top_bottom_convex_hull_decomposition_scene() const { return m_top_bottom_convex_hull_decomposition_scene; } const std::pair, std::vector>& top_bottom_convex_hull_decomposition_bed() const { return m_top_bottom_convex_hull_decomposition_bed; } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: // Source definition of the print bed geometry (PrintConfig::bed_shape) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 4e6d2106b..996bc2fdf 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -30,6 +30,8 @@ #define ENABLE_MEASURE_GIZMO_DEBUG 0 // Enable scene raycast picking debug window #define ENABLE_RAYCAST_PICKING_DEBUG 0 +// Shows an imgui dialog with GLModel statistics data +#define ENABLE_GLMODEL_STATISTICS 0 // Enable rendering of objects using environment map @@ -43,16 +45,12 @@ //==================== #define ENABLE_2_6_0_ALPHA1 1 -// Enable removal of legacy OpenGL calls -#define ENABLE_LEGACY_OPENGL_REMOVAL (1 && ENABLE_2_6_0_ALPHA1) // Enable OpenGL ES -#define ENABLE_OPENGL_ES (0 && ENABLE_LEGACY_OPENGL_REMOVAL) +#define ENABLE_OPENGL_ES 0 // Enable OpenGL core profile context (tested against Mesa 20.1.8 on Windows) -#define ENABLE_GL_CORE_PROFILE (1 && ENABLE_LEGACY_OPENGL_REMOVAL && !ENABLE_OPENGL_ES) +#define ENABLE_GL_CORE_PROFILE (1 && !ENABLE_OPENGL_ES) // Enable OpenGL debug messages using debug context #define ENABLE_OPENGL_DEBUG_OPTION (1 && ENABLE_GL_CORE_PROFILE) -// Shows an imgui dialog with GLModel statistics data -#define ENABLE_GLMODEL_STATISTICS (0 && ENABLE_LEGACY_OPENGL_REMOVAL) // Enable rework of Reload from disk command #define ENABLE_RELOAD_FROM_DISK_REWORK (1 && ENABLE_2_6_0_ALPHA1) // Enable editing volumes transformation in world coordinates and instances in local coordinates diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index a7e70bc43..d19e23ecd 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -11,10 +11,8 @@ #include "GUI_App.hpp" #include "GLCanvas3D.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "Plater.hpp" #include "Camera.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include @@ -31,77 +29,6 @@ static const Slic3r::ColorRGBA DEFAULT_TRANSPARENT_GRID_COLOR = { 0.9f, 0.9f, 0 namespace Slic3r { namespace GUI { -#if !ENABLE_LEGACY_OPENGL_REMOVAL -bool GeometryBuffer::set_from_triangles(const std::vector &triangles, float z) -{ - if (triangles.empty()) { - m_vertices.clear(); - return false; - } - - assert(triangles.size() % 3 == 0); - m_vertices = std::vector(triangles.size(), Vertex()); - - Vec2f min = triangles.front(); - Vec2f max = min; - - for (size_t v_count = 0; v_count < triangles.size(); ++ v_count) { - const Vec2f &p = triangles[v_count]; - Vertex &v = m_vertices[v_count]; - v.position = Vec3f(p.x(), p.y(), z); - v.tex_coords = p; - min = min.cwiseMin(p).eval(); - max = max.cwiseMax(p).eval(); - } - - Vec2f size = max - min; - if (size.x() != 0.f && size.y() != 0.f) { - Vec2f inv_size = size.cwiseInverse(); - inv_size.y() *= -1; - for (Vertex& v : m_vertices) { - v.tex_coords -= min; - v.tex_coords.x() *= inv_size.x(); - v.tex_coords.y() *= inv_size.y(); - } - } - - return true; -} - -bool GeometryBuffer::set_from_lines(const Lines& lines, float z) -{ - m_vertices.clear(); - - unsigned int v_size = 2 * (unsigned int)lines.size(); - if (v_size == 0) - return false; - - m_vertices = std::vector(v_size, Vertex()); - - unsigned int v_count = 0; - for (const Line& l : lines) { - Vertex& v1 = m_vertices[v_count]; - v1.position[0] = unscale(l.a(0)); - v1.position[1] = unscale(l.a(1)); - v1.position[2] = z; - ++v_count; - - Vertex& v2 = m_vertices[v_count]; - v2.position[0] = unscale(l.b(0)); - v2.position[1] = unscale(l.b(1)); - v2.position[2] = z; - ++v_count; - } - - return true; -} - -const float* GeometryBuffer::get_vertices_data() const -{ - return (m_vertices.size() > 0) ? (const float*)m_vertices.data() : nullptr; -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #if !ENABLE_WORLD_COORDINATE const float Bed3D::Axes::DefaultStemRadius = 0.5f; const float Bed3D::Axes::DefaultStemLength = 25.0f; @@ -110,7 +37,6 @@ const float Bed3D::Axes::DefaultTipLength = 5.0f; void Bed3D::Axes::render() { -#if ENABLE_LEGACY_OPENGL_REMOVAL auto render_axis = [this](GLShaderProgram* shader, const Transform3d& transform) { const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); @@ -118,15 +44,7 @@ void Bed3D::Axes::render() shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * transform.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - auto render_axis = [this](const Transform3f& transform) { - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixf(transform.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL }; if (!m_arrow.is_initialized()) @@ -142,31 +60,16 @@ void Bed3D::Axes::render() shader->set_uniform("emission_factor", 0.0f); // x axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::X()); render_axis(shader, Geometry::assemble_transform(m_origin, { 0.0, 0.5 * M_PI, 0.0 })); -#else - m_arrow.set_color(-1, ColorRGBA::X()); - render_axis(Geometry::assemble_transform(m_origin, { 0.0, 0.5 * M_PI, 0.0 }).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // y axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::Y()); render_axis(shader, Geometry::assemble_transform(m_origin, { -0.5 * M_PI, 0.0, 0.0 })); -#else - m_arrow.set_color(-1, ColorRGBA::Y()); - render_axis(Geometry::assemble_transform(m_origin, { -0.5 * M_PI, 0.0, 0.0 }).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // z axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::Z()); render_axis(shader, Geometry::assemble_transform(m_origin)); -#else - m_arrow.set_color(-1, ColorRGBA::Z()); - render_axis(Geometry::assemble_transform(m_origin).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); @@ -221,7 +124,6 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c m_model_filename = model_filename; m_extended_bounding_box = this->calc_extended_bounding_box(); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_contour = ExPolygon(Polygon::new_scale(bed_shape)); const BoundingBox bbox = m_contour.contour.bounding_box(); if (!bbox.defined) @@ -231,20 +133,6 @@ bool Bed3D::set_shape(const Pointfs& bed_shape, const double max_print_height, c m_triangles.reset(); m_gridlines.reset(); m_contourlines.reset(); -#else - ExPolygon poly{ Polygon::new_scale(bed_shape) }; - - calc_triangles(poly); - - const BoundingBox& bed_bbox = poly.contour.bounding_box(); - calc_gridlines(poly, bed_bbox); - - calc_contourlines(poly); - - m_polygon = offset(poly.contour, (float)bed_bbox.radius() * 1.7f, jtRound, scale_(0.5)).front(); - - this->release_VBOs(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_texture.reset(); m_model.reset(); @@ -269,7 +157,6 @@ Point Bed3D::point_projection(const Point& point) const return m_polygon.point_projection(point); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture) { render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture, false); @@ -279,25 +166,9 @@ void Bed3D::render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matri { render_internal(canvas, view_matrix, projection_matrix, bottom, scale_factor, false, false, true); } -#else -void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture) -{ - render_internal(canvas, bottom, scale_factor, show_axes, show_texture, false); -} -void Bed3D::render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor) -{ - render_internal(canvas, bottom, scale_factor, false, false, true); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture, bool picking) -#else -void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, - bool show_axes, bool show_texture, bool picking) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { m_scale_factor = scale_factor; @@ -306,23 +177,13 @@ void Bed3D::render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, glsafe(::glEnable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_model.model.set_color(picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); -#else - m_model.set_color(-1, picking ? PICKING_MODEL_COLOR : DEFAULT_MODEL_COLOR); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL switch (m_type) { -#if ENABLE_LEGACY_OPENGL_REMOVAL case Type::System: { render_system(canvas, view_matrix, projection_matrix, bottom, show_texture); break; } default: case Type::Custom: { render_custom(canvas, view_matrix, projection_matrix, bottom, show_texture, picking); break; } -#else - case Type::System: { render_system(canvas, bottom, show_texture); break; } - default: - case Type::Custom: { render_custom(canvas, bottom, show_texture, picking); break; } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } glsafe(::glDisable(GL_DEPTH_TEST)); @@ -357,7 +218,6 @@ BoundingBoxf3 Bed3D::calc_extended_bounding_box() const return out; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::init_triangles() { if (m_triangles.is_initialized()) @@ -453,42 +313,7 @@ void Bed3D::init_gridlines() m_gridlines.init_from(std::move(init_data)); } -#else -void Bed3D::calc_triangles(const ExPolygon& poly) -{ - if (! m_triangles.set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << "Unable to create bed triangles"; -} -void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox) -{ - Polylines axes_lines; - for (coord_t x = bed_bbox.min.x(); x <= bed_bbox.max.x(); x += scale_(10.0)) { - Polyline line; - line.append(Point(x, bed_bbox.min.y())); - line.append(Point(x, bed_bbox.max.y())); - axes_lines.push_back(line); - } - for (coord_t y = bed_bbox.min.y(); y <= bed_bbox.max.y(); y += scale_(10.0)) { - Polyline line; - line.append(Point(bed_bbox.min.x(), y)); - line.append(Point(bed_bbox.max.x(), y)); - axes_lines.push_back(line); - } - - // clip with a slightly grown expolygon because our lines lay on the contours and may get erroneously clipped - Lines gridlines = to_lines(intersection_pl(axes_lines, offset(poly, (float)SCALED_EPSILON))); - - // append bed contours - Lines contour_lines = to_lines(poly); - std::copy(contour_lines.begin(), contour_lines.end(), std::back_inserter(gridlines)); - - if (!m_gridlines.set_from_lines(gridlines, GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << "Unable to create bed grid lines\n"; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::init_contourlines() { if (m_contourlines.is_initialized()) @@ -514,14 +339,6 @@ void Bed3D::init_contourlines() m_contourlines.init_from(std::move(init_data)); m_contourlines.set_color({ 1.0f, 1.0f, 1.0f, 0.5f }); } -#else -void Bed3D::calc_contourlines(const ExPolygon& poly) -{ - const Lines contour_lines = to_lines(poly); - if (!m_contourlines.set_from_lines(contour_lines, GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << "Unable to create bed contour lines\n"; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Try to match the print bed shape with the shape of an active profile. If such a match exists, // return the print bed model. @@ -551,17 +368,12 @@ void Bed3D::render_axes() { if (m_build_volume.valid()) #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL m_axes.render(Transform3d::Identity(), 0.25f); -#else - m_axes.render(0.25f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #else m_axes.render(); #endif // ENABLE_WORLD_COORDINATE } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture) { if (!bottom) @@ -572,32 +384,12 @@ void Bed3D::render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, co else if (bottom) render_contour(view_matrix, projection_matrix); } -#else -void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) -{ - if (!bottom) - render_model(); - if (show_texture) - render_texture(bottom, canvas); - else if (bottom) - render_contour(); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix) -#else -void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (m_texture_filename.empty()) { m_texture.reset(); -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } @@ -610,11 +402,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) if (m_temp_texture.get_id() == 0 || m_temp_texture.get_source() != m_texture_filename) { // generate a temporary lower resolution texture to show while no main texture levels have been compressed if (!m_temp_texture.load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } canvas.request_extra_frame(); @@ -622,11 +410,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // starts generating the main texture, compression will run asynchronously if (!m_texture.load_from_svg_file(m_texture_filename, true, true, true, max_tex_size)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } } @@ -634,11 +418,7 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // generate a temporary lower resolution texture to show while no main texture levels have been compressed if (m_temp_texture.get_id() == 0 || m_temp_texture.get_source() != m_texture_filename) { if (!m_temp_texture.load_from_file(m_texture_filename, false, GLTexture::None, false)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } canvas.request_extra_frame(); @@ -646,20 +426,12 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // starts generating the main texture, compression will run asynchronously if (!m_texture.load_from_file(m_texture_filename, true, GLTexture::MultiThreaded, true)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } } else { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, false, true, view_matrix, projection_matrix); -#else - render_default(bottom, false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } } @@ -674,7 +446,6 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) canvas.request_extra_frame(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL init_triangles(); GLShaderProgram* shader = wxGetApp().get_shader("printbed"); @@ -713,83 +484,15 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) shader->stop_using(); } -#else - if (m_triangles.get_vertices_count() > 0) { - GLShaderProgram* shader = wxGetApp().get_shader("printbed"); - if (shader != nullptr) { - shader->start_using(); - shader->set_uniform("transparent_background", bottom); - shader->set_uniform("svg_source", boost::algorithm::iends_with(m_texture.get_source(), ".svg")); - - if (m_vbo_id == 0) { - glsafe(::glGenBuffers(1, &m_vbo_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)m_triangles.get_vertices_data_size(), (const GLvoid*)m_triangles.get_vertices_data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } - - glsafe(::glEnable(GL_DEPTH_TEST)); - if (bottom) - glsafe(::glDepthMask(GL_FALSE)); - - glsafe(::glEnable(GL_BLEND)); - glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - - if (bottom) - glsafe(::glFrontFace(GL_CW)); - - const unsigned int stride = m_triangles.get_vertex_data_size(); - - // show the temporary texture while no compressed data is available - GLuint tex_id = (GLuint)m_temp_texture.get_id(); - if (tex_id == 0) - tex_id = (GLuint)m_texture.get_id(); - - glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id)); - - glsafe(::glVertexPointer(3, GL_FLOAT, stride, (const void*)(intptr_t)m_triangles.get_position_offset())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glTexCoordPointer(2, GL_FLOAT, stride, (const void*)(intptr_t)m_triangles.get_tex_coords_offset())); - glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)m_triangles.get_vertices_count())); - - glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); - - if (bottom) - glsafe(::glFrontFace(GL_CCW)); - - glsafe(::glDisable(GL_BLEND)); - if (bottom) - glsafe(::glDepthMask(GL_TRUE)); - - shader->stop_using(); - } - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix) -#else -void Bed3D::render_model() -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (m_model_filename.empty()) return; if (m_model.model.get_filename() != m_model_filename && m_model.model.init_from_file(m_model_filename)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL m_model.model.set_color(DEFAULT_MODEL_COLOR); -#else - m_model.set_color(-1, DEFAULT_MODEL_COLOR); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // move the model so that its origin (0.0, 0.0, 0.0) goes into the bed shape center and a bit down to avoid z-fighting with the texture quad m_model_offset = to_3d(m_build_volume.bounding_volume2d().center(), -0.03); @@ -806,41 +509,24 @@ void Bed3D::render_model() if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.0f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = Geometry::translation_transform(m_model_offset); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", projection_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslated(m_model_offset.x(), m_model_offset.y(), m_model_offset.z())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_model.model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); } } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking) -#else -void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (m_texture_filename.empty() && m_model_filename.empty()) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_default(bottom, picking, show_texture, view_matrix, projection_matrix); -#else - render_default(bottom, picking, show_texture); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return; } -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!bottom) render_model(view_matrix, projection_matrix); @@ -848,26 +534,12 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo render_texture(bottom, canvas, view_matrix, projection_matrix); else if (bottom) render_contour(view_matrix, projection_matrix); -#else - if (!bottom) - render_model(); - - if (show_texture) - render_texture(bottom, canvas); - else if (bottom) - render_contour(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix) -#else -void Bed3D::render_default(bool bottom, bool picking, bool show_texture) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { m_texture.reset(); -#if ENABLE_LEGACY_OPENGL_REMOVAL init_gridlines(); init_triangles(); @@ -906,45 +578,8 @@ void Bed3D::render_default(bool bottom, bool picking, bool show_texture) shader->stop_using(); } -#else - const unsigned int triangles_vcount = m_triangles.get_vertices_count(); - if (triangles_vcount > 0) { - const bool has_model = !m_model.get_filename().empty(); - - glsafe(::glEnable(GL_DEPTH_TEST)); - glsafe(::glEnable(GL_BLEND)); - glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - if (!has_model && !bottom) { - // draw background - glsafe(::glDepthMask(GL_FALSE)); - glsafe(::glColor4fv(picking ? PICKING_MODEL_COLOR.data() : DEFAULT_MODEL_COLOR.data())); - glsafe(::glNormal3d(0.0f, 0.0f, 1.0f)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount)); - glsafe(::glDepthMask(GL_TRUE)); - } - - if (!picking && show_texture) { - // draw grid - glsafe(::glLineWidth(1.5f * m_scale_factor)); - glsafe(::glColor4fv(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR.data() : DEFAULT_TRANSPARENT_GRID_COLOR.data())); - glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines.get_vertices_count())); - } - else if (!show_texture) - render_contour(); - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glDisable(GL_BLEND)); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::render_contour(const Transform3d& view_matrix, const Transform3d& projection_matrix) { init_contourlines(); @@ -971,27 +606,6 @@ void Bed3D::render_contour(const Transform3d& view_matrix, const Transform3d& pr shader->stop_using(); } } -#else -void Bed3D::render_contour() -{ - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glLineWidth(1.5f * m_scale_factor)); - glsafe(::glColor4f(1.0f, 1.0f, 1.0f, 0.5f)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_contourlines.get_vertex_data_size(), (GLvoid*)m_contourlines.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_contourlines.get_vertices_count())); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void Bed3D::release_VBOs() -{ - if (m_vbo_id > 0) { - glsafe(::glDeleteBuffers(1, &m_vbo_id)); - m_vbo_id = 0; - } -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL void Bed3D::register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo) { diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index c12674b4a..ebfc1123d 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -11,9 +11,7 @@ #include "MeshUtils.hpp" #include "libslic3r/BuildVolume.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/ExPolygon.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include #include @@ -23,30 +21,6 @@ namespace GUI { class GLCanvas3D; -#if !ENABLE_LEGACY_OPENGL_REMOVAL -class GeometryBuffer -{ - struct Vertex - { - Vec3f position{ Vec3f::Zero() }; - Vec2f tex_coords{ Vec2f::Zero() }; - }; - - std::vector m_vertices; - -public: - bool set_from_triangles(const std::vector &triangles, float z); - bool set_from_lines(const Lines& lines, float z); - - const float* get_vertices_data() const; - unsigned int get_vertices_data_size() const { return (unsigned int)m_vertices.size() * get_vertex_data_size(); } - unsigned int get_vertex_data_size() const { return (unsigned int)(5 * sizeof(float)); } - size_t get_position_offset() const { return 0; } - size_t get_tex_coords_offset() const { return (size_t)(3 * sizeof(float)); } - unsigned int get_vertices_count() const { return (unsigned int)m_vertices.size(); } -}; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - class Bed3D { #if !ENABLE_WORLD_COORDINATE @@ -91,29 +65,18 @@ private: std::string m_model_filename; // Print volume bounding box exteded with axes and model. BoundingBoxf3 m_extended_bounding_box; -#if ENABLE_LEGACY_OPENGL_REMOVAL // Print bed polygon ExPolygon m_contour; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Slightly expanded print bed polygon, for collision detection. Polygon m_polygon; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_triangles; GLModel m_gridlines; GLModel m_contourlines; -#else - GeometryBuffer m_triangles; - GeometryBuffer m_gridlines; - GeometryBuffer m_contourlines; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLTexture m_texture; // temporary texture shown until the main texture has still no levels compressed GLTexture m_temp_texture; PickingModel m_model; Vec3d m_model_offset{ Vec3d::Zero() }; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - unsigned int m_vbo_id{ 0 }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE CoordAxes m_axes; #else @@ -124,11 +87,7 @@ private: public: Bed3D() = default; -#if ENABLE_LEGACY_OPENGL_REMOVAL ~Bed3D() = default; -#else - ~Bed3D() { release_VBOs(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Update print bed model from configuration. // Return true if the bed shape changed, so the calee will update the UI. @@ -152,52 +111,25 @@ public: bool contains(const Point& point) const; Point point_projection(const Point& point) const; -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture); void render_for_picking(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor); -#else - void render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes, bool show_texture); - void render_for_picking(GLCanvas3D& canvas, bool bottom, float scale_factor); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: // Calculate an extended bounding box from axes and current model for visualization purposes. BoundingBoxf3 calc_extended_bounding_box() const; -#if ENABLE_LEGACY_OPENGL_REMOVAL void init_triangles(); void init_gridlines(); void init_contourlines(); -#else - void calc_triangles(const ExPolygon& poly); - void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox); - void calc_contourlines(const ExPolygon& poly); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL static std::tuple detect_type(const Pointfs& shape); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_internal(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, float scale_factor, bool show_axes, bool show_texture, bool picking); -#else - void render_internal(GLCanvas3D& canvas, bool bottom, float scale_factor, - bool show_axes, bool show_texture, bool picking); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void render_axes(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture); void render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking); void render_default(bool bottom, bool picking, bool show_texture, const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_contour(const Transform3d& view_matrix, const Transform3d& projection_matrix); -#else - void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture); - void render_texture(bool bottom, GLCanvas3D& canvas); - void render_model(); - void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking); - void render_default(bool bottom, bool picking, bool show_texture); - void render_contour(); - - void release_VBOs(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void register_raycasters_for_picking(const GLModel::Geometry& geometry, const Transform3d& trafo); }; diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 4bf05555c..27a67001e 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1,21 +1,11 @@ #include -#if !ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_SMOOTH_NORMALS -#include -#include -#include -#endif // ENABLE_SMOOTH_NORMALS -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #include "3DScene.hpp" #include "GLShader.hpp" #include "GUI_App.hpp" #include "Plater.hpp" #include "BitmapCache.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "Camera.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/BuildVolume.hpp" #include "libslic3r/ExtrusionEntity.hpp" @@ -74,234 +64,12 @@ void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char namespace Slic3r { -#if !ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_SMOOTH_NORMALS -static void smooth_normals_corner(TriangleMesh& mesh, std::vector& normals) -{ - using MapMatrixXfUnaligned = Eigen::Map>; - using MapMatrixXiUnaligned = Eigen::Map>; - - std::vector face_normals = its_face_normals(mesh.its); - - Eigen::MatrixXd vertices = MapMatrixXfUnaligned(mesh.its.vertices.front().data(), - Eigen::Index(mesh.its.vertices.size()), 3).cast(); - Eigen::MatrixXi indices = MapMatrixXiUnaligned(mesh.its.indices.front().data(), - Eigen::Index(mesh.its.indices.size()), 3); - Eigen::MatrixXd in_normals = MapMatrixXfUnaligned(face_normals.front().data(), - Eigen::Index(face_normals.size()), 3).cast(); - Eigen::MatrixXd out_normals; - - igl::per_corner_normals(vertices, indices, in_normals, 1.0, out_normals); - - normals = std::vector(mesh.its.vertices.size()); - for (size_t i = 0; i < mesh.its.indices.size(); ++i) { - for (size_t j = 0; j < 3; ++j) { - normals[mesh.its.indices[i][j]] = out_normals.row(i * 3 + j).cast(); - } - } -} - -static void smooth_normals_vertex(TriangleMesh& mesh, std::vector& normals) -{ - using MapMatrixXfUnaligned = Eigen::Map>; - using MapMatrixXiUnaligned = Eigen::Map>; - - Eigen::MatrixXd vertices = MapMatrixXfUnaligned(mesh.its.vertices.front().data(), - Eigen::Index(mesh.its.vertices.size()), 3).cast(); - Eigen::MatrixXi indices = MapMatrixXiUnaligned(mesh.its.indices.front().data(), - Eigen::Index(mesh.its.indices.size()), 3); - Eigen::MatrixXd out_normals; - -// igl::per_vertex_normals(vertices, indices, igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_UNIFORM, out_normals); -// igl::per_vertex_normals(vertices, indices, igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_AREA, out_normals); - igl::per_vertex_normals(vertices, indices, igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_ANGLE, out_normals); -// igl::per_vertex_normals(vertices, indices, igl::PER_VERTEX_NORMALS_WEIGHTING_TYPE_DEFAULT, out_normals); - - normals = std::vector(mesh.its.vertices.size()); - for (size_t i = 0; i < static_cast(out_normals.rows()); ++i) { - normals[i] = out_normals.row(i).cast(); - } -} -#endif // ENABLE_SMOOTH_NORMALS - -#if ENABLE_SMOOTH_NORMALS -void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh& mesh, bool smooth_normals) -#else -void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh& mesh) -#endif // ENABLE_SMOOTH_NORMALS -{ - assert(triangle_indices.empty() && vertices_and_normals_interleaved_size == 0); - assert(quad_indices.empty() && triangle_indices_size == 0); - assert(vertices_and_normals_interleaved.size() % 6 == 0 && quad_indices_size == vertices_and_normals_interleaved.size()); - -#if ENABLE_SMOOTH_NORMALS - if (smooth_normals) { - TriangleMesh new_mesh(mesh); - std::vector normals; - smooth_normals_corner(new_mesh, normals); -// smooth_normals_vertex(new_mesh, normals); - - this->vertices_and_normals_interleaved.reserve(this->vertices_and_normals_interleaved.size() + 3 * 2 * new_mesh.its.vertices.size()); - for (size_t i = 0; i < new_mesh.its.vertices.size(); ++i) { - const stl_vertex& v = new_mesh.its.vertices[i]; - const stl_normal& n = normals[i]; - this->push_geometry(v(0), v(1), v(2), n(0), n(1), n(2)); - } - - for (size_t i = 0; i < new_mesh.its.indices.size(); ++i) { - const stl_triangle_vertex_indices& idx = new_mesh.its.indices[i]; - this->push_triangle(idx(0), idx(1), idx(2)); - } - } - else { -#endif // ENABLE_SMOOTH_NORMALS - this->load_its_flat_shading(mesh.its); -#if ENABLE_SMOOTH_NORMALS - } -#endif // ENABLE_SMOOTH_NORMALS -} - -void GLIndexedVertexArray::load_its_flat_shading(const indexed_triangle_set &its) -{ - this->vertices_and_normals_interleaved.reserve(this->vertices_and_normals_interleaved.size() + 3 * 3 * 2 * its.indices.size()); - unsigned int vertices_count = 0; - for (int i = 0; i < int(its.indices.size()); ++ i) { - stl_triangle_vertex_indices face = its.indices[i]; - stl_vertex vertex[3] = { its.vertices[face[0]], its.vertices[face[1]], its.vertices[face[2]] }; - stl_vertex n = face_normal_normalized(vertex); - for (int j = 0; j < 3; ++j) - this->push_geometry(vertex[j](0), vertex[j](1), vertex[j](2), n(0), n(1), n(2)); - this->push_triangle(vertices_count, vertices_count + 1, vertices_count + 2); - vertices_count += 3; - } -} - -void GLIndexedVertexArray::finalize_geometry(bool opengl_initialized) -{ - assert(this->vertices_and_normals_interleaved_VBO_id == 0); - assert(this->triangle_indices_VBO_id == 0); - assert(this->quad_indices_VBO_id == 0); - - if (! opengl_initialized) { - // Shrink the data vectors to conserve memory in case the data cannot be transfered to the OpenGL driver yet. - this->shrink_to_fit(); - return; - } - - if (! this->vertices_and_normals_interleaved.empty()) { - glsafe(::glGenBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved.size() * 4, this->vertices_and_normals_interleaved.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - this->vertices_and_normals_interleaved.clear(); - } - if (! this->triangle_indices.empty()) { - glsafe(::glGenBuffers(1, &this->triangle_indices_VBO_id)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices.size() * 4, this->triangle_indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - this->triangle_indices.clear(); - } - if (! this->quad_indices.empty()) { - glsafe(::glGenBuffers(1, &this->quad_indices_VBO_id)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices.size() * 4, this->quad_indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - this->quad_indices.clear(); - } -} - -void GLIndexedVertexArray::release_geometry() -{ - if (this->vertices_and_normals_interleaved_VBO_id) { - glsafe(::glDeleteBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); - this->vertices_and_normals_interleaved_VBO_id = 0; - } - if (this->triangle_indices_VBO_id) { - glsafe(::glDeleteBuffers(1, &this->triangle_indices_VBO_id)); - this->triangle_indices_VBO_id = 0; - } - if (this->quad_indices_VBO_id) { - glsafe(::glDeleteBuffers(1, &this->quad_indices_VBO_id)); - this->quad_indices_VBO_id = 0; - } - this->clear(); -} - -void GLIndexedVertexArray::render() const -{ - assert(this->vertices_and_normals_interleaved_VBO_id != 0); - assert(this->triangle_indices_VBO_id != 0 || this->quad_indices_VBO_id != 0); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); - glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr)); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); - - // Render using the Vertex Buffer Objects. - if (this->triangle_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_size), GL_UNSIGNED_INT, nullptr)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - if (this->quad_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(::glDrawElements(GL_QUADS, GLsizei(this->quad_indices_size), GL_UNSIGNED_INT, nullptr)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -} - -void GLIndexedVertexArray::render( - const std::pair& tverts_range, - const std::pair& qverts_range) const -{ - // this method has been called before calling finalize() ? - if (this->vertices_and_normals_interleaved_VBO_id == 0 && !this->vertices_and_normals_interleaved.empty()) - return; - - assert(this->vertices_and_normals_interleaved_VBO_id != 0); - assert(this->triangle_indices_VBO_id != 0 || this->quad_indices_VBO_id != 0); - - // Render using the Vertex Buffer Objects. - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); - glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr)); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); - - if (this->triangle_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(std::min(this->triangle_indices_size, tverts_range.second - tverts_range.first)), GL_UNSIGNED_INT, (const void*)(tverts_range.first * 4))); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - if (this->quad_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(::glDrawElements(GL_QUADS, GLsizei(std::min(this->quad_indices_size, qverts_range.second - qverts_range.first)), GL_UNSIGNED_INT, (const void*)(qverts_range.first * 4))); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - const float GLVolume::SinkingContours::HalfWidth = 0.25f; void GLVolume::SinkingContours::render() { update(); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) return; @@ -309,14 +77,7 @@ void GLVolume::SinkingContours::render() const GUI::Camera& camera = GUI::wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::translation_transform(m_shift)); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslated(m_shift.x(), m_shift.y(), m_shift.z())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } void GLVolume::SinkingContours::update() @@ -347,18 +108,15 @@ void GLVolume::SinkingContours::update() m_model.reset(); GUI::GLModel::Geometry init_data; -#if ENABLE_LEGACY_OPENGL_REMOVAL init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Triangles, GUI::GLModel::Geometry::EVertexLayout::P3 }; init_data.color = ColorRGBA::WHITE(); unsigned int vertices_counter = 0; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL MeshSlicingParams slicing_params; slicing_params.trafo = m_parent.world_matrix(); const Polygons polygons = union_(slice_mesh(mesh.its, 0.0f, slicing_params)); if (polygons.empty()) return; for (const ExPolygon& expoly : diff_ex(expand(polygons, float(scale_(HalfWidth))), shrink(polygons, float(scale_(HalfWidth))))) { -#if ENABLE_LEGACY_OPENGL_REMOVAL const std::vector triangulation = triangulate_expolygon_3d(expoly); init_data.reserve_vertices(init_data.vertices_count() + triangulation.size()); init_data.reserve_indices(init_data.indices_count() + triangulation.size()); @@ -370,27 +128,6 @@ void GLVolume::SinkingContours::update() } } m_model.init_from(std::move(init_data)); -#else - GUI::GLModel::Geometry::Entity entity; - entity.type = GUI::GLModel::EPrimitiveType::Triangles; - const std::vector triangulation = triangulate_expolygon_3d(expoly); - entity.positions.reserve(entity.positions.size() + triangulation.size()); - entity.normals.reserve(entity.normals.size() + triangulation.size()); - entity.indices.reserve(entity.indices.size() + triangulation.size() / 3); - for (const Vec3d& v : triangulation) { - entity.positions.emplace_back(v.cast() + 0.015f * Vec3f::UnitZ()); // add a small positive z to avoid z-fighting - entity.normals.emplace_back(Vec3f::UnitZ()); - const size_t positions_count = entity.positions.size(); - if (positions_count % 3 == 0) { - entity.indices.emplace_back(positions_count - 3); - entity.indices.emplace_back(positions_count - 2); - entity.indices.emplace_back(positions_count - 1); - } - } - init_data.entities.emplace_back(entity); - } - m_model.init_from(init_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLVolume::NonManifoldEdges::render() @@ -401,7 +138,7 @@ void GLVolume::NonManifoldEdges::render() if (!GUI::OpenGLManager::get_gl_info().is_core_profile()) #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL + GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) return; @@ -416,15 +153,7 @@ void GLVolume::NonManifoldEdges::render() shader->set_uniform("gap_size", 0.0f); #endif // ENABLE_GL_CORE_PROFILE m_model.set_color(complementary(m_parent.render_color)); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(m_parent.world_matrix().data())); - m_model.set_color(-1, complementary(m_parent.render_color)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } void GLVolume::NonManifoldEdges::update() @@ -444,7 +173,6 @@ void GLVolume::NonManifoldEdges::update() const std::vector> edges = its_get_open_edges(mesh.its); if (!edges.empty()) { GUI::GLModel::Geometry init_data; -#if ENABLE_LEGACY_OPENGL_REMOVAL init_data.format = { GUI::GLModel::Geometry::EPrimitiveType::Lines, GUI::GLModel::Geometry::EVertexLayout::P3 }; init_data.reserve_vertices(2 * edges.size()); init_data.reserve_indices(2 * edges.size()); @@ -458,25 +186,6 @@ void GLVolume::NonManifoldEdges::update() init_data.add_line(vertices_count - 2, vertices_count - 1); } m_model.init_from(std::move(init_data)); -#else - GUI::GLModel::Geometry::Entity entity; - entity.type = GUI::GLModel::EPrimitiveType::Lines; - - entity.positions.reserve(2 * edges.size()); - entity.normals.reserve(2 * edges.size()); - entity.indices.reserve(2 * edges.size()); - for (const std::pair& edge : edges) { - entity.positions.emplace_back(mesh.its.vertices[edge.first].cast()); - entity.positions.emplace_back(mesh.its.vertices[edge.second].cast()); - entity.normals.emplace_back(Vec3f::UnitZ()); - entity.normals.emplace_back(Vec3f::UnitZ()); - entity.indices.emplace_back(entity.positions.size() - 2); - entity.indices.emplace_back(entity.positions.size() - 1); - } - - init_data.entities.emplace_back(entity); - m_model.init_from(init_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } @@ -522,9 +231,6 @@ GLVolume::GLVolume(float r, float g, float b, float a) , force_neutral_color(false) , force_sinking_contours(false) , tverts_range(0, size_t(-1)) -#if !ENABLE_LEGACY_OPENGL_REMOVAL - , qverts_range(0, size_t(-1)) -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL { color = { r, g, b, a }; set_render_color(color); @@ -640,7 +346,6 @@ const BoundingBoxf3& GLVolume::transformed_non_sinking_bounding_box() const return *m_transformed_non_sinking_bounding_box; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLVolume::set_range(double min_z, double max_z) { this->tverts_range.first = 0; @@ -669,71 +374,24 @@ void GLVolume::set_range(double min_z, double max_z) } } } -#else -void GLVolume::set_range(double min_z, double max_z) -{ - this->qverts_range.first = 0; - this->qverts_range.second = this->indexed_vertex_array.quad_indices_size; - this->tverts_range.first = 0; - this->tverts_range.second = this->indexed_vertex_array.triangle_indices_size; - if (! this->print_zs.empty()) { - // The Z layer range is specified. - // First test whether the Z span of this object is not out of (min_z, max_z) completely. - if (this->print_zs.front() > max_z || this->print_zs.back() < min_z) { - this->qverts_range.second = 0; - this->tverts_range.second = 0; - } - else { - // Then find the lowest layer to be displayed. - size_t i = 0; - for (; i < this->print_zs.size() && this->print_zs[i] < min_z; ++ i); - if (i == this->print_zs.size()) { - // This shall not happen. - this->qverts_range.second = 0; - this->tverts_range.second = 0; - } - else { - // Remember start of the layer. - this->qverts_range.first = this->offsets[i * 2]; - this->tverts_range.first = this->offsets[i * 2 + 1]; - // Some layers are above $min_z. Which? - for (; i < this->print_zs.size() && this->print_zs[i] <= max_z; ++ i); - if (i < this->print_zs.size()) { - this->qverts_range.second = this->offsets[i * 2]; - this->tverts_range.second = this->offsets[i * 2 + 1]; - } - } - } - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void GLVolume::render() { if (!is_active) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (this->is_left_handed()) glsafe(::glFrontFace(GL_CW)); glsafe(::glCullFace(GL_BACK)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (tverts_range == std::make_pair(0, -1)) model.render(); else model.render(this->tverts_range); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(world_matrix().data())); - this->indexed_vertex_array.render(this->tverts_range, this->qverts_range); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (this->is_left_handed()) glsafe(::glFrontFace(GL_CCW)); @@ -765,44 +423,23 @@ void GLVolume::render_non_manifold_edges() m_non_manifold_edges.render(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector GLVolumeCollection::load_object( const ModelObject* model_object, int obj_idx, const std::vector& instance_idxs) -#else -std::vector GLVolumeCollection::load_object( - const ModelObject *model_object, - int obj_idx, - const std::vector &instance_idxs, - bool opengl_initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { std::vector volumes_idx; for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++volume_idx) for (int instance_idx : instance_idxs) -#if ENABLE_LEGACY_OPENGL_REMOVAL - volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx)); -#else - volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx, opengl_initialized)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL + volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx)); return volumes_idx; } -#if ENABLE_LEGACY_OPENGL_REMOVAL int GLVolumeCollection::load_object_volume( const ModelObject* model_object, int obj_idx, int volume_idx, int instance_idx) -#else -int GLVolumeCollection::load_object_volume( - const ModelObject *model_object, - int obj_idx, - int volume_idx, - int instance_idx, - bool opengl_initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { const ModelVolume *model_volume = model_object->volumes[volume_idx]; const int extruder_id = model_volume->extruder_id(); @@ -811,7 +448,6 @@ int GLVolumeCollection::load_object_volume( this->volumes.emplace_back(new GLVolume()); GLVolume& v = *this->volumes.back(); v.set_color(color_from_model_volume(*model_volume)); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS v.model.init_from(*mesh, true); v.mesh_raycaster = std::make_unique(mesh); @@ -819,14 +455,6 @@ int GLVolumeCollection::load_object_volume( v.model.init_from(*mesh); v.mesh_raycaster = std::make_unique(mesh); #endif // ENABLE_SMOOTH_NORMALS -#else -#if ENABLE_SMOOTH_NORMALS - v.indexed_vertex_array.load_mesh(mesh, true); -#else - v.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_SMOOTH_NORMALS - v.indexed_vertex_array.finalize_geometry(opengl_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL v.composite_id = GLVolume::CompositeID(obj_idx, volume_idx, instance_idx); if (model_volume->is_model_part()) { // GLVolume will reference a convex hull from model_volume! @@ -845,7 +473,6 @@ int GLVolumeCollection::load_object_volume( // Load SLA auxiliary GLVolumes (for support trees or pad). // This function produces volumes for multiple instances in a single shot, // as some object specific mesh conversions may be expensive. -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLVolumeCollection::load_object_auxiliary( const SLAPrintObject* print_object, int obj_idx, @@ -854,17 +481,6 @@ void GLVolumeCollection::load_object_auxiliary( SLAPrintObjectStep milestone, // Timestamp of the last change of the milestone size_t timestamp) -#else -void GLVolumeCollection::load_object_auxiliary( - const SLAPrintObject *print_object, - int obj_idx, - // pairs of - const std::vector>& instances, - SLAPrintObjectStep milestone, - // Timestamp of the last change of the milestone - size_t timestamp, - bool opengl_initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { assert(print_object->is_step_done(milestone)); Transform3d mesh_trafo_inv = print_object->trafo().inverse(); @@ -877,7 +493,6 @@ void GLVolumeCollection::load_object_auxiliary( const ModelInstance& model_instance = *print_object->model_object()->instances[instance_idx.first]; this->volumes.emplace_back(new GLVolume((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR)); GLVolume& v = *this->volumes.back(); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS v.model.init_from(mesh, true); #else @@ -885,14 +500,6 @@ void GLVolumeCollection::load_object_auxiliary( v.model.set_color((milestone == slaposPad) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR); v.mesh_raycaster = std::make_unique(std::make_shared(mesh)); #endif // ENABLE_SMOOTH_NORMALS -#else -#if ENABLE_SMOOTH_NORMALS - v.indexed_vertex_array.load_mesh(mesh, true); -#else - v.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_SMOOTH_NORMALS - v.indexed_vertex_array.finalize_geometry(opengl_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL v.composite_id = GLVolume::CompositeID(obj_idx, -int(milestone), (int)instance_idx.first); v.geometry_id = std::pair(timestamp, model_instance.id().id); // Create a copy of the convex hull mesh for each instance. Use a move operator on the last instance. @@ -908,7 +515,6 @@ void GLVolumeCollection::load_object_auxiliary( } } -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES int GLVolumeCollection::load_wipe_tower_preview( float pos_x, float pos_y, float width, float depth, float height, @@ -918,11 +524,6 @@ int GLVolumeCollection::load_wipe_tower_preview( float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width) #endif // ENABLE_OPENGL_ES -#else -int GLVolumeCollection::load_wipe_tower_preview( - float pos_x, float pos_y, float width, float depth, float height, - float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (depth < 0.01f) return int(this->volumes.size() - 1); @@ -1136,7 +737,6 @@ int GLVolumeCollection::load_wipe_tower_preview( volumes.emplace_back(new GLVolume(color)); GLVolume& v = *volumes.back(); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES if (out_mesh != nullptr) *out_mesh = mesh; @@ -1144,13 +744,7 @@ int GLVolumeCollection::load_wipe_tower_preview( v.model.init_from(mesh); v.model.set_color(color); v.mesh_raycaster = std::make_unique(std::make_shared(mesh)); -#else - v.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL v.set_convex_hull(mesh.convex_hull_3d()); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - v.indexed_vertex_array.finalize_geometry(opengl_initialized); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0)); v.set_volume_rotation(Vec3d(0., 0., (M_PI / 180.) * rotation_angle)); v.composite_id = GLVolume::CompositeID(INT_MAX, 0, 0); @@ -1161,7 +755,6 @@ int GLVolumeCollection::load_wipe_tower_preview( return int(volumes.size() - 1); } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume* GLVolumeCollection::new_toolpath_volume(const ColorRGBA& rgba) { GLVolume* out = new_nontoolpath_volume(rgba); @@ -1176,24 +769,6 @@ GLVolume* GLVolumeCollection::new_nontoolpath_volume(const ColorRGBA& rgba) this->volumes.emplace_back(out); return out; } -#else -GLVolume* GLVolumeCollection::new_toolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats) -{ - GLVolume *out = new_nontoolpath_volume(rgba, reserve_vbo_floats); - out->is_extrusion_path = true; - return out; -} - -GLVolume* GLVolumeCollection::new_nontoolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats) -{ - GLVolume *out = new GLVolume(rgba); - out->is_extrusion_path = false; - // Reserving number of vertices (3x position + 3x color) - out->indexed_vertex_array.reserve(reserve_vbo_floats / 6); - this->volumes.emplace_back(out); - return out; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCollection::ERenderType type, const Transform3d& view_matrix, std::function filter_func) { @@ -1228,12 +803,8 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo return list; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, const Transform3d& projection_matrix, std::function filter_func) const -#else -void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func) const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { GLVolumeWithIdAndZList to_render = volumes_to_render(volumes, type, view_matrix, filter_func); if (to_render.empty()) @@ -1243,14 +814,12 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab if (shader == nullptr) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat"); #if ENABLE_GL_CORE_PROFILE GLShaderProgram* edges_shader = GUI::OpenGLManager::get_gl_info().is_core_profile() ? GUI::wxGetApp().get_shader("dashed_thick_lines") : GUI::wxGetApp().get_shader("flat"); #else GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat"); #endif // ENABLE_GL_CORE_PROFILE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (type == ERenderType::Transparent) { glsafe(::glEnable(GL_BLEND)); @@ -1266,31 +835,18 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab volume.first->set_render_color(true); // render sinking contours of non-hovered volumes -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (sink_shader != nullptr) { sink_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (m_show_sinking_contours) { if (volume.first->is_sinking() && !volume.first->is_below_printbed() && volume.first->hover == GLVolume::HS_None && !volume.first->force_sinking_contours) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->stop_using(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL volume.first->render_sinking_contours(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->start_using(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL sink_shader->stop_using(); } shader->start_using(); -#else - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("z_range", m_z_range); shader->set_uniform("clipping_plane", m_clipping_plane); @@ -1311,16 +867,12 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab #endif // ENABLE_ENVIRONMENT_MAP glcheck(); -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.first->model.set_color(volume.first->render_color); const Transform3d model_matrix = volume.first->world_matrix(); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", projection_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - shader->set_uniform("uniform_color", volume.first->render_color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL volume.first->render(); #if ENABLE_ENVIRONMENT_MAP @@ -1330,56 +882,37 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } if (m_show_sinking_contours) { -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (sink_shader != nullptr) { sink_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (GLVolumeWithIdAndZ& volume : to_render) { // render sinking contours of hovered/displaced volumes if (volume.first->is_sinking() && !volume.first->is_below_printbed() && (volume.first->hover != GLVolume::HS_None || volume.first->force_sinking_contours)) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->stop_using(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glDepthFunc(GL_ALWAYS)); volume.first->render_sinking_contours(); glsafe(::glDepthFunc(GL_LESS)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->start_using(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL sink_shader->start_using(); } shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (edges_shader != nullptr) { edges_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (m_show_non_manifold_edges && GUI::wxGetApp().app_config->get("non_manifold_edges") == "1") { for (GLVolumeWithIdAndZ& volume : to_render) { volume.first->render_non_manifold_edges(); } } -#if ENABLE_LEGACY_OPENGL_REMOVAL edges_shader->stop_using(); } shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (disable_cullface) glsafe(::glEnable(GL_CULL_FACE)); @@ -1558,7 +1091,6 @@ std::string GLVolumeCollection::log_memory_info() const return " (GLVolumeCollection RAM: " + format_memsize_MB(this->cpu_memory_used()) + " GPU: " + format_memsize_MB(this->gpu_memory_used()) + " Both: " + format_memsize_MB(this->gpu_memory_used()) + ")"; } -#if ENABLE_LEGACY_OPENGL_REMOVAL static void thick_lines_to_geometry( const Lines& lines, const std::vector& widths, @@ -2024,519 +1556,7 @@ static void thick_lines_to_geometry( geometry.add_triangle(idx_a[Left], idx_b[Bottom], idx_a[Bottom]); } } -#else -// caller is responsible for supplying NO lines with zero length -static void thick_lines_to_indexed_vertex_array( - const Lines &lines, - const std::vector &widths, - const std::vector &heights, - bool closed, - double top_z, - GLIndexedVertexArray &volume) -{ - assert(! lines.empty()); - if (lines.empty()) - return; -#define LEFT 0 -#define RIGHT 1 -#define TOP 2 -#define BOTTOM 3 - - // right, left, top, bottom - int idx_prev[4] = { -1, -1, -1, -1 }; - double bottom_z_prev = 0.; - Vec2d b1_prev(Vec2d::Zero()); - Vec2d v_prev(Vec2d::Zero()); - int idx_initial[4] = { -1, -1, -1, -1 }; - double width_initial = 0.; - double bottom_z_initial = 0.0; - double len_prev = 0.0; - - // loop once more in case of closed loops - size_t lines_end = closed ? (lines.size() + 1) : lines.size(); - for (size_t ii = 0; ii < lines_end; ++ ii) { - size_t i = (ii == lines.size()) ? 0 : ii; - const Line &line = lines[i]; - double bottom_z = top_z - heights[i]; - double middle_z = 0.5 * (top_z + bottom_z); - double width = widths[i]; - - bool is_first = (ii == 0); - bool is_last = (ii == lines_end - 1); - bool is_closing = closed && is_last; - - Vec2d v = unscale(line.vector()).normalized(); - double len = unscale(line.length()); - - Vec2d a = unscale(line.a); - Vec2d b = unscale(line.b); - Vec2d a1 = a; - Vec2d a2 = a; - Vec2d b1 = b; - Vec2d b2 = b; - { - double dist = 0.5 * width; // scaled - double dx = dist * v(0); - double dy = dist * v(1); - a1 += Vec2d(+dy, -dx); - a2 += Vec2d(-dy, +dx); - b1 += Vec2d(+dy, -dx); - b2 += Vec2d(-dy, +dx); - } - - // calculate new XY normals - Vec2d xy_right_normal = unscale(line.normal()).normalized(); - - int idx_a[4] = { 0, 0, 0, 0 }; // initialized to avoid warnings - int idx_b[4] = { 0, 0, 0, 0 }; // initialized to avoid warnings - int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6); - - bool bottom_z_different = bottom_z_prev != bottom_z; - bottom_z_prev = bottom_z; - - if (!is_first && bottom_z_different) - { - // Found a change of the layer thickness -> Add a cap at the end of the previous segment. - volume.push_quad(idx_b[BOTTOM], idx_b[LEFT], idx_b[TOP], idx_b[RIGHT]); - } - - // Share top / bottom vertices if possible. - if (is_first) { - idx_a[TOP] = idx_last++; - volume.push_geometry(a(0), a(1), top_z , 0., 0., 1.); - } else { - idx_a[TOP] = idx_prev[TOP]; - } - - if (is_first || bottom_z_different) { - // Start of the 1st line segment or a change of the layer thickness while maintaining the print_z. - idx_a[BOTTOM] = idx_last ++; - volume.push_geometry(a(0), a(1), bottom_z, 0., 0., -1.); - idx_a[LEFT ] = idx_last ++; - volume.push_geometry(a2(0), a2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), 0.0); - idx_a[RIGHT] = idx_last ++; - volume.push_geometry(a1(0), a1(1), middle_z, xy_right_normal(0), xy_right_normal(1), 0.0); - } - else { - idx_a[BOTTOM] = idx_prev[BOTTOM]; - } - - if (is_first) { - // Start of the 1st line segment. - width_initial = width; - bottom_z_initial = bottom_z; - memcpy(idx_initial, idx_a, sizeof(int) * 4); - } else { - // Continuing a previous segment. - // Share left / right vertices if possible. - double v_dot = v_prev.dot(v); - // To reduce gpu memory usage, we try to reuse vertices - // To reduce the visual artifacts, due to averaged normals, we allow to reuse vertices only when any of two adjacent edges - // is longer than a fixed threshold. - // The following value is arbitrary, it comes from tests made on a bunch of models showing the visual artifacts - double len_threshold = 2.5; - - // Generate new vertices if the angle between adjacent edges is greater than 45 degrees or thresholds conditions are met - bool sharp = (v_dot < 0.707) || (len_prev > len_threshold) || (len > len_threshold); - if (sharp) { - if (!bottom_z_different) - { - // Allocate new left / right points for the start of this segment as these points will receive their own normals to indicate a sharp turn. - idx_a[RIGHT] = idx_last++; - volume.push_geometry(a1(0), a1(1), middle_z, xy_right_normal(0), xy_right_normal(1), 0.0); - idx_a[LEFT] = idx_last++; - volume.push_geometry(a2(0), a2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), 0.0); - if (cross2(v_prev, v) > 0.) { - // Right turn. Fill in the right turn wedge. - volume.push_triangle(idx_prev[RIGHT], idx_a[RIGHT], idx_prev[TOP]); - volume.push_triangle(idx_prev[RIGHT], idx_prev[BOTTOM], idx_a[RIGHT]); - } - else { - // Left turn. Fill in the left turn wedge. - volume.push_triangle(idx_prev[LEFT], idx_prev[TOP], idx_a[LEFT]); - volume.push_triangle(idx_prev[LEFT], idx_a[LEFT], idx_prev[BOTTOM]); - } - } - } - else - { - if (!bottom_z_different) - { - // The two successive segments are nearly collinear. - idx_a[LEFT ] = idx_prev[LEFT]; - idx_a[RIGHT] = idx_prev[RIGHT]; - } - } - if (is_closing) { - if (!sharp) { - if (!bottom_z_different) - { - // Closing a loop with smooth transition. Unify the closing left / right vertices. - memcpy(volume.vertices_and_normals_interleaved.data() + idx_initial[LEFT ] * 6, volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT ] * 6, sizeof(float) * 6); - memcpy(volume.vertices_and_normals_interleaved.data() + idx_initial[RIGHT] * 6, volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6, sizeof(float) * 6); - volume.vertices_and_normals_interleaved.erase(volume.vertices_and_normals_interleaved.end() - 12, volume.vertices_and_normals_interleaved.end()); - // Replace the left / right vertex indices to point to the start of the loop. - for (size_t u = volume.quad_indices.size() - 16; u < volume.quad_indices.size(); ++ u) { - if (volume.quad_indices[u] == idx_prev[LEFT]) - volume.quad_indices[u] = idx_initial[LEFT]; - else if (volume.quad_indices[u] == idx_prev[RIGHT]) - volume.quad_indices[u] = idx_initial[RIGHT]; - } - } - } - // This is the last iteration, only required to solve the transition. - break; - } - } - - // Only new allocate top / bottom vertices, if not closing a loop. - if (is_closing) { - idx_b[TOP] = idx_initial[TOP]; - } else { - idx_b[TOP] = idx_last ++; - volume.push_geometry(b(0), b(1), top_z , 0., 0., 1.); - } - - if (is_closing && (width == width_initial) && (bottom_z == bottom_z_initial)) { - idx_b[BOTTOM] = idx_initial[BOTTOM]; - } else { - idx_b[BOTTOM] = idx_last ++; - volume.push_geometry(b(0), b(1), bottom_z, 0., 0., -1.); - } - // Generate new vertices for the end of this line segment. - idx_b[LEFT ] = idx_last ++; - volume.push_geometry(b2(0), b2(1), middle_z, -xy_right_normal(0), -xy_right_normal(1), 0.0); - idx_b[RIGHT ] = idx_last ++; - volume.push_geometry(b1(0), b1(1), middle_z, xy_right_normal(0), xy_right_normal(1), 0.0); - - memcpy(idx_prev, idx_b, 4 * sizeof(int)); - bottom_z_prev = bottom_z; - b1_prev = b1; - v_prev = v; - len_prev = len; - - if (bottom_z_different && (closed || (!is_first && !is_last))) - { - // Found a change of the layer thickness -> Add a cap at the beginning of this segment. - volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]); - } - - if (! closed) { - // Terminate open paths with caps. - if (is_first) - volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]); - // We don't use 'else' because both cases are true if we have only one line. - if (is_last) - volume.push_quad(idx_b[BOTTOM], idx_b[LEFT], idx_b[TOP], idx_b[RIGHT]); - } - - // Add quads for a straight hollow tube-like segment. - // bottom-right face - volume.push_quad(idx_a[BOTTOM], idx_b[BOTTOM], idx_b[RIGHT], idx_a[RIGHT]); - // top-right face - volume.push_quad(idx_a[RIGHT], idx_b[RIGHT], idx_b[TOP], idx_a[TOP]); - // top-left face - volume.push_quad(idx_a[TOP], idx_b[TOP], idx_b[LEFT], idx_a[LEFT]); - // bottom-left face - volume.push_quad(idx_a[LEFT], idx_b[LEFT], idx_b[BOTTOM], idx_a[BOTTOM]); - } - -#undef LEFT -#undef RIGHT -#undef TOP -#undef BOTTOM -} - -// caller is responsible for supplying NO lines with zero length -static void thick_lines_to_indexed_vertex_array(const Lines3& lines, - const std::vector& widths, - const std::vector& heights, - bool closed, - GLIndexedVertexArray& volume) -{ - assert(!lines.empty()); - if (lines.empty()) - return; - -#define LEFT 0 -#define RIGHT 1 -#define TOP 2 -#define BOTTOM 3 - - // left, right, top, bottom - int idx_initial[4] = { -1, -1, -1, -1 }; - int idx_prev[4] = { -1, -1, -1, -1 }; - double z_prev = 0.0; - double len_prev = 0.0; - Vec3d n_right_prev = Vec3d::Zero(); - Vec3d n_top_prev = Vec3d::Zero(); - Vec3d unit_v_prev = Vec3d::Zero(); - double width_initial = 0.0; - - // new vertices around the line endpoints - // left, right, top, bottom - Vec3d a[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() }; - Vec3d b[4] = { Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero(), Vec3d::Zero() }; - - // loop once more in case of closed loops - size_t lines_end = closed ? (lines.size() + 1) : lines.size(); - for (size_t ii = 0; ii < lines_end; ++ii) - { - size_t i = (ii == lines.size()) ? 0 : ii; - - const Line3& line = lines[i]; - double height = heights[i]; - double width = widths[i]; - - Vec3d unit_v = unscale(line.vector()).normalized(); - double len = unscale(line.length()); - - Vec3d n_top = Vec3d::Zero(); - Vec3d n_right = Vec3d::Zero(); - - if ((line.a(0) == line.b(0)) && (line.a(1) == line.b(1))) - { - // vertical segment - n_top = Vec3d::UnitY(); - n_right = Vec3d::UnitX(); - if (line.a(2) < line.b(2)) - n_right = -n_right; - } - else - { - // horizontal segment - n_right = unit_v.cross(Vec3d::UnitZ()).normalized(); - n_top = n_right.cross(unit_v).normalized(); - } - - Vec3d rl_displacement = 0.5 * width * n_right; - Vec3d tb_displacement = 0.5 * height * n_top; - Vec3d l_a = unscale(line.a); - Vec3d l_b = unscale(line.b); - - a[RIGHT] = l_a + rl_displacement; - a[LEFT] = l_a - rl_displacement; - a[TOP] = l_a + tb_displacement; - a[BOTTOM] = l_a - tb_displacement; - b[RIGHT] = l_b + rl_displacement; - b[LEFT] = l_b - rl_displacement; - b[TOP] = l_b + tb_displacement; - b[BOTTOM] = l_b - tb_displacement; - - Vec3d n_bottom = -n_top; - Vec3d n_left = -n_right; - - int idx_a[4]; - int idx_b[4]; - int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6); - - bool z_different = (z_prev != l_a(2)); - z_prev = l_b(2); - - // Share top / bottom vertices if possible. - if (ii == 0) - { - idx_a[TOP] = idx_last++; - volume.push_geometry(a[TOP], n_top); - } - else - idx_a[TOP] = idx_prev[TOP]; - - if ((ii == 0) || z_different) - { - // Start of the 1st line segment or a change of the layer thickness while maintaining the print_z. - idx_a[BOTTOM] = idx_last++; - volume.push_geometry(a[BOTTOM], n_bottom); - idx_a[LEFT] = idx_last++; - volume.push_geometry(a[LEFT], n_left); - idx_a[RIGHT] = idx_last++; - volume.push_geometry(a[RIGHT], n_right); - } - else - idx_a[BOTTOM] = idx_prev[BOTTOM]; - - if (ii == 0) - { - // Start of the 1st line segment. - width_initial = width; - ::memcpy(idx_initial, idx_a, sizeof(int) * 4); - } - else - { - // Continuing a previous segment. - // Share left / right vertices if possible. - double v_dot = unit_v_prev.dot(unit_v); - bool is_right_turn = n_top_prev.dot(unit_v_prev.cross(unit_v)) > 0.0; - - // To reduce gpu memory usage, we try to reuse vertices - // To reduce the visual artifacts, due to averaged normals, we allow to reuse vertices only when any of two adjacent edges - // is longer than a fixed threshold. - // The following value is arbitrary, it comes from tests made on a bunch of models showing the visual artifacts - double len_threshold = 2.5; - - // Generate new vertices if the angle between adjacent edges is greater than 45 degrees or thresholds conditions are met - bool is_sharp = (v_dot < 0.707) || (len_prev > len_threshold) || (len > len_threshold); - if (is_sharp) - { - // Allocate new left / right points for the start of this segment as these points will receive their own normals to indicate a sharp turn. - idx_a[RIGHT] = idx_last++; - volume.push_geometry(a[RIGHT], n_right); - idx_a[LEFT] = idx_last++; - volume.push_geometry(a[LEFT], n_left); - - if (is_right_turn) - { - // Right turn. Fill in the right turn wedge. - volume.push_triangle(idx_prev[RIGHT], idx_a[RIGHT], idx_prev[TOP]); - volume.push_triangle(idx_prev[RIGHT], idx_prev[BOTTOM], idx_a[RIGHT]); - } - else - { - // Left turn. Fill in the left turn wedge. - volume.push_triangle(idx_prev[LEFT], idx_prev[TOP], idx_a[LEFT]); - volume.push_triangle(idx_prev[LEFT], idx_a[LEFT], idx_prev[BOTTOM]); - } - } - else - { - // The two successive segments are nearly collinear. - idx_a[LEFT] = idx_prev[LEFT]; - idx_a[RIGHT] = idx_prev[RIGHT]; - } - - if (ii == lines.size()) - { - if (!is_sharp) - { - // Closing a loop with smooth transition. Unify the closing left / right vertices. - ::memcpy(volume.vertices_and_normals_interleaved.data() + idx_initial[LEFT] * 6, volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT] * 6, sizeof(float) * 6); - ::memcpy(volume.vertices_and_normals_interleaved.data() + idx_initial[RIGHT] * 6, volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6, sizeof(float) * 6); - volume.vertices_and_normals_interleaved.erase(volume.vertices_and_normals_interleaved.end() - 12, volume.vertices_and_normals_interleaved.end()); - // Replace the left / right vertex indices to point to the start of the loop. - for (size_t u = volume.quad_indices.size() - 16; u < volume.quad_indices.size(); ++u) - { - if (volume.quad_indices[u] == idx_prev[LEFT]) - volume.quad_indices[u] = idx_initial[LEFT]; - else if (volume.quad_indices[u] == idx_prev[RIGHT]) - volume.quad_indices[u] = idx_initial[RIGHT]; - } - } - - // This is the last iteration, only required to solve the transition. - break; - } - } - - // Only new allocate top / bottom vertices, if not closing a loop. - if (closed && (ii + 1 == lines.size())) - idx_b[TOP] = idx_initial[TOP]; - else - { - idx_b[TOP] = idx_last++; - volume.push_geometry(b[TOP], n_top); - } - - if (closed && (ii + 1 == lines.size()) && (width == width_initial)) - idx_b[BOTTOM] = idx_initial[BOTTOM]; - else - { - idx_b[BOTTOM] = idx_last++; - volume.push_geometry(b[BOTTOM], n_bottom); - } - - // Generate new vertices for the end of this line segment. - idx_b[LEFT] = idx_last++; - volume.push_geometry(b[LEFT], n_left); - idx_b[RIGHT] = idx_last++; - volume.push_geometry(b[RIGHT], n_right); - - ::memcpy(idx_prev, idx_b, 4 * sizeof(int)); - n_right_prev = n_right; - n_top_prev = n_top; - unit_v_prev = unit_v; - len_prev = len; - - if (!closed) - { - // Terminate open paths with caps. - if (i == 0) - volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]); - - // We don't use 'else' because both cases are true if we have only one line. - if (i + 1 == lines.size()) - volume.push_quad(idx_b[BOTTOM], idx_b[LEFT], idx_b[TOP], idx_b[RIGHT]); - } - - // Add quads for a straight hollow tube-like segment. - // bottom-right face - volume.push_quad(idx_a[BOTTOM], idx_b[BOTTOM], idx_b[RIGHT], idx_a[RIGHT]); - // top-right face - volume.push_quad(idx_a[RIGHT], idx_b[RIGHT], idx_b[TOP], idx_a[TOP]); - // top-left face - volume.push_quad(idx_a[TOP], idx_b[TOP], idx_b[LEFT], idx_a[LEFT]); - // bottom-left face - volume.push_quad(idx_a[LEFT], idx_b[LEFT], idx_b[BOTTOM], idx_a[BOTTOM]); - } - -#undef LEFT -#undef RIGHT -#undef TOP -#undef BOTTOM -} - -static void point_to_indexed_vertex_array(const Vec3crd& point, - double width, - double height, - GLIndexedVertexArray& volume) -{ - // builds a double piramid, with vertices on the local axes, around the point - - Vec3d center = unscale(point); - - double scale_factor = 1.0; - double w = scale_factor * width; - double h = scale_factor * height; - - // new vertices ids - int idx_last = int(volume.vertices_and_normals_interleaved.size() / 6); - int idxs[6]; - for (int i = 0; i < 6; ++i) - { - idxs[i] = idx_last + i; - } - - Vec3d displacement_x(w, 0.0, 0.0); - Vec3d displacement_y(0.0, w, 0.0); - Vec3d displacement_z(0.0, 0.0, h); - - Vec3d unit_x(1.0, 0.0, 0.0); - Vec3d unit_y(0.0, 1.0, 0.0); - Vec3d unit_z(0.0, 0.0, 1.0); - - // vertices - volume.push_geometry(center - displacement_x, -unit_x); // idxs[0] - volume.push_geometry(center + displacement_x, unit_x); // idxs[1] - volume.push_geometry(center - displacement_y, -unit_y); // idxs[2] - volume.push_geometry(center + displacement_y, unit_y); // idxs[3] - volume.push_geometry(center - displacement_z, -unit_z); // idxs[4] - volume.push_geometry(center + displacement_z, unit_z); // idxs[5] - - // top piramid faces - volume.push_triangle(idxs[0], idxs[2], idxs[5]); - volume.push_triangle(idxs[2], idxs[1], idxs[5]); - volume.push_triangle(idxs[1], idxs[3], idxs[5]); - volume.push_triangle(idxs[3], idxs[0], idxs[5]); - - // bottom piramid faces - volume.push_triangle(idxs[2], idxs[0], idxs[4]); - volume.push_triangle(idxs[1], idxs[2], idxs[4]); - volume.push_triangle(idxs[3], idxs[1], idxs[4]); - volume.push_triangle(idxs[0], idxs[3], idxs[4]); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::thick_lines_to_verts( const Lines& lines, const std::vector& widths, @@ -2557,52 +1577,8 @@ void _3DScene::thick_lines_to_verts( { thick_lines_to_geometry(lines, widths, heights, closed, geometry); } -#else -void _3DScene::thick_lines_to_verts( - const Lines &lines, - const std::vector &widths, - const std::vector &heights, - bool closed, - double top_z, - GLVolume &volume) -{ - thick_lines_to_indexed_vertex_array(lines, widths, heights, closed, top_z, volume.indexed_vertex_array); -} - -void _3DScene::thick_lines_to_verts(const Lines3& lines, - const std::vector& widths, - const std::vector& heights, - bool closed, - GLVolume& volume) -{ - thick_lines_to_indexed_vertex_array(lines, widths, heights, closed, volume.indexed_vertex_array); -} - -static void thick_point_to_verts(const Vec3crd& point, - double width, - double height, - GLVolume& volume) -{ - point_to_indexed_vertex_array(point, width, height, volume.indexed_vertex_array); -} - -void _3DScene::extrusionentity_to_verts(const Polyline &polyline, float width, float height, float print_z, GLVolume& volume) -{ - if (polyline.size() >= 2) { - size_t num_segments = polyline.size() - 1; - thick_lines_to_verts(polyline.lines(), std::vector(num_segments, width), std::vector(num_segments, height), false, print_z, volume); - } -} // Fill in the qverts and tverts with quads and triangles for the extrusion_path. -void _3DScene::extrusionentity_to_verts(const ExtrusionPath &extrusion_path, float print_z, GLVolume &volume) -{ - extrusionentity_to_verts(extrusion_path.polyline, extrusion_path.width, extrusion_path.height, print_z, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -// Fill in the qverts and tverts with quads and triangles for the extrusion_path. -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { Polyline polyline = extrusion_path.polyline; @@ -2613,21 +1589,8 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionPath& extrusion_path, flo std::vector heights(lines.size(), extrusion_path.height); thick_lines_to_verts(lines, widths, heights, false, print_z, geometry); } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionPath &extrusion_path, float print_z, const Point ©, GLVolume &volume) -{ - Polyline polyline = extrusion_path.polyline; - polyline.remove_duplicate_points(); - polyline.translate(copy); - Lines lines = polyline.lines(); - std::vector widths(lines.size(), extrusion_path.width); - std::vector heights(lines.size(), extrusion_path.height); - thick_lines_to_verts(lines, widths, heights, false, print_z, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Fill in the qverts and tverts with quads and triangles for the extrusion_loop. -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionLoop& extrusion_loop, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { Lines lines; @@ -2644,27 +1607,8 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionLoop& extrusion_loop, flo } thick_lines_to_verts(lines, widths, heights, true, print_z, geometry); } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionLoop &extrusion_loop, float print_z, const Point ©, GLVolume &volume) -{ - Lines lines; - std::vector widths; - std::vector heights; - for (const ExtrusionPath &extrusion_path : extrusion_loop.paths) { - Polyline polyline = extrusion_path.polyline; - polyline.remove_duplicate_points(); - polyline.translate(copy); - Lines lines_this = polyline.lines(); - append(lines, lines_this); - widths.insert(widths.end(), lines_this.size(), extrusion_path.width); - heights.insert(heights.end(), lines_this.size(), extrusion_path.height); - } - thick_lines_to_verts(lines, widths, heights, true, print_z, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Fill in the qverts and tverts with quads and triangles for the extrusion_multi_path. -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_multi_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { Lines lines; @@ -2681,40 +1625,13 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_mult } thick_lines_to_verts(lines, widths, heights, false, print_z, geometry); } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionMultiPath &extrusion_multi_path, float print_z, const Point ©, GLVolume &volume) -{ - Lines lines; - std::vector widths; - std::vector heights; - for (const ExtrusionPath &extrusion_path : extrusion_multi_path.paths) { - Polyline polyline = extrusion_path.polyline; - polyline.remove_duplicate_points(); - polyline.translate(copy); - Lines lines_this = polyline.lines(); - append(lines, lines_this); - widths.insert(widths.end(), lines_this.size(), extrusion_path.width); - heights.insert(heights.end(), lines_this.size(), extrusion_path.height); - } - thick_lines_to_verts(lines, widths, heights, false, print_z, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { for (const ExtrusionEntity* extrusion_entity : extrusion_entity_collection.entities) extrusionentity_to_verts(extrusion_entity, print_z, copy, geometry); } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionEntityCollection &extrusion_entity_collection, float print_z, const Point ©, GLVolume &volume) -{ - for (const ExtrusionEntity *extrusion_entity : extrusion_entity_collection.entities) - extrusionentity_to_verts(extrusion_entity, print_z, copy, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL void _3DScene::extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry) { if (extrusion_entity != nullptr) { @@ -2740,45 +1657,5 @@ void _3DScene::extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, } } } -#else -void _3DScene::extrusionentity_to_verts(const ExtrusionEntity *extrusion_entity, float print_z, const Point ©, GLVolume &volume) -{ - if (extrusion_entity != nullptr) { - auto *extrusion_path = dynamic_cast(extrusion_entity); - if (extrusion_path != nullptr) - extrusionentity_to_verts(*extrusion_path, print_z, copy, volume); - else { - auto *extrusion_loop = dynamic_cast(extrusion_entity); - if (extrusion_loop != nullptr) - extrusionentity_to_verts(*extrusion_loop, print_z, copy, volume); - else { - auto *extrusion_multi_path = dynamic_cast(extrusion_entity); - if (extrusion_multi_path != nullptr) - extrusionentity_to_verts(*extrusion_multi_path, print_z, copy, volume); - else { - auto *extrusion_entity_collection = dynamic_cast(extrusion_entity); - if (extrusion_entity_collection != nullptr) - extrusionentity_to_verts(*extrusion_entity_collection, print_z, copy, volume); - else - throw Slic3r::RuntimeError("Unexpected extrusion_entity type in to_verts()"); - } - } - } - } -} - -void _3DScene::polyline3_to_verts(const Polyline3& polyline, double width, double height, GLVolume& volume) -{ - Lines3 lines = polyline.lines(); - std::vector widths(lines.size(), width); - std::vector heights(lines.size(), height); - thick_lines_to_verts(lines, widths, heights, false, volume); -} - -void _3DScene::point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume) -{ - thick_point_to_verts(point, width, height, volume); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // namespace Slic3r diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index a7146d61c..2eb161480 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -47,209 +47,6 @@ enum ModelInstanceEPrintVolumeState : unsigned char; // Return appropriate color based on the ModelVolume. extern ColorRGBA color_from_model_volume(const ModelVolume& model_volume); -#if !ENABLE_LEGACY_OPENGL_REMOVAL -// A container for interleaved arrays of 3D vertices and normals, -// possibly indexed by triangles and / or quads. -class GLIndexedVertexArray { -public: - // Only Eigen types of Nx16 size are vectorized. This bounding box will not be vectorized. - static_assert(sizeof(Eigen::AlignedBox) == 24, "Eigen::AlignedBox is not being vectorized, thus it does not need to be aligned"); - using BoundingBox = Eigen::AlignedBox; - - GLIndexedVertexArray() { m_bounding_box.setEmpty(); } - GLIndexedVertexArray(const GLIndexedVertexArray &rhs) : - vertices_and_normals_interleaved(rhs.vertices_and_normals_interleaved), - triangle_indices(rhs.triangle_indices), - quad_indices(rhs.quad_indices), - m_bounding_box(rhs.m_bounding_box) - { assert(! rhs.has_VBOs()); m_bounding_box.setEmpty(); } - GLIndexedVertexArray(GLIndexedVertexArray &&rhs) : - vertices_and_normals_interleaved(std::move(rhs.vertices_and_normals_interleaved)), - triangle_indices(std::move(rhs.triangle_indices)), - quad_indices(std::move(rhs.quad_indices)), - m_bounding_box(rhs.m_bounding_box) - { assert(! rhs.has_VBOs()); } - - ~GLIndexedVertexArray() { release_geometry(); } - - GLIndexedVertexArray& operator=(const GLIndexedVertexArray &rhs) - { - assert(vertices_and_normals_interleaved_VBO_id == 0); - assert(triangle_indices_VBO_id == 0); - assert(quad_indices_VBO_id == 0); - assert(rhs.vertices_and_normals_interleaved_VBO_id == 0); - assert(rhs.triangle_indices_VBO_id == 0); - assert(rhs.quad_indices_VBO_id == 0); - this->vertices_and_normals_interleaved = rhs.vertices_and_normals_interleaved; - this->triangle_indices = rhs.triangle_indices; - this->quad_indices = rhs.quad_indices; - this->m_bounding_box = rhs.m_bounding_box; - this->vertices_and_normals_interleaved_size = rhs.vertices_and_normals_interleaved_size; - this->triangle_indices_size = rhs.triangle_indices_size; - this->quad_indices_size = rhs.quad_indices_size; - return *this; - } - - GLIndexedVertexArray& operator=(GLIndexedVertexArray &&rhs) - { - assert(vertices_and_normals_interleaved_VBO_id == 0); - assert(triangle_indices_VBO_id == 0); - assert(quad_indices_VBO_id == 0); - assert(rhs.vertices_and_normals_interleaved_VBO_id == 0); - assert(rhs.triangle_indices_VBO_id == 0); - assert(rhs.quad_indices_VBO_id == 0); - this->vertices_and_normals_interleaved = std::move(rhs.vertices_and_normals_interleaved); - this->triangle_indices = std::move(rhs.triangle_indices); - this->quad_indices = std::move(rhs.quad_indices); - this->m_bounding_box = rhs.m_bounding_box; - this->vertices_and_normals_interleaved_size = rhs.vertices_and_normals_interleaved_size; - this->triangle_indices_size = rhs.triangle_indices_size; - this->quad_indices_size = rhs.quad_indices_size; - return *this; - } - - // Vertices and their normals, interleaved to be used by void glInterleavedArrays(GL_N3F_V3F, 0, x) - std::vector vertices_and_normals_interleaved; - std::vector triangle_indices; - std::vector quad_indices; - - // When the geometry data is loaded into the graphics card as Vertex Buffer Objects, - // the above mentioned std::vectors are cleared and the following variables keep their original length. - size_t vertices_and_normals_interleaved_size{ 0 }; - size_t triangle_indices_size{ 0 }; - size_t quad_indices_size{ 0 }; - - // IDs of the Vertex Array Objects, into which the geometry has been loaded. - // Zero if the VBOs are not sent to GPU yet. - unsigned int vertices_and_normals_interleaved_VBO_id{ 0 }; - unsigned int triangle_indices_VBO_id{ 0 }; - unsigned int quad_indices_VBO_id{ 0 }; - -#if ENABLE_SMOOTH_NORMALS - void load_mesh_full_shading(const TriangleMesh& mesh, bool smooth_normals = false); - void load_mesh(const TriangleMesh& mesh, bool smooth_normals = false) { this->load_mesh_full_shading(mesh, smooth_normals); } -#else - void load_mesh_full_shading(const TriangleMesh& mesh); - void load_mesh(const TriangleMesh& mesh) { this->load_mesh_full_shading(mesh); } -#endif // ENABLE_SMOOTH_NORMALS - - void load_its_flat_shading(const indexed_triangle_set &its); - - inline bool has_VBOs() const { return vertices_and_normals_interleaved_VBO_id != 0; } - - inline void reserve(size_t sz) { - this->vertices_and_normals_interleaved.reserve(sz * 6); - this->triangle_indices.reserve(sz * 3); - this->quad_indices.reserve(sz * 4); - } - - inline void push_geometry(float x, float y, float z, float nx, float ny, float nz) { - assert(this->vertices_and_normals_interleaved_VBO_id == 0); - if (this->vertices_and_normals_interleaved_VBO_id != 0) - return; - - if (this->vertices_and_normals_interleaved.size() + 6 > this->vertices_and_normals_interleaved.capacity()) - this->vertices_and_normals_interleaved.reserve(next_highest_power_of_2(this->vertices_and_normals_interleaved.size() + 6)); - this->vertices_and_normals_interleaved.emplace_back(nx); - this->vertices_and_normals_interleaved.emplace_back(ny); - this->vertices_and_normals_interleaved.emplace_back(nz); - this->vertices_and_normals_interleaved.emplace_back(x); - this->vertices_and_normals_interleaved.emplace_back(y); - this->vertices_and_normals_interleaved.emplace_back(z); - - this->vertices_and_normals_interleaved_size = this->vertices_and_normals_interleaved.size(); - m_bounding_box.extend(Vec3f(x, y, z)); - }; - - inline void push_geometry(double x, double y, double z, double nx, double ny, double nz) { - push_geometry(float(x), float(y), float(z), float(nx), float(ny), float(nz)); - } - - template - inline void push_geometry(const Eigen::MatrixBase& p, const Eigen::MatrixBase& n) { - push_geometry(float(p(0)), float(p(1)), float(p(2)), float(n(0)), float(n(1)), float(n(2))); - } - - inline void push_triangle(int idx1, int idx2, int idx3) { - assert(this->vertices_and_normals_interleaved_VBO_id == 0); - if (this->vertices_and_normals_interleaved_VBO_id != 0) - return; - - if (this->triangle_indices.size() + 3 > this->vertices_and_normals_interleaved.capacity()) - this->triangle_indices.reserve(next_highest_power_of_2(this->triangle_indices.size() + 3)); - this->triangle_indices.emplace_back(idx1); - this->triangle_indices.emplace_back(idx2); - this->triangle_indices.emplace_back(idx3); - this->triangle_indices_size = this->triangle_indices.size(); - }; - - inline void push_quad(int idx1, int idx2, int idx3, int idx4) { - assert(this->vertices_and_normals_interleaved_VBO_id == 0); - if (this->vertices_and_normals_interleaved_VBO_id != 0) - return; - - if (this->quad_indices.size() + 4 > this->vertices_and_normals_interleaved.capacity()) - this->quad_indices.reserve(next_highest_power_of_2(this->quad_indices.size() + 4)); - this->quad_indices.emplace_back(idx1); - this->quad_indices.emplace_back(idx2); - this->quad_indices.emplace_back(idx3); - this->quad_indices.emplace_back(idx4); - this->quad_indices_size = this->quad_indices.size(); - }; - - // Finalize the initialization of the geometry & indices, - // upload the geometry and indices to OpenGL VBO objects - // and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs. - void finalize_geometry(bool opengl_initialized); - // Release the geometry data, release OpenGL VBOs. - void release_geometry(); - - void render() const; - void render(const std::pair& tverts_range, const std::pair& qverts_range) const; - - // Is there any geometry data stored? - bool empty() const { return vertices_and_normals_interleaved_size == 0; } - - void clear() { - this->vertices_and_normals_interleaved.clear(); - this->triangle_indices.clear(); - this->quad_indices.clear(); - vertices_and_normals_interleaved_size = 0; - triangle_indices_size = 0; - quad_indices_size = 0; - m_bounding_box.setEmpty(); - } - - // Shrink the internal storage to tighly fit the data stored. - void shrink_to_fit() { - this->vertices_and_normals_interleaved.shrink_to_fit(); - this->triangle_indices.shrink_to_fit(); - this->quad_indices.shrink_to_fit(); - } - - const BoundingBox& bounding_box() const { return m_bounding_box; } - - // Return an estimate of the memory consumed by this class. - size_t cpu_memory_used() const { return sizeof(*this) + vertices_and_normals_interleaved.capacity() * sizeof(float) + triangle_indices.capacity() * sizeof(int) + quad_indices.capacity() * sizeof(int); } - // Return an estimate of the memory held by GPU vertex buffers. - size_t gpu_memory_used() const - { - size_t memsize = 0; - if (this->vertices_and_normals_interleaved_VBO_id != 0) - memsize += this->vertices_and_normals_interleaved_size * 4; - if (this->triangle_indices_VBO_id != 0) - memsize += this->triangle_indices_size * 4; - if (this->quad_indices_VBO_id != 0) - memsize += this->quad_indices_size * 4; - return memsize; - } - size_t total_memory_used() const { return this->cpu_memory_used() + this->gpu_memory_used(); } - -private: - BoundingBox m_bounding_box; -}; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - class GLVolume { public: static const ColorRGBA SELECTED_COLOR; @@ -389,19 +186,11 @@ public: // Is mouse or rectangle selection over this object to select/deselect it ? EHoverState hover; -#if ENABLE_LEGACY_OPENGL_REMOVAL GUI::GLModel model; // raycaster used for picking std::unique_ptr mesh_raycaster; -#else - // Interleaved triangles & normals with indexed triangles & quads. - GLIndexedVertexArray indexed_vertex_array; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Ranges of triangle and quad indices to be rendered. std::pair tverts_range; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - std::pair qverts_range; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL // If the qverts or tverts contain thick extrusions, then offsets keeps pointers of the starts // of the extrusions per layer. @@ -411,17 +200,7 @@ public: // Bounding box of this volume, in unscaled coordinates. BoundingBoxf3 bounding_box() const { -#if ENABLE_LEGACY_OPENGL_REMOVAL return this->model.get_bounding_box(); -#else - BoundingBoxf3 out; - if (!this->indexed_vertex_array.bounding_box().isEmpty()) { - out.min = this->indexed_vertex_array.bounding_box().min().cast(); - out.max = this->indexed_vertex_array.bounding_box().max().cast(); - out.defined = true; - } - return out; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void set_color(const ColorRGBA& rgba) { color = rgba; } @@ -541,21 +320,12 @@ public: // convex hull const TriangleMesh* convex_hull() const { return m_convex_hull.get(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool empty() const { return this->model.is_empty(); } -#else - bool empty() const { return this->indexed_vertex_array.empty(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void set_range(double low, double high); void render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - void finalize_geometry(bool opengl_initialized) { this->indexed_vertex_array.finalize_geometry(opengl_initialized); } - void release_geometry() { this->indexed_vertex_array.release_geometry(); } -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void set_bounding_boxes_as_dirty() { m_transformed_bounding_box.reset(); m_transformed_convex_hull_bounding_box.reset(); @@ -572,19 +342,11 @@ public: // Return an estimate of the memory consumed by this class. size_t cpu_memory_used() const { -#if ENABLE_LEGACY_OPENGL_REMOVAL - return sizeof(*this) + this->model.cpu_memory_used() + this->print_zs.capacity() * sizeof(coordf_t) + + return sizeof(*this) + this->model.cpu_memory_used() + this->print_zs.capacity() * sizeof(coordf_t) + this->offsets.capacity() * sizeof(size_t); } // Return an estimate of the memory held by GPU vertex buffers. size_t gpu_memory_used() const { return this->model.gpu_memory_used(); } -#else - //FIXME what to do wih m_convex_hull? - return sizeof(*this) - sizeof(this->indexed_vertex_array) + this->indexed_vertex_array.cpu_memory_used() + this->print_zs.capacity() * sizeof(coordf_t) + this->offsets.capacity() * sizeof(size_t); - } - // Return an estimate of the memory held by GPU vertex buffers. - size_t gpu_memory_used() const { return this->indexed_vertex_array.gpu_memory_used(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL size_t total_memory_used() const { return this->cpu_memory_used() + this->gpu_memory_used(); } }; @@ -642,7 +404,6 @@ public: GLVolumeCollection() { set_default_slope_normal_z(); } ~GLVolumeCollection() { clear(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector load_object( const ModelObject* model_object, int obj_idx, @@ -671,54 +432,12 @@ public: int load_wipe_tower_preview( float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width); #endif // ENABLE_OPENGL_ES -#else - std::vector load_object( - const ModelObject *model_object, - int obj_idx, - const std::vector &instance_idxs, - bool opengl_initialized); - int load_object_volume( - const ModelObject *model_object, - int obj_idx, - int volume_idx, - int instance_idx, - bool opengl_initialized); - - // Load SLA auxiliary GLVolumes (for support trees or pad). - void load_object_auxiliary( - const SLAPrintObject *print_object, - int obj_idx, - // pairs of - const std::vector>& instances, - SLAPrintObjectStep milestone, - // Timestamp of the last change of the milestone - size_t timestamp, - bool opengl_initialized); - - int load_wipe_tower_preview( - float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width, bool opengl_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume* new_toolpath_volume(const ColorRGBA& rgba); GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba); // Render the volumes by OpenGL. void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, const Transform3d& projection_matrix, std::function filter_func = std::function()) const; -#else - GLVolume* new_toolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0); - GLVolume* new_nontoolpath_volume(const ColorRGBA& rgba, size_t reserve_vbo_floats = 0); - // Render the volumes by OpenGL. - void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function filter_func = std::function()) const; - // Finalize the initialization of the geometry & indices, - // upload the geometry and indices to OpenGL VBO objects - // and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs. - void finalize_geometry(bool opengl_initialized) { for (auto* v : volumes) v->finalize_geometry(opengl_initialized); } - // Release the geometry data assigned to the volumes. - // If OpenGL VBOs were allocated, an OpenGL context has to be active to release them. - void release_geometry() { for (auto* v : volumes) v->release_geometry(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Clear the geometry void clear() { for (auto *v : volumes) delete v; volumes.clear(); } @@ -770,7 +489,6 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo struct _3DScene { -#if ENABLE_LEGACY_OPENGL_REMOVAL static void thick_lines_to_verts(const Lines& lines, const std::vector& widths, const std::vector& heights, bool closed, double top_z, GUI::GLModel::Geometry& geometry); static void thick_lines_to_verts(const Lines3& lines, const std::vector& widths, const std::vector& heights, bool closed, GUI::GLModel::Geometry& geometry); static void extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); @@ -778,19 +496,6 @@ struct _3DScene static void extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_multi_path, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); static void extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); static void extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GUI::GLModel::Geometry& geometry); -#else - static void thick_lines_to_verts(const Lines& lines, const std::vector& widths, const std::vector& heights, bool closed, double top_z, GLVolume& volume); - static void thick_lines_to_verts(const Lines3& lines, const std::vector& widths, const std::vector& heights, bool closed, GLVolume& volume); - static void extrusionentity_to_verts(const Polyline& polyline, float width, float height, float print_z, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionPath& extrusion_path, float print_z, const Point& copy, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionLoop& extrusion_loop, float print_z, const Point& copy, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionMultiPath& extrusion_multi_path, float print_z, const Point& copy, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionEntityCollection& extrusion_entity_collection, float print_z, const Point& copy, GLVolume& volume); - static void extrusionentity_to_verts(const ExtrusionEntity* extrusion_entity, float print_z, const Point& copy, GLVolume& volume); - static void polyline3_to_verts(const Polyline3& polyline, double width, double height, GLVolume& volume); - static void point3_to_verts(const Vec3crd& point, double width, double height, GLVolume& volume); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; } diff --git a/src/slic3r/GUI/Camera.cpp b/src/slic3r/GUI/Camera.cpp index a549d87da..7a79b8cbf 100644 --- a/src/slic3r/GUI/Camera.cpp +++ b/src/slic3r/GUI/Camera.cpp @@ -177,11 +177,7 @@ double Camera::get_fov() const void Camera::set_viewport(int x, int y, unsigned int w, unsigned int h) { -#if ENABLE_LEGACY_OPENGL_REMOVAL m_viewport = { 0, 0, int(w), int(h) }; -#else - glsafe(::glGetIntegerv(GL_VIEWPORT, m_viewport.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void Camera::apply_viewport() const @@ -189,29 +185,12 @@ void Camera::apply_viewport() const glsafe(::glViewport(m_viewport[0], m_viewport[1], m_viewport[2], m_viewport[3])); } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void Camera::apply_view_matrix() -{ - glsafe(::glMatrixMode(GL_MODELVIEW)); - glsafe(::glLoadIdentity()); - glsafe(::glMultMatrixd(m_view_matrix.data())); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double far_z) { double w = 0.0; double h = 0.0; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const double old_distance = m_distance; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL m_frustrum_zs = calc_tight_frustrum_zs_around(box); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - if (m_distance != old_distance) - // the camera has been moved re-apply view matrix - apply_view_matrix(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL if (near_z > 0.0) m_frustrum_zs.first = std::max(std::min(m_frustrum_zs.first, near_z), FrustrumMinNearZ); @@ -245,30 +224,7 @@ void Camera::apply_projection(const BoundingBoxf3& box, double near_z, double fa } } -#if ENABLE_LEGACY_OPENGL_REMOVAL apply_projection(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second); -#else - glsafe(::glMatrixMode(GL_PROJECTION)); - glsafe(::glLoadIdentity()); - - switch (m_type) - { - default: - case EType::Ortho: - { - glsafe(::glOrtho(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second)); - break; - } - case EType::Perspective: - { - glsafe(::glFrustum(-w, w, -h, h, m_frustrum_zs.first, m_frustrum_zs.second)); - break; - } - } - - glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, m_projection_matrix.data())); - glsafe(::glMatrixMode(GL_MODELVIEW)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void Camera::apply_projection(double left, double right, double bottom, double top, double near_z, double far_z) diff --git a/src/slic3r/GUI/Camera.hpp b/src/slic3r/GUI/Camera.hpp index dca7ba642..abca87b9d 100644 --- a/src/slic3r/GUI/Camera.hpp +++ b/src/slic3r/GUI/Camera.hpp @@ -100,9 +100,6 @@ public: void set_viewport(int x, int y, unsigned int w, unsigned int h); void apply_viewport() const; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - void apply_view_matrix(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL // Calculates and applies the projection matrix tighting the frustrum z range around the given box. // If larger z span is needed, pass the desired values of near and far z (negative values are ignored) void apply_projection(const BoundingBoxf3& box, double near_z = -1.0, double far_z = -1.0); diff --git a/src/slic3r/GUI/CoordAxes.cpp b/src/slic3r/GUI/CoordAxes.cpp index 7370f6f78..277c8ad30 100644 --- a/src/slic3r/GUI/CoordAxes.cpp +++ b/src/slic3r/GUI/CoordAxes.cpp @@ -3,10 +3,8 @@ #include "CoordAxes.hpp" #include "GUI_App.hpp" #include "3DScene.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "Plater.hpp" #include "Camera.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include @@ -20,13 +18,8 @@ const float CoordAxes::DefaultStemLength = 25.0f; const float CoordAxes::DefaultTipRadius = 2.5f * CoordAxes::DefaultStemRadius; const float CoordAxes::DefaultTipLength = 5.0f; -#if ENABLE_LEGACY_OPENGL_REMOVAL void CoordAxes::render(const Transform3d& trafo, float emission_factor) -#else -void CoordAxes::render(float emission_factor) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL auto render_axis = [this](GLShaderProgram& shader, const Transform3d& transform) { const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); @@ -35,13 +28,6 @@ void CoordAxes::render(float emission_factor) shader.set_uniform("projection_matrix", camera.get_projection_matrix()); shader.set_uniform("view_normal_matrix", (Matrix3d)(view_matrix.matrix().block(0, 0, 3, 3) * transform.matrix().block(0, 0, 3, 3).inverse().transpose())); m_arrow.render(); -#else - auto render_axis = [this](const Transform3f& transform) { - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixf(transform.data())); - m_arrow.render(); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; if (!m_arrow.is_initialized()) @@ -59,31 +45,16 @@ void CoordAxes::render(float emission_factor) shader->set_uniform("emission_factor", emission_factor); // x axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::X()); render_axis(*shader, trafo * Geometry::translation_transform(m_origin) * Geometry::rotation_transform({ 0.0, 0.5 * M_PI, 0.0 })); -#else - m_arrow.set_color(-1, ColorRGBA::X()); - render_axis(Geometry::translation_transform(m_origin) * Geometry::rotation_transform({ 0.0, 0.5 * M_PI, 0.0 }).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // y axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::Y()); render_axis(*shader, trafo * Geometry::translation_transform(m_origin) * Geometry::rotation_transform({ -0.5 * M_PI, 0.0, 0.0 })); -#else - m_arrow.set_color(-1, ColorRGBA::Y()); - render_axis(Geometry::translation_transform(m_origin) * Geometry::rotation_transform({ -0.5 * M_PI, 0.0, 0.0 }).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // z axis -#if ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.set_color(ColorRGBA::Z()); render_axis(*shader, trafo * Geometry::translation_transform(m_origin)); -#else - m_arrow.set_color(-1, ColorRGBA::Z()); - render_axis(Geometry::translation_transform(m_origin).cast()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (curr_shader != nullptr) diff --git a/src/slic3r/GUI/CoordAxes.hpp b/src/slic3r/GUI/CoordAxes.hpp index d2e830a65..2679608a3 100644 --- a/src/slic3r/GUI/CoordAxes.hpp +++ b/src/slic3r/GUI/CoordAxes.hpp @@ -49,11 +49,7 @@ public: float get_tip_length() const { return m_tip_length; } float get_total_length() const { return m_stem_length + m_tip_length; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(const Transform3d& trafo, float emission_factor = 0.0f); -#else - void render(float emission_factor = 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; } // GUI diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index ecdf60ca3..bfd4379b4 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -193,7 +193,6 @@ void GCodeViewer::COG::render() glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); Transform3d model_matrix = Geometry::translation_transform(cog()); if (m_fixed_size) { @@ -206,17 +205,6 @@ void GCodeViewer::COG::render() const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); m_model.render(); -#else - glsafe(::glPushMatrix()); - const Vec3d position = cog(); - glsafe(::glTranslated(position.x(), position.y(), position.z())); - if (m_fixed_size) { - const double inv_zoom = wxGetApp().plater()->get_camera().get_inv_zoom(); - glsafe(::glScaled(inv_zoom, inv_zoom, inv_zoom)); - } - m_model.render(); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); @@ -305,11 +293,7 @@ void GCodeViewer::SequentialRangeCap::reset() { void GCodeViewer::SequentialView::Marker::init() { m_model.init_from(stilized_arrow(16, 2.0f, 4.0f, 1.0f, 8.0f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_model.set_color({ 1.0f, 1.0f, 1.0f, 0.5f }); -#else - m_model.set_color(-1, { 1.0f, 1.0f, 1.0f, 0.5f }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& position) @@ -333,7 +317,6 @@ void GCodeViewer::SequentialView::Marker::render() shader->start_using(); shader->set_uniform("emission_factor", 0.0f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); const Transform3d model_matrix = m_world_transform.cast(); @@ -341,17 +324,9 @@ void GCodeViewer::SequentialView::Marker::render() shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixf(m_world_transform.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - shader->stop_using(); glsafe(::glDisable(GL_BLEND)); @@ -721,17 +696,12 @@ void GCodeViewer::init() } case EMoveType::Travel: { buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; -#if ENABLE_LEGACY_OPENGL_REMOVAL buffer.vertices.format = VBuffer::EFormat::Position; #if ENABLE_GL_CORE_PROFILE buffer.shader = OpenGLManager::get_gl_info().is_core_profile() ? "dashed_thick_lines" : "flat"; #else buffer.shader = "flat"; #endif // ENABLE_GL_CORE_PROFILE -#else - buffer.vertices.format = VBuffer::EFormat::PositionNormal3; - buffer.shader = "toolpaths_lines"; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL break; } } @@ -745,11 +715,7 @@ void GCodeViewer::init() m_gl_data_initialized = true; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& print) -#else -void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& print, bool initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { // avoid processing if called with the same gcode_result if (m_last_result_id == gcode_result.id && @@ -779,11 +745,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr m_filament_densities = gcode_result.filament_densities; if (wxGetApp().is_editor()) -#if ENABLE_LEGACY_OPENGL_REMOVAL load_shells(print); -#else - load_shells(print, initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL else { Pointfs bed_shape; std::string texture; @@ -1281,30 +1243,12 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) // format data into the buffers to be rendered as lines auto add_vertices_as_line = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, VertexBuffer& vertices) { -#if ENABLE_LEGACY_OPENGL_REMOVAL auto add_vertex = [&vertices](const GCodeProcessorResult::MoveVertex& vertex) { // add position vertices.push_back(vertex.position.x()); vertices.push_back(vertex.position.y()); vertices.push_back(vertex.position.z()); }; -#else - // x component of the normal to the current segment (the normal is parallel to the XY plane) - const Vec3f dir = (curr.position - prev.position).normalized(); - Vec3f normal(dir.y(), -dir.x(), 0.0); - normal.normalize(); - - auto add_vertex = [&vertices, &normal](const GCodeProcessorResult::MoveVertex& vertex) { - // add position - vertices.push_back(vertex.position.x()); - vertices.push_back(vertex.position.y()); - vertices.push_back(vertex.position.z()); - // add normal - vertices.push_back(normal.x()); - vertices.push_back(normal.y()); - vertices.push_back(normal.z()); - }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // add previous vertex add_vertex(prev); @@ -1555,7 +1499,6 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) Geometry::scale_transform({ width, width, height }); const Eigen::Matrix normal_matrix = trafo.matrix().template block<3, 3>(0, 0).inverse().transpose(); -#if ENABLE_LEGACY_OPENGL_REMOVAL // append vertices const size_t vertices_count = data.vertices_count(); for (size_t i = 0; i < vertices_count; ++i) { @@ -1571,24 +1514,6 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) vertices.push_back(float(normal.y())); vertices.push_back(float(normal.z())); } -#else - for (const auto& entity : data.entities) { - // append vertices - for (size_t i = 0; i < entity.positions.size(); ++i) { - // append position - const Vec3d position = trafo * entity.positions[i].cast(); - vertices.push_back(static_cast(position.x())); - vertices.push_back(static_cast(position.y())); - vertices.push_back(static_cast(position.z())); - - // append normal - const Vec3d normal = normal_matrix * entity.normals[i].cast(); - vertices.push_back(static_cast(normal.x())); - vertices.push_back(static_cast(normal.y())); - vertices.push_back(static_cast(normal.z())); - } - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // append instance position instances.push_back(curr.position.x()); @@ -1599,18 +1524,10 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) }; auto add_indices_as_model_batch = [](const GLModel::Geometry& data, IndexBuffer& indices, IBufferType base_index) { -#if ENABLE_LEGACY_OPENGL_REMOVAL const size_t indices_count = data.indices_count(); for (size_t i = 0; i < indices_count; ++i) { indices.push_back(static_cast(data.extract_index(i) + base_index)); } -#else - for (const auto& entity : data.entities) { - for (size_t i = 0; i < entity.indices.size(); ++i) { - indices.push_back(static_cast(entity.indices[i] + base_index)); - } - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; #if ENABLE_GCODE_VIEWER_STATISTICS @@ -2301,11 +2218,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) progress_dialog->Destroy(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GCodeViewer::load_shells(const Print& print) -#else -void GCodeViewer::load_shells(const Print& print, bool initialized) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (print.objects().empty()) // no shells, return @@ -2322,11 +2235,7 @@ void GCodeViewer::load_shells(const Print& print, bool initialized) } size_t current_volumes_count = m_shells.volumes.volumes.size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_shells.volumes.load_object(model_obj, object_id, instance_ids); -#else - m_shells.volumes.load_object(model_obj, object_id, instance_ids, initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // adjust shells' z if raft is present const SlicingParameters& slicing_parameters = obj->slicing_parameters(); @@ -2350,13 +2259,8 @@ void GCodeViewer::load_shells(const Print& print, bool initialized) const float depth = print.wipe_tower_data(extruders_count).depth; const float brim_width = print.wipe_tower_data(extruders_count).brim_width; -#if ENABLE_LEGACY_OPENGL_REMOVAL m_shells.volumes.load_wipe_tower_preview(config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle, !print.is_step_done(psWipeTower), brim_width); -#else - m_shells.volumes.load_wipe_tower_preview(config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle, - !print.is_step_done(psWipeTower), brim_width, initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } @@ -2947,19 +2851,11 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool void GCodeViewer::render_toolpaths() { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const std::array light_intensity = { 0.25f, 0.70f, 0.75f, 0.75f }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); #if !ENABLE_GL_CORE_PROFILE const double zoom = camera.get_zoom(); #endif // !ENABLE_GL_CORE_PROFILE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - auto shader_init_as_lines = [light_intensity](GLShaderProgram &shader) { - shader.set_uniform("light_intensity", light_intensity); - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL auto render_as_lines = [ #if ENABLE_GCODE_VIEWER_STATISTICS this @@ -3031,11 +2927,7 @@ void GCodeViewer::render_toolpaths() } if (range.vbo > 0) { -#if ENABLE_LEGACY_OPENGL_REMOVAL buffer.model.model.set_color(range.color); -#else - buffer.model.model.set_color(-1, range.color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL buffer.model.model.render_instanced(range.vbo, range.count); #if ENABLE_GCODE_VIEWER_STATISTICS ++m_statistics.gl_instanced_models_calls_count; @@ -3045,19 +2937,11 @@ void GCodeViewer::render_toolpaths() } }; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GCODE_VIEWER_STATISTICS auto render_as_batched_model = [this](TBuffer& buffer, GLShaderProgram& shader, int position_id, int normal_id) { #else auto render_as_batched_model = [](TBuffer& buffer, GLShaderProgram& shader, int position_id, int normal_id) { #endif // ENABLE_GCODE_VIEWER_STATISTICS -#else -#if ENABLE_GCODE_VIEWER_STATISTICS - auto render_as_batched_model = [this](TBuffer& buffer, GLShaderProgram& shader) { -#else - auto render_as_batched_model = [](TBuffer& buffer, GLShaderProgram& shader) { -#endif // ENABLE_GCODE_VIEWER_STATISTICS -#endif // ENABLE_LEGACY_OPENGL_REMOVAL struct Range { @@ -3076,26 +2960,16 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindVertexArray(i_buffer.vao)); #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (position_id != -1) { glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); glsafe(::glEnableVertexAttribArray(position_id)); } -#else - glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const bool has_normals = buffer.vertices.normal_size_floats() > 0; if (has_normals) { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) { glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); glsafe(::glEnableVertexAttribArray(normal_id)); } -#else - glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); @@ -3119,17 +2993,10 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) glsafe(::glDisableVertexAttribArray(normal_id)); if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); -#else - if (has_normals) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) @@ -3158,11 +3025,9 @@ void GCodeViewer::render_toolpaths() shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_normal_matrix", (Matrix3d)Matrix3d::Identity()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) { shader->set_uniform("emission_factor", 0.25f); @@ -3171,24 +3036,15 @@ void GCodeViewer::render_toolpaths() } else if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) { shader->set_uniform("emission_factor", 0.25f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const int position_id = shader->get_attrib_location("v_position"); const int normal_id = shader->get_attrib_location("v_normal"); render_as_batched_model(buffer, *shader, position_id, normal_id); -#else - render_as_batched_model(buffer, *shader); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("emission_factor", 0.0f); } else { shader->set_uniform("emission_factor", 0.15f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const int position_id = shader->get_attrib_location("v_position"); const int normal_id = shader->get_attrib_location("v_normal"); -#else - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Line) - shader_init_as_lines(*shader); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const int uniform_color = shader->get_uniform_location("uniform_color"); auto it_path = buffer.render_paths.begin(); @@ -3205,26 +3061,16 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindVertexArray(i_buffer.vao)); #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (position_id != -1) { glsafe(::glVertexAttribPointer(position_id, buffer.vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); glsafe(::glEnableVertexAttribArray(position_id)); } -#else - glsafe(::glVertexPointer(buffer.vertices.position_size_floats(), GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.position_offset_bytes())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const bool has_normals = buffer.vertices.normal_size_floats() > 0; if (has_normals) { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) { glsafe(::glVertexAttribPointer(normal_id, buffer.vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); glsafe(::glEnableVertexAttribArray(normal_id)); } -#else - glsafe(::glNormalPointer(GL_FLOAT, buffer.vertices.vertex_size_bytes(), (const void*)buffer.vertices.normal_offset_bytes())); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_buffer.ibo)); @@ -3251,17 +3097,10 @@ void GCodeViewer::render_toolpaths() glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) glsafe(::glDisableVertexAttribArray(normal_id)); if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); -#else - if (has_normals) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) @@ -3286,40 +3125,28 @@ void GCodeViewer::render_toolpaths() shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_normal_matrix", (Matrix3d)Matrix3d::Identity()); const int position_id = shader->get_attrib_location("v_position"); const int normal_id = shader->get_attrib_location("v_normal"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) glsafe(::glBindVertexArray(cap.vao)); #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (position_id != -1) { glsafe(::glVertexAttribPointer(position_id, buffer->vertices.position_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); glsafe(::glEnableVertexAttribArray(position_id)); } -#else - glsafe(::glVertexPointer(buffer->vertices.position_size_floats(), GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.position_offset_bytes())); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const bool has_normals = buffer->vertices.normal_size_floats() > 0; if (has_normals) { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) { glsafe(::glVertexAttribPointer(normal_id, buffer->vertices.normal_size_floats(), GL_FLOAT, GL_FALSE, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); glsafe(::glEnableVertexAttribArray(normal_id)); } -#else - glsafe(::glNormalPointer(GL_FLOAT, buffer->vertices.vertex_size_bytes(), (const void*)buffer->vertices.normal_offset_bytes())); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } shader->set_uniform("uniform_color", cap.color); @@ -3332,17 +3159,10 @@ void GCodeViewer::render_toolpaths() ++m_statistics.gl_triangles_calls_count; #endif // ENABLE_GCODE_VIEWER_STATISTICS -#if ENABLE_LEGACY_OPENGL_REMOVAL if (normal_id != -1) glsafe(::glDisableVertexAttribArray(normal_id)); if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); -#else - if (has_normals) - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE @@ -3368,25 +3188,11 @@ void GCodeViewer::render_shells() if (shader == nullptr) return; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - // when the background processing is enabled, it may happen that the shells data have been loaded - // before opengl has been initialized for the preview canvas. - // when this happens, the volumes' data have not been sent to gpu yet. - for (GLVolume* v : m_shells.volumes.volumes) { - if (!v->indexed_vertex_array.has_VBOs()) - v->finalize_geometry(true); - } -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - // glsafe(::glDepthMask(GL_FALSE)); shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, camera.get_view_matrix(), camera.get_projection_matrix()); -#else - m_shells.volumes.render(GLVolumeCollection::ERenderType::Transparent, true, wxGetApp().plater()->get_camera().get_view_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); // glsafe(::glDepthMask(GL_TRUE)); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 0785f6a04..b077de98a 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -364,11 +364,7 @@ class GCodeViewer } case ERenderPrimitiveType::InstancedModel: { return model.model.is_initialized() && !model.instances.buffer.empty(); } case ERenderPrimitiveType::BatchedModel: { -#if ENABLE_LEGACY_OPENGL_REMOVAL return !model.data.vertices.empty() && !model.data.indices.empty() && -#else - return model.data.vertices_count() > 0 && model.data.indices_count() && -#endif // ENABLE_LEGACY_OPENGL_REMOVAL !vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0; } default: { return false; } @@ -418,12 +414,7 @@ class GCodeViewer return; const float radius = m_fixed_size ? 10.0f : 1.0f; - -#if ENABLE_LEGACY_OPENGL_REMOVAL m_model.init_from(smooth_sphere(32, radius)); -#else - m_model.init_from(its_make_sphere(radius, PI / 32.0)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } }; @@ -799,11 +790,7 @@ public: void init(); // extract rendering data from the given parameters -#if ENABLE_LEGACY_OPENGL_REMOVAL void load(const GCodeProcessorResult& gcode_result, const Print& print); -#else - void load(const GCodeProcessorResult& gcode_result, const Print& print, bool initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // recalculate ranges in dependence of what is visible and sets tool/print colors void refresh(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors); void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const; @@ -855,11 +842,7 @@ public: private: void load_toolpaths(const GCodeProcessorResult& gcode_result); -#if ENABLE_LEGACY_OPENGL_REMOVAL void load_shells(const Print& print); -#else - void load_shells(const Print& print, bool initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void render_toolpaths(); void render_shells(); void render_legend(float& legend_height); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 0c505bc0b..9fa54b9a0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -73,26 +73,13 @@ static constexpr const float TRACKBALLSIZE = 0.8f; -#if ENABLE_LEGACY_OPENGL_REMOVAL static const Slic3r::ColorRGBA DEFAULT_BG_DARK_COLOR = { 0.478f, 0.478f, 0.478f, 1.0f }; static const Slic3r::ColorRGBA DEFAULT_BG_LIGHT_COLOR = { 0.753f, 0.753f, 0.753f, 1.0f }; static const Slic3r::ColorRGBA ERROR_BG_DARK_COLOR = { 0.478f, 0.192f, 0.039f, 1.0f }; static const Slic3r::ColorRGBA ERROR_BG_LIGHT_COLOR = { 0.753f, 0.192f, 0.039f, 1.0f }; -#else -static const Slic3r::ColorRGB DEFAULT_BG_DARK_COLOR = { 0.478f, 0.478f, 0.478f }; -static const Slic3r::ColorRGB DEFAULT_BG_LIGHT_COLOR = { 0.753f, 0.753f, 0.753f }; -static const Slic3r::ColorRGB ERROR_BG_DARK_COLOR = { 0.478f, 0.192f, 0.039f }; -static const Slic3r::ColorRGB ERROR_BG_LIGHT_COLOR = { 0.753f, 0.192f, 0.039f }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Number of floats static constexpr const size_t MAX_VERTEX_BUFFER_SIZE = 131072 * 6; // 3.15MB -// Reserve size in number of floats. -#if !ENABLE_LEGACY_OPENGL_REMOVAL -static constexpr const size_t VERTEX_BUFFER_RESERVE_SIZE = 131072 * 2; // 1.05MB -// Reserve size in number of floats, maximum sum of all preallocated buffers. -//static constexpr const size_t VERTEX_BUFFER_RESERVE_SIZE_SUM_MAX = 1024 * 1024 * 128 / 4; // 128MB -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL namespace Slic3r { namespace GUI { @@ -266,14 +253,8 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) GLCanvas3D::LayersEditing::s_overlay_window_width = ImGui::GetWindowSize().x /*+ (float)m_layers_texture.width/4*/; imgui.end(); -#if ENABLE_LEGACY_OPENGL_REMOVAL render_active_object_annotations(canvas); render_profile(canvas); -#else - const Rect& bar_rect = get_bar_rect_viewport(canvas); - render_active_object_annotations(canvas, bar_rect); - render_profile(bar_rect); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } float GLCanvas3D::LayersEditing::get_cursor_z_relative(const GLCanvas3D& canvas) @@ -307,17 +288,6 @@ Rect GLCanvas3D::LayersEditing::get_bar_rect_screen(const GLCanvas3D& canvas) return { w - thickness_bar_width(canvas), 0.0f, w, h }; } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -Rect GLCanvas3D::LayersEditing::get_bar_rect_viewport(const GLCanvas3D& canvas) -{ - const Size& cnv_size = canvas.get_canvas_size(); - float half_w = 0.5f * (float)cnv_size.get_width(); - float half_h = 0.5f * (float)cnv_size.get_height(); - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - return { (half_w - thickness_bar_width(canvas)) * inv_zoom, half_h * inv_zoom, half_w * inv_zoom, -half_h * inv_zoom }; -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - bool GLCanvas3D::LayersEditing::is_initialized() const { return wxGetApp().get_shader("variable_layer_height") != nullptr; @@ -349,7 +319,6 @@ std::string GLCanvas3D::LayersEditing::get_tooltip(const GLCanvas3D& canvas) con return ret; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3D& canvas) { const Size cnv_size = canvas.get_canvas_size(); @@ -359,10 +328,6 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3 return; const float cnv_inv_width = 1.0f / cnv_width; -#else -void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3D& canvas, const Rect& bar_rect) -{ -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("variable_layer_height"); if (shader == nullptr) return; @@ -374,17 +339,14 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3 shader->set_uniform("z_cursor", m_object_max_z * this->get_cursor_z_relative(canvas)); shader->set_uniform("z_cursor_band_width", band_width); shader->set_uniform("object_max_z", m_object_max_z); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("view_model_matrix", Transform3d::Identity()); shader->set_uniform("projection_matrix", Transform3d::Identity()); shader->set_uniform("view_normal_matrix", (Matrix3d)Matrix3d::Identity()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); glsafe(::glBindTexture(GL_TEXTURE_2D, m_z_texture_id)); // Render the color bar -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_profile.background.is_initialized() || m_profile.old_canvas_width != cnv_width) { m_profile.old_canvas_width = cnv_width; m_profile.background.reset(); @@ -412,38 +374,19 @@ void GLCanvas3D::LayersEditing::render_active_object_annotations(const GLCanvas3 } m_profile.background.render(); -#else - const float l = bar_rect.get_left(); - const float r = bar_rect.get_right(); - const float t = bar_rect.get_top(); - const float b = bar_rect.get_bottom(); - - ::glBegin(GL_QUADS); - ::glNormal3f(0.0f, 0.0f, 1.0f); - ::glTexCoord2f(0.0f, 0.0f); ::glVertex2f(l, b); - ::glTexCoord2f(1.0f, 0.0f); ::glVertex2f(r, b); - ::glTexCoord2f(1.0f, 1.0f); ::glVertex2f(r, t); - ::glTexCoord2f(0.0f, 1.0f); ::glVertex2f(l, t); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); shader->stop_using(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLCanvas3D::LayersEditing::render_profile(const GLCanvas3D& canvas) -#else -void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { //FIXME show some kind of legend. if (!m_slicing_parameters) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Size cnv_size = canvas.get_canvas_size(); const float cnv_width = (float)cnv_size.get_width(); const float cnv_height = (float)cnv_size.get_height(); @@ -456,13 +399,7 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) const float cnv_inv_width = 1.0f / cnv_width; const float cnv_inv_height = 1.0f / cnv_height; -#else - // Make the vertical bar a bit wider so the layer height curve does not touch the edge of the bar region. - const float scale_x = bar_rect.get_width() / float(1.12 * m_slicing_parameters->max_layer_height); - const float scale_y = bar_rect.get_height() / m_object_max_z; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL // Baseline if (!m_profile.baseline.is_initialized() || m_profile.old_layer_height_profile != m_layer_height_profile) { m_profile.baseline.reset(); @@ -523,23 +460,6 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect) m_profile.profile.render(); shader->stop_using(); } -#else - const float x = bar_rect.get_left() + float(m_slicing_parameters->layer_height) * scale_x; - - // Baseline - glsafe(::glColor3f(0.0f, 0.0f, 0.0f)); - ::glBegin(GL_LINE_STRIP); - ::glVertex2f(x, bar_rect.get_bottom()); - ::glVertex2f(x, bar_rect.get_top()); - glsafe(::glEnd()); - - // Curve - glsafe(::glColor3f(0.0f, 0.0f, 1.0f)); - ::glBegin(GL_LINE_STRIP); - for (unsigned int i = 0; i < m_layer_height_profile.size(); i += 2) - ::glVertex2f(bar_rect.get_left() + (float)m_layer_height_profile[i + 1] * scale_x, bar_rect.get_bottom() + (float)m_layer_height_profile[i] * scale_y); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const GLVolumeCollection& volumes) @@ -566,10 +486,8 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G shader->set_uniform("z_cursor", float(m_object_max_z) * float(this->get_cursor_z_relative(canvas))); shader->set_uniform("z_cursor_band_width", float(this->band_width)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Initialize the layer height texture mapping. const GLsizei w = (GLsizei)m_layers_texture.width; @@ -589,13 +507,11 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G shader->set_uniform("volume_world_matrix", glvolume->world_matrix()); shader->set_uniform("object_max_z", 0.0f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d& view_matrix = camera.get_view_matrix(); const Transform3d model_matrix = glvolume->world_matrix(); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glvolume->render(); } @@ -944,17 +860,8 @@ void GLCanvas3D::SequentialPrintClearance::set_polygons(const Polygons& polygons if (polygons.empty()) return; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - size_t triangles_count = 0; - for (const Polygon& poly : polygons) { - triangles_count += poly.points.size() - 2; - } - const size_t vertices_count = 3 * triangles_count; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - if (m_render_fill) { GLModel::Geometry fill_data; -#if ENABLE_LEGACY_OPENGL_REMOVAL fill_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; fill_data.color = { 0.3333f, 0.0f, 0.0f, 0.5f }; @@ -974,55 +881,9 @@ void GLCanvas3D::SequentialPrintClearance::set_polygons(const Polygons& polygons } m_fill.init_from(std::move(fill_data)); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; - entity.color = { 0.3333f, 0.0f, 0.0f, 0.5f }; - entity.positions.reserve(vertices_count); - entity.normals.reserve(vertices_count); - entity.indices.reserve(vertices_count); - - const ExPolygons polygons_union = union_ex(polygons); - for (const ExPolygon& poly : polygons_union) { - const std::vector triangulation = triangulate_expolygon_3d(poly); - for (const Vec3d& v : triangulation) { - entity.positions.emplace_back(v.cast() + Vec3f(0.0f, 0.0f, 0.0125f)); // add a small positive z to avoid z-fighting - entity.normals.emplace_back(Vec3f::UnitZ()); - const size_t positions_count = entity.positions.size(); - if (positions_count % 3 == 0) { - entity.indices.emplace_back(positions_count - 3); - entity.indices.emplace_back(positions_count - 2); - entity.indices.emplace_back(positions_count - 1); - } - } - } - - fill_data.entities.emplace_back(entity); - m_fill.init_from(fill_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL m_perimeter.init_from(polygons, 0.025f); // add a small positive z to avoid z-fighting -#else - GLModel::Geometry perimeter_data; - for (const Polygon& poly : polygons) { - GLModel::Geometry::Entity ent; - ent.type = GLModel::EPrimitiveType::LineLoop; - ent.positions.reserve(poly.points.size()); - ent.indices.reserve(poly.points.size()); - unsigned int id_count = 0; - for (const Point& p : poly.points) { - ent.positions.emplace_back(unscale(p.x()), unscale(p.y()), 0.025f); // add a small positive z to avoid z-fighting - ent.normals.emplace_back(Vec3f::UnitZ()); - ent.indices.emplace_back(id_count++); - } - - perimeter_data.entities.emplace_back(ent); - } - - m_perimeter.init_from(perimeter_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::SequentialPrintClearance::render() @@ -1030,32 +891,22 @@ void GLCanvas3D::SequentialPrintClearance::render() const ColorRGBA FILL_COLOR = { 1.0f, 0.0f, 0.0f, 0.5f }; const ColorRGBA NO_FILL_COLOR = { 1.0f, 1.0f, 1.0f, 0.75f }; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#else - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader == nullptr) return; shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_CULL_FACE)); glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_perimeter.set_color(m_render_fill ? FILL_COLOR : NO_FILL_COLOR); -#else - m_perimeter.set_color(-1, m_render_fill ? FILL_COLOR : NO_FILL_COLOR); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_perimeter.render(); m_fill.render(); @@ -1246,50 +1097,12 @@ bool GLCanvas3D::init() glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - // Set antialiasing / multisampling - glsafe(::glDisable(GL_LINE_SMOOTH)); - glsafe(::glDisable(GL_POLYGON_SMOOTH)); - - // ambient lighting - GLfloat ambient[4] = { 0.3f, 0.3f, 0.3f, 1.0f }; - glsafe(::glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient)); - - glsafe(::glEnable(GL_LIGHT0)); - glsafe(::glEnable(GL_LIGHT1)); - - // light from camera - GLfloat specular_cam[4] = { 0.3f, 0.3f, 0.3f, 1.0f }; - glsafe(::glLightfv(GL_LIGHT1, GL_SPECULAR, specular_cam)); - GLfloat diffuse_cam[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; - glsafe(::glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_cam)); - - // light from above - GLfloat specular_top[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; - glsafe(::glLightfv(GL_LIGHT0, GL_SPECULAR, specular_top)); - GLfloat diffuse_top[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; - glsafe(::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_top)); - - // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. - glsafe(::glShadeModel(GL_SMOOTH)); - - // A handy trick -- have surface material mirror the color. - glsafe(::glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)); - glsafe(::glEnable(GL_COLOR_MATERIAL)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - if (m_multisample_allowed) glsafe(::glEnable(GL_MULTISAMPLE)); if (m_main_toolbar.is_enabled()) m_layers_editing.init(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - // on linux the gl context is not valid until the canvas is not shown on screen - // we defer the geometry finalization of volumes until the first call to render() - m_volumes.finalize_geometry(true); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - if (m_gizmos.is_enabled() && !m_gizmos.init()) std::cout << "Unable to initialize gizmos: please, check that all the required textures are available" << std::endl; @@ -1663,18 +1476,8 @@ void GLCanvas3D::render() camera.requires_zoom_to_bed = false; } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - camera.apply_view_matrix(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL camera.apply_projection(_max_bounding_box(true, true)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - GLfloat position_cam[4] = { 1.0f, 0.0f, 1.0f, 0.0f }; - glsafe(::glLightfv(GL_LIGHT1, GL_POSITION, position_cam)); - GLfloat position_top[4] = { -0.5f, -0.5f, 1.0f, 0.0f }; - glsafe(::glLightfv(GL_LIGHT0, GL_POSITION, position_top)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - wxGetApp().imgui()->new_frame(); if (m_picking_enabled) { @@ -1706,11 +1509,7 @@ void GLCanvas3D::render() _render_sla_slices(); _render_selection(); if (is_looking_downward) -#if ENABLE_LEGACY_OPENGL_REMOVAL _render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), false, true); -#else - _render_bed(false, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL _render_objects(GLVolumeCollection::ERenderType::Transparent); _render_sequential_clearance(); @@ -1731,11 +1530,7 @@ void GLCanvas3D::render() _render_selection_sidebar_hints(); _render_current_gizmo(); if (!is_looking_downward) -#if ENABLE_LEGACY_OPENGL_REMOVAL _render_bed(camera.get_view_matrix(), camera.get_projection_matrix(), true, true); -#else - _render_bed(true, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_RAYCAST_PICKING_DEBUG if (m_picking_enabled && !m_mouse.dragging && !m_gizmos.is_dragging() && !m_rectangle_selection.is_dragging()) @@ -1933,11 +1728,7 @@ std::vector GLCanvas3D::load_object(const ModelObject& model_object, int ob instance_idxs.emplace_back(i); } } -#if ENABLE_LEGACY_OPENGL_REMOVAL return m_volumes.load_object(&model_object, obj_idx, instance_idxs); -#else - return m_volumes.load_object(&model_object, obj_idx, instance_idxs, m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } std::vector GLCanvas3D::load_object(const Model& model, int obj_idx) @@ -2165,11 +1956,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re // Note the index of the loaded volume, so that we can reload the main model GLVolume with the hollowed mesh // later in this function. it->volume_idx = m_volumes.volumes.size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx); -#else - m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_volumes.volumes.back()->geometry_id = key.geometry_id; update_object_list = true; } else { @@ -2226,11 +2013,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re GLVolume &volume = *m_volumes.volumes[it->volume_idx]; if (! volume.offsets.empty() && state.step[istep].timestamp != volume.offsets.front()) { // The backend either produced a new hollowed mesh, or it invalidated the one that the front end has seen. -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.model.reset(); -#else - volume.indexed_vertex_array.release_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (state.step[istep].state == PrintStateBase::DONE) { TriangleMesh mesh = print_object->get_mesh(slaposDrillHoles); assert(! mesh.empty()); @@ -2242,46 +2025,27 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re * mo.volumes.front()->get_transformation().get_matrix(); mesh.transform(trafo.inverse()); #if ENABLE_SMOOTH_NORMALS -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.model.init_from(mesh, true); #else - volume.indexed_vertex_array.load_mesh(mesh, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#else -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.model.init_from(mesh); volume.mesh_raycaster = std::make_unique(std::make_shared(mesh)); -#else - volume.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_SMOOTH_NORMALS } else { // Reload the original volume. #if ENABLE_SMOOTH_NORMALS -#if ENABLE_LEGACY_OPENGL_REMOVAL - volume.model.init_from(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh(), true); + volume.model.init_from(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh(), true); #else - volume.indexed_vertex_array.load_mesh(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh(), true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#else -#if ENABLE_LEGACY_OPENGL_REMOVAL const TriangleMesh& new_mesh = m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh(); volume.model.init_from(new_mesh); volume.mesh_raycaster = std::make_unique(std::make_shared(new_mesh)); -#else - volume.indexed_vertex_array.load_mesh(m_model->objects[volume.object_idx()]->volumes[volume.volume_idx()]->mesh()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_SMOOTH_NORMALS } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - volume.finalize_geometry(true); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } - //FIXME it is an ugly hack to write the timestamp into the "offsets" field to not have to add another member variable - // to the GLVolume. We should refactor GLVolume significantly, so that the GLVolume will not contain member variables - // of various concenrs (model vs. 3D print path). - volume.offsets = { state.step[istep].timestamp }; + //FIXME it is an ugly hack to write the timestamp into the "offsets" field to not have to add another member variable + // to the GLVolume. We should refactor GLVolume significantly, so that the GLVolume will not contain member variables + // of various concenrs (model vs. 3D print path). + volume.offsets = { state.step[istep].timestamp }; } else if (state.step[istep].state == PrintStateBase::DONE) { // Check whether there is an existing auxiliary volume to be updated, or a new auxiliary volume to be created. @@ -2306,11 +2070,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re for (size_t istep = 0; istep < sla_steps.size(); ++istep) if (!instances[istep].empty()) -#if ENABLE_LEGACY_OPENGL_REMOVAL m_volumes.load_object_auxiliary(print_object, object_idx, instances[istep], sla_steps[istep], state.step[istep].timestamp); -#else - m_volumes.load_object_auxiliary(print_object, object_idx, instances[istep], sla_steps[istep], state.step[istep].timestamp, m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // Shift-up all volumes of the object so that it has the right elevation with respect to the print bed @@ -2340,7 +2100,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re float depth = print->wipe_tower_data(extruders_count).depth; float brim_width = print->wipe_tower_data(extruders_count).brim_width; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES int volume_idx_wipe_tower_new = m_volumes.load_wipe_tower_preview( x, y, w, depth, (float)height, a, !print->is_step_done(psWipeTower), @@ -2350,11 +2109,6 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re x, y, w, depth, (float)height, a, !print->is_step_done(psWipeTower), brim_width); #endif // ENABLE_OPENGL_ES -#else - int volume_idx_wipe_tower_new = m_volumes.load_wipe_tower_preview( - x, y, w, depth, (float)height, a, !print->is_step_done(psWipeTower), - brim_width, m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (volume_idx_wipe_tower_old != -1) map_glvolume_old_to_new[volume_idx_wipe_tower_old] = volume_idx_wipe_tower_new; } @@ -2446,30 +2200,9 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re m_dirty = true; } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -static void reserve_new_volume_finalize_old_volume(GLVolume& vol_new, GLVolume& vol_old, bool gl_initialized, size_t prealloc_size = VERTEX_BUFFER_RESERVE_SIZE) -{ - // Assign the large pre-allocated buffers to the new GLVolume. - vol_new.indexed_vertex_array = std::move(vol_old.indexed_vertex_array); - // Copy the content back to the old GLVolume. - vol_old.indexed_vertex_array = vol_new.indexed_vertex_array; - // Clear the buffers, but keep them pre-allocated. - vol_new.indexed_vertex_array.clear(); - // Just make sure that clear did not clear the reserved memory. - // Reserving number of vertices (3x position + 3x color) - vol_new.indexed_vertex_array.reserve(prealloc_size / 6); - // Finalize the old geometry, possibly move data to the graphics card. - vol_old.finalize_geometry(gl_initialized); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors) { -#if ENABLE_LEGACY_OPENGL_REMOVAL m_gcode_viewer.load(gcode_result, *this->fff_print()); -#else - m_gcode_viewer.load(gcode_result, *this->fff_print(), m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (wxGetApp().is_editor()) { m_gcode_viewer.update_shells_color_by_extruder(m_config); @@ -4396,12 +4129,7 @@ bool GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) ImGuiWrapper* imgui = wxGetApp().imgui(); -#if ENABLE_LEGACY_OPENGL_REMOVAL imgui->set_next_window_pos(pos_x, m_undoredo_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#else - const float x = pos_x * (float)wxGetApp().plater()->get_camera().get_zoom() + 0.5f * (float)get_canvas_size().get_width(); - imgui->set_next_window_pos(x, m_undoredo_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL std::string title = is_undo ? L("Undo History") : L("Redo History"); imgui->begin(_(title), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); @@ -4440,12 +4168,7 @@ bool GLCanvas3D::_render_search_list(float pos_x) bool action_taken = false; ImGuiWrapper* imgui = wxGetApp().imgui(); -#if ENABLE_LEGACY_OPENGL_REMOVAL imgui->set_next_window_pos(pos_x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#else - const float x = /*pos_x * (float)wxGetApp().plater()->get_camera().get_zoom() + */0.5f * (float)get_canvas_size().get_width(); - imgui->set_next_window_pos(x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL std::string title = L("Search"); imgui->begin(_(title), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); @@ -4498,13 +4221,7 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x) { ImGuiWrapper *imgui = wxGetApp().imgui(); -#if ENABLE_LEGACY_OPENGL_REMOVAL imgui->set_next_window_pos(pos_x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#else - auto canvas_w = float(get_canvas_size().get_width()); - const float x = pos_x * float(wxGetApp().plater()->get_camera().get_zoom()) + 0.5f * canvas_w; - imgui->set_next_window_pos(x, m_main_toolbar.get_height(), ImGuiCond_Always, 0.5f, 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL imgui->begin(_L("Arrange options"), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse); @@ -4640,11 +4357,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const camera.apply_viewport(); camera.zoom_to_box(volumes_box); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d& view_matrix = camera.get_view_matrix(); -#else - camera.apply_view_matrix(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL double near_z = -1.0; double far_z = -1.0; @@ -4653,11 +4366,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const // extends the near and far z of the frustrum to avoid the bed being clipped // box in eye space -#if ENABLE_LEGACY_OPENGL_REMOVAL const BoundingBoxf3 t_bed_box = m_bed.extended_bounding_box().transformed(view_matrix); -#else - const BoundingBoxf3 t_bed_box = m_bed.extended_bounding_box().transformed(camera.get_view_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL near_z = -t_bed_box.max.z(); far_z = -t_bed_box.min.z(); } @@ -4677,26 +4386,18 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const shader->start_using(); shader->set_uniform("emission_factor", 0.0f); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d& projection_matrix = camera.get_projection_matrix(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (GLVolume* vol : visible_volumes) { -#if ENABLE_LEGACY_OPENGL_REMOVAL vol->model.set_color((vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : ColorRGBA::ORANGE()) : ColorRGBA::GRAY()); -#else - shader->set_uniform("uniform_color", (vol->printable && !vol->is_outside) ? (current_printer_technology() == ptSLA ? vol->color : ColorRGBA::ORANGE()) : ColorRGBA::GRAY()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // the volume may have been deactivated by an active gizmo const bool is_active = vol->is_active; vol->is_active = true; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = vol->world_matrix(); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", projection_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL vol->render(); vol->is_active = is_active; } @@ -4706,11 +4407,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const glsafe(::glDisable(GL_DEPTH_TEST)); if (thumbnail_params.show_bed) -#if ENABLE_LEGACY_OPENGL_REMOVAL _render_bed(view_matrix, projection_matrix, !camera.is_looking_downward(), false); -#else - _render_bed(!camera.is_looking_downward(), false); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // restore background color if (thumbnail_params.transparent_background) @@ -4977,25 +4674,11 @@ bool GLCanvas3D::_init_main_toolbar() return true; } // init arrow -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_main_toolbar.init_arrow("toolbar_arrow_2.svg")) -#else - BackgroundTexture::Metadata arrow_data; - arrow_data.filename = "toolbar_arrow.svg"; - arrow_data.left = 0; - arrow_data.top = 0; - arrow_data.right = 0; - arrow_data.bottom = 0; - if (!m_main_toolbar.init_arrow(arrow_data)) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL BOOST_LOG_TRIVIAL(error) << "Main toolbar failed to load arrow texture."; // m_gizmos is created at constructor, thus we can init arrow here. -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_gizmos.init_arrow("toolbar_arrow_2.svg")) -#else - if (!m_gizmos.init_arrow(arrow_data)) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL BOOST_LOG_TRIVIAL(error) << "Gizmos manager failed to load arrow texture."; // m_main_toolbar.set_layout_type(GLToolbar::Layout::Vertical); @@ -5202,17 +4885,7 @@ bool GLCanvas3D::_init_undoredo_toolbar() } // init arrow -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_undoredo_toolbar.init_arrow("toolbar_arrow_2.svg")) -#else - BackgroundTexture::Metadata arrow_data; - arrow_data.filename = "toolbar_arrow.svg"; - arrow_data.left = 0; - arrow_data.top = 0; - arrow_data.right = 0; - arrow_data.bottom = 0; - if (!m_undoredo_toolbar.init_arrow(arrow_data)) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL BOOST_LOG_TRIVIAL(error) << "Undo/Redo toolbar failed to load arrow texture."; // m_undoredo_toolbar.set_layout_type(GLToolbar::Layout::Vertical); @@ -5652,11 +5325,7 @@ void GLCanvas3D::_rectangular_selection_picking_pass() } _render_volumes_for_picking(*camera); -#if ENABLE_LEGACY_OPENGL_REMOVAL _render_bed_for_picking(camera->get_view_matrix(), camera->get_projection_matrix(), !camera->is_looking_downward()); -#else - _render_bed_for_picking(!wxGetApp().plater()->get_camera().is_looking_downward()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (m_multisample_allowed) glsafe(::glEnable(GL_MULTISAMPLE)); @@ -5744,18 +5413,9 @@ void GLCanvas3D::_render_background() use_error_color &= m_gcode_viewer.has_data() && !m_gcode_viewer.is_contained_in_bed(); } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - glsafe(::glMatrixMode(GL_PROJECTION)); - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - // Draws a bottom to top gradient over the complete screen. glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const ColorRGBA bottom_color = use_error_color ? ERROR_BG_DARK_COLOR : DEFAULT_BG_DARK_COLOR; if (!m_background.is_initialized()) { @@ -5787,32 +5447,11 @@ void GLCanvas3D::_render_background() m_background.render(); shader->stop_using(); } -#else - ::glBegin(GL_QUADS); - ::glColor3fv(use_error_color ? ERROR_BG_DARK_COLOR.data(): DEFAULT_BG_DARK_COLOR.data()); - ::glVertex2f(-1.0f, -1.0f); - ::glVertex2f(1.0f, -1.0f); - - ::glColor3fv(use_error_color ? ERROR_BG_LIGHT_COLOR.data() : DEFAULT_BG_LIGHT_COLOR.data()); - ::glVertex2f(1.0f, 1.0f); - ::glVertex2f(-1.0f, 1.0f); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); - glsafe(::glMatrixMode(GL_MODELVIEW)); - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLCanvas3D::_render_bed(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_axes) -#else -void GLCanvas3D::_render_bed(bool bottom, bool show_axes) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { float scale_factor = 1.0; #if ENABLE_RETINA_GL @@ -5826,29 +5465,17 @@ void GLCanvas3D::_render_bed(bool bottom, bool show_axes) && m_gizmos.get_current_type() != GLGizmosManager::Seam && m_gizmos.get_current_type() != GLGizmosManager::MmuSegmentation); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_bed.render(*this, view_matrix, projection_matrix, bottom, scale_factor, show_axes, show_texture); -#else - m_bed.render(*this, bottom, scale_factor, show_axes, show_texture); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLCanvas3D::_render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom) -#else -void GLCanvas3D::_render_bed_for_picking(bool bottom) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { float scale_factor = 1.0; #if ENABLE_RETINA_GL scale_factor = m_retina_helper->get_scale_factor(); #endif // ENABLE_RETINA_GL -#if ENABLE_LEGACY_OPENGL_REMOVAL m_bed.render_for_picking(*this, view_matrix, projection_matrix, bottom, scale_factor); -#else - m_bed.render_for_picking(*this, bottom, scale_factor); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) @@ -5914,33 +5541,20 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) { if (m_picking_enabled && !m_gizmos.is_dragging() && m_layers_editing.is_enabled() && (m_layers_editing.last_object_id != -1) && (m_layers_editing.object_max_z() > 0.0f)) { int object_id = m_layers_editing.last_object_id; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); m_volumes.render(type, false, camera.get_view_matrix(), camera.get_projection_matrix(), [object_id](const GLVolume& volume) { // Which volume to paint without the layer height profile shader? return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id); }); -#else - m_volumes.render(type, false, wxGetApp().plater()->get_camera().get_view_matrix(), [object_id](const GLVolume& volume) { - // Which volume to paint without the layer height profile shader? - return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id); - }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Let LayersEditing handle rendering of the active object using the layer height profile shader. m_layers_editing.render_volumes(*this, m_volumes); } else { // do not cull backfaces to show broken geometry, if any -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); m_volumes.render(type, m_picking_enabled, camera.get_view_matrix(), camera.get_projection_matrix(), [this](const GLVolume& volume) { return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); }); -#else - m_volumes.render(type, m_picking_enabled, wxGetApp().plater()->get_camera().get_view_matrix(), [this](const GLVolume& volume) { - return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); - }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // In case a painting gizmo is open, it should render the painted triangles @@ -5959,12 +5573,8 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type) } case GLVolumeCollection::ERenderType::Transparent: { -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); m_volumes.render(type, false, camera.get_view_matrix(), camera.get_projection_matrix()); -#else - m_volumes.render(type, false, wxGetApp().plater()->get_camera().get_view_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL break; } } @@ -6074,16 +5684,6 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() void GLCanvas3D::_render_overlays() { glsafe(::glDisable(GL_DEPTH_TEST)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - // ensure that the textures are renderered inside the frustrum - const Camera& camera = wxGetApp().plater()->get_camera(); - glsafe(::glTranslated(0.0, 0.0, -(camera.get_near_z() + 0.005))); - // ensure that the overlay fits the frustrum near z plane - double gui_scale = camera.get_gui_scale(); - glsafe(::glScaled(gui_scale, gui_scale, 1.0)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL _check_and_update_toolbar_icon_scale(); @@ -6121,28 +5721,17 @@ void GLCanvas3D::_render_overlays() } } m_labels.render(sorted_instances); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const { -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat_clip"); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // do not cull backfaces to show broken geometry, if any glsafe(::glDisable(GL_CULL_FACE)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - const Transform3d& view_matrix = camera.get_view_matrix(); for (size_t type = 0; type < 2; ++ type) { GLVolumeWithIdAndZList to_render = volumes_to_render(m_volumes.volumes, (type == 0) ? GLVolumeCollection::ERenderType::Opaque : GLVolumeCollection::ERenderType::Transparent, view_matrix); @@ -6152,7 +5741,6 @@ void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const // we reserve color = (0,0,0) for occluders (as the printbed) // so we shift volumes' id by 1 to get the proper color const unsigned int id = 1 + volume.second.first; -#if ENABLE_LEGACY_OPENGL_REMOVAL volume.first->model.set_color(picking_decode(id)); shader->start_using(); shader->set_uniform("view_model_matrix", view_matrix * volume.first->world_matrix()); @@ -6160,20 +5748,10 @@ void GLCanvas3D::_render_volumes_for_picking(const Camera& camera) const shader->set_uniform("volume_world_matrix", volume.first->world_matrix()); shader->set_uniform("z_range", m_volumes.get_z_range()); shader->set_uniform("clipping_plane", m_volumes.get_clipping_plane()); -#else - glsafe(::glColor4fv(picking_decode(id).data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL volume.first->render(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - } - } - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL + } + } glsafe(::glEnable(GL_CULL_FACE)); } @@ -6208,20 +5786,11 @@ void GLCanvas3D::_render_main_toolbar() return; const Size cnv_size = get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const float top = 0.5f * (float)cnv_size.get_height(); -#else - const float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - const float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); const float collapse_toolbar_width = collapse_toolbar.is_enabled() ? collapse_toolbar.get_width() : 0.0f; -#if ENABLE_LEGACY_OPENGL_REMOVAL const float left = -0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width); -#else - const float left = -0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width) * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_main_toolbar.set_position(top, left); m_main_toolbar.render(*this); @@ -6235,20 +5804,10 @@ void GLCanvas3D::_render_undoredo_toolbar() return; const Size cnv_size = get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const float top = 0.5f * (float)cnv_size.get_height(); -#else - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - - const float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLToolbar& collapse_toolbar = wxGetApp().plater()->get_collapse_toolbar(); const float collapse_toolbar_width = collapse_toolbar.is_enabled() ? collapse_toolbar.get_width() : 0.0f; -#if ENABLE_LEGACY_OPENGL_REMOVAL const float left = m_main_toolbar.get_width() - 0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width); -#else - const float left = (m_main_toolbar.get_width() - 0.5f * (m_main_toolbar.get_width() + m_undoredo_toolbar.get_width() + collapse_toolbar_width)) * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_undoredo_toolbar.set_position(top, left); m_undoredo_toolbar.render(*this); @@ -6262,15 +5821,8 @@ void GLCanvas3D::_render_collapse_toolbar() const const Size cnv_size = get_canvas_size(); const float band = m_layers_editing.is_enabled() ? (wxGetApp().imgui()->get_style_scaling() * LayersEditing::THICKNESS_BAR_WIDTH) : 0.0; -#if ENABLE_LEGACY_OPENGL_REMOVAL const float top = 0.5f * (float)cnv_size.get_height(); const float left = 0.5f * (float)cnv_size.get_width() - collapse_toolbar.get_width() - band; -#else - const float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - - const float top = 0.5f * (float)cnv_size.get_height() * inv_zoom; - const float left = (0.5f * (float)cnv_size.get_width() - (float)collapse_toolbar.get_width() - band) * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL collapse_toolbar.set_position(top, left); collapse_toolbar.render(*this); @@ -6294,17 +5846,9 @@ void GLCanvas3D::_render_view_toolbar() const #endif // ENABLE_RETINA_GL const Size cnv_size = get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL // places the toolbar on the bottom-left corner of the 3d scene const float top = -0.5f * (float)cnv_size.get_height() + view_toolbar.get_height(); const float left = -0.5f * (float)cnv_size.get_width(); -#else - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - - // places the toolbar on the bottom-left corner of the 3d scene - float top = (-0.5f * (float)cnv_size.get_height() + view_toolbar.get_height()) * inv_zoom; - float left = -0.5f * (float)cnv_size.get_width() * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL view_toolbar.set_position(top, left); view_toolbar.render(*this); } @@ -6320,7 +5864,6 @@ void GLCanvas3D::_render_camera_target() #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Vec3f& target = wxGetApp().plater()->get_camera().get_target().cast(); m_camera_target.target = target.cast(); @@ -6362,7 +5905,6 @@ void GLCanvas3D::_render_camera_target() #endif // ENABLE_GL_CORE_PROFILE if (shader != nullptr) { shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::translation_transform(m_camera_target.target)); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); @@ -6372,29 +5914,11 @@ void GLCanvas3D::_render_camera_target() shader->set_uniform("width", 0.5f); shader->set_uniform("gap_size", 0.0f); #endif // ENABLE_GL_CORE_PROFILE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (int i = 0; i < 3; ++i) { m_camera_target.axis[i].render(); } shader->stop_using(); } -#else - ::glBegin(GL_LINES); - const Vec3d& target = wxGetApp().plater()->get_camera().get_target(); - // draw line for x axis - ::glColor3f(1.0f, 0.0f, 0.0f); - ::glVertex3d(target.x() - half_length, target.y(), target.z()); - ::glVertex3d(target.x() + half_length, target.y(), target.z()); - // draw line for y axis - ::glColor3f(0.0f, 1.0f, 0.0f); - ::glVertex3d(target.x(), target.y() - half_length, target.z()); - ::glVertex3d(target.x(), target.y() + half_length, target.z()); - // draw line for z axis - ::glColor3f(0.0f, 0.0f, 1.0f); - ::glVertex3d(target.x(), target.y(), target.z() - half_length); - ::glVertex3d(target.x(), target.y(), target.z() + half_length); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } #endif // ENABLE_SHOW_CAMERA_TARGET @@ -6417,52 +5941,29 @@ void GLCanvas3D::_render_sla_slices() if (!obj->is_step_done(slaposSliceSupports)) continue; -#if ENABLE_LEGACY_OPENGL_REMOVAL SlaCap::ObjectIdToModelsMap::iterator it_caps_bottom = m_sla_caps[0].triangles.find(i); SlaCap::ObjectIdToModelsMap::iterator it_caps_top = m_sla_caps[1].triangles.find(i); -#else - SlaCap::ObjectIdToTrianglesMap::iterator it_caps_bottom = m_sla_caps[0].triangles.find(i); - SlaCap::ObjectIdToTrianglesMap::iterator it_caps_top = m_sla_caps[1].triangles.find(i); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (it_caps_bottom == m_sla_caps[0].triangles.end()) it_caps_bottom = m_sla_caps[0].triangles.emplace(i, SlaCap::Triangles()).first; if (!m_sla_caps[0].matches(clip_min_z)) { m_sla_caps[0].z = clip_min_z; -#if ENABLE_LEGACY_OPENGL_REMOVAL it_caps_bottom->second.object.reset(); it_caps_bottom->second.supports.reset(); -#else - it_caps_bottom->second.object.clear(); - it_caps_bottom->second.supports.clear(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } if (it_caps_top == m_sla_caps[1].triangles.end()) it_caps_top = m_sla_caps[1].triangles.emplace(i, SlaCap::Triangles()).first; if (!m_sla_caps[1].matches(clip_max_z)) { m_sla_caps[1].z = clip_max_z; -#if ENABLE_LEGACY_OPENGL_REMOVAL it_caps_top->second.object.reset(); it_caps_top->second.supports.reset(); -#else - it_caps_top->second.object.clear(); - it_caps_top->second.supports.clear(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel& bottom_obj_triangles = it_caps_bottom->second.object; GLModel& bottom_sup_triangles = it_caps_bottom->second.supports; GLModel& top_obj_triangles = it_caps_top->second.object; GLModel& top_sup_triangles = it_caps_top->second.supports; -#else - Pointf3s &bottom_obj_triangles = it_caps_bottom->second.object; - Pointf3s &bottom_sup_triangles = it_caps_bottom->second.supports; - Pointf3s &top_obj_triangles = it_caps_top->second.object; - Pointf3s &top_sup_triangles = it_caps_top->second.supports; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL auto init_model = [](GLModel& model, const Pointf3s& triangles, const ColorRGBA& color) { GLModel::Geometry init_data; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; @@ -6484,10 +5985,6 @@ void GLCanvas3D::_render_sla_slices() if ((!bottom_obj_triangles.is_initialized() || !bottom_sup_triangles.is_initialized() || !top_obj_triangles.is_initialized() || !top_sup_triangles.is_initialized()) && !obj->get_slice_index().empty()) { -#else - if ((bottom_obj_triangles.empty() || bottom_sup_triangles.empty() || top_obj_triangles.empty() || top_sup_triangles.empty()) && - !obj->get_slice_index().empty()) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL double layer_height = print->default_object_config().layer_height.value; double initial_layer_height = print->material_config().initial_layer_height.value; bool left_handed = obj->is_left_handed(); @@ -6507,45 +6004,26 @@ void GLCanvas3D::_render_sla_slices() if (slice_low.is_valid()) { const ExPolygons& obj_bottom = slice_low.get_slice(soModel); const ExPolygons& sup_bottom = slice_low.get_slice(soSupport); -#if ENABLE_LEGACY_OPENGL_REMOVAL // calculate model bottom cap if (!bottom_obj_triangles.is_initialized() && !obj_bottom.empty()) init_model(bottom_obj_triangles, triangulate_expolygons_3d(obj_bottom, clip_min_z - plane_shift_z, !left_handed), { 1.0f, 0.37f, 0.0f, 1.0f }); // calculate support bottom cap if (!bottom_sup_triangles.is_initialized() && !sup_bottom.empty()) init_model(bottom_sup_triangles, triangulate_expolygons_3d(sup_bottom, clip_min_z - plane_shift_z, !left_handed), { 1.0f, 0.0f, 0.37f, 1.0f }); -#else - // calculate model bottom cap - if (bottom_obj_triangles.empty() && !obj_bottom.empty()) - bottom_obj_triangles = triangulate_expolygons_3d(obj_bottom, clip_min_z - plane_shift_z, ! left_handed); - // calculate support bottom cap - if (bottom_sup_triangles.empty() && !sup_bottom.empty()) - bottom_sup_triangles = triangulate_expolygons_3d(sup_bottom, clip_min_z - plane_shift_z, !left_handed); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } if (slice_high.is_valid()) { const ExPolygons& obj_top = slice_high.get_slice(soModel); const ExPolygons& sup_top = slice_high.get_slice(soSupport); -#if ENABLE_LEGACY_OPENGL_REMOVAL // calculate model top cap if (!top_obj_triangles.is_initialized() && !obj_top.empty()) init_model(top_obj_triangles, triangulate_expolygons_3d(obj_top, clip_max_z + plane_shift_z, left_handed), { 1.0f, 0.37f, 0.0f, 1.0f }); // calculate support top cap if (!top_sup_triangles.is_initialized() && !sup_top.empty()) init_model(top_sup_triangles, triangulate_expolygons_3d(sup_top, clip_max_z + plane_shift_z, left_handed), { 1.0f, 0.0f, 0.37f, 1.0f }); -#else - // calculate model top cap - if (top_obj_triangles.empty() && !obj_top.empty()) - top_obj_triangles = triangulate_expolygons_3d(obj_top, clip_max_z + plane_shift_z, left_handed); - // calculate support top cap - if (top_sup_triangles.empty() && !sup_top.empty()) - top_sup_triangles = triangulate_expolygons_3d(sup_top, clip_max_z + plane_shift_z, left_handed); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); if (shader != nullptr) { shader->start_using(); @@ -6576,39 +6054,6 @@ void GLCanvas3D::_render_sla_slices() shader->stop_using(); } -#else - if (!bottom_obj_triangles.empty() || !top_obj_triangles.empty() || !bottom_sup_triangles.empty() || !top_sup_triangles.empty()) { - for (const SLAPrintObject::Instance& inst : obj->instances()) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(unscale(inst.shift.x()), unscale(inst.shift.y()), 0.0)); - glsafe(::glRotatef(Geometry::rad2deg(inst.rotation), 0.0f, 0.0f, 1.0f)); - if (obj->is_left_handed()) - // The polygons are mirrored by X. - glsafe(::glScalef(-1.0f, 1.0f, 1.0f)); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glColor3f(1.0f, 0.37f, 0.0f)); - if (!bottom_obj_triangles.empty()) { - glsafe(::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)bottom_obj_triangles.front().data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, bottom_obj_triangles.size())); - } - if (! top_obj_triangles.empty()) { - glsafe(::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)top_obj_triangles.front().data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, top_obj_triangles.size())); - } - glsafe(::glColor3f(1.0f, 0.0f, 0.37f)); - if (! bottom_sup_triangles.empty()) { - glsafe(::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)bottom_sup_triangles.front().data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, bottom_sup_triangles.size())); - } - if (! top_sup_triangles.empty()) { - glsafe(::glVertexPointer(3, GL_DOUBLE, 0, (GLdouble*)top_sup_triangles.front().data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, top_sup_triangles.size())); - } - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glPopMatrix()); - } - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } @@ -6789,48 +6234,24 @@ void GLCanvas3D::_load_print_toolpaths(const BuildVolume &build_volume) skirt_height = std::min(skirt_height, print_zs.size()); print_zs.erase(print_zs.begin() + skirt_height, print_zs.end()); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume* volume = m_volumes.new_toolpath_volume(color); GLModel::Geometry init_data; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; -#else - GLVolume *volume = m_volumes.new_toolpath_volume(color, VERTEX_BUFFER_RESERVE_SIZE); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (size_t i = 0; i < skirt_height; ++ i) { volume->print_zs.emplace_back(print_zs[i]); -#if ENABLE_LEGACY_OPENGL_REMOVAL volume->offsets.emplace_back(init_data.indices_count()); if (i == 0) _3DScene::extrusionentity_to_verts(print->brim(), print_zs[i], Point(0, 0), init_data); _3DScene::extrusionentity_to_verts(print->skirt(), print_zs[i], Point(0, 0), init_data); -#else - volume->offsets.emplace_back(volume->indexed_vertex_array.quad_indices.size()); - volume->offsets.emplace_back(volume->indexed_vertex_array.triangle_indices.size()); - if (i == 0) - _3DScene::extrusionentity_to_verts(print->brim(), print_zs[i], Point(0, 0), *volume); - _3DScene::extrusionentity_to_verts(print->skirt(), print_zs[i], Point(0, 0), *volume); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. -#if ENABLE_LEGACY_OPENGL_REMOVAL if (init_data.vertices_size_bytes() > MAX_VERTEX_BUFFER_SIZE) { volume->model.init_from(std::move(init_data)); -#else - if (volume->indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLVolume &vol = *volume; volume = m_volumes.new_toolpath_volume(vol.color); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - reserve_new_volume_finalize_old_volume(*volume, vol, m_initialized); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL volume->model.init_from(std::move(init_data)); volume->is_outside = !contains(build_volume, volume->model); -#else - volume->is_outside = ! build_volume.all_paths_inside_vertices_and_normals_interleaved(volume->indexed_vertex_array.vertices_and_normals_interleaved, volume->indexed_vertex_array.bounding_box()); - volume->indexed_vertex_array.finalize_geometry(m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const BuildVolume& build_volume, const std::vector& str_tool_colors, const std::vector& color_print_values) @@ -7002,11 +6423,9 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c // Allocate the volume before locking. GLVolume *volume = new GLVolume(color); volume->is_extrusion_path = true; -#if ENABLE_LEGACY_OPENGL_REMOVAL // to prevent sending data to gpu (in the main thread) while // editing the model geometry volume->model.disable_render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL tbb::spin_mutex::scoped_lock lock; // Lock by ROII, so if the emplace_back() fails, the lock will be released. lock.acquire(new_volume_mutex); @@ -7024,7 +6443,6 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c tbb::blocked_range(0, ctxt.layers.size(), grain_size), [&ctxt, &new_volume, is_selected_separate_extruder, this](const tbb::blocked_range& range) { GLVolumePtrs vols; -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector geometries; auto select_geometry = [&ctxt, &geometries](size_t layer_idx, int extruder, int feature) -> GLModel::Geometry& { return geometries[ctxt.color_by_color_print() ? @@ -7034,41 +6452,21 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c feature ]; }; -#else - auto volume = [&ctxt, &vols](size_t layer_idx, int extruder, int feature) -> GLVolume& { - return *vols[ctxt.color_by_color_print() ? - ctxt.color_print_color_idx_by_layer_idx_and_extruder(layer_idx, extruder) : - ctxt.color_by_tool() ? - std::min(ctxt.number_tools() - 1, std::max(extruder - 1, 0)) : - feature - ]; - }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (ctxt.color_by_color_print() || ctxt.color_by_tool()) { for (size_t i = 0; i < ctxt.number_tools(); ++i) { vols.emplace_back(new_volume(ctxt.color_tool(i))); -#if ENABLE_LEGACY_OPENGL_REMOVAL geometries.emplace_back(GLModel::Geometry()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } else { vols = { new_volume(ctxt.color_perimeters()), new_volume(ctxt.color_infill()), new_volume(ctxt.color_support()) }; -#if ENABLE_LEGACY_OPENGL_REMOVAL geometries = { GLModel::Geometry(), GLModel::Geometry(), GLModel::Geometry() }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL assert(vols.size() == geometries.size()); for (GLModel::Geometry& g : geometries) { g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; } -#else - for (GLVolume *vol : vols) - // Reserving number of vertices (3x position + 3x color) - vol->indexed_vertex_array.reserve(VERTEX_BUFFER_RESERVE_SIZE / 6); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++ idx_layer) { const Layer *layer = ctxt.layers[idx_layer]; @@ -7089,7 +6487,6 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c continue; } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (size_t i = 0; i < vols.size(); ++i) { GLVolume* vol = vols[i]; if (vol->print_zs.empty() || vol->print_zs.back() != layer->print_z) { @@ -7097,14 +6494,6 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c vol->offsets.emplace_back(geometries[i].indices_count()); } } -#else - for (GLVolume* vol : vols) - if (vol->print_zs.empty() || vol->print_zs.back() != layer->print_z) { - vol->print_zs.emplace_back(layer->print_z); - vol->offsets.emplace_back(vol->indexed_vertex_array.quad_indices.size()); - vol->offsets.emplace_back(vol->indexed_vertex_array.triangle_indices.size()); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (const PrintInstance &instance : *ctxt.shifted_copies) { const Point © = instance.shift; @@ -7117,31 +6506,17 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c continue; } if (ctxt.has_perimeters) -#if ENABLE_LEGACY_OPENGL_REMOVAL _3DScene::extrusionentity_to_verts(layerm->perimeters(), float(layer->print_z), copy, select_geometry(idx_layer, layerm->region().config().perimeter_extruder.value, 0)); -#else - _3DScene::extrusionentity_to_verts(layerm->perimeters(), float(layer->print_z), copy, - volume(idx_layer, layerm->region().config().perimeter_extruder.value, 0)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (ctxt.has_infill) { for (const ExtrusionEntity *ee : layerm->fills()) { // fill represents infill extrusions of a single island. const auto *fill = dynamic_cast(ee); if (! fill->entities.empty()) -#if ENABLE_LEGACY_OPENGL_REMOVAL _3DScene::extrusionentity_to_verts(*fill, float(layer->print_z), copy, select_geometry(idx_layer, is_solid_infill(fill->entities.front()->role()) ? layerm->region().config().solid_infill_extruder : layerm->region().config().infill_extruder, 1)); -#else - _3DScene::extrusionentity_to_verts(*fill, float(layer->print_z), copy, - volume(idx_layer, - is_solid_infill(fill->entities.front()->role()) ? - layerm->region().config().solid_infill_extruder : - layerm->region().config().infill_extruder, - 1)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } @@ -7149,50 +6524,27 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c const SupportLayer *support_layer = dynamic_cast(layer); if (support_layer) { for (const ExtrusionEntity *extrusion_entity : support_layer->support_fills.entities) -#if ENABLE_LEGACY_OPENGL_REMOVAL _3DScene::extrusionentity_to_verts(extrusion_entity, float(layer->print_z), copy, select_geometry(idx_layer, (extrusion_entity->role() == erSupportMaterial) ? support_layer->object()->config().support_material_extruder : support_layer->object()->config().support_material_interface_extruder, 2)); -#else - _3DScene::extrusionentity_to_verts(extrusion_entity, float(layer->print_z), copy, - volume(idx_layer, - (extrusion_entity->role() == erSupportMaterial) ? - support_layer->object()->config().support_material_extruder : - support_layer->object()->config().support_material_interface_extruder, - 2)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } // Ensure that no volume grows over the limits. If the volume is too large, allocate a new one. for (size_t i = 0; i < vols.size(); ++i) { GLVolume &vol = *vols[i]; -#if ENABLE_LEGACY_OPENGL_REMOVAL if (geometries[i].vertices_size_bytes() > MAX_VERTEX_BUFFER_SIZE) { vol.model.init_from(std::move(geometries[i])); -#else - if (vol.indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL vols[i] = new_volume(vol.color); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - reserve_new_volume_finalize_old_volume(*vols[i], vol, false); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (size_t i = 0; i < vols.size(); ++i) { if (!geometries[i].is_empty()) vols[i]->model.init_from(std::move(geometries[i])); } -#else - for (GLVolume *vol : vols) - // Ideally one would call vol->indexed_vertex_array.finalize() here to move the buffers to the OpenGL driver, - // but this code runs in parallel and the OpenGL driver is not thread safe. - vol->indexed_vertex_array.shrink_to_fit(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }); }); // task arena @@ -7208,14 +6560,9 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c } for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i) { GLVolume* v = m_volumes.volumes[i]; -#if ENABLE_LEGACY_OPENGL_REMOVAL v->is_outside = !contains(build_volume, v->model); // We are done editinig the model, now it can be sent to gpu v->model.enable_render(); -#else - v->is_outside = ! build_volume.all_paths_inside_vertices_and_normals_interleaved(v->indexed_vertex_array.vertices_and_normals_interleaved, v->indexed_vertex_array.bounding_box()); - v->indexed_vertex_array.finalize_geometry(m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - end" << m_volumes.log_memory_info() << log_memory_info(); @@ -7280,11 +6627,9 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con auto new_volume = [this, &new_volume_mutex](const ColorRGBA& color) { auto *volume = new GLVolume(color); volume->is_extrusion_path = true; -#if ENABLE_LEGACY_OPENGL_REMOVAL // to prevent sending data to gpu (in the main thread) while // editing the model geometry volume->model.disable_render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL tbb::spin_mutex::scoped_lock lock; lock.acquire(new_volume_mutex); m_volumes.volumes.emplace_back(volume); @@ -7298,46 +6643,29 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con [&ctxt, &new_volume](const tbb::blocked_range& range) { // Bounding box of this slab of a wipe tower. GLVolumePtrs vols; -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector geometries; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (ctxt.color_by_tool()) { for (size_t i = 0; i < ctxt.number_tools(); ++i) { vols.emplace_back(new_volume(ctxt.color_tool(i))); -#if ENABLE_LEGACY_OPENGL_REMOVAL geometries.emplace_back(GLModel::Geometry()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } else { vols = { new_volume(ctxt.color_support()) }; -#if ENABLE_LEGACY_OPENGL_REMOVAL geometries = { GLModel::Geometry() }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL assert(vols.size() == geometries.size()); for (GLModel::Geometry& g : geometries) { g.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; } -#else - for (GLVolume *volume : vols) - // Reserving number of vertices (3x position + 3x color) - volume->indexed_vertex_array.reserve(VERTEX_BUFFER_RESERVE_SIZE / 6); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (size_t idx_layer = range.begin(); idx_layer < range.end(); ++idx_layer) { const std::vector &layer = ctxt.tool_change(idx_layer); for (size_t i = 0; i < vols.size(); ++i) { GLVolume &vol = *vols[i]; if (vol.print_zs.empty() || vol.print_zs.back() != layer.front().print_z) { vol.print_zs.emplace_back(layer.front().print_z); -#if ENABLE_LEGACY_OPENGL_REMOVAL vol.offsets.emplace_back(geometries[i].indices_count()); -#else - vol.offsets.emplace_back(vol.indexed_vertex_array.quad_indices.size()); - vol.offsets.emplace_back(vol.indexed_vertex_array.triangle_indices.size()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } for (const WipeTower::ToolChangeResult &extrusions : layer) { @@ -7380,40 +6708,23 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con e_prev = e; } -#if ENABLE_LEGACY_OPENGL_REMOVAL _3DScene::thick_lines_to_verts(lines, widths, heights, lines.front().a == lines.back().b, extrusions.print_z, geometries[ctxt.volume_idx(e.tool, 0)]); -#else - _3DScene::thick_lines_to_verts(lines, widths, heights, lines.front().a == lines.back().b, extrusions.print_z, - *vols[ctxt.volume_idx(e.tool, 0)]); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } for (size_t i = 0; i < vols.size(); ++i) { GLVolume &vol = *vols[i]; -#if ENABLE_LEGACY_OPENGL_REMOVAL if (geometries[i].vertices_size_bytes() > MAX_VERTEX_BUFFER_SIZE) { vol.model.init_from(std::move(geometries[i])); -#else - if (vol.indexed_vertex_array.vertices_and_normals_interleaved.size() > MAX_VERTEX_BUFFER_SIZE) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL vols[i] = new_volume(vol.color); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - reserve_new_volume_finalize_old_volume(*vols[i], vol, false); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (size_t i = 0; i < vols.size(); ++i) { if (!geometries[i].is_empty()) vols[i]->model.init_from(std::move(geometries[i])); } -#else - for (GLVolume *vol : vols) - vol->indexed_vertex_array.shrink_to_fit(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }); BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - finalizing results" << m_volumes.log_memory_info() << log_memory_info(); @@ -7428,14 +6739,9 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const BuildVolume& build_volume, con } for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i) { GLVolume* v = m_volumes.volumes[i]; -#if ENABLE_LEGACY_OPENGL_REMOVAL v->is_outside = !contains(build_volume, v->model); // We are done editinig the model, now it can be sent to gpu v->model.enable_render(); -#else - v->is_outside = ! build_volume.all_paths_inside_vertices_and_normals_interleaved(v->indexed_vertex_array.vertices_and_normals_interleaved, v->indexed_vertex_array.bounding_box()); - v->indexed_vertex_array.finalize_geometry(m_initialized); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - end" << m_volumes.log_memory_info() << log_memory_info(); @@ -7459,21 +6765,10 @@ void GLCanvas3D::_load_sla_shells() m_volumes.volumes.emplace_back(new GLVolume(color)); GLVolume& v = *m_volumes.volumes.back(); #if ENABLE_SMOOTH_NORMALS -#if ENABLE_LEGACY_OPENGL_REMOVAL v.model.init_from(mesh, true); #else - v.indexed_vertex_array.load_mesh(mesh, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#else -#if ENABLE_LEGACY_OPENGL_REMOVAL v.model.init_from(mesh); -#else - v.indexed_vertex_array.load_mesh(mesh); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_SMOOTH_NORMALS -#if !ENABLE_LEGACY_OPENGL_REMOVAL - v.indexed_vertex_array.finalize_geometry(m_initialized); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled; v.composite_id.volume_id = volume_id; v.set_instance_offset(unscale(instance.shift.x(), instance.shift.y(), 0.0)); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index b24a15bbe..41880d2b2 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -243,7 +243,7 @@ class GLCanvas3D int last_object_id{ -1 }; float last_z{ 0.0f }; LayerHeightEditActionType last_action{ LAYER_HEIGHT_EDIT_ACTION_INCREASE }; -#if ENABLE_LEGACY_OPENGL_REMOVAL + struct Profile { GLModel baseline; @@ -253,7 +253,6 @@ class GLCanvas3D std::vector old_layer_height_profile; }; Profile m_profile; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL LayersEditing() = default; ~LayersEditing(); @@ -280,9 +279,6 @@ class GLCanvas3D static float get_cursor_z_relative(const GLCanvas3D& canvas); static bool bar_rect_contains(const GLCanvas3D& canvas, float x, float y); static Rect get_bar_rect_screen(const GLCanvas3D& canvas); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - static Rect get_bar_rect_viewport(const GLCanvas3D& canvas); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL static float get_overlay_window_width() { return LayersEditing::s_overlay_window_width; } float object_max_z() const { return m_object_max_z; } @@ -292,13 +288,8 @@ class GLCanvas3D private: bool is_initialized() const; void generate_layer_height_texture(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_active_object_annotations(const GLCanvas3D& canvas); void render_profile(const GLCanvas3D& canvas); -#else - void render_active_object_annotations(const GLCanvas3D& canvas, const Rect& bar_rect); - void render_profile(const Rect& bar_rect); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void update_slicing_parameters(); static float thickness_bar_width(const GLCanvas3D &canvas); @@ -345,7 +336,6 @@ class GLCanvas3D struct SlaCap { -#if ENABLE_LEGACY_OPENGL_REMOVAL struct Triangles { GLModel object; @@ -354,16 +344,6 @@ class GLCanvas3D typedef std::map ObjectIdToModelsMap; double z; ObjectIdToModelsMap triangles; -#else - struct Triangles - { - Pointf3s object; - Pointf3s supports; - }; - typedef std::map ObjectIdToTrianglesMap; - double z; - ObjectIdToTrianglesMap triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL SlaCap() { reset(); } void reset() { z = DBL_MAX; triangles.clear(); } @@ -638,7 +618,6 @@ private: } m_gizmo_highlighter; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SHOW_CAMERA_TARGET struct CameraTarget { @@ -649,7 +628,6 @@ private: CameraTarget m_camera_target; #endif // ENABLE_SHOW_CAMERA_TARGET GLModel m_background; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL public: explicit GLCanvas3D(wxGLCanvas* canvas, Bed3D &bed); @@ -985,13 +963,8 @@ private: void _picking_pass(); void _rectangular_selection_picking_pass(); void _render_background(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void _render_bed(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_axes); void _render_bed_for_picking(const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom); -#else - void _render_bed(bool bottom, bool show_axes); - void _render_bed_for_picking(bool bottom); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void _render_objects(GLVolumeCollection::ERenderType type); void _render_gcode(); void _render_gcode_cog(); diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 2d4d25f8c..61736f9ac 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -12,10 +12,8 @@ #include "libslic3r/TriangleMesh.hpp" #include "libslic3r/Model.hpp" #include "libslic3r/Polygon.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/BuildVolume.hpp" #include "libslic3r/Geometry/ConvexHull.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GLMODEL_STATISTICS #include @@ -24,20 +22,17 @@ #include #include -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS #include #include #include #endif // ENABLE_SMOOTH_NORMALS -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include namespace Slic3r { namespace GUI { -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS static void smooth_normals_corner(const TriangleMesh& mesh, std::vector& normals) { @@ -64,9 +59,7 @@ static void smooth_normals_corner(const TriangleMesh& mesh, std::vector()); } } -#else - if (!m_render_data.empty()) // call reset() if you want to reuse this model - return; - - for (const Geometry::Entity& entity : data.entities) { - if (entity.positions.empty() || entity.indices.empty()) - continue; - - assert(entity.normals.empty() || entity.normals.size() == entity.positions.size()); - - RenderData rdata; - rdata.type = entity.type; - rdata.color = entity.color; - - // vertices/normals data - std::vector vertices(6 * entity.positions.size()); - for (size_t i = 0; i < entity.positions.size(); ++i) { - const size_t offset = i * 6; - ::memcpy(static_cast(&vertices[offset]), static_cast(entity.positions[i].data()), 3 * sizeof(float)); - if (!entity.normals.empty()) - ::memcpy(static_cast(&vertices[3 + offset]), static_cast(entity.normals[i].data()), 3 * sizeof(float)); - } - - // indices data - std::vector indices = entity.indices; - - rdata.indices_count = static_cast(indices.size()); - - // update bounding box - for (size_t i = 0; i < entity.positions.size(); ++i) { - m_bounding_box.merge(entity.positions[i].cast()); - } - - send_to_gpu(rdata, vertices, indices); - m_render_data.emplace_back(rdata); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_SMOOTH_NORMALS void GLModel::init_from(const TriangleMesh& mesh, bool smooth_normals) { @@ -629,11 +560,7 @@ void GLModel::init_from(const TriangleMesh& mesh) #endif // ENABLE_SMOOTH_NORMALS void GLModel::init_from(const indexed_triangle_set& its) -#else -void GLModel::init_from(const indexed_triangle_set& its, const BoundingBoxf3 &bbox) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (is_initialized()) { // call reset() if you want to reuse this model assert(false); @@ -667,49 +594,10 @@ void GLModel::init_from(const indexed_triangle_set& its, const BoundingBoxf3 &bb for (size_t i = 0; i < vertices_count(); ++i) { m_bounding_box.merge(data.extract_position_3(i).cast()); } -#else - if (!m_render_data.empty()) // call reset() if you want to reuse this model - return; - - RenderData data; - data.type = EPrimitiveType::Triangles; - - std::vector vertices = std::vector(18 * its.indices.size()); - std::vector indices = std::vector(3 * its.indices.size()); - - unsigned int vertices_count = 0; - for (uint32_t i = 0; i < its.indices.size(); ++i) { - stl_triangle_vertex_indices face = its.indices[i]; - stl_vertex vertex[3] = { its.vertices[face[0]], its.vertices[face[1]], its.vertices[face[2]] }; - stl_vertex n = face_normal_normalized(vertex); - for (size_t j = 0; j < 3; ++ j) { - size_t offset = i * 18 + j * 6; - ::memcpy(static_cast(&vertices[offset]), static_cast(vertex[j].data()), 3 * sizeof(float)); - ::memcpy(static_cast(&vertices[3 + offset]), static_cast(n.data()), 3 * sizeof(float)); - } - for (size_t j = 0; j < 3; ++j) - indices[i * 3 + j] = vertices_count + j; - vertices_count += 3; - } - - data.indices_count = static_cast(indices.size()); - m_bounding_box = bbox; - - send_to_gpu(data, vertices, indices); - m_render_data.emplace_back(data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void GLModel::init_from(const indexed_triangle_set& its) -{ - init_from(its, bounding_box(its)); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void GLModel::init_from(const Polygons& polygons, float z) { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (is_initialized()) { // call reset() if you want to reuse this model assert(false); @@ -749,31 +637,6 @@ void GLModel::init_from(const Polygons& polygons, float z) for (size_t i = 0; i < vertices_count(); ++i) { m_bounding_box.merge(data.extract_position_3(i).cast()); } -#else - auto append_polygon = [](const Polygon& polygon, float z, GUI::GLModel::Geometry& data) { - if (!polygon.empty()) { - GUI::GLModel::Geometry::Entity entity; - entity.type = GUI::GLModel::EPrimitiveType::LineLoop; - // contour - entity.positions.reserve(polygon.size() + 1); - entity.indices.reserve(polygon.size() + 1); - unsigned int id = 0; - for (const Point& p : polygon) { - Vec3f position = unscale(p.x(), p.y(), 0.0).cast(); - position.z() = z; - entity.positions.emplace_back(position); - entity.indices.emplace_back(id++); - } - data.entities.emplace_back(entity); - } - }; - - Geometry init_data; - for (const Polygon& polygon : polygons) { - append_polygon(polygon, z, init_data); - } - init_from(init_data); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } bool GLModel::init_from_file(const std::string& filename) @@ -792,37 +655,15 @@ bool GLModel::init_from_file(const std::string& filename) return false; } -#if ENABLE_LEGACY_OPENGL_REMOVAL init_from(model.mesh()); -#else - const TriangleMesh& mesh = model.mesh(); - init_from(mesh.its, mesh.bounding_box()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_filename = filename; return true; } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void GLModel::set_color(int entity_id, const ColorRGBA& color) -{ - for (size_t i = 0; i < m_render_data.size(); ++i) { - if (entity_id == -1 || static_cast(i) == entity_id) - m_render_data[i].color = color; - } -} - -ColorRGBA GLModel::get_color(size_t entity_id) const -{ - if (entity_id < 0 || entity_id >= m_render_data.size()) return ColorRGBA{}; - return m_render_data[entity_id].color; -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void GLModel::reset() { -#if ENABLE_LEGACY_OPENGL_REMOVAL // release gpu memory if (m_render_data.ibo_id > 0) { glsafe(::glDeleteBuffers(1, &m_render_data.ibo_id)); @@ -849,22 +690,10 @@ void GLModel::reset() m_render_data.indices_count = 0; m_render_data.geometry.vertices = std::vector(); m_render_data.geometry.indices = std::vector(); -#else - for (RenderData& data : m_render_data) { - // release gpu memory - if (data.ibo_id > 0) - glsafe(::glDeleteBuffers(1, &data.ibo_id)); - if (data.vbo_id > 0) - glsafe(::glDeleteBuffers(1, &data.vbo_id)); - } - - m_render_data.clear(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_bounding_box = BoundingBoxf3(); m_filename = std::string(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL static GLenum get_primitive_mode(const GLModel::Geometry::Format& format) { switch (format.type) @@ -892,54 +721,10 @@ static GLenum get_index_type(const GLModel::Geometry& data) } void GLModel::render() -#else -void GLModel::render() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL render(std::make_pair(0, indices_count())); -#else - GLShaderProgram* shader = wxGetApp().get_current_shader(); - - for (const RenderData& data : m_render_data) { - if (data.vbo_id == 0 || data.ibo_id == 0) - continue; - - GLenum mode; - switch (data.type) - { - default: - case EPrimitiveType::Triangles: { mode = GL_TRIANGLES; break; } - case EPrimitiveType::Lines: { mode = GL_LINES; break; } - case EPrimitiveType::LineStrip: { mode = GL_LINE_STRIP; break; } - case EPrimitiveType::LineLoop: { mode = GL_LINE_LOOP; break; } - } - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, data.vbo_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)0)); - glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); - - if (shader != nullptr) - shader->set_uniform("uniform_color", data.color); - else - glsafe(::glColor4fv(data.color.data())); - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id)); - glsafe(::glDrawElements(mode, static_cast(data.indices_count), GL_UNSIGNED_INT, (const void*)0)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLModel::render(const std::pair& range) { if (m_render_disabled) @@ -1048,19 +833,13 @@ void GLModel::render(const std::pair& range) ++s_statistics.render_calls; #endif // ENABLE_GLMODEL_STATISTICS } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instances_count) -#else -void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instances_count) const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (instances_vbo == 0 || instances_count == 0) return; GLShaderProgram* shader = wxGetApp().get_current_shader(); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (shader == nullptr || !boost::algorithm::iends_with(shader->get_name(), "_instanced")) return; @@ -1080,19 +859,6 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance if (!send_to_gpu()) return; } -#else - assert(shader == nullptr || boost::algorithm::iends_with(shader->get_name(), "_instanced")); - - // vertex attributes - GLint position_id = (shader != nullptr) ? shader->get_attrib_location("v_position") : -1; - GLint normal_id = (shader != nullptr) ? shader->get_attrib_location("v_normal") : -1; - assert(position_id != -1 && normal_id != -1); - - // instance attributes - GLint offset_id = (shader != nullptr) ? shader->get_attrib_location("i_offset") : -1; - GLint scales_id = (shader != nullptr) ? shader->get_attrib_location("i_scales") : -1; - assert(offset_id != -1 && scales_id != -1); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) @@ -1100,7 +866,6 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, instances_vbo)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const size_t instance_stride = 5 * sizeof(float); glsafe(::glVertexAttribPointer(offset_id, 3, GL_FLOAT, GL_FALSE, instance_stride, (const void*)0)); glsafe(::glEnableVertexAttribArray(offset_id)); @@ -1109,20 +874,7 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance glsafe(::glVertexAttribPointer(scales_id, 2, GL_FLOAT, GL_FALSE, instance_stride, (const void*)(3 * sizeof(float)))); glsafe(::glEnableVertexAttribArray(scales_id)); glsafe(::glVertexAttribDivisor(scales_id, 1)); -#else - if (offset_id != -1) { - glsafe(::glVertexAttribPointer(offset_id, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (GLvoid*)0)); - glsafe(::glEnableVertexAttribArray(offset_id)); - glsafe(::glVertexAttribDivisor(offset_id, 1)); - } - if (scales_id != -1) { - glsafe(::glVertexAttribPointer(scales_id, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (GLvoid*)(3 * sizeof(float)))); - glsafe(::glEnableVertexAttribArray(scales_id)); - glsafe(::glVertexAttribDivisor(scales_id, 1)); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL const Geometry& data = m_render_data.geometry; const GLenum mode = get_primitive_mode(data.format); @@ -1164,51 +916,6 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance glsafe(::glDisableVertexAttribArray(scales_id)); glsafe(::glDisableVertexAttribArray(offset_id)); -#else - for (const RenderData& data : m_render_data) { - if (data.vbo_id == 0 || data.ibo_id == 0) - continue; - - GLenum mode; - switch (data.type) - { - default: - case EPrimitiveType::Triangles: { mode = GL_TRIANGLES; break; } - case EPrimitiveType::Lines: { mode = GL_LINES; break; } - case EPrimitiveType::LineStrip: { mode = GL_LINE_STRIP; break; } - case EPrimitiveType::LineLoop: { mode = GL_LINE_LOOP; break; } - } - - if (shader != nullptr) - shader->set_uniform("uniform_color", data.color); - else - glsafe(::glColor4fv(data.color.data())); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, data.vbo_id)); - if (position_id != -1) { - glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (GLvoid*)0)); - glsafe(::glEnableVertexAttribArray(position_id)); - } - if (normal_id != -1) { - glsafe(::glVertexAttribPointer(normal_id, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (GLvoid*)(3 * sizeof(float)))); - glsafe(::glEnableVertexAttribArray(normal_id)); - } - - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id)); - glsafe(::glDrawElementsInstanced(mode, static_cast(data.indices_count), GL_UNSIGNED_INT, (const void*)0, instances_count)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - - if (normal_id != -1) - glsafe(::glDisableVertexAttribArray(normal_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - } - - if (scales_id != -1) - glsafe(::glDisableVertexAttribArray(scales_id)); - if (offset_id != -1) - glsafe(::glDisableVertexAttribArray(offset_id)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE @@ -1221,7 +928,6 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance #endif // ENABLE_GLMODEL_STATISTICS } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool GLModel::send_to_gpu() { if (m_render_data.vbo_id > 0 || m_render_data.ibo_id > 0) { @@ -1361,27 +1067,6 @@ void GLModel::render_statistics() } #endif // ENABLE_GLMODEL_STATISTICS -#else -void GLModel::send_to_gpu(RenderData& data, const std::vector& vertices, const std::vector& indices) -{ - assert(data.vbo_id == 0); - assert(data.ibo_id == 0); - - // vertex data -> send to gpu - glsafe(::glGenBuffers(1, &data.vbo_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, data.vbo_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - - // indices data -> send to gpu - glsafe(::glGenBuffers(1, &data.ibo_id)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL template inline bool all_vertices_inside(const GLModel::Geometry& geometry, Fn fn) { @@ -1435,33 +1120,15 @@ bool contains(const BuildVolume& volume, const GLModel& model, bool ignore_botto return true; } } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, float tip_height, float stem_radius, float stem_height) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - auto append_vertex = [](GLModel::Geometry::Entity& entity, const Vec3f& position, const Vec3f& normal) { - entity.positions.emplace_back(position); - entity.normals.emplace_back(normal); - }; - auto append_indices = [](GLModel::Geometry::Entity& entity, unsigned int v1, unsigned int v2, unsigned int v3) { - entity.indices.emplace_back(v1); - entity.indices.emplace_back(v2); - entity.indices.emplace_back(v3); - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::max(4, resolution); GLModel::Geometry data; -#if ENABLE_LEGACY_OPENGL_REMOVAL data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(6 * resolution + 2); data.reserve_indices(6 * resolution * 3); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float angle_step = 2.0f * float(PI) / float(resolution); std::vector cosines(resolution); @@ -1476,7 +1143,6 @@ GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, floa const float total_height = tip_height + stem_height; // tip vertices/normals -#if ENABLE_LEGACY_OPENGL_REMOVAL data.add_vertex(Vec3f(0.0f, 0.0f, total_height), (Vec3f)Vec3f::UnitZ()); for (unsigned int i = 0; i < resolution; ++i) { data.add_vertex(Vec3f(tip_radius * sines[i], tip_radius * cosines[i], stem_height), Vec3f(sines[i], cosines[i], 0.0f)); @@ -1535,97 +1201,18 @@ GLModel::Geometry stilized_arrow(unsigned int resolution, float tip_radius, floa const unsigned int v3 = (i < resolution - 1) ? i + 5 * resolution + 3 : 5 * resolution + 2; data.add_triangle(5 * resolution + 1, v3, i + 5 * resolution + 2); } -#else - append_vertex(entity, { 0.0f, 0.0f, total_height }, Vec3f::UnitZ()); - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { tip_radius * sines[i], tip_radius * cosines[i], stem_height }, { sines[i], cosines[i], 0.0f }); - } - - // tip triangles - for (unsigned int i = 0; i < resolution; ++i) { - const int v3 = (i < resolution - 1) ? i + 2 : 1; - append_indices(entity, 0, i + 1, v3); - } - - // tip cap outer perimeter vertices - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { tip_radius * sines[i], tip_radius * cosines[i], stem_height }, -Vec3f::UnitZ()); - } - - // tip cap inner perimeter vertices - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { stem_radius * sines[i], stem_radius * cosines[i], stem_height }, -Vec3f::UnitZ()); - } - - // tip cap triangles - for (unsigned int i = 0; i < resolution; ++i) { - const unsigned int v2 = (i < resolution - 1) ? i + resolution + 2 : resolution + 1; - const unsigned int v3 = (i < resolution - 1) ? i + 2 * resolution + 2 : 2 * resolution + 1; - append_indices(entity, i + resolution + 1, v3, v2); - append_indices(entity, i + resolution + 1, i + 2 * resolution + 1, v3); - } - - // stem bottom vertices - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { stem_radius * sines[i], stem_radius * cosines[i], stem_height }, { sines[i], cosines[i], 0.0f }); - } - - // stem top vertices - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { stem_radius * sines[i], stem_radius * cosines[i], 0.0f }, { sines[i], cosines[i], 0.0f }); - } - - // stem triangles - for (unsigned int i = 0; i < resolution; ++i) { - const int unsigned v2 = (i < resolution - 1) ? i + 3 * resolution + 2 : 3 * resolution + 1; - const int unsigned v3 = (i < resolution - 1) ? i + 4 * resolution + 2 : 4 * resolution + 1; - append_indices(entity, i + 3 * resolution + 1, v3, v2); - append_indices(entity, i + 3 * resolution + 1, i + 4 * resolution + 1, v3); - } - - // stem cap vertices - append_vertex(entity, Vec3f::Zero(), -Vec3f::UnitZ()); - for (unsigned int i = 0; i < resolution; ++i) { - append_vertex(entity, { stem_radius * sines[i], stem_radius * cosines[i], 0.0f }, -Vec3f::UnitZ()); - } - - // stem cap triangles - for (unsigned int i = 0; i < resolution; ++i) { - const unsigned int v3 = (i < resolution - 1) ? i + 5 * resolution + 3 : 5 * resolution + 2; - append_indices(entity, 5 * resolution + 1, v3, i + 5 * resolution + 2); - } - - data.entities.emplace_back(entity); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return data; } GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float tip_height, float tip_width, float stem_width, float thickness) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - auto append_vertex = [](GLModel::Geometry::Entity& entity, const Vec3f& position, const Vec3f& normal) { - entity.positions.emplace_back(position); - entity.normals.emplace_back(normal); - }; - auto append_indices = [](GLModel::Geometry::Entity& entity, unsigned int v1, unsigned int v2, unsigned int v3) { - entity.indices.emplace_back(v1); - entity.indices.emplace_back(v2); - entity.indices.emplace_back(v3); - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - resolution = std::max(2, resolution); GLModel::Geometry data; -#if ENABLE_LEGACY_OPENGL_REMOVAL data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(8 * (resolution + 1) + 30); data.reserve_indices((8 * resolution + 16) * 3); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float half_thickness = 0.5f * thickness; const float half_stem_width = 0.5f * stem_width; @@ -1635,7 +1222,6 @@ GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float ti const float inner_radius = radius - half_stem_width; const float step_angle = 0.5f * float(PI) / float(resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL // tip // top face vertices data.add_vertex(Vec3f(0.0f, outer_radius, half_thickness), (Vec3f)Vec3f::UnitZ()); @@ -1779,187 +1365,22 @@ GLModel::Geometry circular_arrow(unsigned int resolution, float radius, float ti data.add_triangle(ii, ii + 1, ii + resolution + 2); data.add_triangle(ii, ii + resolution + 2, ii + resolution + 1); } -#else - // tip - // top face vertices - append_vertex(entity, { 0.0f, outer_radius, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, radius + half_tip_width, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { -tip_height, radius, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, radius - half_tip_width, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, inner_radius, half_thickness }, Vec3f::UnitZ()); - - // top face triangles - append_indices(entity, 0, 1, 2); - append_indices(entity, 0, 2, 4); - append_indices(entity, 4, 2, 3); - - // bottom face vertices - append_vertex(entity, { 0.0f, outer_radius, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, radius + half_tip_width, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { -tip_height, radius, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, radius - half_tip_width, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { 0.0f, inner_radius, -half_thickness }, -Vec3f::UnitZ()); - - // bottom face triangles - append_indices(entity, 5, 7, 6); - append_indices(entity, 5, 9, 7); - append_indices(entity, 9, 8, 7); - - // side faces vertices - append_vertex(entity, { 0.0f, outer_radius, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, radius + half_tip_width, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, outer_radius, half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, radius + half_tip_width, half_thickness }, Vec3f::UnitX()); - - Vec3f normal(-half_tip_width, tip_height, 0.0f); - normal.normalize(); - append_vertex(entity, { 0.0f, radius + half_tip_width, -half_thickness }, normal); - append_vertex(entity, { -tip_height, radius, -half_thickness }, normal); - append_vertex(entity, { 0.0f, radius + half_tip_width, half_thickness }, normal); - append_vertex(entity, { -tip_height, radius, half_thickness }, normal); - - normal = Vec3f(-half_tip_width, -tip_height, 0.0f); - normal.normalize(); - append_vertex(entity, { -tip_height, radius, -half_thickness }, normal); - append_vertex(entity, { 0.0f, radius - half_tip_width, -half_thickness }, normal); - append_vertex(entity, { -tip_height, radius, half_thickness }, normal); - append_vertex(entity, { 0.0f, radius - half_tip_width, half_thickness }, normal); - - append_vertex(entity, { 0.0f, radius - half_tip_width, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, inner_radius, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, radius - half_tip_width, half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { 0.0f, inner_radius, half_thickness }, Vec3f::UnitX()); - - // side face triangles - for (int i = 0; i < 4; ++i) { - const int ii = i * 4; - append_indices(entity, 10 + ii, 11 + ii, 13 + ii); - append_indices(entity, 10 + ii, 13 + ii, 12 + ii); - } - - // stem - // top face vertices - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - append_vertex(entity, { inner_radius * ::sin(angle), inner_radius * ::cos(angle), half_thickness }, Vec3f::UnitZ()); - } - - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - append_vertex(entity, { outer_radius * ::sin(angle), outer_radius * ::cos(angle), half_thickness }, Vec3f::UnitZ()); - } - - // top face triangles - for (unsigned int i = 0; i < resolution; ++i) { - append_indices(entity, 26 + i, 27 + i, 27 + resolution + i); - append_indices(entity, 27 + i, 28 + resolution + i, 27 + resolution + i); - } - - // bottom face vertices - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - append_vertex(entity, { inner_radius * ::sin(angle), inner_radius * ::cos(angle), -half_thickness }, -Vec3f::UnitZ()); - } - - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - append_vertex(entity, { outer_radius * ::sin(angle), outer_radius * ::cos(angle), -half_thickness }, -Vec3f::UnitZ()); - } - - // bottom face triangles - for (unsigned int i = 0; i < resolution; ++i) { - append_indices(entity, 28 + 2 * resolution + i, 29 + 3 * resolution + i, 29 + 2 * resolution + i); - append_indices(entity, 29 + 2 * resolution + i, 29 + 3 * resolution + i, 30 + 3 * resolution + i); - } - - // side faces vertices and triangles - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - const float c = ::cos(angle); - const float s = ::sin(angle); - append_vertex(entity, { inner_radius * s, inner_radius * c, -half_thickness }, { -s, -c, 0.0f }); - } - - for (unsigned int i = 0; i <= resolution; ++i) { - const float angle = static_cast(i) * step_angle; - const float c = ::cos(angle); - const float s = ::sin(angle); - append_vertex(entity, { inner_radius * s, inner_radius * c, half_thickness }, { -s, -c, 0.0f }); - } - - unsigned int first_id = 26 + 4 * (resolution + 1); - for (unsigned int i = 0; i < resolution; ++i) { - const unsigned int ii = first_id + i; - append_indices(entity, ii, ii + 1, ii + resolution + 2); - append_indices(entity, ii, ii + resolution + 2, ii + resolution + 1); - } - - append_vertex(entity, { inner_radius, 0.0f, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { outer_radius, 0.0f, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { inner_radius, 0.0f, half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { outer_radius, 0.0f, half_thickness }, -Vec3f::UnitY()); - - first_id = 26 + 6 * (resolution + 1); - append_indices(entity, first_id, first_id + 1, first_id + 3); - append_indices(entity, first_id, first_id + 3, first_id + 2); - - for (int i = int(resolution); i >= 0; --i) { - const float angle = static_cast(i) * step_angle; - const float c = ::cos(angle); - const float s = ::sin(angle); - append_vertex(entity, { outer_radius * s, outer_radius * c, -half_thickness }, { s, c, 0.0f }); - } - - for (int i = int(resolution); i >= 0; --i) { - const float angle = static_cast(i) * step_angle; - const float c = ::cos(angle); - const float s = ::sin(angle); - append_vertex(entity, { outer_radius * s, outer_radius * c, +half_thickness }, { s, c, 0.0f }); - } - - first_id = 30 + 6 * (resolution + 1); - for (unsigned int i = 0; i < resolution; ++i) { - const unsigned int ii = first_id + i; - append_indices(entity, ii, ii + 1, ii + resolution + 2); - append_indices(entity, ii, ii + resolution + 2, ii + resolution + 1); - } - - data.entities.emplace_back(entity); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return data; } GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_width, float stem_height, float thickness) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - auto append_vertex = [](GLModel::Geometry::Entity& entity, const Vec3f& position, const Vec3f& normal) { - entity.positions.emplace_back(position); - entity.normals.emplace_back(normal); - }; - auto append_indices = [](GLModel::Geometry::Entity& entity, unsigned int v1, unsigned int v2, unsigned int v3) { - entity.indices.emplace_back(v1); - entity.indices.emplace_back(v2); - entity.indices.emplace_back(v3); - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - GLModel::Geometry data; -#if ENABLE_LEGACY_OPENGL_REMOVAL data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(42); data.reserve_indices(72); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float half_thickness = 0.5f * thickness; const float half_stem_width = 0.5f * stem_width; const float half_tip_width = 0.5f * tip_width; const float total_height = tip_height + stem_height; -#if ENABLE_LEGACY_OPENGL_REMOVAL // top face vertices data.add_vertex(Vec3f(half_stem_width, 0.0f, half_thickness), (Vec3f)Vec3f::UnitZ()); data.add_vertex(Vec3f(half_stem_width, stem_height, half_thickness), (Vec3f)Vec3f::UnitZ()); @@ -2038,88 +1459,6 @@ GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_w data.add_triangle(14 + ii, 15 + ii, 17 + ii); data.add_triangle(14 + ii, 17 + ii, 16 + ii); } -#else - // top face vertices - append_vertex(entity, { half_stem_width, 0.0, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { half_stem_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { half_tip_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { 0.0, total_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { -half_tip_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { -half_stem_width, stem_height, half_thickness }, Vec3f::UnitZ()); - append_vertex(entity, { -half_stem_width, 0.0, half_thickness }, Vec3f::UnitZ()); - - // top face triangles - append_indices(entity, 0, 1, 6); - append_indices(entity, 6, 1, 5); - append_indices(entity, 4, 5, 3); - append_indices(entity, 5, 1, 3); - append_indices(entity, 1, 2, 3); - - // bottom face vertices - append_vertex(entity, { half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { 0.0, total_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { -half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitZ()); - append_vertex(entity, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitZ()); - - // bottom face triangles - append_indices(entity, 7, 13, 8); - append_indices(entity, 13, 12, 8); - append_indices(entity, 12, 11, 10); - append_indices(entity, 8, 12, 10); - append_indices(entity, 9, 8, 10); - - // side faces vertices - append_vertex(entity, { half_stem_width, 0.0, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { half_stem_width, stem_height, -half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { half_stem_width, 0.0, half_thickness }, Vec3f::UnitX()); - append_vertex(entity, { half_stem_width, stem_height, half_thickness }, Vec3f::UnitX()); - - append_vertex(entity, { half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_stem_width, stem_height, half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_tip_width, stem_height, half_thickness }, -Vec3f::UnitY()); - - Vec3f normal(tip_height, half_tip_width, 0.0f); - normal.normalize(); - append_vertex(entity, { half_tip_width, stem_height, -half_thickness }, normal); - append_vertex(entity, { 0.0, total_height, -half_thickness }, normal); - append_vertex(entity, { half_tip_width, stem_height, half_thickness }, normal); - append_vertex(entity, { 0.0, total_height, half_thickness }, normal); - - normal = Vec3f(-tip_height, half_tip_width, 0.0f); - normal.normalize(); - append_vertex(entity, { 0.0, total_height, -half_thickness }, normal); - append_vertex(entity, { -half_tip_width, stem_height, -half_thickness }, normal); - append_vertex(entity, { 0.0, total_height, half_thickness }, normal); - append_vertex(entity, { -half_tip_width, stem_height, half_thickness }, normal); - - append_vertex(entity, { -half_tip_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { -half_tip_width, stem_height, half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { -half_stem_width, stem_height, half_thickness }, -Vec3f::UnitY()); - - append_vertex(entity, { -half_stem_width, stem_height, -half_thickness }, -Vec3f::UnitX()); - append_vertex(entity, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitX()); - append_vertex(entity, { -half_stem_width, stem_height, half_thickness }, -Vec3f::UnitX()); - append_vertex(entity, { -half_stem_width, 0.0, half_thickness }, -Vec3f::UnitX()); - - append_vertex(entity, { -half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_stem_width, 0.0, -half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { -half_stem_width, 0.0, half_thickness }, -Vec3f::UnitY()); - append_vertex(entity, { half_stem_width, 0.0, half_thickness }, -Vec3f::UnitY()); - - // side face triangles - for (int i = 0; i < 7; ++i) { - const int ii = i * 4; - append_indices(entity, 14 + ii, 15 + ii, 17 + ii); - append_indices(entity, 14 + ii, 17 + ii, 16 + ii); - } - - data.entities.emplace_back(entity); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return data; } @@ -2129,18 +1468,12 @@ GLModel::Geometry diamond(unsigned int resolution) resolution = std::max(4, resolution); GLModel::Geometry data; -#if ENABLE_LEGACY_OPENGL_REMOVAL data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; data.reserve_vertices(resolution + 2); data.reserve_indices((2 * (resolution + 1)) * 3); -#else - GLModel::Geometry::Entity entity; - entity.type = GLModel::EPrimitiveType::Triangles; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float step = 2.0f * float(PI) / float(resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL // vertices for (unsigned int i = 0; i < resolution; ++i) { const float ii = float(i) * step; @@ -2164,48 +1497,10 @@ GLModel::Geometry diamond(unsigned int resolution) data.add_triangle(i + 0, resolution + 1, i + 1); } data.add_triangle(resolution - 1, resolution + 1, 0); -#else - // positions - for (unsigned int i = 0; i < resolution; ++i) { - const float ii = float(i) * step; - entity.positions.emplace_back(0.5f * ::cos(ii), 0.5f * ::sin(ii), 0.0f); - } - entity.positions.emplace_back(0.0f, 0.0f, 0.5f); - entity.positions.emplace_back(0.0f, 0.0f, -0.5f); - - // normals - for (const Vec3f& v : entity.positions) { - entity.normals.emplace_back(v.normalized()); - } - - // triangles - // top - for (unsigned int i = 0; i < resolution; ++i) { - entity.indices.push_back(i + 0); - entity.indices.push_back(i + 1); - entity.indices.push_back(resolution); - } - entity.indices.push_back(resolution - 1); - entity.indices.push_back(0); - entity.indices.push_back(resolution); - - // bottom - for (unsigned int i = 0; i < resolution; ++i) { - entity.indices.push_back(i + 0); - entity.indices.push_back(resolution + 1); - entity.indices.push_back(i + 1); - } - entity.indices.push_back(resolution - 1); - entity.indices.push_back(resolution + 1); - entity.indices.push_back(0); - - data.entities.emplace_back(entity); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return data; } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry smooth_sphere(unsigned int resolution, float radius) { resolution = std::max(4, resolution); @@ -2390,7 +1685,6 @@ GLModel::Geometry smooth_torus(unsigned int primary_resolution, unsigned int sec return data; } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GLModel.hpp b/src/slic3r/GUI/GLModel.hpp index 2d1e352c4..ef4ab6d47 100644 --- a/src/slic3r/GUI/GLModel.hpp +++ b/src/slic3r/GUI/GLModel.hpp @@ -15,37 +15,15 @@ namespace Slic3r { class TriangleMesh; class Polygon; using Polygons = std::vector; -#if ENABLE_LEGACY_OPENGL_REMOVAL class BuildVolume; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL namespace GUI { class GLModel { public: -#if !ENABLE_LEGACY_OPENGL_REMOVAL - enum class EPrimitiveType : unsigned char - { - Triangles, - Lines, - LineStrip, - LineLoop - }; - - struct RenderData - { - EPrimitiveType type; - unsigned int vbo_id{ 0 }; - unsigned int ibo_id{ 0 }; - size_t indices_count{ 0 }; - ColorRGBA color; - }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - struct Geometry { -#if ENABLE_LEGACY_OPENGL_REMOVAL enum class EPrimitiveType : unsigned char { Points, @@ -175,28 +153,8 @@ namespace GUI { #if ENABLE_OPENGL_ES static bool has_extra(const Format& format); #endif // ENABLE_OPENGL_ES -#else - struct Entity - { - EPrimitiveType type; - std::vector positions; - std::vector normals; - std::vector indices; - ColorRGBA color; - }; - - std::vector entities; - - size_t vertices_count() const; - size_t vertices_size_floats() const { return vertices_count() * 6; } - size_t vertices_size_bytes() const { return vertices_size_floats() * sizeof(float); } - - size_t indices_count() const; - size_t indices_size_bytes() const { return indices_count() * sizeof(unsigned int); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; -#if ENABLE_LEGACY_OPENGL_REMOVAL struct RenderData { Geometry geometry; @@ -208,10 +166,8 @@ namespace GUI { size_t vertices_count{ 0 }; size_t indices_count{ 0 }; }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GLMODEL_STATISTICS struct Statistics { @@ -245,9 +201,6 @@ namespace GUI { // enable_render() // to keep the data on cpu side until needed. bool m_render_disabled{ false }; -#else - std::vector m_render_data; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL BoundingBoxf3 m_bounding_box; std::string m_filename; @@ -255,7 +208,6 @@ namespace GUI { GLModel() = default; virtual ~GLModel() { reset(); } -#if ENABLE_LEGACY_OPENGL_REMOVAL size_t vertices_count() const { return m_render_data.vertices_count > 0 ? m_render_data.vertices_count : m_render_data.geometry.vertices_count(); } size_t indices_count() const { return m_render_data.indices_count > 0 ? @@ -274,42 +226,24 @@ namespace GUI { #else void init_from(const TriangleMesh& mesh); #endif // ENABLE_SMOOTH_NORMALS -#else - void init_from(const Geometry& data); - void init_from(const indexed_triangle_set& its, const BoundingBoxf3& bbox); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void init_from(const indexed_triangle_set& its); void init_from(const Polygons& polygons, float z); bool init_from_file(const std::string& filename); -#if ENABLE_LEGACY_OPENGL_REMOVAL void set_color(const ColorRGBA& color) { m_render_data.geometry.color = color; } const ColorRGBA& get_color() const { return m_render_data.geometry.color; } -#else - // if entity_id == -1 set the color of all entities - void set_color(int entity_id, const ColorRGBA& color); - ColorRGBA get_color(size_t entity_id = 0U) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void reset(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(); void render(const std::pair& range); void render_instanced(unsigned int instances_vbo, unsigned int instances_count); bool is_initialized() const { return vertices_count() > 0 && indices_count() > 0; } bool is_empty() const { return m_render_data.geometry.is_empty(); } -#else - void render() const; - void render_instanced(unsigned int instances_vbo, unsigned int instances_count) const; - - bool is_initialized() const { return !m_render_data.empty(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const BoundingBoxf3& get_bounding_box() const { return m_bounding_box; } const std::string& get_filename() const { return m_filename; } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool is_render_disabled() const { return m_render_disabled; } void enable_render() { m_render_disabled = false; } void disable_render() { m_render_disabled = true; } @@ -338,19 +272,12 @@ namespace GUI { s_statistics.render_instanced_calls = 0; } #endif // ENABLE_GLMODEL_STATISTICS -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: -#if ENABLE_LEGACY_OPENGL_REMOVAL bool send_to_gpu(); -#else - void send_to_gpu(RenderData& data, const std::vector& vertices, const std::vector& indices); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; -#if ENABLE_LEGACY_OPENGL_REMOVAL bool contains(const BuildVolume& volume, const GLModel& model, bool ignore_bottom = true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // create an arrow with cylindrical stem and conical tip, with the given dimensions and resolution // the origin of the arrow is in the center of the stem cap @@ -375,7 +302,6 @@ namespace GUI { // the diamond is contained into a box with size [1, 1, 1] GLModel::Geometry diamond(unsigned int resolution); -#if ENABLE_LEGACY_OPENGL_REMOVAL // create a sphere with smooth normals // the origin of the sphere is in its center GLModel::Geometry smooth_sphere(unsigned int resolution, float radius); @@ -387,7 +313,6 @@ namespace GUI { // the axis of the torus is the Z axis // the origin of the torus is in its center GLModel::Geometry smooth_torus(unsigned int primary_resolution, unsigned int secondary_resolution, float radius, float thickness); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index d4b474117..12f286ddb 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -60,7 +60,6 @@ namespace GUI { return; const Size cnv_size = canvas.get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const float cnv_width = (float)cnv_size.get_width(); const float cnv_height = (float)cnv_size.get_height(); if (cnv_width == 0.0f || cnv_height == 0.0f) @@ -72,49 +71,15 @@ namespace GUI { const float right = 2.0f * (get_right() * cnv_inv_width - 0.5f); const float top = -2.0f * (get_top() * cnv_inv_height - 0.5f); const float bottom = -2.0f * (get_bottom() * cnv_inv_height - 0.5f); -#else - const Camera& camera = wxGetApp().plater()->get_camera(); - const float inv_zoom = (float)camera.get_inv_zoom(); - - const float cnv_half_width = 0.5f * (float)cnv_size.get_width(); - const float cnv_half_height = 0.5f * (float)cnv_size.get_height(); - if (cnv_half_width == 0.0f || cnv_half_height == 0.0f) - return; - - const Vec2d start(m_start_corner.x() - cnv_half_width, cnv_half_height - m_start_corner.y()); - const Vec2d end(m_end_corner.x() - cnv_half_width, cnv_half_height - m_end_corner.y()); - - const float left = (float)std::min(start.x(), end.x()) * inv_zoom; - const float top = (float)std::max(start.y(), end.y()) * inv_zoom; - const float right = (float)std::max(start.x(), end.x()) * inv_zoom; - const float bottom = (float)std::min(start.y(), end.y()) * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE const bool core_profile = OpenGLManager::get_gl_info().is_core_profile(); if (!core_profile) #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(1.5f)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - float color[3]; - color[0] = (m_state == EState::Select) ? 0.3f : 1.0f; - color[1] = (m_state == EState::Select) ? 1.0f : 0.3f; - color[2] = 0.3f; - glsafe(::glColor3fv(color)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glDisable(GL_DEPTH_TEST)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - // ensure that the rectangle is renderered inside the frustrum - glsafe(::glTranslated(0.0, 0.0, -(camera.get_near_z() + 0.5))); - // ensure that the overlay fits the frustrum near z plane - const double gui_scale = camera.get_gui_scale(); - glsafe(::glScaled(gui_scale, gui_scale, 1.0)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #if !ENABLE_OPENGL_ES #if ENABLE_GL_CORE_PROFILE if (!core_profile) { @@ -127,7 +92,6 @@ namespace GUI { #endif // ENABLE_GL_CORE_PROFILE #endif // !ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #elif ENABLE_GL_CORE_PROFILE @@ -210,14 +174,6 @@ namespace GUI { m_rectangle.render(); shader->stop_using(); } -#else - ::glBegin(GL_LINE_LOOP); - ::glVertex2f((GLfloat)left, (GLfloat)bottom); - ::glVertex2f((GLfloat)right, (GLfloat)bottom); - ::glVertex2f((GLfloat)right, (GLfloat)top); - ::glVertex2f((GLfloat)left, (GLfloat)top); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_OPENGL_ES #if ENABLE_GL_CORE_PROFILE @@ -225,10 +181,6 @@ namespace GUI { #endif // ENABLE_GL_CORE_PROFILE glsafe(::glPopAttrib()); #endif // !ENABLE_OPENGL_ES - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } // namespace GUI diff --git a/src/slic3r/GUI/GLSelectionRectangle.hpp b/src/slic3r/GUI/GLSelectionRectangle.hpp index ac8abb6aa..e57e02e72 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.hpp +++ b/src/slic3r/GUI/GLSelectionRectangle.hpp @@ -2,9 +2,7 @@ #define slic3r_GLSelectionRectangle_hpp_ #include "libslic3r/Point.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "GLModel.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL namespace Slic3r { namespace GUI { @@ -51,11 +49,9 @@ private: EState m_state{ EState::Off }; Vec2d m_start_corner{ Vec2d::Zero() }; Vec2d m_end_corner{ Vec2d::Zero() }; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_rectangle; Vec2d m_old_start_corner{ Vec2d::Zero() }; Vec2d m_old_end_corner{ Vec2d::Zero() }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; diff --git a/src/slic3r/GUI/GLShadersManager.cpp b/src/slic3r/GUI/GLShadersManager.cpp index f0b91faf3..804d48971 100644 --- a/src/slic3r/GUI/GLShadersManager.cpp +++ b/src/slic3r/GUI/GLShadersManager.cpp @@ -36,7 +36,6 @@ std::pair GLShadersManager::init() bool valid = true; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_OPENGL_ES const std::string prefix = "ES/"; // used to render wireframed triangles @@ -62,73 +61,36 @@ std::pair GLShadersManager::init() // used to render thick and/or dashed lines valid &= append_shader("dashed_thick_lines", { prefix + "dashed_thick_lines.vs", prefix + "dashed_thick_lines.fs", prefix + "dashed_thick_lines.gs" }); #endif // ENABLE_OPENGL_ES -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // used to render toolpaths center of gravity -#if ENABLE_LEGACY_OPENGL_REMOVAL valid &= append_shader("toolpaths_cog", { prefix + "toolpaths_cog.vs", prefix + "toolpaths_cog.fs" }); -#else - valid &= append_shader("toolpaths_cog", { "toolpaths_cog.vs", "toolpaths_cog.fs" }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL // used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview valid &= append_shader("gouraud_light", { prefix + "gouraud_light.vs", prefix + "gouraud_light.fs" }); // used to render printbed valid &= append_shader("printbed", { prefix + "printbed.vs", prefix + "printbed.fs" }); -#else - // used to render bed axes and model, selection hints, gcode sequential view marker model, preview shells, options in gcode preview - valid &= append_shader("gouraud_light", { "gouraud_light.vs", "gouraud_light.fs" }); - // used to render printbed - valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // used to render options in gcode preview if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) { -#if ENABLE_LEGACY_OPENGL_REMOVAL valid &= append_shader("gouraud_light_instanced", { prefix + "gouraud_light_instanced.vs", prefix + "gouraud_light_instanced.fs" }); -#else - valid &= append_shader("gouraud_light_instanced", { "gouraud_light_instanced.vs", "gouraud_light_instanced.fs" }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL // used to render objects in 3d editor valid &= append_shader("gouraud", { prefix + "gouraud.vs", prefix + "gouraud.fs" } -#else - // used to render extrusion and travel paths as lines in gcode preview - valid &= append_shader("toolpaths_lines", { "toolpaths_lines.vs", "toolpaths_lines.fs" }); - // used to render objects in 3d editor - valid &= append_shader("gouraud", { "gouraud.vs", "gouraud.fs" } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_ENVIRONMENT_MAP , { "ENABLE_ENVIRONMENT_MAP"sv } #endif // ENABLE_ENVIRONMENT_MAP ); -#if ENABLE_LEGACY_OPENGL_REMOVAL // used to render variable layers heights in 3d editor valid &= append_shader("variable_layer_height", { prefix + "variable_layer_height.vs", prefix + "variable_layer_height.fs" }); // used to render highlight contour around selected triangles inside the multi-material gizmo valid &= append_shader("mm_contour", { prefix + "mm_contour.vs", prefix + "mm_contour.fs" }); -#else - // used to render variable layers heights in 3d editor - valid &= append_shader("variable_layer_height", { "variable_layer_height.vs", "variable_layer_height.fs" }); - // used to render highlight contour around selected triangles inside the multi-material gizmo - valid &= append_shader("mm_contour", { "mm_contour.vs", "mm_contour.fs" }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Used to render painted triangles inside the multi-material gizmo. Triangle normals are computed inside fragment shader. // For Apple's on Arm CPU computed triangle normals inside fragment shader using dFdx and dFdy has the opposite direction. // Because of this, objects had darker colors inside the multi-material gizmo. // Based on https://stackoverflow.com/a/66206648, the similar behavior was also spotted on some other devices with Arm CPU. // Since macOS 12 (Monterey), this issue with the opposite direction on Apple's Arm CPU seems to be fixed, and computed // triangle normals inside fragment shader have the right direction. -#if ENABLE_LEGACY_OPENGL_REMOVAL if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12) valid &= append_shader("mm_gouraud", { prefix + "mm_gouraud.vs", prefix + "mm_gouraud.fs" }, { "FLIP_TRIANGLE_NORMALS"sv }); else valid &= append_shader("mm_gouraud", { prefix + "mm_gouraud.vs", prefix + "mm_gouraud.fs" }); -#else - if (platform_flavor() == PlatformFlavor::OSXOnArm && wxPlatformInfo::Get().GetOSMajorVersion() < 12) - valid &= append_shader("mm_gouraud", {"mm_gouraud.vs", "mm_gouraud.fs"}, {"FLIP_TRIANGLE_NORMALS"sv}); - else - valid &= append_shader("mm_gouraud", {"mm_gouraud.vs", "mm_gouraud.fs"}); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL return { valid, error }; } diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index 2374b088b..07a2edbe2 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -3,10 +3,8 @@ #include "3DScene.hpp" #include "OpenGLManager.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "GUI_App.hpp" #include "GLModel.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "BitmapCache.hpp" #include @@ -342,7 +340,6 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right, glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id)); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry init_data; init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P2T2 }; init_data.reserve_vertices(4); @@ -364,21 +361,11 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right, GLShaderProgram* shader = wxGetApp().get_shader("flat_texture"); if (shader != nullptr) { shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("view_model_matrix", Transform3d::Identity()); shader->set_uniform("projection_matrix", Transform3d::Identity()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL model.render(); shader->stop_using(); } -#else - ::glBegin(GL_QUADS); - ::glTexCoord2f(uvs.left_bottom.u, uvs.left_bottom.v); ::glVertex2f(left, bottom); - ::glTexCoord2f(uvs.right_bottom.u, uvs.right_bottom.v); ::glVertex2f(right, bottom); - ::glTexCoord2f(uvs.right_top.u, uvs.right_top.v); ::glVertex2f(right, top); - ::glTexCoord2f(uvs.left_top.u, uvs.left_top.v); ::glVertex2f(left, top); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); diff --git a/src/slic3r/GUI/GLToolbar.cpp b/src/slic3r/GUI/GLToolbar.cpp index 9d7f621ba..76075e1af 100644 --- a/src/slic3r/GUI/GLToolbar.cpp +++ b/src/slic3r/GUI/GLToolbar.cpp @@ -85,11 +85,7 @@ bool GLToolbarItem::update_enabled_state() return ret; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbarItem::render(const GLCanvas3D& parent, unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const -#else -void GLToolbarItem::render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { auto uvs = [this](unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) -> GLTexture::Quad_UVs { assert(tex_width != 0 && tex_height != 0); @@ -118,7 +114,6 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b GLTexture::render_sub_texture(tex_id, left, right, bottom, top, uvs(tex_width, tex_height, icon_size)); if (is_pressed()) { -#if ENABLE_LEGACY_OPENGL_REMOVAL const Size cnv_size = parent.get_canvas_size(); const float cnv_w = (float)cnv_size.get_width(); const float cnv_h = (float)cnv_size.get_height(); @@ -131,12 +126,6 @@ void GLToolbarItem::render(unsigned int tex_id, float left, float right, float b m_data.left.render_callback(out_left, out_right, out_bottom, out_top); else if (m_last_action_type == Right && m_data.right.can_render()) m_data.right.render_callback(out_left, out_right, out_bottom, out_top); -#else - if (m_last_action_type == Left && m_data.left.can_render()) - m_data.left.render_callback(left, right, bottom, top); - else if (m_last_action_type == Right && m_data.right.can_render()) - m_data.right.render_callback(left, right, bottom, top); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } @@ -202,7 +191,6 @@ bool GLToolbar::init(const BackgroundTexture::Metadata& background_texture) return res; } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool GLToolbar::init_arrow(const std::string& filename) { if (m_arrow_texture.get_id() != 0) @@ -211,24 +199,6 @@ bool GLToolbar::init_arrow(const std::string& filename) const std::string path = resources_dir() + "/icons/"; return (!filename.empty()) ? m_arrow_texture.load_from_svg_file(path + filename, false, false, false, 512) : false; } -#else -bool GLToolbar::init_arrow(const BackgroundTexture::Metadata& arrow_texture) -{ - if (m_arrow_texture.texture.get_id() != 0) - return true; - - std::string path = resources_dir() + "/icons/"; - bool res = false; - - if (!arrow_texture.filename.empty()) - res = m_arrow_texture.texture.load_from_svg_file(path + arrow_texture.filename, false, false, false, 1000); - - if (res) - m_arrow_texture.metadata = arrow_texture; - - return res; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLToolbar::Layout::EType GLToolbar::get_layout_type() const { @@ -693,7 +663,6 @@ void GLToolbar::update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent) } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) { const Size cnv_size = parent.get_canvas_size(); @@ -891,224 +860,6 @@ void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& } } } -#else -void GLToolbar::update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent) -{ - // NB: mouse_pos is already scaled appropriately - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = m_layout.scale * inv_zoom; - - Size cnv_size = parent.get_canvas_size(); - Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left + scaled_border; - float top = m_layout.top - scaled_border; - - for (GLToolbarItem* item : m_items) - { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - left += separator_stride; - else - { - float right = left + scaled_icons_size; - float bottom = top - scaled_icons_size; - - GLToolbarItem::EState state = item->get_state(); - bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top); - - switch (state) - { - case GLToolbarItem::Normal: - { - if (inside) - { - item->set_state(GLToolbarItem::Hover); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Hover: - { - if (!inside) - { - item->set_state(GLToolbarItem::Normal); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Pressed: - { - if (inside) - { - item->set_state(GLToolbarItem::HoverPressed); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::HoverPressed: - { - if (!inside) - { - item->set_state(GLToolbarItem::Pressed); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Disabled: - { - if (inside) - { - item->set_state(GLToolbarItem::HoverDisabled); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::HoverDisabled: - { - if (!inside) - { - item->set_state(GLToolbarItem::Disabled); - parent.set_as_dirty(); - } - - break; - } - default: - { - break; - } - } - - left += icon_stride; - } - } -} - -void GLToolbar::update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent) -{ - // NB: mouse_pos is already scaled appropriately - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = m_layout.scale * inv_zoom; - - Size cnv_size = parent.get_canvas_size(); - Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left + scaled_border; - float top = m_layout.top - scaled_border; - - for (GLToolbarItem* item : m_items) - { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - top -= separator_stride; - else - { - float right = left + scaled_icons_size; - float bottom = top - scaled_icons_size; - - GLToolbarItem::EState state = item->get_state(); - bool inside = (left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top); - - switch (state) - { - case GLToolbarItem::Normal: - { - if (inside) - { - item->set_state(GLToolbarItem::Hover); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Hover: - { - if (!inside) - { - item->set_state(GLToolbarItem::Normal); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Pressed: - { - if (inside) - { - item->set_state(GLToolbarItem::HoverPressed); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::HoverPressed: - { - if (!inside) - { - item->set_state(GLToolbarItem::Pressed); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::Disabled: - { - if (inside) - { - item->set_state(GLToolbarItem::HoverDisabled); - parent.set_as_dirty(); - } - - break; - } - case GLToolbarItem::HoverDisabled: - { - if (!inside) - { - item->set_state(GLToolbarItem::Disabled); - parent.set_as_dirty(); - } - - break; - } - default: - { - break; - } - } - - top -= icon_stride; - } - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLToolbarItem* GLToolbar::get_item(const std::string& item_name) { @@ -1135,7 +886,6 @@ int GLToolbar::contains_mouse(const Vec2d& mouse_pos, const GLCanvas3D& parent) } } -#if ENABLE_LEGACY_OPENGL_REMOVAL int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const { const Size cnv_size = parent.get_canvas_size(); @@ -1283,154 +1033,7 @@ int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& return -1; } -#else -int GLToolbar::contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const -{ - // NB: mouse_pos is already scaled appropriately - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = m_layout.scale * inv_zoom; - - Size cnv_size = parent.get_canvas_size(); - Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - - float left = m_layout.left + scaled_border; - float top = m_layout.top - scaled_border; - - - for (size_t id=0; idis_visible()) - continue; - - if (item->is_separator()) - { - float right = left + scaled_separator_size; - float bottom = top - scaled_icons_size; - - // mouse inside the separator - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return id; - - left = right; - right += scaled_gap_size; - - if (id < m_items.size() - 1) - { - // mouse inside the gap - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return -2; - } - - left = right; - } - else - { - float right = left + scaled_icons_size; - float bottom = top - scaled_icons_size; - - // mouse inside the icon - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return id; - - left = right; - right += scaled_gap_size; - - if (id < m_items.size() - 1) - { - // mouse inside the gap - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return -2; - } - - left = right; - } - } - - return -1; -} - -int GLToolbar::contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const -{ - // NB: mouse_pos is already scaled appropriately - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = m_layout.scale * inv_zoom; - - Size cnv_size = parent.get_canvas_size(); - Vec2d scaled_mouse_pos((mouse_pos(0) - 0.5 * (double)cnv_size.get_width()) * inv_zoom, (0.5 * (double)cnv_size.get_height() - mouse_pos(1)) * inv_zoom); - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - - float left = m_layout.left + scaled_border; - float top = m_layout.top - scaled_border; - - for (size_t id=0; idis_visible()) - continue; - - if (item->is_separator()) - { - float right = left + scaled_icons_size; - float bottom = top - scaled_separator_size; - - // mouse inside the separator - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return id; - - top = bottom; - bottom -= scaled_gap_size; - - if (id < m_items.size() - 1) - { - // mouse inside the gap - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return -2; - } - - top = bottom; - } - else - { - float right = left + scaled_icons_size; - float bottom = top - scaled_icons_size; - - // mouse inside the icon - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return id; - - top = bottom; - bottom -= scaled_gap_size; - - if (id < m_items.size() - 1) - { - // mouse inside the gap - if ((left <= (float)scaled_mouse_pos(0)) && ((float)scaled_mouse_pos(0) <= right) && (bottom <= (float)scaled_mouse_pos(1)) && ((float)scaled_mouse_pos(1) <= top)) - return -2; - } - - top = bottom; - } - } - - return -1; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbar::render_background(float left, float top, float right, float bottom, float border_w, float border_h) const { const unsigned int tex_id = m_background_texture.texture.get_id(); @@ -1507,86 +1110,7 @@ void GLToolbar::render_background(float left, float top, float right, float bott GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); } } -#else -void GLToolbar::render_background(float left, float top, float right, float bottom, float border) const -{ - unsigned int tex_id = m_background_texture.texture.get_id(); - float tex_width = (float)m_background_texture.texture.get_width(); - float tex_height = (float)m_background_texture.texture.get_height(); - if (tex_id != 0 && tex_width > 0 && tex_height > 0) { - float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f; - float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f; - float internal_left = left + border; - float internal_right = right - border; - float internal_top = top - border; - float internal_bottom = bottom + border; - - float left_uv = 0.0f; - float right_uv = 1.0f; - float top_uv = 1.0f; - float bottom_uv = 0.0f; - - float internal_left_uv = (float)m_background_texture.metadata.left * inv_tex_width; - float internal_right_uv = 1.0f - (float)m_background_texture.metadata.right * inv_tex_width; - float internal_top_uv = 1.0f - (float)m_background_texture.metadata.top * inv_tex_height; - float internal_bottom_uv = (float)m_background_texture.metadata.bottom * inv_tex_height; - - // top-left corner - if ((m_layout.horizontal_orientation == Layout::HO_Left) || (m_layout.vertical_orientation == Layout::VO_Top)) - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { left_uv, internal_top_uv }, { internal_left_uv, internal_top_uv }, { internal_left_uv, top_uv }, { left_uv, top_uv } }); - - // top edge - if (m_layout.vertical_orientation == Layout::VO_Top) - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, top_uv }, { internal_left_uv, top_uv } }); - - // top-right corner - if ((m_layout.horizontal_orientation == Layout::HO_Right) || (m_layout.vertical_orientation == Layout::VO_Top)) - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_right_uv, internal_top_uv }, { right_uv, internal_top_uv }, { right_uv, top_uv }, { internal_right_uv, top_uv } }); - - // center-left edge - if (m_layout.horizontal_orientation == Layout::HO_Left) - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { left_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv }, { internal_left_uv, internal_top_uv }, { left_uv, internal_top_uv } }); - - // center - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // center-right edge - if (m_layout.horizontal_orientation == Layout::HO_Right) - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_right_uv, internal_bottom_uv }, { right_uv, internal_bottom_uv }, { right_uv, internal_top_uv }, { internal_right_uv, internal_top_uv } }); - - // bottom-left corner - if ((m_layout.horizontal_orientation == Layout::HO_Left) || (m_layout.vertical_orientation == Layout::VO_Bottom)) - GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { left_uv, bottom_uv }, { internal_left_uv, bottom_uv }, { internal_left_uv, internal_bottom_uv }, { left_uv, internal_bottom_uv } }); - - // bottom edge - if (m_layout.vertical_orientation == Layout::VO_Bottom) - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, bottom_uv }, { internal_right_uv, bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } }); - - // bottom-right corner - if ((m_layout.horizontal_orientation == Layout::HO_Right) || (m_layout.vertical_orientation == Layout::VO_Bottom)) - GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - else - GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item) { // arrow texture not initialized @@ -1655,75 +1179,7 @@ void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighte GLTexture::render_sub_texture(tex_id, left, right, bottom, top, { { left_uv, top_uv }, { right_uv, top_uv }, { right_uv, bottom_uv }, { left_uv, bottom_uv } }); } } -#else -void GLToolbar::render_arrow(const GLCanvas3D& parent, GLToolbarItem* highlighted_item) -{ - // arrow texture not initialized - if (m_arrow_texture.texture.get_id() == 0) - return; - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = inv_zoom * m_layout.scale; - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float border = m_layout.border * factor; - - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left; - float top = m_layout.top - icon_stride; - - bool found = false; - for (const GLToolbarItem* item : m_items) { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - left += separator_stride; - else { - if (item->get_name() == highlighted_item->get_name()) { - found = true; - break; - } - left += icon_stride; - } - } - if (!found) - return; - - left += border; - top -= separator_stride; - float right = left + scaled_icons_size; - - unsigned int tex_id = m_arrow_texture.texture.get_id(); - // arrow width and height - float arr_tex_width = (float)m_arrow_texture.texture.get_width(); - float arr_tex_height = (float)m_arrow_texture.texture.get_height(); - if ((tex_id != 0) && (arr_tex_width > 0) && (arr_tex_height > 0)) { - float inv_tex_width = (arr_tex_width != 0.0f) ? 1.0f / arr_tex_width : 0.0f; - float inv_tex_height = (arr_tex_height != 0.0f) ? 1.0f / arr_tex_height : 0.0f; - - float internal_left = left + border - scaled_icons_size * 1.5f; // add scaled_icons_size for huge arrow - float internal_right = right - border + scaled_icons_size * 1.5f; - float internal_top = top - border; - // bottom is not moving and should be calculated from arrow texture sides ratio - float arrow_sides_ratio = (float)m_arrow_texture.texture.get_height() / (float)m_arrow_texture.texture.get_width(); - float internal_bottom = internal_top - (internal_right - internal_left) * arrow_sides_ratio ; - - float internal_left_uv = (float)m_arrow_texture.metadata.left * inv_tex_width; - float internal_right_uv = 1.0f - (float)m_arrow_texture.metadata.right * inv_tex_width; - float internal_top_uv = 1.0f - (float)m_arrow_texture.metadata.top * inv_tex_height; - float internal_bottom_uv = (float)m_arrow_texture.metadata.bottom * inv_tex_height; - - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } }); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLToolbar::render_horizontal(const GLCanvas3D& parent) { const Size cnv_size = parent.get_canvas_size(); @@ -1833,101 +1289,6 @@ void GLToolbar::render_vertical(const GLCanvas3D& parent) } } } -#else -void GLToolbar::render_horizontal(const GLCanvas3D& parent) -{ - unsigned int tex_id = m_icons_texture.get_id(); - int tex_width = m_icons_texture.get_width(); - int tex_height = m_icons_texture.get_height(); - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = inv_zoom * m_layout.scale; - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - float scaled_width = get_width() * inv_zoom; - float scaled_height = get_height() * inv_zoom; - - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left; - float top = m_layout.top; - float right = left + scaled_width; - float bottom = top - scaled_height; - - render_background(left, top, right, bottom, scaled_border); - - left += scaled_border; - top -= scaled_border; - - if ((tex_id == 0) || (tex_width <= 0) || (tex_height <= 0)) - return; - - // renders icons - for (const GLToolbarItem* item : m_items) - { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - left += separator_stride; - else - { - item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); - left += icon_stride; - } - } -} - -void GLToolbar::render_vertical(const GLCanvas3D& parent) -{ - unsigned int tex_id = m_icons_texture.get_id(); - int tex_width = m_icons_texture.get_width(); - int tex_height = m_icons_texture.get_height(); - - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float factor = inv_zoom * m_layout.scale; - - float scaled_icons_size = m_layout.icons_size * factor; - float scaled_separator_size = m_layout.separator_size * factor; - float scaled_gap_size = m_layout.gap_size * factor; - float scaled_border = m_layout.border * factor; - float scaled_width = get_width() * inv_zoom; - float scaled_height = get_height() * inv_zoom; - - float separator_stride = scaled_separator_size + scaled_gap_size; - float icon_stride = scaled_icons_size + scaled_gap_size; - - float left = m_layout.left; - float top = m_layout.top; - float right = left + scaled_width; - float bottom = top - scaled_height; - - render_background(left, top, right, bottom, scaled_border); - - left += scaled_border; - top -= scaled_border; - - if (tex_id == 0 || tex_width <= 0 || tex_height <= 0) - return; - - // renders icons - for (const GLToolbarItem* item : m_items) { - if (!item->is_visible()) - continue; - - if (item->is_separator()) - top -= separator_stride; - else { - item->render(tex_id, left, left + scaled_icons_size, top - scaled_icons_size, top, (unsigned int)tex_width, (unsigned int)tex_height, (unsigned int)(m_layout.icons_size * m_layout.scale)); - top -= icon_stride; - } - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL bool GLToolbar::generate_icons_texture() { diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index 1a836164c..6961827ce 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -153,11 +153,7 @@ public: // returns true if the state changes bool update_enabled_state(); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(const GLCanvas3D& parent, unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; -#else - void render(unsigned int tex_id, float left, float right, float bottom, float top, unsigned int tex_width, unsigned int tex_height, unsigned int icon_size) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: void set_visible(bool visible) { m_data.visible = visible; } @@ -251,11 +247,7 @@ private: GLTexture m_icons_texture; bool m_icons_texture_dirty; BackgroundTexture m_background_texture; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLTexture m_arrow_texture; -#else - BackgroundTexture m_arrow_texture; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL Layout m_layout; ItemsList m_items; @@ -282,11 +274,7 @@ public: bool init(const BackgroundTexture::Metadata& background_texture); -#if ENABLE_LEGACY_OPENGL_REMOVAL bool init_arrow(const std::string& filename); -#else - bool init_arrow(const BackgroundTexture::Metadata& arrow_texture); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL Layout::EType get_layout_type() const; void set_layout_type(Layout::EType type); @@ -357,11 +345,7 @@ private: int contains_mouse_horizontal(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; int contains_mouse_vertical(const Vec2d& mouse_pos, const GLCanvas3D& parent) const; -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_background(float left, float top, float right, float bottom, float border_w, float border_h) const; -#else - void render_background(float left, float top, float right, float bottom, float border) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void render_horizontal(const GLCanvas3D& parent); void render_vertical(const GLCanvas3D& parent); diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index 8265cb75e..a08673e23 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -289,12 +289,7 @@ static void generate_thumbnail_from_model(const std::string& filename) GLVolumeCollection volumes; volumes.volumes.push_back(new GLVolume()); GLVolume* volume = volumes.volumes.back(); -#if ENABLE_LEGACY_OPENGL_REMOVAL volume->model.init_from(model.mesh()); -#else - volume->indexed_vertex_array.load_mesh(model.mesh()); - volume->indexed_vertex_array.finalize_geometry(true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL volume->set_instance_transformation(model.objects[0]->instances[0]->get_transformation()); volume->set_volume_transformation(model.objects[0]->volumes[0]->get_transformation()); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index a3829fc21..322c63151 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -5,9 +5,7 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/GUI_ObjectManipulation.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // TODO: Display tooltips quicker on Linux @@ -55,23 +53,17 @@ void GLGizmoBase::Grabber::unregister_raycasters_for_picking() void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) { -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_current_shader(); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (!s_cube.model.is_initialized()) { // This cannot be done in constructor, OpenGL is not yet // initialized at that point (on Linux at least). indexed_triangle_set its = its_make_cube(1.0, 1.0, 1.0); its_translate(its, -0.5f * Vec3f::Ones()); -#if ENABLE_LEGACY_OPENGL_REMOVAL s_cube.model.init_from(its); s_cube.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); -#else - s_cube.init_from(its, BoundingBoxf3{ { -0.5, -0.5, -0.5 }, { 0.5, 0.5, 0.5 } }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } if (!s_cone.model.is_initialized()) { @@ -82,7 +74,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) const float half_size = dragging ? get_dragging_half_size(size) : get_half_size(size); -#if ENABLE_LEGACY_OPENGL_REMOVAL s_cube.model.set_color(render_color); s_cone.model.set_color(render_color); @@ -97,16 +88,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) shader->set_uniform("view_model_matrix", view_model_matrix); Matrix3d view_normal_matrix = view_matrix_no_offset * elements_matrices[0].matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - s_cube.set_color(-1, render_color); - s_cone.set_color(-1, render_color); - glsafe(::glPushMatrix()); - glsafe(::glTranslated(center.x(), center.y(), center.z())); - glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0)); - glsafe(::glRotated(Geometry::rad2deg(angles.y()), 0.0, 1.0, 0.0)); - glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0)); - glsafe(::glScaled(2.0 * half_size, 2.0 * half_size, 2.0 * half_size)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL s_cube.model.render(); auto render_extension = [&view_matrix, &view_matrix_no_offset, shader](const Transform3d& matrix) { @@ -117,7 +98,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) s_cone.model.render(); }; -#if ENABLE_LEGACY_OPENGL_REMOVAL if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) { elements_matrices[1] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, 0.5 * double(PI), 0.0 }); render_extension(elements_matrices[1]); @@ -142,52 +122,6 @@ void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) elements_matrices[6] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitZ()) * Geometry::rotation_transform({ double(PI), 0.0, 0.0 }); render_extension(elements_matrices[6]); } -#else - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(1.0, 0.0, 0.0)); - glsafe(::glRotated(0.5 * Geometry::rad2deg(double(PI)), 0.0, 1.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegX)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(-1.0, 0.0, 0.0)); - glsafe(::glRotated(-0.5 * Geometry::rad2deg(double(PI)), 0.0, 1.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosY)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 1.0, 0.0)); - glsafe(::glRotated(-0.5 * Geometry::rad2deg(double(PI)), 1.0, 0.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegY)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, -1.0, 0.0)); - glsafe(::glRotated(0.5 * Geometry::rad2deg(double(PI)), 1.0, 0.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosZ)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, 1.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } - if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegZ)) != 0) { - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, -1.0)); - glsafe(::glRotated(Geometry::rad2deg(double(PI)), 1.0, 0.0, 0.0)); - s_cone.render(); - glsafe(::glPopMatrix()); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL if (raycasters[0] == nullptr) { GLCanvas3D& canvas = *wxGetApp().plater()->canvas3D(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index 3c3f5c287..38d8c2661 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -66,9 +66,7 @@ protected: bool dragging{ false }; Vec3d center{ Vec3d::Zero() }; Vec3d angles{ Vec3d::Zero() }; -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d matrix{ Transform3d::Identity() }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA color{ ColorRGBA::WHITE() }; EGrabberExtension extensions{ EGrabberExtension::None }; // the picking id shared by all the elements diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 542aceead..be04d804d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -535,28 +535,16 @@ void GLGizmoEmboss::on_render() { if (m_temp_transformation.has_value()) { // draw text volume on temporary position -#if ENABLE_LEGACY_OPENGL_REMOVAL GLVolume& gl_volume = *selection.get_volume(*selection.get_volume_idxs().begin()); -#else - const GLVolume& gl_volume = *selection.get_volume(*selection.get_volume_idxs().begin()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(m_temp_transformation->data())); - GLShaderProgram *shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d matrix = camera.get_view_matrix() * (*m_temp_transformation); shader->set_uniform("view_model_matrix", matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_normal_matrix", (Matrix3d) (matrix).matrix().block(0, 0, 3, 3).inverse().transpose()); shader->set_uniform("emission_factor", 0.0f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // dragging object must be selected so draw it with correct color //auto color = gl_volume.color; @@ -569,25 +557,15 @@ void GLGizmoEmboss::on_render() { glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - shader->set_uniform("uniform_color", color); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL gl_volume.model.set_color(color); gl_volume.model.render(); -#else - gl_volume.indexed_vertex_array.render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glDisable(GL_DEPTH_TEST)); if (is_transparent) glsafe(::glDisable(GL_BLEND)); shader->stop_using(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } bool is_surface_dragging = m_temp_transformation.has_value(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp index 463eb3182..a1bbe84e9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp @@ -1,10 +1,8 @@ // Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. #include "GLGizmoFlatten.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" @@ -100,13 +98,11 @@ void GLGizmoFlatten::on_render() { const Selection& selection = m_parent.get_selection(); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); if (shader == nullptr) return; shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); @@ -115,42 +111,25 @@ void GLGizmoFlatten::on_render() if (selection.is_single_full_instance()) { const Transform3d& inst_matrix = selection.get_first_volume()->get_instance_transformation().get_matrix(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d model_matrix = Geometry::translation_transform(selection.get_first_volume()->get_sla_shift_z() * Vec3d::UnitZ()) * inst_matrix; const Transform3d view_model_matrix = camera.get_view_matrix() * model_matrix; shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(0.f, 0.f, selection.get_first_volume()->get_sla_shift_z())); - glsafe(::glMultMatrixd(inst_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (this->is_plane_update_necessary()) update_planes(); for (int i = 0; i < (int)m_planes.size(); ++i) { -#if ENABLE_LEGACY_OPENGL_REMOVAL m_planes_casters[i]->set_transform(model_matrix); m_planes[i].vbo.model.set_color(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR : DEFAULT_PLANE_COLOR); m_planes[i].vbo.model.render(); -#else - glsafe(::glColor4fv(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR.data() : DEFAULT_PLANE_COLOR.data())); - if (m_planes[i].vbo.has_VBOs()) - m_planes[i].vbo.render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glDisable(GL_BLEND)); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLGizmoFlatten::on_register_raycasters_for_picking() @@ -395,7 +374,6 @@ void GLGizmoFlatten::update_planes() // And finally create respective VBOs. The polygon is convex with // the vertices in order, so triangulation is trivial. for (auto& plane : m_planes) { -#if ENABLE_LEGACY_OPENGL_REMOVAL indexed_triangle_set its; its.vertices.reserve(plane.vertices.size()); its.indices.reserve(plane.vertices.size() / 3); @@ -407,14 +385,6 @@ void GLGizmoFlatten::update_planes() } plane.vbo.model.init_from(its); plane.vbo.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); -#else - plane.vbo.reserve(plane.vertices.size()); - for (const auto& vert : plane.vertices) - plane.vbo.push_geometry(vert, plane.normal); - for (size_t i=1; i vertices; // should be in fact local in update_planes() -#if ENABLE_LEGACY_OPENGL_REMOVAL PickingModel vbo; -#else - GLIndexedVertexArray vbo; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL Vec3d normal; float area; int picking_id{ -1 }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index be04fb92c..99994f7b6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -117,24 +117,16 @@ void GLGizmoHollow::on_unregister_raycasters_for_picking() void GLGizmoHollow::render_points(const Selection& selection) { -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); if (shader == nullptr) return; shader->start_using(); ScopeGuard guard([shader]() { shader->stop_using(); }); -#else - GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light"); - if (shader) - shader->start_using(); - ScopeGuard guard([shader]() { if (shader) shader->stop_using(); }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const GLVolume* vol = selection.get_first_volume(); const Transform3d trafo = vol->world_matrix(); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_scaling_factor_matrix().inverse(); #else @@ -143,14 +135,6 @@ void GLGizmoHollow::render_points(const Selection& selection) const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#else - const Transform3d& instance_scaling_matrix_inverse = trafo.get_matrix(true, true, false, true).inverse(); - const Transform3d& instance_matrix = trafo.get_matrix(); - - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, m_c->selection_info()->get_sla_shift())); - glsafe(::glMultMatrixd(instance_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA render_color; const sla::DrainHoles& drain_holes = m_c->selection_info()->model_object()->sla_drain_holes; @@ -176,17 +160,9 @@ void GLGizmoHollow::render_points(const Selection& selection) else render_color = point_selected ? ColorRGBA(1.0f, 0.3f, 0.3f, 0.5f) : ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_cylinder.model.set_color(render_color); // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. const Transform3d hole_matrix = Geometry::translation_transform(drain_hole.pos.cast()) * instance_scaling_matrix_inverse; -#else - const_cast(&m_cylinder)->set_color(-1, render_color); - // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z())); - glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CW)); @@ -195,30 +171,16 @@ void GLGizmoHollow::render_points(const Selection& selection) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast()); const Eigen::AngleAxisd aa(q); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = trafo * hole_matrix * Transform3d(aa.toRotationMatrix()) * Geometry::translation_transform(-drain_hole.height * Vec3d::UnitZ()) * Geometry::scale_transform(Vec3d(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); - glsafe(::glTranslated(0., 0., -drain_hole.height)); - glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_cylinder.model.render(); if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CCW)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } bool GLGizmoHollow::is_mesh_point_clipped(const Vec3d& point) const diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index 8c67014b6..fd7963050 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -193,26 +193,16 @@ void GLGizmoMmuSegmentation::render_triangles(const Selection &selection) const if (is_left_handed) glsafe(::glFrontFace(GL_CW)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix * trafo_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * trafo_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("volume_world_matrix", trafo_matrix); shader->set_uniform("volume_mirrored", is_left_handed); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_triangle_selectors[mesh_id]->render(m_imgui, trafo_matrix); -#else - m_triangle_selectors[mesh_id]->render(m_imgui); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (is_left_handed) glsafe(::glFrontFace(GL_CCW)); @@ -582,11 +572,7 @@ ColorRGBA GLGizmoMmuSegmentation::get_cursor_sphere_right_button_color() const return color; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void TriangleSelectorMmGui::render(ImGuiWrapper* imgui, const Transform3d& matrix) -#else -void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (m_update_render_data) update_render_data(); @@ -595,14 +581,12 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) if (!shader) return; assert(shader->get_name() == "mm_gouraud"); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix * matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (size_t color_idx = 0; color_idx < m_gizmo_scene.triangle_indices.size(); ++color_idx) { if (m_gizmo_scene.has_VBOs(color_idx)) { @@ -615,21 +599,7 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) } } -#if ENABLE_LEGACY_OPENGL_REMOVAL render_paint_contour(matrix); -#else - if (m_paint_contour.has_VBO()) { - ScopeGuard guard_mm_gouraud([shader]() { shader->start_using(); }); - shader->stop_using(); - - auto *contour_shader = wxGetApp().get_shader("mm_contour"); - contour_shader->start_using(); - contour_shader->set_uniform("offset", OpenGLManager::get_gl_info().is_mesa() ? 0.0005 : 0.00001); - m_paint_contour.render(); - contour_shader->stop_using(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - m_update_render_data = false; } @@ -662,29 +632,7 @@ void TriangleSelectorMmGui::update_render_data() m_gizmo_scene.triangle_indices_sizes[color_idx] = m_gizmo_scene.triangle_indices[color_idx].size(); m_gizmo_scene.finalize_triangle_indices(); - -#if ENABLE_LEGACY_OPENGL_REMOVAL update_paint_contour(); -#else - m_paint_contour.release_geometry(); - std::vector contour_edges = this->get_seed_fill_contour(); - m_paint_contour.contour_vertices.reserve(contour_edges.size() * 6); - for (const Vec2i &edge : contour_edges) { - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.x()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.y()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.z()); - - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.x()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.y()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.z()); - } - - m_paint_contour.contour_indices.assign(m_paint_contour.contour_vertices.size() / 3, 0); - std::iota(m_paint_contour.contour_indices.begin(), m_paint_contour.contour_indices.end(), 0); - m_paint_contour.contour_indices_size = m_paint_contour.contour_indices.size(); - - m_paint_contour.finalize_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } wxString GLGizmoMmuSegmentation::handle_snapshot_action_name(bool shift_down, GLGizmoPainterBase::Button button_down) const @@ -729,11 +677,9 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const assert(this->vertices_VBO_id != 0); assert(this->triangle_indices_VBO_ids[triangle_indices_idx] != 0); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_current_shader(); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) @@ -741,7 +687,6 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const // the following binding is needed to set the vertex attributes #endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const GLint position_id = shader->get_attrib_location("v_position"); if (position_id != -1) { glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (GLvoid*)0)); @@ -751,24 +696,13 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const // Render using the Vertex Buffer Objects. if (this->triangle_indices_VBO_ids[triangle_indices_idx] != 0 && this->triangle_indices_sizes[triangle_indices_idx] > 0) { -#else - glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), (const void*)(0 * sizeof(float)))); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - // Render using the Vertex Buffer Objects. - if (this->triangle_indices_sizes[triangle_indices_idx] > 0) { -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_ids[triangle_indices_idx])); glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_sizes[triangle_indices_idx]), GL_UNSIGNED_INT, nullptr)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } -#if ENABLE_LEGACY_OPENGL_REMOVAL if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); -#else - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); #if ENABLE_GL_CORE_PROFILE diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp index 502db6ebc..67eccd8e8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp @@ -69,13 +69,7 @@ public: : TriangleSelectorGUI(mesh), m_colors(colors), m_default_volume_color(default_volume_color), m_gizmo_scene(2 * (colors.size() + 1)) {} ~TriangleSelectorMmGui() override = default; -#if ENABLE_LEGACY_OPENGL_REMOVAL void render(ImGuiWrapper* imgui, const Transform3d& matrix) override; -#else - // Render current selection. Transformation matrices are supposed - // to be already set. - void render(ImGuiWrapper* imgui) override; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL private: void update_render_data(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index bb5ebfd26..69fcc5414 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -5,9 +5,7 @@ #if ENABLE_WORLD_COORDINATE #include "slic3r/GUI/GUI_ObjectManipulation.hpp" #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/Model.hpp" #include @@ -151,18 +149,11 @@ void GLGizmoMove3D::on_render() glsafe(::glEnable(GL_DEPTH_TEST)); #if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL calc_selection_box_and_center(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d base_matrix = local_transform(m_parent.get_selection()); for (int i = 0; i < 3; ++i) { m_grabbers[i].matrix = base_matrix; } -#else - transform_to_local(m_parent.get_selection()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const Vec3d zero = Vec3d::Zero(); const Vec3d half_box_size = 0.5 * m_bounding_box.size(); @@ -201,7 +192,6 @@ void GLGizmoMove3D::on_render() #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE auto render_grabber_connection = [this, &zero](unsigned int id) { #else @@ -240,10 +230,8 @@ void GLGizmoMove3D::on_render() m_grabber_connections[id].model.render(); } }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (m_hover_id == -1) { -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); #else @@ -264,31 +252,14 @@ void GLGizmoMove3D::on_render() shader->set_uniform("width", 0.25f); shader->set_uniform("gap_size", 0.0f); #endif // ENABLE_GL_CORE_PROFILE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // draw axes for (unsigned int i = 0; i < 3; ++i) { -#if ENABLE_LEGACY_OPENGL_REMOVAL render_grabber_connection(i); -#else - if (m_grabbers[i].enabled) { - glsafe(::glColor4fv(AXES_COLOR[i].data())); - ::glBegin(GL_LINES); -#if ENABLE_WORLD_COORDINATE - ::glVertex3dv(zero.data()); -#else - ::glVertex3dv(center.data()); -#endif // ENABLE_WORLD_COORDINATE - ::glVertex3dv(m_grabbers[i].center.data()); - glsafe(::glEnd()); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // draw grabbers #if ENABLE_WORLD_COORDINATE @@ -299,7 +270,6 @@ void GLGizmoMove3D::on_render() } else { // draw axis -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); #else @@ -327,19 +297,6 @@ void GLGizmoMove3D::on_render() } shader = wxGetApp().get_shader("gouraud_light"); -#else - glsafe(::glColor4fv(AXES_COLOR[m_hover_id].data())); - ::glBegin(GL_LINES); -#if ENABLE_WORLD_COORDINATE - ::glVertex3dv(zero.data()); -#else - ::glVertex3dv(center.data()); -#endif // ENABLE_WORLD_COORDINATE - ::glVertex3dv(m_grabbers[m_hover_id].center.data()); - glsafe(::glEnd()); - - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -354,12 +311,6 @@ void GLGizmoMove3D::on_render() shader->stop_using(); } } - -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE } void GLGizmoMove3D::on_register_raycasters_for_picking() @@ -400,7 +351,6 @@ double GLGizmoMove3D::calc_projection(const UpdateData& data) const } #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d GLGizmoMove3D::local_transform(const Selection& selection) const { Transform3d ret = Geometry::translation_transform(m_center); @@ -413,20 +363,6 @@ Transform3d GLGizmoMove3D::local_transform(const Selection& selection) const } return ret; } -#else -void GLGizmoMove3D::transform_to_local(const Selection& selection) const -{ - glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z())); - - if (!wxGetApp().obj_manipul()->is_world_coordinates()) { - const GLVolume& v = *selection.get_first_volume(); - Transform3d orient_matrix = v.get_instance_transformation().get_matrix(true, false, true, true); - if (selection.is_single_volume_or_modifier() && wxGetApp().obj_manipul()->is_local_coordinates()) - orient_matrix = orient_matrix * v.get_volume_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoMove3D::calc_selection_box_and_center() { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp index 3a69e86ef..5f1d562e9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp @@ -25,14 +25,12 @@ class GLGizmoMove3D : public GLGizmoBase Vec3d m_starting_box_center{ Vec3d::Zero() }; Vec3d m_starting_box_bottom_center{ Vec3d::Zero() }; -#if ENABLE_LEGACY_OPENGL_REMOVAL struct GrabberConnection { GLModel model; Vec3d old_center{ Vec3d::Zero() }; }; std::array m_grabber_connections; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL public: GLGizmoMove3D(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); @@ -68,11 +66,7 @@ protected: private: double calc_projection(const UpdateData& data) const; #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d local_transform(const Selection& selection) const; -#else - void transform_to_local(const Selection& selection) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void calc_selection_box_and_center(); #endif // ENABLE_WORLD_COORDINATE }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp index 154d1f1be..8d2633774 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp @@ -19,11 +19,7 @@ namespace Slic3r::GUI { -#if ENABLE_LEGACY_OPENGL_REMOVAL std::shared_ptr GLGizmoPainterBase::s_sphere = nullptr; -#else -std::shared_ptr GLGizmoPainterBase::s_sphere = nullptr; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) @@ -32,13 +28,8 @@ GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& ic GLGizmoPainterBase::~GLGizmoPainterBase() { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (s_sphere != nullptr) s_sphere.reset(); -#else - if (s_sphere != nullptr && s_sphere->has_VBOs()) - s_sphere->release_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } void GLGizmoPainterBase::data_changed() @@ -106,17 +97,12 @@ void GLGizmoPainterBase::render_triangles(const Selection& selection) const if (is_left_handed) glsafe(::glFrontFace(GL_CW)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix * trafo_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * trafo_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // For printers with multiple extruders, it is necessary to pass trafo_matrix // to the shader input variable print_box.volume_world_matrix before @@ -124,13 +110,7 @@ void GLGizmoPainterBase::render_triangles(const Selection& selection) const // wrong transformation matrix is used for "Clipping of view". shader->set_uniform("volume_world_matrix", trafo_matrix); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_triangle_selectors[mesh_id]->render(m_imgui, trafo_matrix); -#else - m_triangle_selectors[mesh_id]->render(m_imgui); - - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (is_left_handed) glsafe(::glFrontFace(GL_CCW)); } @@ -165,14 +145,7 @@ void GLGizmoPainterBase::render_cursor() void GLGizmoPainterBase::render_cursor_circle() { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const Camera &camera = wxGetApp().plater()->get_camera(); - const float zoom = float(camera.get_zoom()); - const float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - const Size cnv_size = m_parent.get_canvas_size(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const float cnv_width = float(cnv_size.get_width()); const float cnv_height = float(cnv_size.get_height()); if (cnv_width == 0.0f || cnv_height == 0.0f) @@ -188,43 +161,19 @@ void GLGizmoPainterBase::render_cursor_circle() #else const float radius = m_cursor_radius * float(wxGetApp().plater()->get_camera().get_zoom()); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#else - const float cnv_half_width = 0.5f * float(cnv_size.get_width()); - const float cnv_half_height = 0.5f * float(cnv_size.get_height()); - if (cnv_half_width == 0.0f || cnv_half_height == 0.0f) - return; - const Vec2d mouse_pos(m_parent.get_local_mouse_position().x(), m_parent.get_local_mouse_position().y()); - Vec2d center(mouse_pos.x() - cnv_half_width, cnv_half_height - mouse_pos.y()); - center = center * inv_zoom; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (!OpenGLManager::get_gl_info().is_core_profile()) #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(1.5f)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - static const std::array color = { 0.f, 1.f, 0.3f }; - glsafe(::glColor3fv(color.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glDisable(GL_DEPTH_TEST)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - // ensure that the circle is renderered inside the frustrum - glsafe(::glTranslated(0.0, 0.0, -(camera.get_near_z() + 0.5))); - // ensure that the overlay fits the frustrum near z plane - const double gui_scale = camera.get_gui_scale(); - glsafe(::glScaled(gui_scale, gui_scale, 1.0)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #if !ENABLE_GL_CORE_PROFILE && !ENABLE_OPENGL_ES glsafe(::glPushAttrib(GL_ENABLE_BIT)); glsafe(::glLineStipple(4, 0xAAAA)); glsafe(::glEnable(GL_LINE_STIPPLE)); #endif // !ENABLE_GL_CORE_PROFILE && !ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES if (!m_circle.is_initialized() || std::abs(m_old_cursor_radius - radius) > EPSILON) { m_old_cursor_radius = radius; @@ -299,19 +248,10 @@ void GLGizmoPainterBase::render_cursor_circle() m_circle.render(); shader->stop_using(); } -#else - ::glBegin(GL_LINE_LOOP); - for (double angle=0; angle<2*M_PI; angle+=M_PI/20.) - ::glVertex2f(GLfloat(center.x()+m_cursor_radius*cos(angle)), GLfloat(center.y()+m_cursor_radius*sin(angle))); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_GL_CORE_PROFILE && !ENABLE_OPENGL_ES glsafe(::glPopAttrib()); #endif // !ENABLE_GL_CORE_PROFILE && !ENABLE_OPENGL_ES -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); } @@ -319,21 +259,13 @@ void GLGizmoPainterBase::render_cursor_circle() void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const { if (s_sphere == nullptr) { -#if ENABLE_LEGACY_OPENGL_REMOVAL s_sphere = std::make_shared(); s_sphere->init_from(its_make_sphere(1.0, double(PI) / 12.0)); -#else - s_sphere = std::make_shared(); - s_sphere->load_its_flat_shading(its_make_sphere(1.0, double(PI) / 12.0)); - s_sphere->finalize_geometry(true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE const Transform3d complete_scaling_matrix_inverse = Geometry::Transformation(trafo).get_scaling_factor_matrix().inverse(); @@ -342,15 +274,6 @@ void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const #endif // ENABLE_WORLD_COORDINATE const bool is_left_handed = Geometry::Transformation(trafo).is_left_handed(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo.data())); - // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. - glsafe(::glTranslatef(m_rr.hit.x(), m_rr.hit.y(), m_rr.hit.z())); - glsafe(::glMultMatrixd(complete_scaling_matrix_inverse.data())); - glsafe(::glScaled(m_cursor_radius, m_cursor_radius, m_cursor_radius)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - if (is_left_handed) glsafe(::glFrontFace(GL_CW)); @@ -359,7 +282,7 @@ void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const render_color = this->get_cursor_sphere_left_button_color(); else if (m_button_down == Button::Right) render_color = this->get_cursor_sphere_right_button_color(); -#if ENABLE_LEGACY_OPENGL_REMOVAL + shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); @@ -372,23 +295,12 @@ void GLGizmoPainterBase::render_cursor_sphere(const Transform3d& trafo) const assert(s_sphere != nullptr); s_sphere->set_color(render_color); -#else - glsafe(::glColor4fv(render_color.data())); - - assert(s_sphere != nullptr); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL s_sphere->render(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (is_left_handed) glsafe(::glFrontFace(GL_CCW)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } @@ -967,11 +879,7 @@ ColorRGBA TriangleSelectorGUI::get_seed_fill_color(const ColorRGBA& base_color) return saturate(base_color, 0.75f); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void TriangleSelectorGUI::render(ImGuiWrapper* imgui, const Transform3d& matrix) -#else -void TriangleSelectorGUI::render(ImGuiWrapper* imgui) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { static const ColorRGBA enforcers_color = { 0.47f, 0.47f, 1.0f, 1.0f }; static const ColorRGBA blockers_color = { 1.0f, 0.44f, 0.44f, 1.0f }; @@ -989,18 +897,10 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui) for (auto iva : {std::make_pair(&m_iva_enforcers, enforcers_color), std::make_pair(&m_iva_blockers, blockers_color)}) { -#if ENABLE_LEGACY_OPENGL_REMOVAL iva.first->set_color(iva.second); iva.first->render(); -#else - if (iva.first->has_VBOs()) { - shader->set_uniform("uniform_color", iva.second); - iva.first->render(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (auto& iva : m_iva_seed_fills) { size_t color_idx = &iva - &m_iva_seed_fills.front(); const ColorRGBA& color = TriangleSelectorGUI::get_seed_fill_color(color_idx == 1 ? enforcers_color : @@ -1009,32 +909,8 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui) iva.set_color(color); iva.render(); } -#else - for (auto& iva : m_iva_seed_fills) - if (iva.has_VBOs()) { - size_t color_idx = &iva - &m_iva_seed_fills.front(); - const ColorRGBA& color = TriangleSelectorGUI::get_seed_fill_color(color_idx == 1 ? enforcers_color : - color_idx == 2 ? blockers_color : - GLVolume::NEUTRAL_COLOR); - shader->set_uniform("uniform_color", color); - iva.render(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL render_paint_contour(matrix); -#else - if (m_paint_contour.has_VBO()) { - ScopeGuard guard_gouraud([shader]() { shader->start_using(); }); - shader->stop_using(); - - auto *contour_shader = wxGetApp().get_shader("mm_contour"); - contour_shader->start_using(); - contour_shader->set_uniform("offset", OpenGLManager::get_gl_info().is_mesa() ? 0.0005 : 0.00001); - m_paint_contour.render(); - contour_shader->stop_using(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG if (imgui) @@ -1050,7 +926,6 @@ void TriangleSelectorGUI::update_render_data() int blc_cnt = 0; std::vector seed_fill_cnt(m_iva_seed_fills.size(), 0); -#if ENABLE_LEGACY_OPENGL_REMOVAL for (auto* iva : { &m_iva_enforcers, &m_iva_blockers }) { iva->reset(); } @@ -1066,13 +941,6 @@ void TriangleSelectorGUI::update_render_data() std::array iva_seed_fills_data; for (auto& data : iva_seed_fills_data) data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3 }; -#else - for (auto *iva : {&m_iva_enforcers, &m_iva_blockers}) - iva->release_geometry(); - - for (auto &iva : m_iva_seed_fills) - iva.release_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // small value used to offset triangles along their normal to avoid z-fighting static const float offset = 0.001f; @@ -1082,15 +950,9 @@ void TriangleSelectorGUI::update_render_data() continue; int tr_state = int(tr.get_state()); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel::Geometry &iva = tr.is_selected_by_seed_fill() ? iva_seed_fills_data[tr_state] : tr.get_state() == EnforcerBlockerType::ENFORCER ? iva_enforcers_data : iva_blockers_data; -#else - GLIndexedVertexArray &iva = tr.is_selected_by_seed_fill() ? m_iva_seed_fills[tr_state] : - tr.get_state() == EnforcerBlockerType::ENFORCER ? m_iva_enforcers : - m_iva_blockers; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL int &cnt = tr.is_selected_by_seed_fill() ? seed_fill_cnt[tr_state] : tr.get_state() == EnforcerBlockerType::ENFORCER ? enf_cnt : blc_cnt; @@ -1102,21 +964,13 @@ void TriangleSelectorGUI::update_render_data() const Vec3f n = (v1 - v0).cross(v2 - v1).normalized(); // small value used to offset triangles along their normal to avoid z-fighting const Vec3f offset_n = offset * n; -#if ENABLE_LEGACY_OPENGL_REMOVAL iva.add_vertex(v0 + offset_n, n); iva.add_vertex(v1 + offset_n, n); iva.add_vertex(v2 + offset_n, n); iva.add_triangle((unsigned int)cnt, (unsigned int)cnt + 1, (unsigned int)cnt + 2); -#else - iva.push_geometry(v0 + offset_n, n); - iva.push_geometry(v1 + offset_n, n); - iva.push_geometry(v2 + offset_n, n); - iva.push_triangle(cnt, cnt + 1, cnt + 2); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL cnt += 3; } -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!iva_enforcers_data.is_empty()) m_iva_enforcers.init_from(std::move(iva_enforcers_data)); if (!iva_blockers_data.is_empty()) @@ -1127,94 +981,8 @@ void TriangleSelectorGUI::update_render_data() } update_paint_contour(); -#else - for (auto *iva : {&m_iva_enforcers, &m_iva_blockers}) - iva->finalize_geometry(true); - - for (auto &iva : m_iva_seed_fills) - iva.finalize_geometry(true); - - m_paint_contour.release_geometry(); - std::vector contour_edges = this->get_seed_fill_contour(); - m_paint_contour.contour_vertices.reserve(contour_edges.size() * 6); - for (const Vec2i &edge : contour_edges) { - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.x()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.y()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(0)].v.z()); - - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.x()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.y()); - m_paint_contour.contour_vertices.emplace_back(m_vertices[edge(1)].v.z()); - } - - m_paint_contour.contour_indices.assign(m_paint_contour.contour_vertices.size() / 3, 0); - std::iota(m_paint_contour.contour_indices.begin(), m_paint_contour.contour_indices.end(), 0); - m_paint_contour.contour_indices_size = m_paint_contour.contour_indices.size(); - - m_paint_contour.finalize_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void GLPaintContour::render() const -{ - assert(m_contour_VBO_id != 0); - assert(m_contour_EBO_id != 0); - - glsafe(::glLineWidth(4.0f)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_contour_VBO_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), nullptr)); - - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - - if (this->contour_indices_size > 0) { - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_contour_EBO_id)); - glsafe(::glDrawElements(GL_LINES, GLsizei(this->contour_indices_size), GL_UNSIGNED_INT, nullptr)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - } - - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -} - -void GLPaintContour::finalize_geometry() -{ - assert(m_contour_VBO_id == 0); - assert(m_contour_EBO_id == 0); - - if (!this->contour_vertices.empty()) { - glsafe(::glGenBuffers(1, &m_contour_VBO_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_contour_VBO_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, this->contour_vertices.size() * sizeof(float), this->contour_vertices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - this->contour_vertices.clear(); - } - - if (!this->contour_indices.empty()) { - glsafe(::glGenBuffers(1, &m_contour_EBO_id)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_contour_EBO_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->contour_indices.size() * sizeof(unsigned int), this->contour_indices.data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - this->contour_indices.clear(); - } -} - -void GLPaintContour::release_geometry() -{ - if (m_contour_VBO_id) { - glsafe(::glDeleteBuffers(1, &m_contour_VBO_id)); - m_contour_VBO_id = 0; - } - if (m_contour_EBO_id) { - glsafe(::glDeleteBuffers(1, &m_contour_EBO_id)); - m_contour_EBO_id = 0; - } - this->clear(); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) { @@ -1250,91 +1018,48 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) INVALID }; -#if ENABLE_LEGACY_OPENGL_REMOVAL for (auto& va : m_varrays) va.reset(); -#else - for (auto& va : m_varrays) - va.release_geometry(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL std::array cnts; ::glScalef(1.01f, 1.01f, 1.01f); -#if ENABLE_LEGACY_OPENGL_REMOVAL std::array varrays_data; for (auto& data : varrays_data) data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::UINT }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (int tr_id=0; tr_idadd_vertex(m_vertices[tr.verts_idxs[i]].v, Vec3f(0.0f, 0.0f, 1.0f)); } va->add_uint_triangle((unsigned int)*cnt, (unsigned int)*cnt + 1, (unsigned int)*cnt + 2); -#else - for (int i = 0; i < 3; ++i) - va->push_geometry(double(m_vertices[tr.verts_idxs[i]].v[0]), - double(m_vertices[tr.verts_idxs[i]].v[1]), - double(m_vertices[tr.verts_idxs[i]].v[2]), - 0., 0., 1.); - va->push_triangle(*cnt, - *cnt + 1, - *cnt + 2); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL *cnt += 3; } -#if ENABLE_LEGACY_OPENGL_REMOVAL for (int i = 0; i < 3; ++i) { if (!varrays_data[i].is_empty()) m_varrays[i].init_from(std::move(varrays_data[i])); } -#else -// for (auto* iva : { &m_iva_enforcers, &m_iva_blockers }) -// iva->finalize_geometry(true); -// -// for (auto& iva : m_iva_seed_fills) -// iva.finalize_geometry(true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); if (curr_shader != nullptr) curr_shader->stop_using(); @@ -1346,11 +1071,9 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ::glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); for (vtype i : {ORIGINAL, SPLIT, INVALID}) { -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel& va = m_varrays[i]; switch (i) { case ORIGINAL: va.set_color({ 0.0f, 0.0f, 1.0f, 1.0f }); break; @@ -1358,32 +1081,17 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) case INVALID: va.set_color({ 1.0f, 1.0f, 0.0f, 1.0f }); break; } va.render(); -#else - GLIndexedVertexArray& va = m_varrays[i]; - va.finalize_geometry(true); - if (va.has_VBOs()) { - switch (i) { - case ORIGINAL : ::glColor3f(0.f, 0.f, 1.f); break; - case SPLIT : ::glColor3f(1.f, 0.f, 0.f); break; - case INVALID : ::glColor3f(1.f, 1.f, 0.f); break; - } - va.render(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } ::glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); } if (curr_shader != nullptr) curr_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } #endif // PRUSASLICER_TRIANGLE_SELECTOR_DEBUG -#if ENABLE_LEGACY_OPENGL_REMOVAL void TriangleSelectorGUI::update_paint_contour() { m_paint_contour.reset(); @@ -1430,6 +1138,5 @@ void TriangleSelectorGUI::render_paint_contour(const Transform3d& matrix) if (curr_shader != nullptr) curr_shader->start_using(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp index d4261761f..44c7f40ab 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp @@ -3,11 +3,7 @@ #include "GLGizmoBase.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GLModel.hpp" -#else -#include "slic3r/GUI/3DScene.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/ObjectID.hpp" #include "libslic3r/TriangleSelector.hpp" @@ -33,59 +29,14 @@ enum class PainterGizmoType { MMU_SEGMENTATION }; -#if !ENABLE_LEGACY_OPENGL_REMOVAL -class GLPaintContour -{ -public: - GLPaintContour() = default; - - void render() const; - - inline bool has_VBO() const { return m_contour_EBO_id != 0; } - - // Release the geometry data, release OpenGL VBOs. - void release_geometry(); - - // Finalize the initialization of the contour geometry and the indices, upload both to OpenGL VBO objects - // and possibly releasing it if it has been loaded into the VBOs. - void finalize_geometry(); - - void clear() - { - this->contour_vertices.clear(); - this->contour_indices.clear(); - this->contour_indices_size = 0; - } - - std::vector contour_vertices; - std::vector contour_indices; - - // When the triangle indices are loaded into the graphics card as Vertex Buffer Objects, - // the above mentioned std::vectors are cleared and the following variables keep their original length. - size_t contour_indices_size{0}; - - // IDs of the Vertex Array Objects, into which the geometry has been loaded. - // Zero if the VBOs are not sent to GPU yet. - GLuint m_contour_VBO_id{0}; - GLuint m_contour_EBO_id{0}; -}; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - class TriangleSelectorGUI : public TriangleSelector { public: explicit TriangleSelectorGUI(const TriangleMesh& mesh) : TriangleSelector(mesh) {} virtual ~TriangleSelectorGUI() = default; -#if ENABLE_LEGACY_OPENGL_REMOVAL virtual void render(ImGuiWrapper* imgui, const Transform3d& matrix); void render(const Transform3d& matrix) { this->render(nullptr, matrix); } -#else - // Render current selection. Transformation matrices are supposed - // to be already set. - virtual void render(ImGuiWrapper *imgui); - void render() { this->render(nullptr); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void request_update_render_data() { m_update_render_data = true; } @@ -103,29 +54,18 @@ protected: private: void update_render_data(); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_iva_enforcers; GLModel m_iva_blockers; std::array m_iva_seed_fills; #ifdef PRUSASLICER_TRIANGLE_SELECTOR_DEBUG std::array m_varrays; #endif // PRUSASLICER_TRIANGLE_SELECTOR_DEBUG -#else - GLIndexedVertexArray m_iva_enforcers; - GLIndexedVertexArray m_iva_blockers; - std::array m_iva_seed_fills; - std::array m_varrays; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL protected: -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_paint_contour; void update_paint_contour(); void render_paint_contour(const Transform3d& matrix); -#else - GLPaintContour m_paint_contour; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL }; @@ -208,13 +148,11 @@ protected: bool m_paint_on_overhangs_only = false; float m_highlight_by_angle_threshold_deg = 0.f; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_circle; #if !ENABLE_GL_CORE_PROFILE Vec2d m_old_center{ Vec2d::Zero() }; #endif // !ENABLE_GL_CORE_PROFILE float m_old_cursor_radius{ 0.0f }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL static constexpr float SmartFillAngleMin = 0.0f; static constexpr float SmartFillAngleMax = 90.f; @@ -248,11 +186,7 @@ private: const Camera& camera, const std::vector& trafo_matrices) const; -#if ENABLE_LEGACY_OPENGL_REMOVAL static std::shared_ptr s_sphere; -#else - static std::shared_ptr s_sphere; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL bool m_internal_stack_active = false; bool m_schedule_update = false; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 5b39c0929..6e7cf9c83 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -179,18 +179,13 @@ void GLGizmoRotate::on_render() glsafe(::glEnable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_grabbers.front().matrix = local_transform(selection); -#else - glsafe(::glPushMatrix()); - transform_to_local(selection); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (!OpenGLManager::get_gl_info().is_core_profile()) #endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); -#if ENABLE_LEGACY_OPENGL_REMOVAL + #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); #else @@ -228,32 +223,12 @@ void GLGizmoRotate::on_render() render_grabber_connection(color, radius_changed); shader->stop_using(); } -#else - glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data())); - - render_circle(); - - if (m_hover_id != -1) { - render_scale(); - render_snap_radii(); - render_reference_radius(); - } - - glsafe(::glColor4fv(m_highlight_color.data())); - - if (m_hover_id != -1) - render_angle(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE render_grabber(m_bounding_box); #else render_grabber(box); #endif // ENABLE_WORLD_COORDINATE - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } #if ENABLE_WORLD_COORDINATE @@ -336,13 +311,8 @@ void GLGizmoRotate3D::load_rotoptimize_state() } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_circle(const ColorRGBA& color, bool radius_changed) -#else -void GLGizmoRotate::render_circle() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_circle.is_initialized() || radius_changed) { m_circle.reset(); @@ -363,29 +333,13 @@ void GLGizmoRotate::render_circle() const m_circle.set_color(color); m_circle.render(); -#else - ::glBegin(GL_LINE_LOOP); - for (unsigned int i = 0; i < ScaleStepsCount; ++i) { - const float angle = float(i) * ScaleStepRad; - const float x = ::cos(angle) * m_radius; - const float y = ::sin(angle) * m_radius; - const float z = 0.0f; - ::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z); - } - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_scale(const ColorRGBA& color, bool radius_changed) -#else -void GLGizmoRotate::render_scale() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { const float out_radius_long = m_snap_fine_out_radius; const float out_radius_short = m_radius * (1.0f + 0.5f * ScaleLongTooth); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_scale.is_initialized() || radius_changed) { m_scale.reset(); @@ -417,36 +371,14 @@ void GLGizmoRotate::render_scale() const m_scale.set_color(color); m_scale.render(); -#else - ::glBegin(GL_LINES); - for (unsigned int i = 0; i < ScaleStepsCount; ++i) { - const float angle = (float)i * ScaleStepRad; - const float cosa = ::cos(angle); - const float sina = ::sin(angle); - const float in_x = cosa * m_radius; - const float in_y = sina * m_radius; - const float in_z = 0.0f; - const float out_x = (i % ScaleLongEvery == 0) ? cosa * out_radius_long : cosa * out_radius_short; - const float out_y = (i % ScaleLongEvery == 0) ? sina * out_radius_long : sina * out_radius_short; - const float out_z = 0.0f; - ::glVertex3f((GLfloat)in_x, (GLfloat)in_y, (GLfloat)in_z); - ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z); - } - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_snap_radii(const ColorRGBA& color, bool radius_changed) -#else -void GLGizmoRotate::render_snap_radii() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { const float step = 2.0f * float(PI) / float(SnapRegionsCount); const float in_radius = m_radius / 3.0f; const float out_radius = 2.0f * in_radius; -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_snap_radii.is_initialized() || radius_changed) { m_snap_radii.reset(); @@ -478,26 +410,8 @@ void GLGizmoRotate::render_snap_radii() const m_snap_radii.set_color(color); m_snap_radii.render(); -#else - ::glBegin(GL_LINES); - for (unsigned int i = 0; i < SnapRegionsCount; ++i) { - const float angle = (float)i * step; - const float cosa = ::cos(angle); - const float sina = ::sin(angle); - const float in_x = cosa * in_radius; - const float in_y = sina * in_radius; - const float in_z = 0.0f; - const float out_x = cosa * out_radius; - const float out_y = sina * out_radius; - const float out_z = 0.0f; - ::glVertex3f((GLfloat)in_x, (GLfloat)in_y, (GLfloat)in_z); - ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z); - } - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_changed) { if (!m_reference_radius.is_initialized() || radius_changed) { @@ -521,26 +435,12 @@ void GLGizmoRotate::render_reference_radius(const ColorRGBA& color, bool radius_ m_reference_radius.set_color(color); m_reference_radius.render(); } -#else -void GLGizmoRotate::render_reference_radius() const -{ - ::glBegin(GL_LINES); - ::glVertex3f(0.0f, 0.0f, 0.0f); - ::glVertex3f((GLfloat)(m_radius * (1.0f + GrabberOffset)), 0.0f, 0.0f); - glsafe(::glEnd()); -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_angle_arc(const ColorRGBA& color, bool radius_changed) -#else -void GLGizmoRotate::render_angle() const -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { const float step_angle = float(m_angle) / float(AngleResolution); const float ex_radius = m_radius * (1.0f + GrabberOffset); -#if ENABLE_LEGACY_OPENGL_REMOVAL const bool angle_changed = std::abs(m_old_angle - m_angle) > EPSILON; m_old_angle = m_angle; @@ -565,20 +465,8 @@ void GLGizmoRotate::render_angle() const m_angle_arc.set_color(color); m_angle_arc.render(); -#else - ::glBegin(GL_LINE_STRIP); - for (unsigned int i = 0; i <= AngleResolution; ++i) { - const float angle = float(i) * step_angle; - const float x = ::cos(angle) * ex_radius; - const float y = ::sin(angle) * ex_radius; - const float z = 0.0f; - ::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z); - } - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radius_changed) { if (!m_grabber_connection.model.is_initialized() || radius_changed || !m_grabber_connection.old_center.isApprox(m_grabbers.front().center)) { @@ -603,28 +491,13 @@ void GLGizmoRotate::render_grabber_connection(const ColorRGBA& color, bool radiu m_grabber_connection.model.set_color(color); m_grabber_connection.model.render(); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const double grabber_radius = double(m_radius) * (1.0 + double(GrabberOffset)); - m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0); - m_grabbers[0].angles.z() = m_angle; - - glsafe(::glColor4fv((m_hover_id != -1) ? m_drag_color.data() : m_highlight_color.data())); - - ::glBegin(GL_LINES); - ::glVertex3f(0.0f, 0.0f, 0.0f); - ::glVertex3dv(m_grabbers[0].center.data()); - glsafe(::glEnd()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - m_grabbers.front().color = m_highlight_color; render_grabbers(box); } -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d GLGizmoRotate::local_transform(const Selection& selection) const { Transform3d ret; @@ -666,43 +539,6 @@ Transform3d GLGizmoRotate::local_transform(const Selection& selection) const return Geometry::assemble_transform(m_center) * ret; #endif // ENABLE_WORLD_COORDINATE } -#else -void GLGizmoRotate::transform_to_local(const Selection& selection) const -{ - glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z())); - -#if ENABLE_WORLD_COORDINATE - glsafe(::glMultMatrixd(m_orient_matrix.data())); -#else - if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes()) { - const Transform3d orient_matrix = selection.get_first_volume()->get_instance_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } -#endif // ENABLE_WORLD_COORDINATE - - switch (m_axis) - { - case X: - { - glsafe(::glRotatef(90.0f, 0.0f, 1.0f, 0.0f)); - glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f)); - break; - } - case Y: - { - glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f)); - glsafe(::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f)); - break; - } - default: - case Z: - { - // no rotation - break; - } - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) const diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index d117a1219..fa52e3a78 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -40,7 +40,6 @@ private: Transform3d m_orient_matrix{ Transform3d::Identity() }; #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_circle; GLModel m_scale; GLModel m_snap_radii; @@ -55,7 +54,6 @@ private: float m_old_radius{ 0.0f }; float m_old_hover_radius{ 0.0f }; float m_old_angle{ 0.0f }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // emboss need to draw rotation gizmo in local coordinate systems bool m_using_local_coordinate{false}; @@ -100,27 +98,15 @@ protected: void on_render() override; private: -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_circle(const ColorRGBA& color, bool radius_changed); void render_scale(const ColorRGBA& color, bool radius_changed); void render_snap_radii(const ColorRGBA& color, bool radius_changed); void render_reference_radius(const ColorRGBA& color, bool radius_changed); void render_angle_arc(const ColorRGBA& color, bool radius_changed); void render_grabber_connection(const ColorRGBA& color, bool radius_changed); -#else - void render_circle() const; - void render_scale() const; - void render_snap_radii() const; - void render_reference_radius() const; - void render_angle() const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void render_grabber(const BoundingBoxf3& box); -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d local_transform(const Selection& selection) const; -#else - void transform_to_local(const Selection& selection) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate #if ENABLE_WORLD_COORDINATE diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index 42c74594c..1787e5cf8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -5,9 +5,7 @@ #if ENABLE_WORLD_COORDINATE #include "slic3r/GUI/GUI_ObjectManipulation.hpp" #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "libslic3r/Model.hpp" #include @@ -29,7 +27,6 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen , m_drag_color(DEFAULT_DRAG_COLOR) , m_highlight_color(DEFAULT_HIGHLIGHT_COLOR) { -#if ENABLE_LEGACY_OPENGL_REMOVAL m_grabber_connections[0].grabber_indices = { 0, 1 }; m_grabber_connections[1].grabber_indices = { 2, 3 }; m_grabber_connections[2].grabber_indices = { 4, 5 }; @@ -37,7 +34,6 @@ GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent, const std::string& icon_filen m_grabber_connections[4].grabber_indices = { 7, 8 }; m_grabber_connections[5].grabber_indices = { 8, 9 }; m_grabber_connections[6].grabber_indices = { 9, 6 }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } std::string GLGizmoScale3D::get_tooltip() const @@ -380,15 +376,10 @@ void GLGizmoScale3D::on_render() glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d base_matrix = local_transform(selection); for (int i = 0; i < 10; ++i) { m_grabbers[i].matrix = base_matrix; } -#else - glsafe(::glPushMatrix()); - transform_to_local(selection); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const float grabber_mean_size = (float)((m_bounding_box.size().x() + m_bounding_box.size().y() + m_bounding_box.size().z()) / 3.0); #else @@ -397,7 +388,6 @@ void GLGizmoScale3D::on_render() #endif // ENABLE_WORLD_COORDINATE if (m_hover_id == -1) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -431,32 +421,11 @@ void GLGizmoScale3D::on_render() render_grabbers_connection(9, 6, m_base_color); shader->stop_using(); } -#else - // draw connections - if (m_grabbers[0].enabled && m_grabbers[1].enabled) { - glsafe(::glColor4fv(m_grabbers[0].color.data())); - render_grabbers_connection(0, 1); - } - if (m_grabbers[2].enabled && m_grabbers[3].enabled) { - glsafe(::glColor4fv(m_grabbers[2].color.data())); - render_grabbers_connection(2, 3); - } - if (m_grabbers[4].enabled && m_grabbers[5].enabled) { - glsafe(::glColor4fv(m_grabbers[4].color.data())); - render_grabbers_connection(4, 5); - } - glsafe(::glColor4fv(m_base_color.data())); - render_grabbers_connection(6, 7); - render_grabbers_connection(7, 8); - render_grabbers_connection(8, 9); - render_grabbers_connection(9, 6); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // draw grabbers render_grabbers(grabber_mean_size); } else if ((m_hover_id == 0 || m_hover_id == 1) && m_grabbers[0].enabled && m_grabbers[1].enabled) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -484,14 +453,6 @@ void GLGizmoScale3D::on_render() // draw grabbers shader = wxGetApp().get_shader("gouraud_light"); -#else - // draw connection - glsafe(::glColor4fv(AXES_COLOR[0].data())); - render_grabbers_connection(0, 1); - - // draw grabbers - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -501,7 +462,6 @@ void GLGizmoScale3D::on_render() } } else if ((m_hover_id == 2 || m_hover_id == 3) && m_grabbers[2].enabled && m_grabbers[3].enabled) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -529,14 +489,6 @@ void GLGizmoScale3D::on_render() // draw grabbers shader = wxGetApp().get_shader("gouraud_light"); -#else - // draw connection - glsafe(::glColor4fv(AXES_COLOR[1].data())); - render_grabbers_connection(2, 3); - - // draw grabbers - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -546,7 +498,6 @@ void GLGizmoScale3D::on_render() } } else if ((m_hover_id == 4 || m_hover_id == 5) && m_grabbers[4].enabled && m_grabbers[5].enabled) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -574,14 +525,6 @@ void GLGizmoScale3D::on_render() // draw grabbers shader = wxGetApp().get_shader("gouraud_light"); -#else - // draw connection - glsafe(::glColor4fv(AXES_COLOR[2].data())); - render_grabbers_connection(4, 5); - - // draw grabbers - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -591,7 +534,6 @@ void GLGizmoScale3D::on_render() } } else if (m_hover_id >= 6) { -#if ENABLE_LEGACY_OPENGL_REMOVAL // draw connections #if ENABLE_GL_CORE_PROFILE GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); @@ -622,17 +564,6 @@ void GLGizmoScale3D::on_render() // draw grabbers shader = wxGetApp().get_shader("gouraud_light"); -#else - // draw connection - glsafe(::glColor4fv(m_drag_color.data())); - render_grabbers_connection(6, 7); - render_grabbers_connection(7, 8); - render_grabbers_connection(8, 9); - render_grabbers_connection(9, 6); - - // draw grabbers - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (shader != nullptr) { shader->start_using(); shader->set_uniform("emission_factor", 0.1f); @@ -642,12 +573,6 @@ void GLGizmoScale3D::on_render() shader->stop_using(); } } - -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE } void GLGizmoScale3D::on_register_raycasters_for_picking() @@ -661,7 +586,6 @@ void GLGizmoScale3D::on_unregister_raycasters_for_picking() m_parent.set_raycaster_gizmos_on_top(false); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color) { auto grabber_connection = [this](unsigned int id_1, unsigned int id_2) { @@ -701,18 +625,6 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int m_grabber_connections[id].model.set_color(color); m_grabber_connections[id].model.render(); } -#else -void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const -{ - unsigned int grabbers_count = (unsigned int)m_grabbers.size(); - if (id_1 < grabbers_count && id_2 < grabbers_count) { - ::glBegin(GL_LINES); - ::glVertex3dv(m_grabbers[id_1].center.data()); - ::glVertex3dv(m_grabbers[id_2].center.data()); - glsafe(::glEnd()); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE void GLGizmoScale3D::do_scale_along_axis(Axis axis, const UpdateData& data) @@ -884,7 +796,6 @@ double GLGizmoScale3D::calc_ratio(const UpdateData& data) const } #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d GLGizmoScale3D::local_transform(const Selection& selection) const { Transform3d ret = Geometry::translation_transform(m_center); @@ -897,19 +808,6 @@ Transform3d GLGizmoScale3D::local_transform(const Selection& selection) const } return ret; } -#else -void GLGizmoScale3D::transform_to_local(const Selection& selection) const -{ - glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z())); - - if (!wxGetApp().obj_manipul()->is_world_coordinates()) { - Transform3d orient_matrix = selection.get_first_volume()->get_instance_transformation().get_matrix(true, false, true, true); - if (selection.is_single_volume_or_modifier() && wxGetApp().obj_manipul()->is_local_coordinates()) - orient_matrix = orient_matrix * selection.get_first_volume()->get_volume_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_WORLD_COORDINATE } // namespace GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp index bf5511528..96594786e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp @@ -48,7 +48,6 @@ class GLGizmoScale3D : public GLGizmoBase double m_snap_step{ 0.05 }; StartingData m_starting; -#if ENABLE_LEGACY_OPENGL_REMOVAL struct GrabberConnection { GLModel model; @@ -57,7 +56,6 @@ class GLGizmoScale3D : public GLGizmoBase Vec3d old_v2{ Vec3d::Zero() }; }; std::array m_grabber_connections; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA m_base_color; ColorRGBA m_drag_color; @@ -98,22 +96,14 @@ protected: virtual void on_unregister_raycasters_for_picking() override; private: -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_grabbers_connection(unsigned int id_1, unsigned int id_2, const ColorRGBA& color); -#else - void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void do_scale_along_axis(Axis axis, const UpdateData& data); void do_scale_uniform(const UpdateData& data); double calc_ratio(const UpdateData& data) const; #if ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL Transform3d local_transform(const Selection& selection) const; -#else - void transform_to_local(const Selection& selection) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_WORLD_COORDINATE }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp index a12736953..177d9d5a7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp @@ -650,25 +650,13 @@ void GLGizmoSimplify::init_model() } assert(volume != nullptr); -#if ENABLE_LEGACY_OPENGL_REMOVAL // set actual triangle count m_triangle_count += volume->mesh().its.indices.size(); -#else - const indexed_triangle_set &its = volume->mesh().its; - - // set actual triangle count - m_triangle_count += its.indices.size(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL assert(m_glmodels.find(id) == m_glmodels.end()); GLModel &glmodel = m_glmodels[id]; // create new glmodel -#if ENABLE_LEGACY_OPENGL_REMOVAL glmodel.init_from(volume->mesh()); glmodel.set_color(selected_volume->color); -#else - glmodel.init_from(its); - glmodel.set_color(-1,selected_volume->color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_parent.toggle_model_objects_visibility(false, info->model_object(), info->get_active_instance(), @@ -720,11 +708,7 @@ void GLGizmoSimplify::update_model(const State::Data &data) #else glmodel.init_from(its); #endif // ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL glmodel.set_color(color); -#else - glmodel.set_color(-1, color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_triangle_count += its.indices.size(); } @@ -759,10 +743,6 @@ void GLGizmoSimplify::on_render() GLModel &glmodel = it->second; const Transform3d trafo_matrix = selected_volume->world_matrix(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo_matrix.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL auto* gouraud_shader = wxGetApp().get_shader("gouraud_light"); #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES bool depth_test_enabled = ::glIsEnabled(GL_DEPTH_TEST); @@ -771,7 +751,6 @@ void GLGizmoSimplify::on_render() #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES glsafe(::glEnable(GL_DEPTH_TEST)); gouraud_shader->start_using(); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); const Transform3d view_model_matrix = view_matrix * trafo_matrix; @@ -779,7 +758,6 @@ void GLGizmoSimplify::on_render() gouraud_shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * trafo_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); gouraud_shader->set_uniform("view_normal_matrix", view_normal_matrix); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glmodel.render(); gouraud_shader->stop_using(); @@ -791,12 +769,10 @@ void GLGizmoSimplify::on_render() #endif // ENABLE_OPENGL_ES contour_shader->start_using(); contour_shader->set_uniform("offset", OpenGLManager::get_gl_info().is_mesa() ? 0.0005 : 0.00001); -#if ENABLE_LEGACY_OPENGL_REMOVAL contour_shader->set_uniform("view_model_matrix", view_model_matrix); contour_shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const ColorRGBA color = glmodel.get_color(); glmodel.set_color(ColorRGBA::WHITE()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE if (!OpenGLManager::get_gl_info().is_core_profile()) #endif // ENABLE_GL_CORE_PROFILE @@ -808,9 +784,7 @@ void GLGizmoSimplify::on_render() #if !ENABLE_OPENGL_ES glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); #endif // !ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL glmodel.set_color(color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL contour_shader->stop_using(); } #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES @@ -819,9 +793,6 @@ void GLGizmoSimplify::on_render() #else glsafe(::glPopAttrib()); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 1520a2ef1..c22cdf606 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -151,22 +151,12 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) if (! has_points && ! has_holes) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); if (shader == nullptr) return; shader->start_using(); ScopeGuard guard([shader]() { shader->stop_using(); }); -#else - GLShaderProgram* shader = picking ? nullptr : wxGetApp().get_shader("gouraud_light"); - if (shader != nullptr) - shader->start_using(); - ScopeGuard guard([shader]() { - if (shader != nullptr) - shader->stop_using(); - }); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const GLVolume* vol = selection.get_first_volume(); const Geometry::Transformation transformation(vol->world_matrix()); @@ -175,17 +165,9 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) #else const Transform3d& instance_scaling_matrix_inverse = transformation.get_matrix(true, true, false, true).inverse(); #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#else - const Transform3d& instance_matrix = transformation.get_matrix(); - const float z_shift = m_c->selection_info()->get_sla_shift(); - glsafe(::glPushMatrix()); - glsafe(::glTranslated(0.0, 0.0, z_shift)); - glsafe(::glMultMatrixd(instance_matrix.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ColorRGBA render_color; for (size_t i = 0; i < cache_size; ++i) { @@ -218,24 +200,12 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) render_color = { 0.5f, 0.5f, 0.5f, 1.f }; } -#if ENABLE_LEGACY_OPENGL_REMOVAL m_cone.model.set_color(render_color); m_sphere.model.set_color(render_color); -#else - m_cone.set_color(-1, render_color); - m_sphere.set_color(-1, render_color); - if (shader && !picking) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - shader->set_uniform("emission_factor", 0.5f); + shader->set_uniform("emission_factor", 0.5f); // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d support_matrix = Geometry::translation_transform(support_point.pos.cast()) * instance_scaling_matrix_inverse; -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(support_point.pos.x(), support_point.pos.y(), support_point.pos.z())); - glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CW)); @@ -250,7 +220,6 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast()); const Eigen::AngleAxisd aa(q); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = vol->world_matrix() * support_matrix * Transform3d(aa.toRotationMatrix()) * Geometry::translation_transform((CONE_HEIGHT + support_point.head_front_radius * RenderPointScale) * Vec3d::UnitZ()) * Geometry::rotation_transform({ double(PI), 0.0, 0.0 }) * Geometry::scale_transform({ CONE_RADIUS, CONE_RADIUS, CONE_HEIGHT }); @@ -258,64 +227,30 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) shader->set_uniform("view_model_matrix", view_matrix * model_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); - glsafe(::glTranslatef(0.f, 0.f, cone_height + support_point.head_front_radius * RenderPointScale)); - glsafe(::glRotated(180., 1., 0., 0.)); - glsafe(::glScaled(cone_radius, cone_radius, cone_height)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_cone.model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } const double radius = (double)support_point.head_front_radius * RenderPointScale; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = vol->world_matrix() * support_matrix * Geometry::scale_transform(radius); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glPushMatrix()); - glsafe(::glScaled(radius, radius, radius)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_sphere.model.render(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CCW)); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } // Now render the drain holes: if (has_holes) { render_color = { 0.7f, 0.7f, 0.7f, 0.7f }; -#if ENABLE_LEGACY_OPENGL_REMOVAL m_cylinder.set_color(render_color); -#else - m_cylinder.set_color(-1, render_color); - if (shader != nullptr) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("emission_factor", 0.5f); for (const sla::DrainHole& drain_hole : m_c->selection_info()->model_object()->sla_drain_holes) { if (is_mesh_point_clipped(drain_hole.pos.cast())) continue; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d hole_matrix = Geometry::translation_transform(drain_hole.pos.cast()) * instance_scaling_matrix_inverse; -#else - // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(drain_hole.pos.x(), drain_hole.pos.y(), drain_hole.pos.z())); - glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CW)); @@ -324,30 +259,17 @@ void GLGizmoSlaSupports::render_points(const Selection& selection) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast()); const Eigen::AngleAxisd aa(q); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d model_matrix = vol->world_matrix() * hole_matrix * Transform3d(aa.toRotationMatrix()) * Geometry::translation_transform(-drain_hole.height * Vec3d::UnitZ()) * Geometry::scale_transform(Vec3d(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); shader->set_uniform("view_model_matrix", view_matrix * model_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader->set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); - glsafe(::glTranslated(0., 0., -drain_hole.height)); - glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_cylinder.render(); if (vol->is_left_handed()) glsafe(::glFrontFace(GL_CCW)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } } - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index b044cc5c8..0e1d5ae0c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -217,35 +217,19 @@ void InstancesHider::render_cut() const else clipper->set_limiting_plane(ClippingPlane::ClipsNothing()); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - if (mv->is_model_part()) - glsafe(::glColor3f(0.8f, 0.3f, 0.0f)); - else { - const ColorRGBA color = color_from_model_volume(*mv); - glsafe(::glColor4fv(color.data())); - } -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES bool depth_test_enabled = ::glIsEnabled(GL_DEPTH_TEST); #else glsafe(::glPushAttrib(GL_DEPTH_TEST)); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL clipper->render_cut(mv->is_model_part() ? ColorRGBA(0.8f, 0.3f, 0.0f, 1.0f) : color_from_model_volume(*mv)); -#else - clipper->render_cut(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES if (depth_test_enabled) glsafe(::glEnable(GL_DEPTH_TEST)); #else glsafe(::glPopAttrib()); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL ++clipper_id; } @@ -445,16 +429,8 @@ void ObjectClipper::render_cut() const clipper->set_plane(*m_clp); clipper->set_transformation(trafo); clipper->set_limiting_plane(ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD)); -#if ENABLE_LEGACY_OPENGL_REMOVAL clipper->render_cut({ 1.0f, 0.37f, 0.0f, 1.0f }); clipper->render_contour({ 1.f, 1.f, 1.f, 1.f}); -#else - glsafe(::glPushMatrix()); - glsafe(::glColor3f(1.0f, 0.37f, 0.0f)); - clipper->render_cut(); - glsafe(::glColor3f(1.f, 1.f, 1.f)); - clipper->render_contour(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL ++clipper_id; } @@ -602,16 +578,8 @@ void SupportsClipper::render_cut() const m_clipper->set_plane(*ocl->get_clipping_plane()); m_clipper->set_transformation(supports_trafo); -#if ENABLE_LEGACY_OPENGL_REMOVAL m_clipper->render_cut({ 1.0f, 0.f, 0.37f, 1.0f }); m_clipper->render_contour({ 1.f, 1.f, 1.f, 1.f }); -#else - glsafe(::glPushMatrix()); - glsafe(::glColor3f(1.0f, 0.f, 0.37f)); - m_clipper->render_cut(); - glsafe(::glColor3f(1.0f, 1.f, 1.f)); - m_clipper->render_contour(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 9c0f50c8f..0a229caf9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -128,7 +128,6 @@ bool GLGizmosManager::init() return true; } -#if ENABLE_LEGACY_OPENGL_REMOVAL bool GLGizmosManager::init_arrow(const std::string& filename) { if (m_arrow_texture.get_id() != 0) @@ -137,23 +136,6 @@ bool GLGizmosManager::init_arrow(const std::string& filename) const std::string path = resources_dir() + "/icons/"; return (!filename.empty()) ? m_arrow_texture.load_from_svg_file(path + filename, false, false, false, 512) : false; } -#else -bool GLGizmosManager::init_arrow(const BackgroundTexture::Metadata & arrow_texture) -{ - if (m_arrow_texture.texture.get_id() != 0) - return true; - - std::string path = resources_dir() + "/icons/"; - bool res = false; - - if (!arrow_texture.filename.empty()) - res = m_arrow_texture.texture.load_from_svg_file(path + arrow_texture.filename, false, false, false, 1000); - if (res) - m_arrow_texture.metadata = arrow_texture; - - return res; -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmosManager::set_overlay_icon_size(float size) { @@ -678,7 +660,6 @@ void GLGizmosManager::update_after_undo_redo(const UndoRedo::Snapshot& snapshot) dynamic_cast(m_gizmos[SlaSupports].get())->reslice_SLA_supports(true); } -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border_w, float border_h) const { const unsigned int tex_id = m_background_texture.texture.get_id(); @@ -731,62 +712,7 @@ void GLGizmosManager::render_background(float left, float top, float right, floa GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); } } -#else -void GLGizmosManager::render_background(float left, float top, float right, float bottom, float border) const -{ - const unsigned int tex_id = m_background_texture.texture.get_id(); - const float tex_width = float(m_background_texture.texture.get_width()); - const float tex_height = float(m_background_texture.texture.get_height()); - if (tex_id != 0 && tex_width > 0 && tex_height > 0) { - const float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f; - const float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f; - const float internal_left = left + border; - const float internal_right = right - border; - const float internal_top = top - border; - const float internal_bottom = bottom + border; - - // float left_uv = 0.0f; - const float right_uv = 1.0f; - const float top_uv = 1.0f; - const float bottom_uv = 0.0f; - - const float internal_left_uv = float(m_background_texture.metadata.left) * inv_tex_width; - const float internal_right_uv = 1.0f - float(m_background_texture.metadata.right) * inv_tex_width; - const float internal_top_uv = 1.0f - float(m_background_texture.metadata.top) * inv_tex_height; - const float internal_bottom_uv = float(m_background_texture.metadata.bottom) * inv_tex_height; - - // top-left corner - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_top, top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // top edge - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_top, top, { { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, top_uv }, { internal_left_uv, top_uv } }); - - // top-right corner - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_top, top, { { internal_right_uv, internal_top_uv }, { right_uv, internal_top_uv }, { right_uv, top_uv }, { internal_right_uv, top_uv } }); - - // center-left edge - GLTexture::render_sub_texture(tex_id, left, internal_left, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // center - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, internal_bottom, internal_top, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // center-right edge - GLTexture::render_sub_texture(tex_id, internal_right, right, internal_bottom, internal_top, { { internal_right_uv, internal_bottom_uv }, { right_uv, internal_bottom_uv }, { right_uv, internal_top_uv }, { internal_right_uv, internal_top_uv } }); - - // bottom-left corner - GLTexture::render_sub_texture(tex_id, left, internal_left, bottom, internal_bottom, { { internal_left_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_right_uv, internal_top_uv }, { internal_left_uv, internal_top_uv } }); - - // bottom edge - GLTexture::render_sub_texture(tex_id, internal_left, internal_right, bottom, internal_bottom, { { internal_left_uv, bottom_uv }, { internal_right_uv, bottom_uv }, { internal_right_uv, internal_bottom_uv }, { internal_left_uv, internal_bottom_uv } }); - - // bottom-right corner - GLTexture::render_sub_texture(tex_id, internal_right, right, bottom, internal_bottom, { { internal_right_uv, bottom_uv }, { right_uv, bottom_uv }, { right_uv, internal_bottom_uv }, { internal_right_uv, internal_bottom_uv } }); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const { const std::vector selectable_idxs = get_selectable_idxs(); @@ -833,48 +759,7 @@ void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_t top_y -= stride_y; } } -#else -void GLGizmosManager::render_arrow(const GLCanvas3D& parent, EType highlighted_type) const -{ - std::vector selectable_idxs = get_selectable_idxs(); - if (selectable_idxs.empty()) - return; - float cnv_w = (float)m_parent.get_canvas_size().get_width(); - float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - float height = get_scaled_total_height(); - float zoomed_border = m_layout.scaled_border() * inv_zoom; - float zoomed_top_x = (-0.5f * cnv_w) * inv_zoom; - float zoomed_top_y = (0.5f * height) * inv_zoom; - zoomed_top_x += zoomed_border; - zoomed_top_y -= zoomed_border; - float icons_size = m_layout.scaled_icons_size(); - float zoomed_icons_size = icons_size * inv_zoom; - float zoomed_stride_y = m_layout.scaled_stride_y() * inv_zoom; - for (size_t idx : selectable_idxs) - { - if (idx == highlighted_type) { - int tex_width = m_icons_texture.get_width(); - int tex_height = m_icons_texture.get_height(); - unsigned int tex_id = m_arrow_texture.texture.get_id(); - float inv_tex_width = (tex_width != 0.0f) ? 1.0f / tex_width : 0.0f; - float inv_tex_height = (tex_height != 0.0f) ? 1.0f / tex_height : 0.0f; - float internal_left_uv = (float)m_arrow_texture.metadata.left * inv_tex_width; - float internal_right_uv = 1.0f - (float)m_arrow_texture.metadata.right * inv_tex_width; - float internal_top_uv = 1.0f - (float)m_arrow_texture.metadata.top * inv_tex_height; - float internal_bottom_uv = (float)m_arrow_texture.metadata.bottom * inv_tex_height; - - float arrow_sides_ratio = (float)m_arrow_texture.texture.get_height() / (float)m_arrow_texture.texture.get_width(); - - GLTexture::render_sub_texture(tex_id, zoomed_top_x + zoomed_icons_size * 1.2f, zoomed_top_x + zoomed_icons_size * 1.2f + zoomed_icons_size * 2.2f * arrow_sides_ratio, zoomed_top_y - zoomed_icons_size * 1.6f , zoomed_top_y + zoomed_icons_size * 0.6f, { { internal_left_uv, internal_bottom_uv }, { internal_left_uv, internal_top_uv }, { internal_right_uv, internal_top_uv }, { internal_right_uv, internal_bottom_uv } }); - break; - } - zoomed_top_y -= zoomed_stride_y; - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL void GLGizmosManager::do_render_overlay() const { const std::vector selectable_idxs = get_selectable_idxs(); @@ -946,80 +831,6 @@ void GLGizmosManager::do_render_overlay() const if (m_current != Undefined) m_gizmos[m_current]->render_input_window(get_scaled_total_width(), current_y, cnv_h - wxGetApp().plater()->get_view_toolbar().get_height()); } -#else -void GLGizmosManager::do_render_overlay() const -{ - std::vector selectable_idxs = get_selectable_idxs(); - if (selectable_idxs.empty()) - return; - - const float cnv_w = (float)m_parent.get_canvas_size().get_width(); - const float cnv_h = (float)m_parent.get_canvas_size().get_height(); - const float zoom = (float)wxGetApp().plater()->get_camera().get_zoom(); - const float inv_zoom = (float)wxGetApp().plater()->get_camera().get_inv_zoom(); - - const float height = get_scaled_total_height(); - const float width = get_scaled_total_width(); - const float zoomed_border = m_layout.scaled_border() * inv_zoom; - - float zoomed_top_x = (-0.5f * cnv_w) * inv_zoom; - float zoomed_top_y = (0.5f * height) * inv_zoom; - - float zoomed_left = zoomed_top_x; - float zoomed_top = zoomed_top_y; - float zoomed_right = zoomed_left + width * inv_zoom; - float zoomed_bottom = zoomed_top - height * inv_zoom; - - render_background(zoomed_left, zoomed_top, zoomed_right, zoomed_bottom, zoomed_border); - - zoomed_top_x += zoomed_border; - zoomed_top_y -= zoomed_border; - - const float icons_size = m_layout.scaled_icons_size(); - const float zoomed_icons_size = icons_size * inv_zoom; - const float zoomed_stride_y = m_layout.scaled_stride_y() * inv_zoom; - - const unsigned int icons_texture_id = m_icons_texture.get_id(); - const int tex_width = m_icons_texture.get_width(); - const int tex_height = m_icons_texture.get_height(); - - if (icons_texture_id == 0 || tex_width <= 1 || tex_height <= 1) - return; - - const float du = (float)(tex_width - 1) / (6.0f * (float)tex_width); // 6 is the number of possible states if the icons - const float dv = (float)(tex_height - 1) / (float)(m_gizmos.size() * tex_height); - - // tiles in the texture are spaced by 1 pixel - const float u_offset = 1.0f / (float)tex_width; - const float v_offset = 1.0f / (float)tex_height; - - float current_y = FLT_MAX; - for (size_t idx : selectable_idxs) { - GLGizmoBase* gizmo = m_gizmos[idx].get(); - const unsigned int sprite_id = gizmo->get_sprite_id(); - // higlighted state needs to be decided first so its highlighting in every other state - const int icon_idx = (m_highlight.first == idx ? (m_highlight.second ? 4 : 5) : (m_current == idx) ? 2 : ((m_hover == idx) ? 1 : (gizmo->is_activable()? 0 : 3))); - - const float u_left = u_offset + icon_idx * du; - const float u_right = u_left + du - u_offset; - const float v_top = v_offset + sprite_id * dv; - const float v_bottom = v_top + dv - v_offset; - - GLTexture::render_sub_texture(icons_texture_id, zoomed_top_x, zoomed_top_x + zoomed_icons_size, zoomed_top_y - zoomed_icons_size, zoomed_top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } }); - if (idx == m_current || current_y == FLT_MAX) { - // The FLT_MAX trick is here so that even non-selectable but activable - // gizmos are passed some meaningful value. - current_y = 0.5f * cnv_h - zoomed_top_y * zoom; - } - zoomed_top_y -= zoomed_stride_y; - } - - if (m_current != Undefined) { - const float toolbar_top = cnv_h - wxGetApp().plater()->get_view_toolbar().get_height(); - m_gizmos[m_current]->render_input_window(width, current_y, toolbar_top); - } -} -#endif // ENABLE_LEGACY_OPENGL_REMOVAL float GLGizmosManager::get_scaled_total_height() const { diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index b380c55c4..8c98596bf 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -34,7 +34,6 @@ public: Rect() = default; Rect(float left, float top, float right, float bottom) : m_left(left) , m_top(top) , m_right(right) , m_bottom(bottom) {} -#if ENABLE_LEGACY_OPENGL_REMOVAL bool operator == (const Rect& other) const { if (std::abs(m_left - other.m_left) > EPSILON) return false; if (std::abs(m_top - other.m_top) > EPSILON) return false; @@ -43,7 +42,6 @@ public: return true; } bool operator != (const Rect& other) const { return !operator==(other); } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL float get_left() const { return m_left; } void set_left(float left) { m_left = left; } @@ -107,11 +105,7 @@ private: GLTexture m_icons_texture; bool m_icons_texture_dirty; BackgroundTexture m_background_texture; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLTexture m_arrow_texture; -#else - BackgroundTexture m_arrow_texture; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL Layout m_layout; EType m_current; EType m_hover; @@ -139,11 +133,7 @@ public: bool init(); -#if ENABLE_LEGACY_OPENGL_REMOVAL bool init_arrow(const std::string& filename); -#else - bool init_arrow(const BackgroundTexture::Metadata& arrow_texture); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL template void load(Archive& ar) @@ -244,11 +234,7 @@ private: bool alt_down = false, bool control_down = false); -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_background(float left, float top, float right, float bottom, float border_w, float border_h) const; -#else - void render_background(float left, float top, float right, float bottom, float border) const; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void do_render_overlay() const; diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 17709788d..64cf7d9ed 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -1764,11 +1764,9 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) if (draw_data == nullptr || draw_data->CmdListsCount == 0) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("imgui"); if (shader == nullptr) return; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) ImGuiIO& io = ImGui::GetIO(); @@ -1777,15 +1775,11 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) if (fb_width == 0 || fb_height == 0) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); if (curr_shader != nullptr) curr_shader->stop_using(); shader->start_using(); -#else - draw_data->ScaleClipRects(io.DisplayFramebufferScale); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES // Backup GL state @@ -1834,19 +1828,11 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_STENCIL_TEST)); glsafe(::glEnable(GL_SCISSOR_TEST)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glDisable(GL_LIGHTING)); - glsafe(::glDisable(GL_COLOR_MATERIAL)); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); - glsafe(::glEnableClientState(GL_COLOR_ARRAY)); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_TEXTURE_2D)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL // Setup viewport, orthographic projection matrix // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height)); @@ -1864,18 +1850,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) shader->set_uniform("Texture", 0); shader->set_uniform("ProjMtx", ortho_projection); -#else - // Setup viewport, orthographic projection matrix - // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps. - glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height)); - glsafe(::glMatrixMode(GL_PROJECTION)); - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - glsafe(::glOrtho(draw_data->DisplayPos.x, draw_data->DisplayPos.x + draw_data->DisplaySize.x, draw_data->DisplayPos.y + draw_data->DisplaySize.y, draw_data->DisplayPos.y, -1.0f, +1.0f)); - glsafe(::glMatrixMode(GL_MODELVIEW)); - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL // Will project scissor/clipping rectangles into framebuffer space const ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports @@ -1886,7 +1860,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) const ImDrawList* cmd_list = draw_data->CmdLists[n]; const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; -#if ENABLE_LEGACY_OPENGL_REMOVAL const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert); const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx); @@ -1923,11 +1896,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glGenBuffers(1, &ibo_id)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id)); glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, idx_buffer, GL_STATIC_DRAW)); -#else - glsafe(::glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos)))); - glsafe(::glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv)))); - glsafe(::glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col)))); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; ++cmd_i) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; @@ -1935,7 +1903,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // User callback (registered via ImDrawList::AddCallback) pcmd->UserCallback(cmd_list, pcmd); else { -#if ENABLE_LEGACY_OPENGL_REMOVAL // Project scissor/clipping rectangles into framebuffer space const ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); const ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); @@ -1948,24 +1915,9 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // Bind texture, Draw glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)))); -#else - // Project scissor/clipping rectangles into framebuffer space - const ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); - const ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); - if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) - continue; - - // Apply scissor/clipping rectangle (Y is inverted in OpenGL) - glsafe(::glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y))); - - // Bind texture, Draw - glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); - glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } -#if ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); if (color_id != -1) @@ -1983,7 +1935,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) if (vao_id > 0) glsafe(::glDeleteVertexArrays(1, &vao_id)); #endif // ENABLE_GL_CORE_PROFILE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } #if ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES @@ -2006,15 +1957,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // Restore modified state glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, last_texture_env_mode)); glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture)); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glDisableClientState(GL_COLOR_ARRAY)); - glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glMatrixMode(GL_MODELVIEW)); - glsafe(::glPopMatrix()); - glsafe(::glMatrixMode(GL_PROJECTION)); - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glPopAttrib()); glsafe(::glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glsafe(::glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]))); @@ -2022,12 +1964,10 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3])); #endif // ENABLE_GL_CORE_PROFILE || ENABLE_OPENGL_ES -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); if (curr_shader != nullptr) curr_shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } bool ImGuiWrapper::display_initialized() const diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 8ac1af7dc..39e463a19 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -6,10 +6,8 @@ #include "libslic3r/ClipperUtils.hpp" #include "libslic3r/Model.hpp" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/Plater.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/Camera.hpp" #include @@ -77,15 +75,10 @@ void MeshClipper::set_transformation(const Geometry::Transformation& trafo) } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void MeshClipper::render_cut(const ColorRGBA& color) -#else -void MeshClipper::render_cut() -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (! m_result) recalculate_triangles(); -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); if (curr_shader != nullptr) curr_shader->stop_using(); @@ -105,22 +98,14 @@ void MeshClipper::render_cut() if (curr_shader != nullptr) curr_shader->start_using(); -#else - if (m_vertex_array.has_VBOs()) - m_vertex_array.render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void MeshClipper::render_contour(const ColorRGBA& color) -#else -void MeshClipper::render_contour() -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { if (! m_result) recalculate_triangles(); -#if ENABLE_LEGACY_OPENGL_REMOVAL + GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); if (curr_shader != nullptr) curr_shader->stop_using(); @@ -140,10 +125,6 @@ void MeshClipper::render_contour() if (curr_shader != nullptr) curr_shader->start_using(); -#else - if (m_vertex_array_expanded.has_VBOs()) - m_vertex_array_expanded.render(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } bool MeshClipper::is_projection_inside_cut(const Vec3d& point_in) const @@ -265,7 +246,6 @@ void MeshClipper::recalculate_triangles() tr2.pretranslate(0.002 * m_plane.get_normal().normalized()); -#if ENABLE_LEGACY_OPENGL_REMOVAL std::vector triangles2d; for (const ExPolygon& exp : expolys) { @@ -352,16 +332,6 @@ void MeshClipper::recalculate_triangles() isl.expoly = std::move(exp); isl.expoly_bb = get_extents(exp); } -#else - #error NOT IMPLEMENTED -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - - - -#if ENABLE_LEGACY_OPENGL_REMOVAL -#else - #error NOT IMPLEMENTED -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } diff --git a/src/slic3r/GUI/MeshUtils.hpp b/src/slic3r/GUI/MeshUtils.hpp index f1225c4ff..441532fdb 100644 --- a/src/slic3r/GUI/MeshUtils.hpp +++ b/src/slic3r/GUI/MeshUtils.hpp @@ -7,11 +7,7 @@ #include "libslic3r/AABBMesh.hpp" #include "admesh/stl.h" -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/GLModel.hpp" -#else -#include "slic3r/GUI/3DScene.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include #include @@ -102,12 +98,8 @@ public: // Render the triangulated cut. Transformation matrices should // be set in world coords. -#if ENABLE_LEGACY_OPENGL_REMOVAL void render_cut(const ColorRGBA& color); void render_contour(const ColorRGBA& color); -#else - void render_cut(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL void pass_mouse_click(const Vec3d& pt); @@ -122,7 +114,6 @@ private: const TriangleMesh* m_negative_mesh = nullptr; ClippingPlane m_plane; ClippingPlane m_limiting_plane = ClippingPlane::ClipsNothing(); -#if ENABLE_LEGACY_OPENGL_REMOVAL struct CutIsland { GLModel model; @@ -136,11 +127,6 @@ private: Transform3d trafo; // this rotates the cut into world coords }; std::optional m_result; - -#else - #error NOT IMLEMENTED - GLIndexedVertexArray m_vertex_array; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL bool m_fill_cut = true; double m_contour_width = 0.; }; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index c3a7ec18b..2dde431f0 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -584,8 +584,16 @@ bool Selection::is_sla_compliant() const bool Selection::is_single_text() const { +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#if ENABLE_WORLD_COORDINATE +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ if (!is_single_volume_or_modifier()) - return false; +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +#else + if (!is_single_volume() && !is_single_modifier()) +#endif // ENABLE_WORLD_COORDINATE +//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + return false; const GLVolume* gl_volume = (*m_volumes)[*m_list.begin()]; const ModelVolume* model_volume = m_model->objects[gl_volume->object_idx()]->volumes[gl_volume->volume_idx()]; @@ -1693,7 +1701,6 @@ void Selection::render(float scale_factor) m_scale_factor = scale_factor; // render cumulative bounding box of selected volumes -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE BoundingBoxf3 box; Transform3d trafo; @@ -1722,9 +1729,6 @@ void Selection::render(float scale_factor) #else render_bounding_box(get_bounding_box(), ColorRGB::WHITE()); #endif // ENABLE_WORLD_COORDINATE -#else - render_selected_volumes(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL render_synchronized_volumes(); } @@ -1734,38 +1738,26 @@ void Selection::render_center(bool gizmo_is_dragging) if (!m_valid || is_empty()) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader("flat"); if (shader == nullptr) return; shader->start_using(); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL const Vec3d center = gizmo_is_dragging ? m_cache.dragging_center : get_bounding_box().center(); glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); Transform3d view_model_matrix = camera.get_view_matrix() * Geometry::assemble_transform(center); shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); m_vbo_sphere.set_color(ColorRGBA::WHITE()); -#else - glsafe(::glPushMatrix()); - glsafe(::glTranslated(center.x(), center.y(), center.z())); - m_vbo_sphere.set_color(-1, ColorRGBA::WHITE()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_vbo_sphere.render(); -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->stop_using(); -#else - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } #endif // ENABLE_RENDER_SELECTION_CENTER @@ -1774,33 +1766,16 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) if (sidebar_field.empty()) return; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLShaderProgram* shader = wxGetApp().get_shader(boost::starts_with(sidebar_field, "layer") ? "flat" : "gouraud_light"); if (shader == nullptr) return; shader->start_using(); -#else - GLShaderProgram* shader = nullptr; - - if (!boost::starts_with(sidebar_field, "layer")) { - shader = wxGetApp().get_shader("gouraud_light"); - if (shader == nullptr) - return; - - shader->start_using(); - glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); -#if ENABLE_LEGACY_OPENGL_REMOVAL const Transform3d base_matrix = Geometry::translation_transform(get_bounding_box().center()); Transform3d orient_matrix = Transform3d::Identity(); -#else - glsafe(::glPushMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE const Vec3d center = get_bounding_box().center(); @@ -1808,28 +1783,16 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) #endif // ENABLE_WORLD_COORDINATE if (!boost::starts_with(sidebar_field, "layer")) { -#if ENABLE_LEGACY_OPENGL_REMOVAL shader->set_uniform("emission_factor", 0.05f); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL -#if !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE - const Vec3d& center = get_bounding_box().center(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE #if ENABLE_WORLD_COORDINATE if (is_single_full_instance() && !wxGetApp().obj_manipul()->is_world_coordinates()) { + orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix(); + axes_center = (*m_volumes)[*m_list.begin()]->get_instance_offset(); #else + const Vec3d& center = get_bounding_box().center(); if (is_single_full_instance() && !wxGetApp().obj_manipul()->get_world_coordinates()) { -#endif // ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE glsafe(::glTranslated(center.x(), center.y(), center.z())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE -#if ENABLE_WORLD_COORDINATE - orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix(); - axes_center = (*m_volumes)[*m_list.begin()]->get_instance_offset(); -#else if (!boost::starts_with(sidebar_field, "position")) { -#if !ENABLE_LEGACY_OPENGL_REMOVAL - Transform3d orient_matrix = Transform3d::Identity(); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL if (boost::starts_with(sidebar_field, "scale")) orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); else if (boost::starts_with(sidebar_field, "rotation")) { @@ -1843,21 +1806,11 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) orient_matrix.rotate(Eigen::AngleAxisd(rotation.z(), Vec3d::UnitZ())); } } -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glMultMatrixd(orient_matrix.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } #endif // ENABLE_WORLD_COORDINATE } #if ENABLE_WORLD_COORDINATE else if (is_single_volume_or_modifier()) { -#else - else if (is_single_volume() || is_single_modifier()) { -#endif // ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE - glsafe(::glTranslated(center.x(), center.y(), center.z())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL&& !ENABLE_WORLD_COORDINATE -#if ENABLE_WORLD_COORDINATE if (!wxGetApp().obj_manipul()->is_world_coordinates()) { if (wxGetApp().obj_manipul()->is_local_coordinates()) { const GLVolume* v = (*m_volumes)[*m_list.begin()]; @@ -1870,55 +1823,32 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) } } #else -#if ENABLE_LEGACY_OPENGL_REMOVAL - orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); -#else + else if (is_single_volume() || is_single_modifier()) { glsafe(::glTranslated(center.x(), center.y(), center.z())); - Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL + orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); if (!boost::starts_with(sidebar_field, "position")) orient_matrix = orient_matrix * (*m_volumes)[*m_list.begin()]->get_volume_transformation().get_matrix(true, false, true, true); - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glMultMatrixd(orient_matrix.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_WORLD_COORDINATE } else { -#if ENABLE_LEGACY_OPENGL_REMOVAL|| ENABLE_WORLD_COORDINATE if (requires_local_axes()) #if ENABLE_WORLD_COORDINATE orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_rotation_matrix(); #else orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); #endif // ENABLE_WORLD_COORDINATE -#else - glsafe(::glTranslated(center.x(), center.y(), center.z())); - if (requires_local_axes()) { - const Transform3d orient_matrix = (*m_volumes)[*m_list.begin()]->get_instance_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL|| ENABLE_WORLD_COORDINATE } } -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!boost::starts_with(sidebar_field, "layer")) glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE if (!boost::starts_with(sidebar_field, "layer")) { shader->set_uniform("emission_factor", 0.1f); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glTranslated(center.x(), center.y(), center.z())); - glsafe(::glMultMatrixd(orient_matrix.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL } #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL if (boost::starts_with(sidebar_field, "position")) render_sidebar_position_hints(sidebar_field, *shader, base_matrix * orient_matrix); else if (boost::starts_with(sidebar_field, "rotation")) @@ -1934,39 +1864,8 @@ void Selection::render_sidebar_hints(const std::string& sidebar_field) m_axes.render(Geometry::translation_transform(axes_center) * orient_matrix, 0.25f); } #endif // ENABLE_WORLD_COORDINATE -#else - if (boost::starts_with(sidebar_field, "position")) - render_sidebar_position_hints(sidebar_field); - else if (boost::starts_with(sidebar_field, "rotation")) - render_sidebar_rotation_hints(sidebar_field); - else if (boost::starts_with(sidebar_field, "scale") || boost::starts_with(sidebar_field, "size")) - render_sidebar_scale_hints(sidebar_field); - else if (boost::starts_with(sidebar_field, "layer")) - render_sidebar_layers_hints(sidebar_field); -#if ENABLE_WORLD_COORDINATE - if (!boost::starts_with(sidebar_field, "layer")) { - glsafe(::glPopMatrix()); - glsafe(::glPushMatrix()); - glsafe(::glTranslated(axes_center.x(), axes_center.y(), axes_center.z())); - glsafe(::glMultMatrixd(orient_matrix.data())); - if (!wxGetApp().obj_manipul()->is_world_coordinates()) - m_axes.render(0.25f); - glsafe(::glPopMatrix()); - } -#endif // ENABLE_WORLD_COORDINATE -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE - -#if !ENABLE_LEGACY_OPENGL_REMOVAL - if (!boost::starts_with(sidebar_field, "layer")) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - shader->stop_using(); + shader->stop_using(); } bool Selection::requires_local_axes() const @@ -2380,23 +2279,11 @@ void Selection::do_remove_object(unsigned int object_idx) } } -#if !ENABLE_LEGACY_OPENGL_REMOVAL -void Selection::render_selected_volumes() const -{ - float color[3] = { 1.0f, 1.0f, 1.0f }; - render_bounding_box(get_bounding_box(), color); -} -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - void Selection::render_synchronized_volumes() { if (m_mode == Instance) return; -#if !ENABLE_LEGACY_OPENGL_REMOVAL - float color[3] = { 1.0f, 1.0f, 0.0f }; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - #if ENABLE_WORLD_COORDINATE const ECoordinatesType coordinates_type = wxGetApp().obj_manipul()->get_coordinates_type(); BoundingBoxf3 box; @@ -2415,7 +2302,6 @@ void Selection::render_synchronized_volumes() if (v.object_idx() != object_idx || v.volume_idx() != volume_idx) continue; -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE if (coordinates_type == ECoordinatesType::World) { box = v.transformed_convex_hull_bounding_box(); @@ -2433,36 +2319,16 @@ void Selection::render_synchronized_volumes() #else render_bounding_box(v.transformed_convex_hull_bounding_box(), ColorRGB::YELLOW()); #endif // ENABLE_WORLD_COORDINATE -#else - render_bounding_box(v.transformed_convex_hull_bounding_box(), color); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } } } -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE void Selection::render_bounding_box(const BoundingBoxf3& box, const Transform3d& trafo, const ColorRGB& color) #else void Selection::render_bounding_box(const BoundingBoxf3& box, const ColorRGB& color) #endif // ENABLE_WORLD_COORDINATE { -#else -void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) const -{ - if (color == nullptr) - return; - - const Vec3f b_min = box.min.cast(); - const Vec3f b_max = box.max.cast(); - const Vec3f size = 0.2f * box.size().cast(); - - glsafe(::glEnable(GL_DEPTH_TEST)); - glsafe(::glColor3fv(color)); - glsafe(::glLineWidth(2.0f * m_scale_factor)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - -#if ENABLE_LEGACY_OPENGL_REMOVAL const BoundingBoxf3& curr_box = m_box.get_bounding_box(); if (!m_box.is_initialized() || !is_approx(box.min, curr_box.min) || !is_approx(box.max, curr_box.max)) { @@ -2556,13 +2422,6 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con if (shader == nullptr) return; -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPushMatrix()); - glsafe(::glMultMatrixd(trafo.data())); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE - shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); #if ENABLE_WORLD_COORDINATE @@ -2580,49 +2439,6 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con m_box.set_color(to_rgba(color)); m_box.render(); shader->stop_using(); - -#if ENABLE_WORLD_COORDINATE -#if !ENABLE_LEGACY_OPENGL_REMOVAL - glsafe(::glPopMatrix()); -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL -#endif // ENABLE_WORLD_COORDINATE -#else - ::glBegin(GL_LINES); - - ::glVertex3f(b_min(0), b_min(1), b_min(2)); ::glVertex3f(b_min(0) + size(0), b_min(1), b_min(2)); - ::glVertex3f(b_min(0), b_min(1), b_min(2)); ::glVertex3f(b_min(0), b_min(1) + size(1), b_min(2)); - ::glVertex3f(b_min(0), b_min(1), b_min(2)); ::glVertex3f(b_min(0), b_min(1), b_min(2) + size(2)); - - ::glVertex3f(b_max(0), b_min(1), b_min(2)); ::glVertex3f(b_max(0) - size(0), b_min(1), b_min(2)); - ::glVertex3f(b_max(0), b_min(1), b_min(2)); ::glVertex3f(b_max(0), b_min(1) + size(1), b_min(2)); - ::glVertex3f(b_max(0), b_min(1), b_min(2)); ::glVertex3f(b_max(0), b_min(1), b_min(2) + size(2)); - - ::glVertex3f(b_max(0), b_max(1), b_min(2)); ::glVertex3f(b_max(0) - size(0), b_max(1), b_min(2)); - ::glVertex3f(b_max(0), b_max(1), b_min(2)); ::glVertex3f(b_max(0), b_max(1) - size(1), b_min(2)); - ::glVertex3f(b_max(0), b_max(1), b_min(2)); ::glVertex3f(b_max(0), b_max(1), b_min(2) + size(2)); - - ::glVertex3f(b_min(0), b_max(1), b_min(2)); ::glVertex3f(b_min(0) + size(0), b_max(1), b_min(2)); - ::glVertex3f(b_min(0), b_max(1), b_min(2)); ::glVertex3f(b_min(0), b_max(1) - size(1), b_min(2)); - ::glVertex3f(b_min(0), b_max(1), b_min(2)); ::glVertex3f(b_min(0), b_max(1), b_min(2) + size(2)); - - ::glVertex3f(b_min(0), b_min(1), b_max(2)); ::glVertex3f(b_min(0) + size(0), b_min(1), b_max(2)); - ::glVertex3f(b_min(0), b_min(1), b_max(2)); ::glVertex3f(b_min(0), b_min(1) + size(1), b_max(2)); - ::glVertex3f(b_min(0), b_min(1), b_max(2)); ::glVertex3f(b_min(0), b_min(1), b_max(2) - size(2)); - - ::glVertex3f(b_max(0), b_min(1), b_max(2)); ::glVertex3f(b_max(0) - size(0), b_min(1), b_max(2)); - ::glVertex3f(b_max(0), b_min(1), b_max(2)); ::glVertex3f(b_max(0), b_min(1) + size(1), b_max(2)); - ::glVertex3f(b_max(0), b_min(1), b_max(2)); ::glVertex3f(b_max(0), b_min(1), b_max(2) - size(2)); - - ::glVertex3f(b_max(0), b_max(1), b_max(2)); ::glVertex3f(b_max(0) - size(0), b_max(1), b_max(2)); - ::glVertex3f(b_max(0), b_max(1), b_max(2)); ::glVertex3f(b_max(0), b_max(1) - size(1), b_max(2)); - ::glVertex3f(b_max(0), b_max(1), b_max(2)); ::glVertex3f(b_max(0), b_max(1), b_max(2) - size(2)); - - ::glVertex3f(b_min(0), b_max(1), b_max(2)); ::glVertex3f(b_min(0) + size(0), b_max(1), b_max(2)); - ::glVertex3f(b_min(0), b_max(1), b_max(2)); ::glVertex3f(b_min(0), b_max(1) - size(1), b_max(2)); - ::glVertex3f(b_min(0), b_max(1), b_max(2)); ::glVertex3f(b_min(0), b_max(1), b_max(2) - size(2)); - - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } static ColorRGBA get_color(Axis axis) @@ -2630,13 +2446,8 @@ static ColorRGBA get_color(Axis axis) return AXES_COLOR[axis]; } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Selection::render_sidebar_position_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix) -#else -void Selection::render_sidebar_position_hints(const std::string& sidebar_field) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader.set_uniform("projection_matrix", camera.get_projection_matrix()); @@ -2663,31 +2474,10 @@ void Selection::render_sidebar_position_hints(const std::string& sidebar_field) m_arrow.set_color(get_color(Z)); m_arrow.render(); } -#else - if (boost::ends_with(sidebar_field, "x")) { - glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); - m_arrow.set_color(-1, get_color(X)); - m_arrow.render(); - } - else if (boost::ends_with(sidebar_field, "y")) { - m_arrow.set_color(-1, get_color(Y)); - m_arrow.render(); - } - else if (boost::ends_with(sidebar_field, "z")) { - glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); - m_arrow.set_color(-1, get_color(Z)); - m_arrow.render(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix) -#else -void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { -#if ENABLE_LEGACY_OPENGL_REMOVAL auto render_sidebar_rotation_hint = [this](GLShaderProgram& shader, const Transform3d& view_matrix, const Transform3d& model_matrix) { shader.set_uniform("view_model_matrix", view_matrix * model_matrix); Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); @@ -2716,35 +2506,9 @@ void Selection::render_sidebar_rotation_hints(const std::string& sidebar_field) m_curved_arrow.set_color(get_color(Z)); render_sidebar_rotation_hint(shader, view_matrix, matrix); } -#else - auto render_sidebar_rotation_hint = [this]() { - m_curved_arrow.render(); - glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); - m_curved_arrow.render(); - }; - - if (boost::ends_with(sidebar_field, "x")) { - glsafe(::glRotated(90.0, 0.0, 1.0, 0.0)); - m_curved_arrow.set_color(-1, get_color(X)); - render_sidebar_rotation_hint(); - } - else if (boost::ends_with(sidebar_field, "y")) { - glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); - m_curved_arrow.set_color(-1, get_color(Y)); - render_sidebar_rotation_hint(); - } - else if (boost::ends_with(sidebar_field, "z")) { - m_curved_arrow.set_color(-1, get_color(Z)); - render_sidebar_rotation_hint(); - } -#endif // ENABLE_LEGACY_OPENGL_REMOVAL } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Selection::render_sidebar_scale_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix) -#else -void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { #if ENABLE_WORLD_COORDINATE const bool uniform_scale = wxGetApp().obj_manipul()->get_uniform_scaling(); @@ -2752,80 +2516,36 @@ void Selection::render_sidebar_scale_hints(const std::string& sidebar_field) const bool uniform_scale = requires_uniform_scale() || wxGetApp().obj_manipul()->get_uniform_scaling(); #endif // ENABLE_WORLD_COORDINATE -#if ENABLE_LEGACY_OPENGL_REMOVAL auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis, GLShaderProgram& shader, const Transform3d& view_matrix, const Transform3d& model_matrix) { m_arrow.set_color(uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); Transform3d matrix = model_matrix * Geometry::translation_transform(5.0 * Vec3d::UnitY()); shader.set_uniform("view_model_matrix", view_matrix * matrix); Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader.set_uniform("view_normal_matrix", view_normal_matrix); -#else - auto render_sidebar_scale_hint = [this, uniform_scale](Axis axis) { - m_arrow.set_color(-1, uniform_scale ? UNIFORM_SCALE_COLOR : get_color(axis)); - GLShaderProgram* shader = wxGetApp().get_current_shader(); - if (shader != nullptr) - shader->set_uniform("emission_factor", 0.0f); - - glsafe(::glTranslated(0.0, 5.0, 0.0)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.render(); -#if ENABLE_LEGACY_OPENGL_REMOVAL matrix = model_matrix * Geometry::translation_transform(-5.0 * Vec3d::UnitY()) * Geometry::rotation_transform(PI * Vec3d::UnitZ()); shader.set_uniform("view_model_matrix", view_matrix * matrix); view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); shader.set_uniform("view_normal_matrix", view_normal_matrix); -#else - glsafe(::glTranslated(0.0, -10.0, 0.0)); - glsafe(::glRotated(180.0, 0.0, 0.0, 1.0)); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL m_arrow.render(); }; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader.set_uniform("projection_matrix", camera.get_projection_matrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - if (boost::ends_with(sidebar_field, "x") || uniform_scale) { -#if ENABLE_LEGACY_OPENGL_REMOVAL + if (boost::ends_with(sidebar_field, "x") || uniform_scale) render_sidebar_scale_hint(X, shader, view_matrix, matrix * Geometry::rotation_transform(-0.5 * PI * Vec3d::UnitZ())); -#else - glsafe(::glPushMatrix()); - glsafe(::glRotated(-90.0, 0.0, 0.0, 1.0)); - render_sidebar_scale_hint(X); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - } - if (boost::ends_with(sidebar_field, "y") || uniform_scale) { -#if ENABLE_LEGACY_OPENGL_REMOVAL + if (boost::ends_with(sidebar_field, "y") || uniform_scale) render_sidebar_scale_hint(Y, shader, view_matrix, matrix); -#else - glsafe(::glPushMatrix()); - render_sidebar_scale_hint(Y); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - } - if (boost::ends_with(sidebar_field, "z") || uniform_scale) { -#if ENABLE_LEGACY_OPENGL_REMOVAL + if (boost::ends_with(sidebar_field, "z") || uniform_scale) render_sidebar_scale_hint(Z, shader, view_matrix, matrix * Geometry::rotation_transform(0.5 * PI * Vec3d::UnitX())); -#else - glsafe(::glPushMatrix()); - glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); - render_sidebar_scale_hint(Z); - glsafe(::glPopMatrix()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL - } } -#if ENABLE_LEGACY_OPENGL_REMOVAL void Selection::render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader) -#else -void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) -#endif // ENABLE_LEGACY_OPENGL_REMOVAL { static const float Margin = 10.0f; @@ -2856,29 +2576,19 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) const BoundingBoxf3& box = get_bounding_box(); -#if !ENABLE_LEGACY_OPENGL_REMOVAL - const float min_x = float(box.min.x()) - Margin; - const float max_x = float(box.max.x()) + Margin; - const float min_y = float(box.min.y()) - Margin; - const float max_y = float(box.max.y()) + Margin; -#endif // !ENABLE_LEGACY_OPENGL_REMOVAL - // view dependend order of rendering to keep correct transparency const bool camera_on_top = wxGetApp().plater()->get_camera().is_looking_downward(); const float z1 = camera_on_top ? min_z : max_z; const float z2 = camera_on_top ? max_z : min_z; -#if ENABLE_LEGACY_OPENGL_REMOVAL const Vec3f p1 = { float(box.min.x()) - Margin, float(box.min.y()) - Margin, z1 }; const Vec3f p2 = { float(box.max.x()) + Margin, float(box.max.y()) + Margin, z2 }; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_CULL_FACE)); glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); -#if ENABLE_LEGACY_OPENGL_REMOVAL if (!m_planes.models[0].is_initialized() || !is_approx(m_planes.check_points[0], p1)) { m_planes.check_points[0] = p1; m_planes.models[0].reset(); @@ -2931,23 +2641,6 @@ void Selection::render_sidebar_layers_hints(const std::string& sidebar_field) m_planes.models[0].render(); m_planes.models[1].set_color((camera_on_top && type == 2) || (!camera_on_top && type == 1) ? SOLID_PLANE_COLOR : TRANSPARENT_PLANE_COLOR); m_planes.models[1].render(); -#else - ::glBegin(GL_QUADS); - ::glColor4fv((camera_on_top && type == 1) || (!camera_on_top && type == 2) ? SOLID_PLANE_COLOR.data() : TRANSPARENT_PLANE_COLOR.data()); - ::glVertex3f(min_x, min_y, z1); - ::glVertex3f(max_x, min_y, z1); - ::glVertex3f(max_x, max_y, z1); - ::glVertex3f(min_x, max_y, z1); - glsafe(::glEnd()); - - ::glBegin(GL_QUADS); - ::glColor4fv((camera_on_top && type == 2) || (!camera_on_top && type == 1) ? SOLID_PLANE_COLOR.data() : TRANSPARENT_PLANE_COLOR.data()); - ::glVertex3f(min_x, min_y, z2); - ::glVertex3f(max_x, min_y, z2); - ::glVertex3f(max_x, max_y, z2); - ::glVertex3f(min_x, max_y, z2); - glsafe(::glEnd()); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glDisable(GL_BLEND)); diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index 6468f6a87..107e56f41 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -253,7 +253,6 @@ private: #endif // ENABLE_WORLD_COORDINATE GLModel m_arrow; GLModel m_curved_arrow; -#if ENABLE_LEGACY_OPENGL_REMOVAL GLModel m_box; struct Planes { @@ -261,7 +260,6 @@ private: std::array models; }; Planes m_planes; -#endif // ENABLE_LEGACY_OPENGL_REMOVAL float m_scale_factor; @@ -467,7 +465,6 @@ private: void set_bounding_boxes_dirty() { m_bounding_box.reset(); m_unscaled_instance_bounding_box.reset(); m_scaled_instance_bounding_box.reset(); } #endif // ENABLE_WORLD_COORDINATE void render_synchronized_volumes(); -#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_WORLD_COORDINATE void render_bounding_box(const BoundingBoxf3& box, const Transform3d& trafo, const ColorRGB& color); #else @@ -479,14 +476,6 @@ private: void render_sidebar_rotation_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix); void render_sidebar_scale_hints(const std::string& sidebar_field, GLShaderProgram& shader, const Transform3d& matrix); void render_sidebar_layers_hints(const std::string& sidebar_field, GLShaderProgram& shader); -#else - void render_selected_volumes() const; - void render_bounding_box(const BoundingBoxf3& box, float* color) const; - void render_sidebar_position_hints(const std::string& sidebar_field); - void render_sidebar_rotation_hints(const std::string& sidebar_field); - void render_sidebar_scale_hints(const std::string& sidebar_field); - void render_sidebar_layers_hints(const std::string& sidebar_field); -#endif // ENABLE_LEGACY_OPENGL_REMOVAL public: enum class SyncRotationType { diff --git a/src/slic3r/Utils/UndoRedo.cpp b/src/slic3r/Utils/UndoRedo.cpp index 8fe20d012..67cb23d57 100644 --- a/src/slic3r/Utils/UndoRedo.cpp +++ b/src/slic3r/Utils/UndoRedo.cpp @@ -21,9 +21,7 @@ #include #include -#if ENABLE_LEGACY_OPENGL_REMOVAL #include "slic3r/GUI/3DScene.hpp" -#endif // ENABLE_LEGACY_OPENGL_REMOVAL #include