mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-23 00:31:11 -06:00
Warning texture moved to c++
This commit is contained in:
parent
7cff6ef6db
commit
3fdc5e20a7
9 changed files with 230 additions and 76 deletions
|
@ -1898,6 +1898,11 @@ bool _3DScene::is_layers_editing_enabled(wxGLCanvas* canvas)
|
|||
return s_canvas_mgr.is_layers_editing_enabled(canvas);
|
||||
}
|
||||
|
||||
void _3DScene::enable_warning_texture(wxGLCanvas* canvas, bool enable)
|
||||
{
|
||||
s_canvas_mgr.enable_warning_texture(canvas, enable);
|
||||
}
|
||||
|
||||
void _3DScene::zoom_to_bed(wxGLCanvas* canvas)
|
||||
{
|
||||
s_canvas_mgr.zoom_to_bed(canvas);
|
||||
|
@ -1928,6 +1933,16 @@ void _3DScene::render_cutting_plane(wxGLCanvas* canvas)
|
|||
s_canvas_mgr.render_cutting_plane(canvas);
|
||||
}
|
||||
|
||||
void _3DScene::render_warning_texture(wxGLCanvas* canvas)
|
||||
{
|
||||
s_canvas_mgr.render_warning_texture(canvas);
|
||||
}
|
||||
|
||||
void _3DScene::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top)
|
||||
{
|
||||
s_canvas_mgr.render_texture(canvas, tex_id, left, right, bottom, top);
|
||||
}
|
||||
|
||||
void _3DScene::register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback)
|
||||
{
|
||||
s_canvas_mgr.register_on_viewport_changed_callback(canvas, callback);
|
||||
|
|
|
@ -590,6 +590,8 @@ public:
|
|||
|
||||
static bool is_layers_editing_enabled(wxGLCanvas* canvas);
|
||||
|
||||
static void enable_warning_texture(wxGLCanvas* canvas, bool enable);
|
||||
|
||||
static void zoom_to_bed(wxGLCanvas* canvas);
|
||||
static void zoom_to_volumes(wxGLCanvas* canvas);
|
||||
static void select_view(wxGLCanvas* canvas, const std::string& direction);
|
||||
|
@ -597,6 +599,9 @@ public:
|
|||
static void render_bed(wxGLCanvas* canvas);
|
||||
static void render_axes(wxGLCanvas* canvas);
|
||||
static void render_cutting_plane(wxGLCanvas* canvas);
|
||||
static void render_warning_texture(wxGLCanvas* canvas);
|
||||
|
||||
static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);
|
||||
|
||||
static void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);
|
||||
|
||||
|
|
|
@ -411,6 +411,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
|
|||
, m_volumes(nullptr)
|
||||
, m_dirty(true)
|
||||
, m_apply_zoom_to_volumes_filter(false)
|
||||
, m_warning_texture_enabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -682,6 +683,11 @@ bool GLCanvas3D::is_layers_editing_enabled() const
|
|||
return m_layers_editing.is_enabled();
|
||||
}
|
||||
|
||||
void GLCanvas3D::enable_warning_texture(bool enable)
|
||||
{
|
||||
m_warning_texture_enabled = enable;
|
||||
}
|
||||
|
||||
void GLCanvas3D::zoom_to_bed()
|
||||
{
|
||||
_zoom_to_bounding_box(bed_bounding_box());
|
||||
|
@ -743,6 +749,64 @@ void GLCanvas3D::render_cutting_plane()
|
|||
m_cutting_plane.render_contour();
|
||||
}
|
||||
|
||||
void GLCanvas3D::render_warning_texture()
|
||||
{
|
||||
if (!m_warning_texture_enabled)
|
||||
return;
|
||||
|
||||
// If the warning texture has not been loaded into the GPU, do it now.
|
||||
unsigned int tex_id = _3DScene::finalize_warning_texture();
|
||||
if (tex_id > 0)
|
||||
{
|
||||
unsigned int w = _3DScene::get_warning_texture_width();
|
||||
unsigned int h = _3DScene::get_warning_texture_height();
|
||||
if ((w > 0) && (h > 0))
|
||||
{
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
::glPushMatrix();
|
||||
::glLoadIdentity();
|
||||
|
||||
std::pair<int, int> cnv_size = _get_canvas_size();
|
||||
float zoom = get_camera_zoom();
|
||||
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
|
||||
float l = (-0.5f * (float)w) * inv_zoom;
|
||||
float t = (-0.5f * cnv_size.second + (float)h) * inv_zoom;
|
||||
float r = l + (float)w * inv_zoom;
|
||||
float b = t - (float)h * inv_zoom;
|
||||
|
||||
render_texture(tex_id, l, r, b, t);
|
||||
|
||||
::glPopMatrix();
|
||||
::glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::render_texture(unsigned int tex_id, float left, float right, float bottom, float top)
|
||||
{
|
||||
::glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
::glDisable(GL_LIGHTING);
|
||||
::glEnable(GL_BLEND);
|
||||
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
::glEnable(GL_TEXTURE_2D);
|
||||
|
||||
::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id);
|
||||
|
||||
::glBegin(GL_QUADS);
|
||||
::glTexCoord2d(0.0f, 1.0f); glVertex3f(left, bottom, 0.0f);
|
||||
::glTexCoord2d(1.0f, 1.0f); glVertex3f(right, bottom, 0.0f);
|
||||
::glTexCoord2d(1.0f, 0.0f); glVertex3f(right, top, 0.0f);
|
||||
::glTexCoord2d(0.0f, 0.0f); glVertex3f(left, top, 0.0f);
|
||||
::glEnd();
|
||||
|
||||
::glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
::glDisable(GL_TEXTURE_2D);
|
||||
::glDisable(GL_BLEND);
|
||||
::glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void GLCanvas3D::register_on_viewport_changed_callback(void* callback)
|
||||
{
|
||||
if (callback != nullptr)
|
||||
|
|
|
@ -151,6 +151,7 @@ private:
|
|||
|
||||
bool m_dirty;
|
||||
bool m_apply_zoom_to_volumes_filter;
|
||||
bool m_warning_texture_enabled;
|
||||
|
||||
PerlCallback m_on_viewport_changed_callback;
|
||||
|
||||
|
@ -213,6 +214,8 @@ public:
|
|||
|
||||
bool is_layers_editing_enabled() const;
|
||||
|
||||
void enable_warning_texture(bool enable);
|
||||
|
||||
void zoom_to_bed();
|
||||
void zoom_to_volumes();
|
||||
void select_view(const std::string& direction);
|
||||
|
@ -220,6 +223,9 @@ public:
|
|||
void render_bed();
|
||||
void render_axes();
|
||||
void render_cutting_plane();
|
||||
void render_warning_texture();
|
||||
|
||||
void render_texture(unsigned int tex_id, float left, float right, float bottom, float top);
|
||||
|
||||
void register_on_viewport_changed_callback(void* callback);
|
||||
|
||||
|
|
|
@ -355,6 +355,13 @@ bool GLCanvas3DManager::is_layers_editing_enabled(wxGLCanvas* canvas) const
|
|||
return (it != m_canvases.end()) ? it->second->is_layers_editing_enabled() : false;
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::enable_warning_texture(wxGLCanvas* canvas, bool enable)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
if (it != m_canvases.end())
|
||||
it->second->enable_warning_texture(enable);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
|
@ -397,6 +404,20 @@ void GLCanvas3DManager::render_cutting_plane(wxGLCanvas* canvas)
|
|||
it->second->render_cutting_plane();
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::render_warning_texture(wxGLCanvas* canvas)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
if (it != m_canvases.end())
|
||||
it->second->render_warning_texture();
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
if (it != m_canvases.end())
|
||||
it->second->render_texture(tex_id, left, right, bottom, top);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
|
|
|
@ -100,6 +100,8 @@ public:
|
|||
|
||||
bool is_layers_editing_enabled(wxGLCanvas* canvas) const;
|
||||
|
||||
void enable_warning_texture(wxGLCanvas* canvas, bool enable);
|
||||
|
||||
void zoom_to_bed(wxGLCanvas* canvas);
|
||||
void zoom_to_volumes(wxGLCanvas* canvas);
|
||||
void select_view(wxGLCanvas* canvas, const std::string& direction);
|
||||
|
@ -107,6 +109,9 @@ public:
|
|||
void render_bed(wxGLCanvas* canvas);
|
||||
void render_axes(wxGLCanvas* canvas);
|
||||
void render_cutting_plane(wxGLCanvas* canvas);
|
||||
void render_warning_texture(wxGLCanvas* canvas);
|
||||
|
||||
void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);
|
||||
|
||||
void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue