Tech ENABLE_LEGACY_OPENGL_REMOVAL set as default
This commit is contained in:
parent
7b569c4eb7
commit
028dfb5d9e
74 changed files with 37 additions and 6847 deletions
|
@ -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 <GL/glew.h>
|
||||
|
||||
|
@ -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<Vec2f> &triangles, float z)
|
||||
{
|
||||
if (triangles.empty()) {
|
||||
m_vertices.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(triangles.size() % 3 == 0);
|
||||
m_vertices = std::vector<Vertex>(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<Vertex>(v_size, Vertex());
|
||||
|
||||
unsigned int v_count = 0;
|
||||
for (const Line& l : lines) {
|
||||
Vertex& v1 = m_vertices[v_count];
|
||||
v1.position[0] = unscale<float>(l.a(0));
|
||||
v1.position[1] = unscale<float>(l.a(1));
|
||||
v1.position[2] = z;
|
||||
++v_count;
|
||||
|
||||
Vertex& v2 = m_vertices[v_count];
|
||||
v2.position[0] = unscale<float>(l.b(0));
|
||||
v2.position[1] = unscale<float>(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<float>());
|
||||
#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<float>());
|
||||
#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<float>());
|
||||
#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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue