OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::GLTexture::Compressor Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLTexture.hpp>

Collaboration diagram for Slic3r::GUI::GLTexture::Compressor:

Classes

struct  Level

Public Member Functions

 Compressor (GLTexture &texture)
 ~Compressor ()
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 ()
bool all_compressed_data_sent_to_gpu () const

Static Public Member Functions

static bool has_compressed_texture_to_refresh ()

Private Member Functions

void compress ()

Private Attributes

GLTexture & m_texture
std::vector< Level > m_levels
std::thread m_thread
std::atomic< bool > m_abort_compressing
std::atomic< unsigned int > m_num_levels_compressed

Static Private Attributes

static std::atomic< bool > m_dirty = false

Detailed Description

Constructor & Destructor Documentation

◆ Compressor()

Slic3r::GUI::GLTexture::Compressor::Compressor ( GLTexture & texture)
inlineexplicit
GLTexture & m_texture
Definition GLTexture.hpp:38
std::atomic< bool > m_abort_compressing
Definition GLTexture.hpp:43
std::atomic< unsigned int > m_num_levels_compressed
Definition GLTexture.hpp:46

References Slic3r::GUI::GLTexture::GLTexture(), m_abort_compressing, m_num_levels_compressed, and m_texture.

Here is the call graph for this function:

◆ ~Compressor()

Slic3r::GUI::GLTexture::Compressor::~Compressor ( )
inline
52{ reset(); }
void reset()
Definition GLTexture.cpp:55

References reset().

Here is the call graph for this function:

Member Function Documentation

◆ add_level()

void Slic3r::GUI::GLTexture::Compressor::add_level ( unsigned int w,
unsigned int h,
const std::vector< unsigned char > & data )
inline
56{ m_levels.emplace_back(w, h, data); }
std::vector< Level > m_levels
Definition GLTexture.hpp:39

References m_levels.

◆ all_compressed_data_sent_to_gpu()

bool Slic3r::GUI::GLTexture::Compressor::all_compressed_data_sent_to_gpu ( ) const
inline
62{ return m_levels.empty(); }

References m_levels.

◆ compress()

void Slic3r::GUI::GLTexture::Compressor::compress ( )
private
125{
126 // reference: https://github.com/Cyan4973/RygsDXTc
127
128 assert(m_num_levels_compressed == 0);
129 assert(m_abort_compressing == false);
130
131 for (Level& level : m_levels) {
133 break;
134
135 // stb_dxt library, despite claiming that the needed size of the destination buffer is equal to (source buffer size)/4,
136 // crashes if doing so, requiring a minimum of 64 bytes and up to a third of the source buffer size, so we set the destination buffer initial size to be half the source buffer size
137 level.compressed_data = std::vector<unsigned char>(std::max((unsigned int)64, (unsigned int)level.src_data.size() / 2), 0);
138 int compressed_size = 0;
139 rygCompress(level.compressed_data.data(), level.src_data.data(), level.w, level.h, 1, compressed_size);
140 level.compressed_data.resize(compressed_size);
141
142 // we are done with the source data, we can discard it
143 level.src_data.clear();
145 }
146
147 // Trigger an idle event to refresh the scene once the texture data is ready
148 // This fixes the issue that the bed texture is black after switching printer model until mouse moves to the 3d scene
149 m_dirty = true;
150 wxWakeUpIdle();
151}
static std::atomic< bool > m_dirty
Definition GLTexture.hpp:48

References m_abort_compressing, m_dirty, m_levels, and m_num_levels_compressed.

Referenced by start_compressing().

Here is the caller graph for this function:

◆ has_compressed_texture_to_refresh()

bool Slic3r::GUI::GLTexture::Compressor::has_compressed_texture_to_refresh ( )
inlinestatic
64{ return m_dirty.exchange(false); }

References m_dirty.

Referenced by Slic3r::GUI::GLCanvas3D::on_idle().

Here is the caller graph for this function:

◆ reset()

void Slic3r::GUI::GLTexture::Compressor::reset ( )
56{
57 if (m_thread.joinable()) {
59 m_thread.join();
60 m_levels.clear();
62 m_abort_compressing = false;
63 }
64 assert(m_levels.empty());
65 assert(m_abort_compressing == false);
66 assert(m_num_levels_compressed == 0);
67}
std::thread m_thread
Definition GLTexture.hpp:40

References m_abort_compressing, m_levels, m_num_levels_compressed, and m_thread.

Referenced by ~Compressor().

Here is the caller graph for this function:

◆ send_compressed_data_to_gpu()

void Slic3r::GUI::GLTexture::Compressor::send_compressed_data_to_gpu ( )
95{
96 // this method should be called inside the main thread of Slicer or a new OpenGL context (sharing resources) would be needed
97 if (m_levels.empty())
98 return;
99
102 // Querying the atomic m_num_levels_compressed value synchronizes processor caches, so that the dat of m_levels modified by the worker thread are accessible to the calling thread.
103 int num_compressed = (int)m_num_levels_compressed;
104 for (int i = 0; i < num_compressed; ++ i) {
105 Level& level = m_levels[i];
106 if (! level.sent_to_gpu && ! level.compressed_data.empty()) {
107 glsafe(::glCompressedTexSubImage2D(GL_TEXTURE_2D, (GLint)i, 0, 0, (GLsizei)level.w, (GLsizei)level.h, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)level.compressed_data.size(), (const GLvoid*)level.compressed_data.data()));
110 level.sent_to_gpu = true;
111 // we are done with the compressed data, we can discard it
112 level.compressed_data.clear();
113 }
114 }
116
117 if (num_compressed == (int)m_levels.size())
118 // Finalize the worker thread, close it.
119 this->reset();
120}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
#define GL_TEXTURE_MIN_FILTER
Definition gl.h:1828
#define glCompressedTexSubImage2D
Definition gl.h:3497
void GLvoid
Definition gl.h:2057
#define glPixelStorei
Definition gl.h:4451
#define GL_TEXTURE_MAX_LEVEL
Definition gl.h:1826
#define GL_LINEAR
Definition gl.h:930
#define glTexParameteri
Definition gl.h:4911
int GLint
Definition gl.h:2062
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
Definition gl.h:449
#define GL_LINEAR_MIPMAP_LINEAR
Definition gl.h:932
#define GL_UNPACK_ALIGNMENT
Definition gl.h:1924
int GLsizei
Definition gl.h:2065
#define glBindTexture
Definition gl.h:3299
#define GL_TEXTURE_2D
Definition gl.h:1739

References Slic3r::GUI::GLTexture::Compressor::Level::compressed_data, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GL_TEXTURE_MIN_FILTER, GL_UNPACK_ALIGNMENT, glBindTexture, glCompressedTexSubImage2D, glPixelStorei, glsafe, glTexParameteri, Slic3r::GUI::GLTexture::Compressor::Level::h, m_levels, m_num_levels_compressed, m_texture, Slic3r::GUI::GLTexture::reset(), Slic3r::GUI::GLTexture::Compressor::Level::sent_to_gpu, and Slic3r::GUI::GLTexture::Compressor::Level::w.

Here is the call graph for this function:

◆ start_compressing()

void Slic3r::GUI::GLTexture::Compressor::start_compressing ( )
70{
71 // The worker thread should be stopped already.
72 assert(! m_thread.joinable());
73 assert(! m_levels.empty());
74 assert(m_abort_compressing == false);
75 assert(m_num_levels_compressed == 0);
76 if (! m_levels.empty()) {
77 std::thread thrd(&GLTexture::Compressor::compress, this);
78 m_thread = std::move(thrd);
79 }
80}
void compress()
Definition GLTexture.cpp:124

References compress(), m_abort_compressing, m_levels, m_num_levels_compressed, and m_thread.

Here is the call graph for this function:

◆ unsent_compressed_data_available()

bool Slic3r::GUI::GLTexture::Compressor::unsent_compressed_data_available ( ) const
83{
84 if (m_levels.empty())
85 return false;
86 // Querying the atomic m_num_levels_compressed value synchronizes processor caches, so that the data of m_levels modified by the worker thread are accessible to the calling thread.
87 unsigned int num_compressed = m_num_levels_compressed;
88 for (unsigned int i = 0; i < num_compressed; ++ i)
89 if (! m_levels[i].sent_to_gpu && ! m_levels[i].compressed_data.empty())
90 return true;
91 return false;
92}

References m_levels, and m_num_levels_compressed.

Member Data Documentation

◆ m_abort_compressing

std::atomic<bool> Slic3r::GUI::GLTexture::Compressor::m_abort_compressing
private

◆ m_dirty

std::atomic< bool > Slic3r::GUI::GLTexture::Compressor::m_dirty = false
staticprivate

◆ m_levels

std::vector<Level> Slic3r::GUI::GLTexture::Compressor::m_levels
private

◆ m_num_levels_compressed

std::atomic<unsigned int> Slic3r::GUI::GLTexture::Compressor::m_num_levels_compressed
private

◆ m_texture

GLTexture& Slic3r::GUI::GLTexture::Compressor::m_texture
private

◆ m_thread

std::thread Slic3r::GUI::GLTexture::Compressor::m_thread
private

Referenced by reset(), and start_compressing().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLTexture.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLTexture.cpp