mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	Update 3D scene when all compressed texture data are sent to GPU
This commit is contained in:
		
							parent
							
								
									a9ea9b3e0a
								
							
						
					
					
						commit
						836f2d777f
					
				
					 6 changed files with 117 additions and 2 deletions
				
			
		|  | @ -9,6 +9,9 @@ | |||
| #include "GUI_App.hpp" | ||||
| #include "PresetBundle.hpp" | ||||
| #include "Gizmos/GLGizmoBase.hpp" | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
| #include "GLCanvas3D.hpp" | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| 
 | ||||
| #include <GL/glew.h> | ||||
| 
 | ||||
|  | @ -273,6 +276,9 @@ void Bed3D::Axes::render_axis(double length) const | |||
| 
 | ||||
| Bed3D::Bed3D() | ||||
|     : m_type(Custom) | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     , m_requires_canvas_update(false) | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| #if ENABLE_TEXTURES_FROM_SVG | ||||
|     , m_vbo_id(0) | ||||
| #endif // ENABLE_TEXTURES_FROM_SVG
 | ||||
|  | @ -328,14 +334,34 @@ Point Bed3D::point_projection(const Point& point) const | |||
| } | ||||
| 
 | ||||
| #if ENABLE_TEXTURES_FROM_SVG | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
| void Bed3D::render(GLCanvas3D* canvas, float theta, bool useVBOs, float scale_factor) const | ||||
| #else | ||||
| void Bed3D::render(float theta, bool useVBOs, float scale_factor) const | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| { | ||||
|     m_scale_factor = scale_factor; | ||||
| 
 | ||||
|     EType type = useVBOs ? m_type : Custom; | ||||
|     switch (type) | ||||
| 
 | ||||
|     { | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     case MK2: | ||||
|     { | ||||
|         render_prusa(canvas, "mk2", theta > 90.0f); | ||||
|         break; | ||||
|     } | ||||
|     case MK3: | ||||
|     { | ||||
|         render_prusa(canvas, "mk3", theta > 90.0f); | ||||
|         break; | ||||
|     } | ||||
|     case SL1: | ||||
|     { | ||||
|         render_prusa(canvas, "sl1", theta > 90.0f); | ||||
|         break; | ||||
|     } | ||||
| #else | ||||
|     case MK2: | ||||
|     { | ||||
|         render_prusa("mk2", theta > 90.0f); | ||||
|  | @ -351,6 +377,7 @@ void Bed3D::render(float theta, bool useVBOs, float scale_factor) const | |||
|         render_prusa("sl1", theta > 90.0f); | ||||
|         break; | ||||
|     } | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
|     default: | ||||
|     case Custom: | ||||
|     { | ||||
|  | @ -360,7 +387,11 @@ void Bed3D::render(float theta, bool useVBOs, float scale_factor) const | |||
|     } | ||||
| } | ||||
| #else | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
| void Bed3D::render(GLCanvas3D* canvas, float theta, bool useVBOs, float scale_factor) const | ||||
| #else | ||||
| void Bed3D::render(float theta, bool useVBOs, float scale_factor) const | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| { | ||||
|     m_scale_factor = scale_factor; | ||||
| 
 | ||||
|  | @ -369,6 +400,23 @@ void Bed3D::render(float theta, bool useVBOs, float scale_factor) const | |||
| 
 | ||||
|     switch (m_type) | ||||
|     { | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     case MK2: | ||||
|     { | ||||
|         render_prusa(canvas, "mk2", theta, useVBOs); | ||||
|         break; | ||||
|     } | ||||
|     case MK3: | ||||
|     { | ||||
|         render_prusa(canvas, "mk3", theta, useVBOs); | ||||
|         break; | ||||
|     } | ||||
|     case SL1: | ||||
|     { | ||||
|         render_prusa(canvas, "sl1", theta, useVBOs); | ||||
|         break; | ||||
|     } | ||||
| #else | ||||
|     case MK2: | ||||
|     { | ||||
|         render_prusa("mk2", theta, useVBOs); | ||||
|  | @ -383,7 +431,8 @@ void Bed3D::render(float theta, bool useVBOs, float scale_factor) const | |||
|     { | ||||
|         render_prusa("sl1", theta, useVBOs); | ||||
|         break; | ||||
|     } | ||||
|     }  | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
|     default: | ||||
|     case Custom: | ||||
|     { | ||||
|  | @ -487,7 +536,11 @@ Bed3D::EType Bed3D::detect_type(const Pointfs& shape) const | |||
| } | ||||
| 
 | ||||
| #if ENABLE_TEXTURES_FROM_SVG | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
| void Bed3D::render_prusa(GLCanvas3D* canvas, const std::string &key, bool bottom) const | ||||
| #else | ||||
| void Bed3D::render_prusa(const std::string &key, bool bottom) const | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| { | ||||
|     std::string tex_path = resources_dir() + "/icons/bed/" + key; | ||||
| 
 | ||||
|  | @ -557,6 +610,15 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const | |||
|         // the temporary texture is not needed anymore, reset it
 | ||||
|         if (m_temp_texture.get_id() != 0) | ||||
|             m_temp_texture.reset(); | ||||
| 
 | ||||
|         m_requires_canvas_update = true; | ||||
|     } | ||||
|     else if (m_requires_canvas_update && m_texture.all_compressed_data_sent_to_gpu()) | ||||
|     { | ||||
|         if (canvas != nullptr) | ||||
|             canvas->stop_keeping_dirty(); | ||||
| 
 | ||||
|         m_requires_canvas_update = false; | ||||
|     } | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,6 +13,10 @@ typedef class GLUquadric GLUquadricObj; | |||
| namespace Slic3r { | ||||
| namespace GUI { | ||||
| 
 | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
| class GLCanvas3D; | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| 
 | ||||
| class GeometryBuffer | ||||
| { | ||||
| #if ENABLE_TEXTURES_FROM_SVG | ||||
|  | @ -94,6 +98,8 @@ private: | |||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     // temporary texture shown until the main texture has still no levels compressed
 | ||||
|     mutable GLTexture m_temp_texture; | ||||
|     // used to trigger 3D scene update once all compressed textures have been sent to GPU
 | ||||
|     mutable bool m_requires_canvas_update; | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
|     mutable Shader m_shader; | ||||
|     mutable unsigned int m_vbo_id; | ||||
|  | @ -125,7 +131,11 @@ public: | |||
|     bool contains(const Point& point) const; | ||||
|     Point point_projection(const Point& point) const; | ||||
| 
 | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     void render(GLCanvas3D* canvas, float theta, bool useVBOs, float scale_factor) const; | ||||
| #else | ||||
|     void render(float theta, bool useVBOs, float scale_factor) const; | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
|     void render_axes() const; | ||||
| 
 | ||||
| private: | ||||
|  | @ -134,7 +144,11 @@ private: | |||
|     void calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox); | ||||
|     EType detect_type(const Pointfs& shape) const; | ||||
| #if ENABLE_TEXTURES_FROM_SVG | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     void render_prusa(GLCanvas3D* canvas, const std::string& key, bool bottom) const; | ||||
| #else | ||||
|     void render_prusa(const std::string& key, bool bottom) const; | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
|     void render_prusa_shader(bool transparent) const; | ||||
| #else | ||||
|     void render_prusa(const std::string &key, float theta, bool useVBOs) const; | ||||
|  |  | |||
|  | @ -1266,6 +1266,9 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar | |||
| #endif // ENABLE_SVG_ICONS
 | ||||
|     , m_use_clipping_planes(false) | ||||
|     , m_sidebar_field("") | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     , m_keep_dirty(false) | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
|     , m_config(nullptr) | ||||
|     , m_process(nullptr) | ||||
|     , m_model(nullptr) | ||||
|  | @ -1483,6 +1486,10 @@ void GLCanvas3D::bed_shape_changed() | |||
|     m_camera.set_scene_box(scene_bounding_box()); | ||||
|     m_camera.requires_zoom_to_bed = true; | ||||
|     m_dirty = true; | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     if (m_bed.is_prusa()) | ||||
|         start_keeping_dirty(); | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| } | ||||
| 
 | ||||
| void GLCanvas3D::set_color_by(const std::string& value) | ||||
|  | @ -2353,6 +2360,11 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt) | |||
|         return; | ||||
| 
 | ||||
|     _refresh_if_shown_on_screen(); | ||||
| 
 | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     if (m_keep_dirty) | ||||
|         m_dirty = true; | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| } | ||||
| 
 | ||||
| void GLCanvas3D::on_char(wxKeyEvent& evt) | ||||
|  | @ -3966,7 +3978,11 @@ void GLCanvas3D::_render_bed(float theta) const | |||
| #if ENABLE_RETINA_GL | ||||
|     scale_factor = m_retina_helper->get_scale_factor(); | ||||
| #endif // ENABLE_RETINA_GL
 | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     m_bed.render(const_cast<GLCanvas3D*>(this), theta, m_use_VBOs, scale_factor); | ||||
| #else | ||||
|     m_bed.render(theta, m_use_VBOs, scale_factor); | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| } | ||||
| 
 | ||||
| void GLCanvas3D::_render_axes() const | ||||
|  |  | |||
|  | @ -449,6 +449,9 @@ private: | |||
|     bool m_use_clipping_planes; | ||||
|     mutable SlaCap m_sla_caps[2]; | ||||
|     std::string m_sidebar_field; | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     bool m_keep_dirty; | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| 
 | ||||
|     mutable GLVolumeCollection m_volumes; | ||||
|     Selection m_selection; | ||||
|  | @ -635,6 +638,11 @@ public: | |||
|     void set_cursor(ECursorType type); | ||||
|     void msw_rescale(); | ||||
| 
 | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     void start_keeping_dirty() { m_keep_dirty = true; } | ||||
|     void stop_keeping_dirty() { m_keep_dirty = false; } | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| 
 | ||||
| private: | ||||
|     bool _is_shown_on_screen() const; | ||||
| 
 | ||||
|  |  | |||
|  | @ -85,6 +85,17 @@ void GLTexture::Compressor::send_compressed_data_to_gpu() | |||
|     glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); | ||||
| } | ||||
| 
 | ||||
| bool GLTexture::Compressor::all_compressed_data_sent_to_gpu() const | ||||
| { | ||||
|     for (const Level& level : m_levels) | ||||
|     { | ||||
|         if (!level.sent_to_gpu) | ||||
|             return false; | ||||
|     } | ||||
| 
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| void GLTexture::Compressor::compress() | ||||
| { | ||||
|     // reference: https://github.com/Cyan4973/RygsDXTc
 | ||||
|  | @ -512,7 +523,9 @@ bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, boo | |||
| bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, unsigned int max_size_px) | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| { | ||||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|     bool compression_enabled = compress && GLEW_EXT_texture_compression_s3tc; | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| 
 | ||||
|     NSVGimage* image = nsvgParseFromFile(filename.c_str(), "px", 96.0f); | ||||
|     if (image == nullptr) | ||||
|  |  | |||
|  | @ -42,6 +42,7 @@ namespace GUI { | |||
| 
 | ||||
|             bool unsent_compressed_data_available() const; | ||||
|             void send_compressed_data_to_gpu(); | ||||
|             bool all_compressed_data_sent_to_gpu() const; | ||||
| 
 | ||||
|         private: | ||||
|             void compress(); | ||||
|  | @ -109,6 +110,7 @@ namespace GUI { | |||
| #if ENABLE_COMPRESSED_TEXTURES | ||||
|         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(); } | ||||
| #endif // ENABLE_COMPRESSED_TEXTURES
 | ||||
| 
 | ||||
|         static void render_texture(unsigned int tex_id, float left, float right, float bottom, float top); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Enrico Turri
						Enrico Turri