Asynchronous texture compression on CPU

This commit is contained in:
Enrico Turri 2019-05-31 15:25:02 +02:00
parent 58adeb01d1
commit f0baefb6ff
4 changed files with 1256 additions and 7 deletions

View file

@ -11,6 +11,42 @@ namespace GUI {
class GLTexture
{
#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;
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;
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
public:
struct UV
{
@ -33,6 +69,9 @@ namespace GUI {
int m_width;
int m_height;
std::string m_source;
#if ENABLE_COMPRESSED_TEXTURES
Compressor m_compressor;
#endif // ENABLE_COMPRESSED_TEXTURES
public:
GLTexture();
@ -66,6 +105,11 @@ namespace GUI {
const std::string& get_source() const { return m_source; }
#if ENABLE_COMPRESSED_TEXTURES
bool unsent_compressed_data_available() const;
void send_compressed_data_to_gpu();
#endif // ENABLE_COMPRESSED_TEXTURES
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);
@ -80,6 +124,8 @@ namespace GUI {
#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, bool apply_anisotropy, unsigned int max_size_px);
friend class Compressor;
#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);