2018-06-13 07:12:16 +00:00
|
|
|
#ifndef slic3r_GLTexture_hpp_
|
|
|
|
#define slic3r_GLTexture_hpp_
|
|
|
|
|
|
|
|
#include <string>
|
2019-03-15 11:53:15 +00:00
|
|
|
#include <vector>
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2018-06-14 08:37:28 +00:00
|
|
|
class wxImage;
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
namespace GUI {
|
|
|
|
|
2018-06-14 08:37:28 +00:00
|
|
|
class GLTexture
|
2018-06-13 07:12:16 +00:00
|
|
|
{
|
2019-05-31 13:25:02 +00:00
|
|
|
#if ENABLE_COMPRESSED_TEXTURES
|
|
|
|
class Compressor
|
|
|
|
{
|
|
|
|
struct Level
|
|
|
|
{
|
|
|
|
unsigned int w;
|
|
|
|
unsigned int h;
|
|
|
|
std::vector<unsigned char> src_data;
|
|
|
|
std::vector<unsigned char> compressed_data;
|
2019-06-03 11:53:30 +00:00
|
|
|
bool compressed;
|
2019-05-31 13:25:02 +00:00
|
|
|
bool sent_to_gpu;
|
|
|
|
|
2019-06-03 11:53:30 +00:00
|
|
|
Level(unsigned int w, unsigned int h, const std::vector<unsigned char>& data) : w(w), h(h), src_data(data), compressed(false), sent_to_gpu(false) {}
|
2019-05-31 13:25:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GLTexture& m_texture;
|
|
|
|
std::vector<Level> m_levels;
|
|
|
|
bool m_is_compressing;
|
|
|
|
bool m_abort_compressing;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Compressor(GLTexture& texture) : m_texture(texture), m_is_compressing(false), m_abort_compressing(false) {}
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
void add_level(unsigned int w, unsigned int h, const std::vector<unsigned char>& data);
|
|
|
|
|
|
|
|
void start_compressing();
|
|
|
|
|
|
|
|
bool unsent_compressed_data_available() const;
|
|
|
|
void send_compressed_data_to_gpu();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void compress();
|
|
|
|
};
|
|
|
|
#endif // ENABLE_COMPRESSED_TEXTURES
|
|
|
|
|
2018-07-31 10:25:00 +00:00
|
|
|
public:
|
|
|
|
struct UV
|
|
|
|
{
|
|
|
|
float u;
|
|
|
|
float v;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Quad_UVs
|
|
|
|
{
|
|
|
|
UV left_bottom;
|
|
|
|
UV right_bottom;
|
|
|
|
UV right_top;
|
|
|
|
UV left_top;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Quad_UVs FullTextureUVs;
|
|
|
|
|
2018-07-18 13:07:52 +00:00
|
|
|
protected:
|
2018-06-13 07:12:16 +00:00
|
|
|
unsigned int m_id;
|
|
|
|
int m_width;
|
|
|
|
int m_height;
|
|
|
|
std::string m_source;
|
2019-05-31 13:25:02 +00:00
|
|
|
#if ENABLE_COMPRESSED_TEXTURES
|
|
|
|
Compressor m_compressor;
|
|
|
|
#endif // ENABLE_COMPRESSED_TEXTURES
|
2018-06-13 07:12:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GLTexture();
|
2018-07-18 13:07:52 +00:00
|
|
|
virtual ~GLTexture();
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2019-05-28 10:53:16 +00:00
|
|
|
#if ENABLE_COMPRESSED_TEXTURES
|
|
|
|
bool load_from_file(const std::string& filename, bool use_mipmaps, bool compress);
|
2019-05-28 13:21:34 +00:00
|
|
|
bool load_from_svg_file(const std::string& filename, bool use_mipmaps, bool compress, bool apply_anisotropy, unsigned int max_size_px);
|
2019-05-28 10:53:16 +00:00
|
|
|
#else
|
2019-02-20 14:23:23 +00:00
|
|
|
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);
|
2019-05-28 10:53:16 +00:00
|
|
|
#endif // ENABLE_COMPRESSED_TEXTURES
|
2019-02-26 11:56:13 +00:00
|
|
|
// meanings of states: (std::pair<int, bool>)
|
|
|
|
// first field (int):
|
|
|
|
// 0 -> no changes
|
|
|
|
// 1 -> use white only color variant
|
|
|
|
// 2 -> use gray only color variant
|
|
|
|
// second field (bool):
|
|
|
|
// false -> no changes
|
|
|
|
// true -> add background color
|
2019-05-28 10:53:16 +00:00
|
|
|
#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
|
2019-02-26 11:56:13 +00:00
|
|
|
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);
|
2019-05-28 10:53:16 +00:00
|
|
|
#endif // ENABLE_COMPRESSED_TEXTURES
|
2018-06-13 07:12:16 +00:00
|
|
|
void reset();
|
|
|
|
|
2019-02-20 14:23:23 +00:00
|
|
|
unsigned int get_id() const { return m_id; }
|
|
|
|
int get_width() const { return m_width; }
|
|
|
|
int get_height() const { return m_height; }
|
2018-07-18 13:07:52 +00:00
|
|
|
|
2019-02-20 14:23:23 +00:00
|
|
|
const std::string& get_source() const { return m_source; }
|
2018-06-13 07:12:16 +00:00
|
|
|
|
2019-05-31 13:25:02 +00:00
|
|
|
#if ENABLE_COMPRESSED_TEXTURES
|
2019-06-02 09:01:51 +00:00
|
|
|
bool unsent_compressed_data_available() const { return m_compressor.unsent_compressed_data_available(); }
|
|
|
|
void send_compressed_data_to_gpu() { m_compressor.send_compressed_data_to_gpu(); }
|
2019-05-31 13:25:02 +00:00
|
|
|
#endif // ENABLE_COMPRESSED_TEXTURES
|
|
|
|
|
2018-06-13 07:12:16 +00:00
|
|
|
static void render_texture(unsigned int tex_id, float left, float right, float bottom, float top);
|
2018-07-31 10:25:00 +00:00
|
|
|
static void render_sub_texture(unsigned int tex_id, float left, float right, float bottom, float top, const Quad_UVs& uvs);
|
2018-06-14 08:37:28 +00:00
|
|
|
|
2018-07-18 13:07:52 +00:00
|
|
|
protected:
|
2019-05-28 10:53:16 +00:00
|
|
|
#if ENABLE_COMPRESSED_TEXTURES
|
|
|
|
unsigned int generate_mipmaps(wxImage& image, bool compress);
|
|
|
|
#else
|
2019-02-20 14:23:23 +00:00
|
|
|
unsigned int generate_mipmaps(wxImage& image);
|
2019-05-28 10:53:16 +00:00
|
|
|
#endif // ENABLE_COMPRESSED_TEXTURES
|
|
|
|
|
2019-02-20 14:23:23 +00:00
|
|
|
private:
|
2019-05-28 10:53:16 +00:00
|
|
|
#if ENABLE_COMPRESSED_TEXTURES
|
|
|
|
bool load_from_png(const std::string& filename, bool use_mipmaps, bool compress);
|
2019-05-28 13:21:34 +00:00
|
|
|
bool load_from_svg(const std::string& filename, bool use_mipmaps, bool compress, bool apply_anisotropy, unsigned int max_size_px);
|
2019-05-31 13:25:02 +00:00
|
|
|
|
|
|
|
friend class Compressor;
|
2019-05-28 10:53:16 +00:00
|
|
|
#else
|
2019-02-20 14:23:23 +00:00
|
|
|
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);
|
2019-05-28 10:53:16 +00:00
|
|
|
#endif // ENABLE_COMPRESSED_TEXTURES
|
2018-06-13 07:12:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif // slic3r_GLTexture_hpp_
|
|
|
|
|