Unified opengl textures

This commit is contained in:
Enrico Turri 2018-07-18 15:07:52 +02:00
parent b69e23ce73
commit 3fac0d92cd
4 changed files with 501 additions and 220 deletions

View File

@ -540,8 +540,11 @@ double GLVolume::layer_height_texture_z_to_row_id() const
void GLVolume::generate_layer_height_texture(PrintObject *print_object, bool force)
{
GLTexture *tex = this->layer_height_texture.get();
if (tex == nullptr)
//########################################################################################################################################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;
@ -588,7 +591,10 @@ std::vector<int> GLVolumeCollection::load_object(
};
// Object will have a single common layer height texture for all volumes.
std::shared_ptr<GLTexture> layer_height_texture = std::make_shared<GLTexture>();
//########################################################################################################################################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) {
@ -1580,45 +1586,44 @@ _3DScene::LegendTexture _3DScene::s_legend_texture;
_3DScene::WarningTexture _3DScene::s_warning_texture;
GUI::GLCanvas3DManager _3DScene::s_canvas_mgr;
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
//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;
// Generate a texture data, but don't load it into the GPU yet, as the GPU context may not yet be valid.
//########################################################################################################################################3
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();
reset();
if (msg.empty())
return false;
@ -1630,11 +1635,11 @@ bool _3DScene::WarningTexture::generate(const std::string& msg)
// calculates texture size
wxCoord w, h;
memDC.GetTextExtent(msg, &w, &h);
m_tex_width = (unsigned int)w;
m_tex_height = (unsigned int)h;
m_width = (int)w;
m_height = (int)h;
// generates bitmap
wxBitmap bitmap(m_tex_width, m_tex_height);
wxBitmap bitmap(m_width, m_height);
#if defined(__APPLE__) || defined(_MSC_VER)
bitmap.UseAlpha();
@ -1652,38 +1657,107 @@ bool _3DScene::WarningTexture::generate(const std::string& msg)
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]);
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)
// prepare buffer
std::vector<unsigned char> data(4 * m_width * m_height, 0);
for (int h = 0; h < m_height; ++h)
{
int hh = h * m_width;
unsigned char* px_ptr = data.data() + 4 * hh;
for (int w = 0; w < m_width; ++w)
{
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;
}
*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;
}
}
// sends buffer to gpu
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
::glGenTextures(1, &m_id);
::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id);
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)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);
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;
// Generate a texture data, but don't load it into the GPU yet, as the GPU context may not yet be valid.
//########################################################################################################################################3
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();
reset();
// collects items to render
auto title = _(preview_data.get_legend_title());
@ -1701,25 +1775,25 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con
// 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;
int title_width = (int)w;
int title_height = (int)h;
unsigned int max_text_width = 0;
unsigned int max_text_height = 0;
int max_text_width = 0;
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);
max_text_width = std::max(max_text_width, (int)w);
max_text_height = std::max(max_text_height, (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;
m_width = std::max(2 * Px_Border + title_width, 2 * (Px_Border + Px_Square_Contour) + Px_Square + Px_Text_Offset + max_text_width);
m_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;
m_height += (items_count - 1) * Px_Square_Contour;
// generates bitmap
wxBitmap bitmap(m_tex_width, m_tex_height);
wxBitmap bitmap(m_width, m_height);
#if defined(__APPLE__) || defined(_MSC_VER)
bitmap.UseAlpha();
@ -1732,15 +1806,15 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con
memDC.SetTextForeground(*wxWHITE);
// draw title
unsigned int title_x = Px_Border;
unsigned int title_y = Px_Border;
int title_x = Px_Border;
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;
int squares_contour_x = Px_Border;
int squares_contour_y = Px_Border + title_height + Px_Title_Offset;
int squares_contour_width = Px_Square + 2 * Px_Square_Contour;
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;
@ -1752,15 +1826,15 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con
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;
int icon_x = squares_contour_x + Px_Square_Contour;
int icon_x_inner = icon_x + 1;
int icon_y = squares_contour_y + Px_Square_Contour;
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;
int text_x = icon_x + Px_Square + Px_Text_Offset;
int text_y_offset = (Px_Square - max_text_height) / 2;
unsigned int px_inner_square = Px_Square - 2;
int px_inner_square = Px_Square - 2;
for (const GCodePreviewData::LegendItem& item : items)
{
@ -1785,7 +1859,7 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con
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);
memDC.DrawText(GUI::from_u8(item.text), text_x, icon_y + text_y_offset);
// update y
icon_y += icon_y_step;
@ -1794,28 +1868,177 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con
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]);
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)
// prepare buffer
std::vector<unsigned char> data(4 * m_width * m_height, 0);
for (int h = 0; h < m_height; ++h)
{
int hh = h * m_width;
unsigned char* px_ptr = data.data() + 4 * hh;
for (int w = 0; w < m_width; ++w)
{
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;
}
*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;
}
}
// sends buffer to gpu
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
::glGenTextures(1, &m_id);
::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id);
::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)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);
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();
@ -2223,36 +2446,60 @@ 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();
}
//###################################################################################################################################################
//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_texture();
//###################################################################################################################################################
s_legend_texture.reset();
// s_legend_texture.reset_texture();
//###################################################################################################################################################
}
unsigned int _3DScene::finalize_legend_texture()
//###################################################################################################################################################
unsigned int _3DScene::get_legend_texture_id()
{
return s_legend_texture.finalize();
return s_legend_texture.get_id();
}
unsigned int _3DScene::get_warning_texture_width()
int _3DScene::get_legend_texture_width()
{
return s_warning_texture.get_texture_width();
return s_legend_texture.get_width();
}
unsigned int _3DScene::get_warning_texture_height()
int _3DScene::get_legend_texture_height()
{
return s_warning_texture.get_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);
@ -2260,12 +2507,32 @@ void _3DScene::generate_warning_texture(const std::string& msg)
void _3DScene::reset_warning_texture()
{
s_warning_texture.reset_texture();
//###################################################################################################################################################
s_warning_texture.reset();
// s_warning_texture.reset_texture();
//###################################################################################################################################################
}
unsigned int _3DScene::finalize_warning_texture()
//###################################################################################################################################################
unsigned int _3DScene::get_warning_texture_id()
{
return s_warning_texture.finalize();
return s_warning_texture.get_id();
}
int _3DScene::get_warning_texture_width()
{
return s_warning_texture.get_width();
}
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

View File

@ -7,6 +7,9 @@
#include "../../libslic3r/TriangleMesh.hpp"
#include "../../libslic3r/Utils.hpp"
#include "../../slic3r/GUI/GLCanvas3DManager.hpp"
//#################################################################################################################################
#include "../../slic3r/GUI/GLTexture.hpp"
//#################################################################################################################################
class wxBitmap;
class wxWindow;
@ -199,10 +202,16 @@ private:
}
};
class GLTexture
//########################################################################################################################################3
class LayersTexture
//class GLTexture
//########################################################################################################################################3
{
public:
GLTexture() : width(0), height(0), levels(0), cells(0) {}
//########################################################################################################################################3
LayersTexture() : width(0), height(0), levels(0), cells(0) {}
// GLTexture() : width(0), height(0), levels(0), cells(0) {}
//########################################################################################################################################3
// Texture data
std::vector<char> data;
@ -341,7 +350,10 @@ public:
void release_geometry() { this->indexed_vertex_array.release_geometry(); }
/************************************************ Layer height texture ****************************************************/
std::shared_ptr<GLTexture> layer_height_texture;
//########################################################################################################################################3
std::shared_ptr<LayersTexture> layer_height_texture;
// std::shared_ptr<GLTexture> layer_height_texture;
//########################################################################################################################################3
// Data to render this volume using the layer height texture
LayerHeightTextureData layer_height_texture_data;
@ -437,63 +449,93 @@ private:
class _3DScene
{
class TextureBase
{
protected:
unsigned int m_tex_id;
unsigned int m_tex_width;
unsigned int m_tex_height;
//###################################################################################################################################################
// class TextureBase
// {
// protected:
// unsigned int m_tex_id;
// unsigned int m_tex_width;
// unsigned int m_tex_height;
//
// // generate() fills in m_data with the pixels, while finalize() moves the data to the GPU before rendering.
// std::vector<unsigned char> m_data;
//
// public:
// TextureBase() : m_tex_id(0), m_tex_width(0), m_tex_height(0) {}
// virtual ~TextureBase() { _destroy_texture(); }
//
// // If not loaded, load the texture data into the GPU. Return a texture ID or 0 if the texture has zero size.
// unsigned int finalize();
//
// unsigned int get_texture_id() const { return m_tex_id; }
// unsigned int get_texture_width() const { return m_tex_width; }
// unsigned int get_texture_height() const { return m_tex_height; }
//
// void reset_texture() { _destroy_texture(); }
//
// private:
// void _destroy_texture();
// };
//###################################################################################################################################################
// generate() fills in m_data with the pixels, while finalize() moves the data to the GPU before rendering.
std::vector<unsigned char> m_data;
public:
TextureBase() : m_tex_id(0), m_tex_width(0), m_tex_height(0) {}
virtual ~TextureBase() { _destroy_texture(); }
// If not loaded, load the texture data into the GPU. Return a texture ID or 0 if the texture has zero size.
unsigned int finalize();
unsigned int get_texture_id() const { return m_tex_id; }
unsigned int get_texture_width() const { return m_tex_width; }
unsigned int get_texture_height() const { return m_tex_height; }
void reset_texture() { _destroy_texture(); }
private:
void _destroy_texture();
};
class WarningTexture : public TextureBase
//###################################################################################################################################################
class WarningTexture : public GUI::GLTexture
{
static const unsigned char Background_Color[3];
static const unsigned char Opacity;
public:
WarningTexture() : TextureBase() {}
// Generate a texture data, but don't load it into the GPU yet, as the glcontext may not be valid yet.
bool generate(const std::string& msg);
};
class LegendTexture : public TextureBase
// class WarningTexture : public TextureBase
// {
// static const unsigned char Background_Color[3];
// static const unsigned char Opacity;
//
// public:
// WarningTexture() : TextureBase() {}
//
// // Generate a texture data, but don't load it into the GPU yet, as the glcontext may not be valid yet.
// bool generate(const std::string& msg);
// };
//###################################################################################################################################################
//###################################################################################################################################################
class LegendTexture : public GUI::GLTexture
{
static const unsigned int Px_Title_Offset = 5;
static const unsigned int Px_Text_Offset = 5;
static const unsigned int Px_Square = 20;
static const unsigned int Px_Square_Contour = 1;
static const unsigned int Px_Border = Px_Square / 2;
static const int Px_Title_Offset = 5;
static const int Px_Text_Offset = 5;
static const int Px_Square = 20;
static const int Px_Square_Contour = 1;
static const int Px_Border = Px_Square / 2;
static const unsigned char Squares_Border_Color[3];
static const unsigned char Background_Color[3];
static const unsigned char Opacity;
public:
LegendTexture() : TextureBase() {}
// Generate a texture data, but don't load it into the GPU yet, as the glcontext may not be valid yet.
bool generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
};
// class LegendTexture : public TextureBase
// {
// static const unsigned int Px_Title_Offset = 5;
// static const unsigned int Px_Text_Offset = 5;
// static const unsigned int Px_Square = 20;
// static const unsigned int Px_Square_Contour = 1;
// static const unsigned int Px_Border = Px_Square / 2;
// static const unsigned char Squares_Border_Color[3];
// static const unsigned char Background_Color[3];
// static const unsigned char Opacity;
//
// public:
// LegendTexture() : TextureBase() {}
//
// // Generate a texture data, but don't load it into the GPU yet, as the glcontext may not be valid yet.
// bool generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
// };
//###################################################################################################################################################
static LegendTexture s_legend_texture;
static WarningTexture s_warning_texture;
static GUI::GLCanvas3DManager s_canvas_mgr;
@ -599,19 +641,33 @@ public:
// generates the legend texture in dependence of the current shown view type
static void generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
static unsigned int get_legend_texture_width();
static unsigned int get_legend_texture_height();
//###################################################################################################################################################
// static unsigned int get_legend_texture_width();
// static unsigned int get_legend_texture_height();
//###################################################################################################################################################
static void reset_legend_texture();
static unsigned int finalize_legend_texture();
//###################################################################################################################################################
static unsigned int get_legend_texture_id();
static int get_legend_texture_width();
static int get_legend_texture_height();
// static unsigned int finalize_legend_texture();
//###################################################################################################################################################
static unsigned int get_warning_texture_width();
static unsigned int get_warning_texture_height();
//###################################################################################################################################################
// static unsigned int get_warning_texture_width();
// static unsigned int get_warning_texture_height();
//###################################################################################################################################################
// generates a warning texture containing the given message
static void generate_warning_texture(const std::string& msg);
static void reset_warning_texture();
static unsigned int finalize_warning_texture();
//###################################################################################################################################################
static unsigned int get_warning_texture_id();
static int get_warning_texture_width();
static int get_warning_texture_height();
// static unsigned int finalize_warning_texture();
//###################################################################################################################################################
static void thick_lines_to_verts(const Lines& lines, const std::vector<double>& widths, const std::vector<double>& heights, bool closed, double top_z, GLVolume& volume);
static void thick_lines_to_verts(const Lines3& lines, const std::vector<double>& widths, const std::vector<double>& heights, bool closed, GLVolume& volume);

View File

@ -10,7 +10,10 @@ namespace GUI {
class GLTexture
{
private:
//###################################################################################################################################################
protected:
// private:
//###################################################################################################################################################
unsigned int m_id;
int m_width;
int m_height;
@ -18,7 +21,10 @@ namespace GUI {
public:
GLTexture();
~GLTexture();
//###################################################################################################################################################
virtual ~GLTexture();
// ~GLTexture();
//###################################################################################################################################################
bool load_from_file(const std::string& filename, bool generate_mipmaps);
void reset();
@ -26,11 +32,15 @@ namespace GUI {
unsigned int get_id() const;
int get_width() const;
int get_height() const;
const std::string& get_source() const;
static void render_texture(unsigned int tex_id, float left, float right, float bottom, float top);
private:
//###################################################################################################################################################
protected:
// private:
//###################################################################################################################################################
void _generate_mipmaps(wxImage& image);
};

View File

@ -628,63 +628,11 @@ register_on_update_geometry_info_callback(canvas, callback)
CODE:
_3DScene::register_on_update_geometry_info_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
unsigned int
finalize_legend_texture()
CODE:
RETVAL = _3DScene::finalize_legend_texture();
OUTPUT:
RETVAL
unsigned int
get_legend_texture_width()
CODE:
RETVAL = _3DScene::get_legend_texture_width();
OUTPUT:
RETVAL
unsigned int
get_legend_texture_height()
CODE:
RETVAL = _3DScene::get_legend_texture_height();
OUTPUT:
RETVAL
void
reset_legend_texture()
CODE:
_3DScene::reset_legend_texture();
void
generate_warning_texture(std::string msg)
CODE:
_3DScene::generate_warning_texture(msg);
unsigned int
finalize_warning_texture()
CODE:
RETVAL = _3DScene::finalize_warning_texture();
OUTPUT:
RETVAL
unsigned int
get_warning_texture_width()
CODE:
RETVAL = _3DScene::get_warning_texture_width();
OUTPUT:
RETVAL
unsigned int
get_warning_texture_height()
CODE:
RETVAL = _3DScene::get_warning_texture_height();
OUTPUT:
RETVAL
void
reset_warning_texture()
CODE:
_3DScene::reset_warning_texture();
std::vector<int>
load_model_object(canvas, model_object, obj_idx, instance_idxs)
SV *canvas;