Legend texture moved to c++

This commit is contained in:
Enrico Turri 2018-05-21 14:57:43 +02:00
parent 3fdc5e20a7
commit bf7b9eb3e7
9 changed files with 129 additions and 52 deletions

View file

@ -1903,6 +1903,11 @@ void _3DScene::enable_warning_texture(wxGLCanvas* canvas, bool enable)
s_canvas_mgr.enable_warning_texture(canvas, enable);
}
void _3DScene::enable_legend_texture(wxGLCanvas* canvas, bool enable)
{
s_canvas_mgr.enable_legend_texture(canvas, enable);
}
void _3DScene::zoom_to_bed(wxGLCanvas* canvas)
{
s_canvas_mgr.zoom_to_bed(canvas);
@ -1938,6 +1943,11 @@ void _3DScene::render_warning_texture(wxGLCanvas* canvas)
s_canvas_mgr.render_warning_texture(canvas);
}
void _3DScene::render_legend_texture(wxGLCanvas* canvas)
{
s_canvas_mgr.render_legend_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);

View file

@ -591,6 +591,7 @@ public:
static bool is_layers_editing_enabled(wxGLCanvas* canvas);
static void enable_warning_texture(wxGLCanvas* canvas, bool enable);
static void enable_legend_texture(wxGLCanvas* canvas, bool enable);
static void zoom_to_bed(wxGLCanvas* canvas);
static void zoom_to_volumes(wxGLCanvas* canvas);
@ -600,6 +601,7 @@ public:
static void render_axes(wxGLCanvas* canvas);
static void render_cutting_plane(wxGLCanvas* canvas);
static void render_warning_texture(wxGLCanvas* canvas);
static void render_legend_texture(wxGLCanvas* canvas);
static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);

View file

@ -412,6 +412,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
, m_dirty(true)
, m_apply_zoom_to_volumes_filter(false)
, m_warning_texture_enabled(false)
, m_legend_texture_enabled(false)
{
}
@ -688,6 +689,11 @@ void GLCanvas3D::enable_warning_texture(bool enable)
m_warning_texture_enabled = enable;
}
void GLCanvas3D::enable_legend_texture(bool enable)
{
m_legend_texture_enabled = enable;
}
void GLCanvas3D::zoom_to_bed()
{
_zoom_to_bounding_box(bed_bounding_box());
@ -770,7 +776,7 @@ void GLCanvas3D::render_warning_texture()
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 t = (-0.5f * (float)cnv_size.second + (float)h) * inv_zoom;
float r = l + (float)w * inv_zoom;
float b = t - (float)h * inv_zoom;
@ -782,6 +788,38 @@ void GLCanvas3D::render_warning_texture()
}
}
void GLCanvas3D::render_legend_texture()
{
if (!m_legend_texture_enabled)
return;
// If the legend texture has not been loaded into the GPU, do it now.
unsigned int tex_id = _3DScene::finalize_legend_texture();
if (tex_id > 0)
{
unsigned int w = _3DScene::get_legend_texture_width();
unsigned int h = _3DScene::get_legend_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)cnv_size.first) * inv_zoom;
float t = (0.5f * (float)cnv_size.second) * 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);

View file

@ -152,6 +152,7 @@ private:
bool m_dirty;
bool m_apply_zoom_to_volumes_filter;
bool m_warning_texture_enabled;
bool m_legend_texture_enabled;
PerlCallback m_on_viewport_changed_callback;
@ -215,6 +216,7 @@ public:
bool is_layers_editing_enabled() const;
void enable_warning_texture(bool enable);
void enable_legend_texture(bool enable);
void zoom_to_bed();
void zoom_to_volumes();
@ -224,6 +226,7 @@ public:
void render_axes();
void render_cutting_plane();
void render_warning_texture();
void render_legend_texture();
void render_texture(unsigned int tex_id, float left, float right, float bottom, float top);

View file

@ -362,6 +362,13 @@ void GLCanvas3DManager::enable_warning_texture(wxGLCanvas* canvas, bool enable)
it->second->enable_warning_texture(enable);
}
void GLCanvas3DManager::enable_legend_texture(wxGLCanvas* canvas, bool enable)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->enable_legend_texture(enable);
}
void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);
@ -411,6 +418,13 @@ void GLCanvas3DManager::render_warning_texture(wxGLCanvas* canvas)
it->second->render_warning_texture();
}
void GLCanvas3DManager::render_legend_texture(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->render_legend_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);

View file

@ -101,6 +101,7 @@ public:
bool is_layers_editing_enabled(wxGLCanvas* canvas) const;
void enable_warning_texture(wxGLCanvas* canvas, bool enable);
void enable_legend_texture(wxGLCanvas* canvas, bool enable);
void zoom_to_bed(wxGLCanvas* canvas);
void zoom_to_volumes(wxGLCanvas* canvas);
@ -110,6 +111,7 @@ public:
void render_axes(wxGLCanvas* canvas);
void render_cutting_plane(wxGLCanvas* canvas);
void render_warning_texture(wxGLCanvas* canvas);
void render_legend_texture(wxGLCanvas* canvas);
void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);

View file

@ -418,6 +418,13 @@ enable_warning_texture(canvas, enable)
CODE:
_3DScene::enable_warning_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), enable);
void
enable_legend_texture(canvas, enable)
SV *canvas;
bool enable;
CODE:
_3DScene::enable_legend_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), enable);
void
zoom_to_bed(canvas)
SV *canvas;
@ -461,6 +468,12 @@ render_warning_texture(canvas)
CODE:
_3DScene::render_warning_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
void
render_legend_texture(canvas)
SV *canvas;
CODE:
_3DScene::render_legend_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
void
render_texture(canvas, tex_id, left, right, bottom, top)
SV *canvas;