Texture compression set as an option
This commit is contained in:
parent
61c41aa90f
commit
886da08f89
@ -517,7 +517,11 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const
|
||||
|
||||
if ((m_texture.get_id() == 0) || (m_texture.get_source() != filename))
|
||||
{
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (!m_texture.load_from_svg_file(filename, true, true, max_tex_size))
|
||||
#else
|
||||
if (!m_texture.load_from_svg_file(filename, true, max_tex_size))
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
render_custom();
|
||||
return;
|
||||
|
@ -405,7 +405,11 @@ void GLCanvas3D::LayersEditing::_render_tooltip_texture(const GLCanvas3D& canvas
|
||||
if (m_tooltip_texture.get_id() == 0)
|
||||
{
|
||||
std::string filename = resources_dir() + "/icons/variable_layer_height_tooltip.png";
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (!m_tooltip_texture.load_from_file(filename, false, true))
|
||||
#else
|
||||
if (!m_tooltip_texture.load_from_file(filename, false))
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
return;
|
||||
}
|
||||
|
||||
@ -437,7 +441,11 @@ void GLCanvas3D::LayersEditing::_render_reset_texture(const Rect& reset_rect) co
|
||||
if (m_reset_texture.get_id() == 0)
|
||||
{
|
||||
std::string filename = resources_dir() + "/icons/variable_layer_height_reset.png";
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (!m_reset_texture.load_from_file(filename, false, true))
|
||||
#else
|
||||
if (!m_reset_texture.load_from_file(filename, false))
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
return;
|
||||
}
|
||||
|
||||
@ -729,7 +737,11 @@ void GLCanvas3D::WarningTexture::activate(WarningTexture::Warning warning, bool
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
generate(text, canvas, true, red_colored); // GUI::GLTexture::reset() is called at the beginning of generate(...)
|
||||
#else
|
||||
_generate(text, canvas, red_colored); // GUI::GLTexture::reset() is called at the beginning of generate(...)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
|
||||
// save information for rescaling
|
||||
m_msg_text = text;
|
||||
@ -790,7 +802,11 @@ static void msw_disable_cleartype(wxFont &font)
|
||||
}
|
||||
#endif /* __WXMSW__ */
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool GLCanvas3D::WarningTexture::generate(const std::string& msg_utf8, const GLCanvas3D& canvas, bool compress, bool red_colored/* = false*/)
|
||||
#else
|
||||
bool GLCanvas3D::WarningTexture::_generate(const std::string& msg_utf8, const GLCanvas3D& canvas, const bool red_colored/* = false*/)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
reset();
|
||||
|
||||
@ -865,7 +881,7 @@ bool GLCanvas3D::WarningTexture::_generate(const std::string& msg_utf8, const GL
|
||||
glsafe(::glGenTextures(1, &m_id));
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id));
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
if (compress && GLEW_EXT_texture_compression_s3tc)
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
@ -922,7 +938,11 @@ void GLCanvas3D::WarningTexture::msw_rescale(const GLCanvas3D& canvas)
|
||||
if (m_msg_text.empty())
|
||||
return;
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
generate(m_msg_text, canvas, true, m_is_colored_red);
|
||||
#else
|
||||
_generate(m_msg_text, canvas, m_is_colored_red);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
}
|
||||
|
||||
const unsigned char GLCanvas3D::LegendTexture::Squares_Border_Color[3] = { 64, 64, 64 };
|
||||
@ -965,7 +985,11 @@ void GLCanvas3D::LegendTexture::fill_color_print_legend_values(const GCodePrevie
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas, bool compress)
|
||||
#else
|
||||
bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
reset();
|
||||
|
||||
@ -1155,7 +1179,7 @@ bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, c
|
||||
glsafe(::glGenTextures(1, &m_id));
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id));
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
if (compress && GLEW_EXT_texture_compression_s3tc)
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
@ -1714,9 +1738,9 @@ void GLCanvas3D::render()
|
||||
imgui.text(" ms");
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
ImGui::Separator();
|
||||
imgui.text("Textures: ");
|
||||
imgui.text("Compressed textures: ");
|
||||
ImGui::SameLine();
|
||||
imgui.text(GLCanvas3DManager::are_compressed_textures_supported() ? "compressed" : "uncompressed");
|
||||
imgui.text(GLCanvas3DManager::are_compressed_textures_supported() ? "supported" : "not supported");
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
#if ENABLE_TEXTURES_MAXSIZE_DEPENDENT_ON_OPENGL_VERSION
|
||||
imgui.text("Max texture size: ");
|
||||
@ -5698,7 +5722,11 @@ std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& col
|
||||
|
||||
void GLCanvas3D::_generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors)
|
||||
{
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
m_legend_texture.generate(preview_data, tool_colors, *this, true);
|
||||
#else
|
||||
m_legend_texture.generate(preview_data, tool_colors, *this);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
}
|
||||
|
||||
void GLCanvas3D::_set_warning_texture(WarningTexture::Warning warning, bool state)
|
||||
|
@ -374,7 +374,11 @@ class GLCanvas3D
|
||||
std::vector<Warning> m_warnings;
|
||||
|
||||
// Generates the texture with given text.
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool generate(const std::string& msg, const GLCanvas3D& canvas, bool compress, bool red_colored = false);
|
||||
#else
|
||||
bool _generate(const std::string& msg, const GLCanvas3D& canvas, const bool red_colored = false);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
};
|
||||
|
||||
class LegendTexture : public GUI::GLTexture
|
||||
@ -397,7 +401,11 @@ class GLCanvas3D
|
||||
void fill_color_print_legend_values(const GCodePreviewData& preview_data, const GLCanvas3D& canvas,
|
||||
std::vector<std::pair<double, double>>& cp_legend_values);
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas, bool compress);
|
||||
#else
|
||||
bool generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
|
||||
void render(const GLCanvas3D& canvas) const;
|
||||
};
|
||||
|
@ -18,10 +18,6 @@
|
||||
|
||||
#include "libslic3r/Utils.hpp"
|
||||
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
#include <chrono>
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
@ -40,7 +36,11 @@ GLTexture::~GLTexture()
|
||||
reset();
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool GLTexture::load_from_file(const std::string& filename, bool use_mipmaps, bool compress)
|
||||
#else
|
||||
bool GLTexture::load_from_file(const std::string& filename, bool use_mipmaps)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
reset();
|
||||
|
||||
@ -48,12 +48,20 @@ bool GLTexture::load_from_file(const std::string& filename, bool use_mipmaps)
|
||||
return false;
|
||||
|
||||
if (boost::algorithm::iends_with(filename, ".png"))
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
return load_from_png(filename, use_mipmaps, compress);
|
||||
#else
|
||||
return load_from_png(filename, use_mipmaps);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool GLTexture::load_from_svg_file(const std::string& filename, bool use_mipmaps, bool compress, unsigned int max_size_px)
|
||||
#else
|
||||
bool GLTexture::load_from_svg_file(const std::string& filename, bool use_mipmaps, unsigned int max_size_px)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
reset();
|
||||
|
||||
@ -61,12 +69,20 @@ bool GLTexture::load_from_svg_file(const std::string& filename, bool use_mipmaps
|
||||
return false;
|
||||
|
||||
if (boost::algorithm::iends_with(filename, ".svg"))
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
return load_from_svg(filename, use_mipmaps, compress, max_size_px);
|
||||
#else
|
||||
return load_from_svg(filename, use_mipmaps, max_size_px);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool GLTexture::load_from_svg_files_as_sprites_array(const std::vector<std::string>& filenames, const std::vector<std::pair<int, bool>>& states, unsigned int sprite_size_px, bool compress)
|
||||
#else
|
||||
bool GLTexture::load_from_svg_files_as_sprites_array(const std::vector<std::string>& filenames, const std::vector<std::pair<int, bool>>& states, unsigned int sprite_size_px)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
reset();
|
||||
|
||||
@ -183,7 +199,7 @@ bool GLTexture::load_from_svg_files_as_sprites_array(const std::vector<std::stri
|
||||
glsafe(::glGenTextures(1, &m_id));
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, m_id));
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
if (compress && GLEW_EXT_texture_compression_s3tc)
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
@ -263,7 +279,11 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right,
|
||||
glsafe(::glDisable(GL_BLEND));
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
unsigned int GLTexture::generate_mipmaps(wxImage& image, bool compress)
|
||||
#else
|
||||
unsigned int GLTexture::generate_mipmaps(wxImage& image)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
int w = image.GetWidth();
|
||||
int h = image.GetHeight();
|
||||
@ -296,7 +316,7 @@ unsigned int GLTexture::generate_mipmaps(wxImage& image)
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
if (compress && GLEW_EXT_texture_compression_s3tc)
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, level, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)w, (GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, (GLsizei)w, (GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
@ -308,7 +328,11 @@ unsigned int GLTexture::generate_mipmaps(wxImage& image)
|
||||
return (unsigned int)level;
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool GLTexture::load_from_png(const std::string& filename, bool use_mipmaps, bool compress)
|
||||
#else
|
||||
bool GLTexture::load_from_png(const std::string& filename, bool use_mipmaps)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
// Load a PNG with an alpha channel.
|
||||
wxImage image;
|
||||
@ -354,7 +378,7 @@ bool GLTexture::load_from_png(const std::string& filename, bool use_mipmaps)
|
||||
glsafe(::glGenTextures(1, &m_id));
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, m_id));
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
if (compress && GLEW_EXT_texture_compression_s3tc)
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
@ -364,7 +388,11 @@ bool GLTexture::load_from_png(const std::string& filename, bool use_mipmaps)
|
||||
if (use_mipmaps)
|
||||
{
|
||||
// we manually generate mipmaps because glGenerateMipmap() function is not reliable on all graphics cards
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
unsigned int levels_count = generate_mipmaps(image, compress);
|
||||
#else
|
||||
unsigned int levels_count = generate_mipmaps(image);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels_count));
|
||||
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
|
||||
}
|
||||
@ -382,12 +410,12 @@ bool GLTexture::load_from_png(const std::string& filename, bool use_mipmaps)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, bool compress, unsigned int max_size_px)
|
||||
#else
|
||||
bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, unsigned int max_size_px)
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
auto start_time = std::chrono::high_resolution_clock::now();
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
NSVGimage* image = nsvgParseFromFile(filename.c_str(), "px", 96.0f);
|
||||
if (image == nullptr)
|
||||
{
|
||||
@ -427,18 +455,13 @@ bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, uns
|
||||
glsafe(::glGenTextures(1, &m_id));
|
||||
glsafe(::glBindTexture(GL_TEXTURE_2D, m_id));
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
if (compress && GLEW_EXT_texture_compression_s3tc)
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
#else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
auto end_time = std::chrono::high_resolution_clock::now();
|
||||
std::cout << "texture level 0 to GPU in: " << std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count() << std::endl;
|
||||
start_time = end_time;
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
if (use_mipmaps)
|
||||
{
|
||||
// we manually generate mipmaps because glGenerateMipmap() function is not reliable on all graphics cards
|
||||
@ -455,7 +478,7 @@ bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, uns
|
||||
|
||||
nsvgRasterize(rast, image, 0, 0, scale, data.data(), lod_w, lod_h, lod_w * 4);
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
if (compress && GLEW_EXT_texture_compression_s3tc)
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, level, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)lod_w, (GLsizei)lod_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, (GLsizei)lod_w, (GLsizei)lod_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()));
|
||||
@ -481,11 +504,6 @@ bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, uns
|
||||
nsvgDeleteRasterizer(rast);
|
||||
nsvgDelete(image);
|
||||
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
end_time = std::chrono::high_resolution_clock::now();
|
||||
std::cout << "mipmaps to GPU in: " << std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count() << std::endl;
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,13 @@ namespace GUI {
|
||||
GLTexture();
|
||||
virtual ~GLTexture();
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool load_from_file(const std::string& filename, bool use_mipmaps, bool compress);
|
||||
bool load_from_svg_file(const std::string& filename, bool use_mipmaps, bool compress, unsigned int max_size_px);
|
||||
#else
|
||||
bool load_from_file(const std::string& filename, bool use_mipmaps);
|
||||
bool load_from_svg_file(const std::string& filename, bool use_mipmaps, unsigned int max_size_px);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
// meanings of states: (std::pair<int, bool>)
|
||||
// first field (int):
|
||||
// 0 -> no changes
|
||||
@ -48,7 +53,11 @@ namespace GUI {
|
||||
// second field (bool):
|
||||
// false -> no changes
|
||||
// true -> add background color
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool load_from_svg_files_as_sprites_array(const std::vector<std::string>& filenames, const std::vector<std::pair<int, bool>>& states, unsigned int sprite_size_px, bool compress);
|
||||
#else
|
||||
bool load_from_svg_files_as_sprites_array(const std::vector<std::string>& filenames, const std::vector<std::pair<int, bool>>& states, unsigned int sprite_size_px);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
void reset();
|
||||
|
||||
unsigned int get_id() const { return m_id; }
|
||||
@ -61,10 +70,20 @@ namespace GUI {
|
||||
static void render_sub_texture(unsigned int tex_id, float left, float right, float bottom, float top, const Quad_UVs& uvs);
|
||||
|
||||
protected:
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
unsigned int generate_mipmaps(wxImage& image, bool compress);
|
||||
#else
|
||||
unsigned int generate_mipmaps(wxImage& image);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
|
||||
private:
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool load_from_png(const std::string& filename, bool use_mipmaps, bool compress);
|
||||
bool load_from_svg(const std::string& filename, bool use_mipmaps, bool compress, unsigned int max_size_px);
|
||||
#else
|
||||
bool load_from_png(const std::string& filename, bool use_mipmaps);
|
||||
bool load_from_svg(const std::string& filename, bool use_mipmaps, unsigned int max_size_px);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
|
@ -194,7 +194,11 @@ bool GLToolbar::init(const ItemsIconsTexture::Metadata& icons_texture, const Bac
|
||||
#endif // ENABLE_SVG_ICONS
|
||||
|
||||
if (!background_texture.filename.empty())
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
res = m_background_texture.texture.load_from_file(path + background_texture.filename, false, true);
|
||||
#else
|
||||
res = m_background_texture.texture.load_from_file(path + background_texture.filename, false);
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
|
||||
if (res)
|
||||
m_background_texture.metadata = background_texture;
|
||||
@ -1338,7 +1342,11 @@ bool GLToolbar::generate_icons_texture() const
|
||||
states.push_back(std::make_pair(1, true));
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool res = m_icons_texture.load_from_svg_files_as_sprites_array(filenames, states, (unsigned int)(m_layout.icons_size * m_layout.scale), true);
|
||||
#else
|
||||
bool res = m_icons_texture.load_from_svg_files_as_sprites_array(filenames, states, (unsigned int)(m_layout.icons_size * m_layout.scale));
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
if (res)
|
||||
m_icons_texture_dirty = false;
|
||||
|
||||
|
@ -65,7 +65,11 @@ bool GLGizmosManager::init(GLCanvas3D& parent)
|
||||
|
||||
if (!m_background_texture.metadata.filename.empty())
|
||||
{
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (!m_background_texture.texture.load_from_file(resources_dir() + "/icons/" + m_background_texture.metadata.filename, false, true))
|
||||
#else
|
||||
if (!m_background_texture.texture.load_from_file(resources_dir() + "/icons/" + m_background_texture.metadata.filename, false))
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
reset();
|
||||
return false;
|
||||
@ -1160,7 +1164,11 @@ bool GLGizmosManager::generate_icons_texture() const
|
||||
states.push_back(std::make_pair(0, false));
|
||||
states.push_back(std::make_pair(0, true));
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
bool res = m_icons_texture.load_from_svg_files_as_sprites_array(filenames, states, (unsigned int)(m_overlay_icons_size * m_overlay_scale), true);
|
||||
#else
|
||||
bool res = m_icons_texture.load_from_svg_files_as_sprites_array(filenames, states, (unsigned int)(m_overlay_icons_size * m_overlay_scale));
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
if (res)
|
||||
m_icons_texture_dirty = false;
|
||||
|
||||
|
@ -206,7 +206,11 @@ void ImGuiWrapper::new_frame()
|
||||
}
|
||||
|
||||
if (m_font_texture == 0) {
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
init_font(true);
|
||||
#else
|
||||
init_font();
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
}
|
||||
|
||||
ImGui::NewFrame();
|
||||
@ -383,7 +387,11 @@ bool ImGuiWrapper::want_any_input() const
|
||||
return io.WantCaptureMouse || io.WantCaptureKeyboard || io.WantTextInput;
|
||||
}
|
||||
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
void ImGuiWrapper::init_font(bool compress)
|
||||
#else
|
||||
void ImGuiWrapper::init_font()
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
{
|
||||
destroy_font();
|
||||
|
||||
@ -413,7 +421,7 @@ void ImGuiWrapper::init_font()
|
||||
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
|
||||
glsafe(::glPixelStorei(GL_UNPACK_ROW_LENGTH, 0));
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
if (GLEW_EXT_texture_compression_s3tc)
|
||||
if (compress && GLEW_EXT_texture_compression_s3tc)
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
else
|
||||
glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
|
@ -77,7 +77,11 @@ public:
|
||||
bool want_any_input() const;
|
||||
|
||||
private:
|
||||
#if ENABLE_COMPRESSED_TEXTURES
|
||||
void init_font(bool compress);
|
||||
#else
|
||||
void init_font();
|
||||
#endif // ENABLE_COMPRESSED_TEXTURES
|
||||
void init_input();
|
||||
void init_style();
|
||||
void render_draw_data(ImDrawData *draw_data);
|
||||
|
Loading…
Reference in New Issue
Block a user