Code cleanup

This commit is contained in:
Enrico Turri 2018-07-18 15:52:20 +02:00
parent be7b786fee
commit 7f267987cb
4 changed files with 4 additions and 386 deletions

View file

@ -540,10 +540,7 @@ double GLVolume::layer_height_texture_z_to_row_id() const
void GLVolume::generate_layer_height_texture(PrintObject *print_object, bool force)
{
//########################################################################################################################################3
LayersTexture *tex = this->layer_height_texture.get();
// GLTexture *tex = this->layer_height_texture.get();
//########################################################################################################################################3
if (tex == nullptr)
// No layer_height_texture is assigned to this GLVolume, therefore the layer height texture cannot be filled.
return;
@ -591,10 +588,7 @@ std::vector<int> GLVolumeCollection::load_object(
};
// Object will have a single common layer height texture for all volumes.
//########################################################################################################################################3
std::shared_ptr<LayersTexture> layer_height_texture = std::make_shared<LayersTexture>();
// std::shared_ptr<GLTexture> layer_height_texture = std::make_shared<GLTexture>();
//########################################################################################################################################3
std::vector<int> volumes_idx;
for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++ volume_idx) {
@ -1599,41 +1593,9 @@ _3DScene::LegendTexture _3DScene::s_legend_texture;
_3DScene::WarningTexture _3DScene::s_warning_texture;
GUI::GLCanvas3DManager _3DScene::s_canvas_mgr;
//########################################################################################################################################3
//unsigned int _3DScene::TextureBase::finalize()
//{
// if ((m_tex_id == 0) && !m_data.empty()) {
// // sends buffer to gpu
// ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// ::glGenTextures(1, &m_tex_id);
// ::glBindTexture(GL_TEXTURE_2D, (GLuint)m_tex_id);
// ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_tex_width, (GLsizei)m_tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)m_data.data());
// ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
// ::glBindTexture(GL_TEXTURE_2D, 0);
// m_data.clear();
// }
// return (m_tex_width > 0 && m_tex_height > 0) ? m_tex_id : 0;
//}
//
//void _3DScene::TextureBase::_destroy_texture()
//{
// if (m_tex_id > 0)
// {
// ::glDeleteTextures(1, &m_tex_id);
// m_tex_id = 0;
// m_tex_height = 0;
// m_tex_width = 0;
// }
// m_data.clear();
//}
//########################################################################################################################################3
const unsigned char _3DScene::WarningTexture::Background_Color[3] = { 9, 91, 134 };
const unsigned char _3DScene::WarningTexture::Opacity = 255;
//########################################################################################################################################3
bool _3DScene::WarningTexture::generate(const std::string& msg)
{
reset();
@ -1701,73 +1663,10 @@ bool _3DScene::WarningTexture::generate(const std::string& msg)
return true;
}
//// Generate a texture data, but don't load it into the GPU yet, as the GPU context may not yet be valid.
//bool _3DScene::WarningTexture::generate(const std::string& msg)
//{
// // Mark the texture as released, but don't release the texture from the GPU yet.
// m_tex_width = m_tex_height = 0;
// m_data.clear();
//
// if (msg.empty())
// return false;
//
// wxMemoryDC memDC;
// // select default font
// memDC.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
//
// // calculates texture size
// wxCoord w, h;
// memDC.GetTextExtent(msg, &w, &h);
// m_tex_width = (unsigned int)w;
// m_tex_height = (unsigned int)h;
//
// // generates bitmap
// wxBitmap bitmap(m_tex_width, m_tex_height);
//
//#if defined(__APPLE__) || defined(_MSC_VER)
// bitmap.UseAlpha();
//#endif
//
// memDC.SelectObject(bitmap);
// memDC.SetBackground(wxBrush(wxColour(Background_Color[0], Background_Color[1], Background_Color[2])));
// memDC.Clear();
//
// memDC.SetTextForeground(*wxWHITE);
//
// // draw message
// memDC.DrawText(msg, 0, 0);
//
// memDC.SelectObject(wxNullBitmap);
//
// // Convert the bitmap into a linear data ready to be loaded into the GPU.
// {
// wxImage image = bitmap.ConvertToImage();
// image.SetMaskColour(Background_Color[0], Background_Color[1], Background_Color[2]);
//
// // prepare buffer
// m_data.assign(4 * m_tex_width * m_tex_height, 0);
// for (unsigned int h = 0; h < m_tex_height; ++h)
// {
// unsigned int hh = h * m_tex_width;
// unsigned char* px_ptr = m_data.data() + 4 * hh;
// for (unsigned int w = 0; w < m_tex_width; ++w)
// {
// *px_ptr++ = image.GetRed(w, h);
// *px_ptr++ = image.GetGreen(w, h);
// *px_ptr++ = image.GetBlue(w, h);
// *px_ptr++ = image.IsTransparent(w, h) ? 0 : Opacity;
// }
// }
// }
// return true;
//}
//########################################################################################################################################3
const unsigned char _3DScene::LegendTexture::Squares_Border_Color[3] = { 64, 64, 64 };
const unsigned char _3DScene::LegendTexture::Background_Color[3] = { 9, 91, 134 };
const unsigned char _3DScene::LegendTexture::Opacity = 255;
//########################################################################################################################################3
bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors)
{
reset();
@ -1912,146 +1811,6 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con
return true;
}
//// Generate a texture data, but don't load it into the GPU yet, as the GPU context may not yet be valid.
//bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors)
//{
// // Mark the texture as released, but don't release the texture from the GPU yet.
// m_tex_width = m_tex_height = 0;
// m_data.clear();
//
// // collects items to render
// auto title = _(preview_data.get_legend_title());
// const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors);
//
// unsigned int items_count = (unsigned int)items.size();
// if (items_count == 0)
// // nothing to render, return
// return false;
//
// wxMemoryDC memDC;
// // select default font
// memDC.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
//
// // calculates texture size
// wxCoord w, h;
// memDC.GetTextExtent(title, &w, &h);
// unsigned int title_width = (unsigned int)w;
// unsigned int title_height = (unsigned int)h;
//
// unsigned int max_text_width = 0;
// unsigned int max_text_height = 0;
// for (const GCodePreviewData::LegendItem& item : items)
// {
// memDC.GetTextExtent(GUI::from_u8(item.text), &w, &h);
// max_text_width = std::max(max_text_width, (unsigned int)w);
// max_text_height = std::max(max_text_height, (unsigned int)h);
// }
//
// m_tex_width = std::max(2 * Px_Border + title_width, 2 * (Px_Border + Px_Square_Contour) + Px_Square + Px_Text_Offset + max_text_width);
// m_tex_height = 2 * (Px_Border + Px_Square_Contour) + title_height + Px_Title_Offset + items_count * Px_Square;
// if (items_count > 1)
// m_tex_height += (items_count - 1) * Px_Square_Contour;
//
// // generates bitmap
// wxBitmap bitmap(m_tex_width, m_tex_height);
//
//#if defined(__APPLE__) || defined(_MSC_VER)
// bitmap.UseAlpha();
//#endif
//
// memDC.SelectObject(bitmap);
// memDC.SetBackground(wxBrush(wxColour(Background_Color[0], Background_Color[1], Background_Color[2])));
// memDC.Clear();
//
// memDC.SetTextForeground(*wxWHITE);
//
// // draw title
// unsigned int title_x = Px_Border;
// unsigned int title_y = Px_Border;
// memDC.DrawText(title, title_x, title_y);
//
// // draw icons contours as background
// unsigned int squares_contour_x = Px_Border;
// unsigned int squares_contour_y = Px_Border + title_height + Px_Title_Offset;
// unsigned int squares_contour_width = Px_Square + 2 * Px_Square_Contour;
// unsigned int squares_contour_height = items_count * Px_Square + 2 * Px_Square_Contour;
// if (items_count > 1)
// squares_contour_height += (items_count - 1) * Px_Square_Contour;
//
// wxColour color(Squares_Border_Color[0], Squares_Border_Color[1], Squares_Border_Color[2]);
// wxPen pen(color);
// wxBrush brush(color);
// memDC.SetPen(pen);
// memDC.SetBrush(brush);
// memDC.DrawRectangle(wxRect(squares_contour_x, squares_contour_y, squares_contour_width, squares_contour_height));
//
// // draw items (colored icon + text)
// unsigned int icon_x = squares_contour_x + Px_Square_Contour;
// unsigned int icon_x_inner = icon_x + 1;
// unsigned int icon_y = squares_contour_y + Px_Square_Contour;
// unsigned int icon_y_step = Px_Square + Px_Square_Contour;
//
// unsigned int text_x = icon_x + Px_Square + Px_Text_Offset;
// unsigned int text_y_offset = (Px_Square - max_text_height) / 2;
//
// unsigned int px_inner_square = Px_Square - 2;
//
// for (const GCodePreviewData::LegendItem& item : items)
// {
// // draw darker icon perimeter
// const std::vector<unsigned char>& item_color_bytes = item.color.as_bytes();
// wxImage::HSVValue dark_hsv = wxImage::RGBtoHSV(wxImage::RGBValue(item_color_bytes[0], item_color_bytes[1], item_color_bytes[2]));
// dark_hsv.value *= 0.75;
// wxImage::RGBValue dark_rgb = wxImage::HSVtoRGB(dark_hsv);
// color.Set(dark_rgb.red, dark_rgb.green, dark_rgb.blue, item_color_bytes[3]);
// pen.SetColour(color);
// brush.SetColour(color);
// memDC.SetPen(pen);
// memDC.SetBrush(brush);
// memDC.DrawRectangle(wxRect(icon_x, icon_y, Px_Square, Px_Square));
//
// // draw icon interior
// color.Set(item_color_bytes[0], item_color_bytes[1], item_color_bytes[2], item_color_bytes[3]);
// pen.SetColour(color);
// brush.SetColour(color);
// memDC.SetPen(pen);
// memDC.SetBrush(brush);
// memDC.DrawRectangle(wxRect(icon_x_inner, icon_y + 1, px_inner_square, px_inner_square));
//
// // draw text
// memDC.DrawText(GUI::from_u8(item.text), text_x, icon_y + text_y_offset);
//
// // update y
// icon_y += icon_y_step;
// }
//
// memDC.SelectObject(wxNullBitmap);
//
// // Convert the bitmap into a linear data ready to be loaded into the GPU.
// {
// wxImage image = bitmap.ConvertToImage();
// image.SetMaskColour(Background_Color[0], Background_Color[1], Background_Color[2]);
//
// // prepare buffer
// m_data.assign(4 * m_tex_width * m_tex_height, 0);
// for (unsigned int h = 0; h < m_tex_height; ++h)
// {
// unsigned int hh = h * m_tex_width;
// unsigned char* px_ptr = m_data.data() + 4 * hh;
// for (unsigned int w = 0; w < m_tex_width; ++w)
// {
// *px_ptr++ = image.GetRed(w, h);
// *px_ptr++ = image.GetGreen(w, h);
// *px_ptr++ = image.GetBlue(w, h);
// *px_ptr++ = image.IsTransparent(w, h) ? 0 : Opacity;
// }
// }
// }
// return true;
//}
//########################################################################################################################################3
void _3DScene::init_gl()
{
s_canvas_mgr.init_gl();
@ -2459,27 +2218,11 @@ void _3DScene::generate_legend_texture(const GCodePreviewData& preview_data, con
s_legend_texture.generate(preview_data, tool_colors);
}
//###################################################################################################################################################
//unsigned int _3DScene::get_legend_texture_width()
//{
// return s_legend_texture.get_texture_width();
//}
//
//unsigned int _3DScene::get_legend_texture_height()
//{
// return s_legend_texture.get_texture_height();
//}
//###################################################################################################################################################
void _3DScene::reset_legend_texture()
{
//###################################################################################################################################################
s_legend_texture.reset();
// s_legend_texture.reset_texture();
//###################################################################################################################################################
}
//###################################################################################################################################################
unsigned int _3DScene::get_legend_texture_id()
{
return s_legend_texture.get_id();
@ -2495,24 +2238,6 @@ int _3DScene::get_legend_texture_height()
return s_legend_texture.get_height();
}
//unsigned int _3DScene::finalize_legend_texture()
//{
// return s_legend_texture.finalize();
//}
//###################################################################################################################################################
//###################################################################################################################################################
//unsigned int _3DScene::get_warning_texture_width()
//{
// return s_warning_texture.get_texture_width();
//}
//
//unsigned int _3DScene::get_warning_texture_height()
//{
// return s_warning_texture.get_texture_height();
//}
//###################################################################################################################################################
void _3DScene::generate_warning_texture(const std::string& msg)
{
s_warning_texture.generate(msg);
@ -2520,13 +2245,9 @@ void _3DScene::generate_warning_texture(const std::string& msg)
void _3DScene::reset_warning_texture()
{
//###################################################################################################################################################
s_warning_texture.reset();
// s_warning_texture.reset_texture();
//###################################################################################################################################################
}
//###################################################################################################################################################
unsigned int _3DScene::get_warning_texture_id()
{
return s_warning_texture.get_id();
@ -2542,10 +2263,4 @@ int _3DScene::get_warning_texture_height()
return s_warning_texture.get_height();
}
//unsigned int _3DScene::finalize_warning_texture()
//{
// return s_warning_texture.finalize();
//}
//###################################################################################################################################################
} // namespace Slic3r