mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-06 23:31:19 +00:00
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes. clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer. * Remove Unused Project Includes From Files With Platform-Specific Code A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block. * Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass The platform-file pass treated pchheader.hpp as an ordinary header and emptied it, and left GUI_Preview.hpp and 14 other files relying on headers they no longer reached directly. * Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call * Include Headers That Files Reached Through Ones the Cleanup Removed * Drop Includes Duplicated by the Cleanup or by Main's Own Additions * Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
158 lines
6.1 KiB
C++
158 lines
6.1 KiB
C++
#ifndef slic3r_GLTexture_hpp_
|
|
#define slic3r_GLTexture_hpp_
|
|
|
|
#include <atomic>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
#include <array>
|
|
#include <thread>
|
|
|
|
#include <wx/colour.h>
|
|
#include <wx/font.h>
|
|
#include <wx/gdicmn.h>
|
|
|
|
class wxFont;
|
|
|
|
|
|
namespace Slic3r {
|
|
namespace GUI {
|
|
|
|
class GLTexture
|
|
{
|
|
public:
|
|
|
|
class Compressor
|
|
{
|
|
struct Level
|
|
{
|
|
unsigned int w;
|
|
unsigned int h;
|
|
std::vector<unsigned char> src_data;
|
|
std::vector<unsigned char> compressed_data;
|
|
bool sent_to_gpu;
|
|
|
|
Level(unsigned int w, unsigned int h, const std::vector<unsigned char>& data) : w(w), h(h), src_data(data), sent_to_gpu(false) {}
|
|
};
|
|
|
|
GLTexture& m_texture;
|
|
std::vector<Level> m_levels;
|
|
std::thread m_thread;
|
|
// Does the caller want the background thread to stop?
|
|
// This atomic also works as a memory barrier for synchronizing the cancel event with the worker thread.
|
|
std::atomic<bool> m_abort_compressing;
|
|
// How many levels were compressed since the start of the background processing thread?
|
|
// This atomic also works as a memory barrier for synchronizing results of the worker thread with the calling thread.
|
|
std::atomic<unsigned int> m_num_levels_compressed;
|
|
|
|
static std::atomic<bool> m_dirty;
|
|
|
|
public:
|
|
explicit Compressor(GLTexture& texture) : m_texture(texture), m_abort_compressing(false), m_num_levels_compressed(0) {}
|
|
~Compressor() { reset(); }
|
|
|
|
void reset();
|
|
|
|
void add_level(unsigned int w, unsigned int h, const std::vector<unsigned char>& data) { m_levels.emplace_back(w, h, data); }
|
|
|
|
void start_compressing();
|
|
|
|
bool unsent_compressed_data_available() const;
|
|
void send_compressed_data_to_gpu();
|
|
bool all_compressed_data_sent_to_gpu() const { return m_levels.empty(); }
|
|
|
|
static bool has_compressed_texture_to_refresh() { return m_dirty.exchange(false); }
|
|
|
|
private:
|
|
void compress();
|
|
};
|
|
|
|
enum ECompressionType : unsigned char
|
|
{
|
|
None,
|
|
SingleThreaded,
|
|
MultiThreaded
|
|
};
|
|
|
|
struct UV
|
|
{
|
|
float u{ 0.0f };
|
|
float v{ 0.0f };
|
|
};
|
|
|
|
struct Quad_UVs
|
|
{
|
|
UV left_bottom;
|
|
UV right_bottom;
|
|
UV right_top;
|
|
UV left_top;
|
|
};
|
|
|
|
static Quad_UVs FullTextureUVs;
|
|
|
|
protected:
|
|
unsigned int m_id{ 0 };
|
|
int m_width{ 0 };
|
|
int m_height{ 0 };
|
|
std::string m_source;
|
|
Compressor m_compressor;
|
|
|
|
public:
|
|
GLTexture();
|
|
virtual ~GLTexture();
|
|
|
|
bool load_from_file(const std::string& filename, bool use_mipmaps, ECompressionType compression_type, bool apply_anisotropy);
|
|
bool load_from_svg_file(const std::string& filename, bool use_mipmaps, bool compress, bool apply_anisotropy, unsigned int max_size_px);
|
|
//BBS load GLTexture from raw pixel data
|
|
// `data` is RGBA, w * h * 4 bytes. With use_mipmaps, a real box-filtered mipmap chain is
|
|
// built, so the texture may safely be drawn smaller than its pixel size.
|
|
bool load_from_raw_data(std::vector<unsigned char> data, unsigned int w, unsigned int h, bool apply_anisotropy = false,
|
|
bool use_mipmaps = true);
|
|
// 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
|
|
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);
|
|
void reset();
|
|
//BBS: add generate logic for text strings
|
|
int m_original_width;
|
|
int m_original_height;
|
|
|
|
bool generate_texture_from_text(const std::string& text_str, wxFont& font, int& ww, int& hh, int &hl, wxColor background = *wxBLACK, wxColor foreground = *wxWHITE);
|
|
bool generate_from_text(const std::string& text_str, wxFont& font, wxColor background = *wxBLACK, wxColor foreground = *wxWHITE);
|
|
bool generate_from_text_string(const std::string& text_str, wxFont& font, wxColor background = *wxBLACK, wxColor foreground = *wxWHITE);
|
|
|
|
unsigned int get_id() const { return m_id; }
|
|
int get_original_width() const { return m_original_width; }
|
|
int get_width() const { return m_width; }
|
|
int get_height() const { return m_height; }
|
|
|
|
const std::string& get_source() const { return m_source; }
|
|
|
|
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(); }
|
|
bool all_compressed_data_sent_to_gpu() const { return m_compressor.all_compressed_data_sent_to_gpu(); }
|
|
|
|
static void render_texture(unsigned int tex_id, float left, float right, float bottom, float top);
|
|
static void render_sub_texture(unsigned int tex_id, float left, float right, float bottom, float top, const Quad_UVs& uvs);
|
|
// Copies the bound read framebuffer into an RGBA texture, creating it on first use and
|
|
// reallocating it when the size changes.
|
|
static void copy_from_framebuffer(unsigned int& tex_id, std::array<unsigned int, 2>& tex_size, unsigned int width, unsigned int height, int filter);
|
|
|
|
private:
|
|
bool load_from_png(const std::string& filename, bool use_mipmaps, ECompressionType compression_type, bool apply_anisotropy);
|
|
bool load_from_svg(const std::string& filename, bool use_mipmaps, bool compress, bool apply_anisotropy, unsigned int max_size_px);
|
|
|
|
friend class Compressor;
|
|
};
|
|
|
|
} // namespace GUI
|
|
} // namespace Slic3r
|
|
|
|
#endif // slic3r_GLTexture_hpp_
|
|
|