From: <br...@us...> - 2009-04-05 05:33:04
|
Revision: 3884 http://openvrml.svn.sourceforge.net/openvrml/?rev=3884&view=rev Author: braden Date: 2009-04-05 05:32:54 +0000 (Sun, 05 Apr 2009) Log Message: ----------- Clean up allocated GL resources on window resize so that the viewer can be reinitialized. Some platforms and bindings (notably SDL on Windows) destroy the GL context on resize. Modified Paths: -------------- trunk/ChangeLog trunk/src/libopenvrml-gl/openvrml/gl/viewer.cpp trunk/src/libopenvrml-gl/openvrml/gl/viewer.h Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-04-05 05:12:57 UTC (rev 3883) +++ trunk/ChangeLog 2009-04-05 05:32:54 UTC (rev 3884) @@ -1,5 +1,29 @@ 2009-04-05 Braden McDaniel <br...@en...> + Clean up allocated GL resources on window resize so that the + viewer can be reinitialized. Some platforms and bindings (notably + SDL on Windows) destroy the GL context on resize. + + * src/libopenvrml-gl/openvrml/gl/viewer.cpp + (openvrml::gl::viewer::viewer()): Initialize the tesselator to 0; + allocate the tesselator in openvrml::gl::viewer::initialize + instead. + (openvrml::gl::viewer::~viewer()): Call shutdown. + (openvrml::gl::viewer::initialize()): Allocate the GLU tesselator + here. + (openvrml::gl::viewer::delete_list): Function object to call + glDeleteLists. + (openvrml::gl::viewer::delete_texture): Function object to call + glDeleteTextures. + (openvrml::gl::viewer::shutdown()): Clean up display lists, + textures objects, and the GLU tesselator. + (openvrml::gl::viewer::resize(size_t, size_t)): Call shutdown. + * src/libopenvrml-gl/openvrml/gl/viewer.h + (openvrml::gl::viewer): Declare structs delete_list and + delete_texture; added shutdown member function. + +2009-04-05 Braden McDaniel <br...@en...> + * src/node/vrml97/abstract_indexed_set.h (openvrml_node_vrml97::abstract_indexed_set_node<Derived>::do_color() const): Override openvrml::geometry_node::do_color instead of Modified: trunk/src/libopenvrml-gl/openvrml/gl/viewer.cpp =================================================================== --- trunk/src/libopenvrml-gl/openvrml/gl/viewer.cpp 2009-04-05 05:12:57 UTC (rev 3883) +++ trunk/src/libopenvrml-gl/openvrml/gl/viewer.cpp 2009-04-05 05:32:54 UTC (rev 3884) @@ -911,7 +911,7 @@ win_height(1), objects(0), nested_objects(0), - tesselator(gluNewTess()), + tesselator(0), sensitive(0), active_sensitive(0), over_sensitive(0), @@ -936,7 +936,7 @@ */ openvrml::gl::viewer::~viewer() OPENVRML_NOTHROW { - gluDeleteTess(this->tesselator); + this->shutdown(); } /** @@ -944,6 +944,9 @@ */ void openvrml::gl::viewer::initialize() { + assert(!this->tesselator); + this->tesselator = gluNewTess(); + glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); @@ -966,6 +969,39 @@ this->gl_initialized = true; } +struct OPENVRML_LOCAL openvrml::gl::viewer::delete_list { + void operator()(const list_map_t::value_type & value) const + { + glDeleteLists(value.second, 1); + } +}; + +struct OPENVRML_LOCAL openvrml::gl::viewer::delete_texture { + void operator()(const texture_map_t::value_type & value) const + { + glDeleteTextures(1, &value.second); + } +}; + +/** + * @brief Shut down. + */ +void openvrml::gl::viewer::shutdown() +{ + std::for_each(this->list_map_.begin(), this->list_map_.end(), + delete_list()); + this->list_map_.clear(); + + std::for_each(this->texture_map_.begin(), this->texture_map_.end(), + delete_texture()); + this->texture_map_.clear(); + + if (this->tesselator) { gluDeleteTess(this->tesselator); } + this->tesselator = 0; + + this->gl_initialized = false; +} + namespace { // Call this after each frame for debugging... @@ -3989,9 +4025,18 @@ */ void openvrml::gl::viewer::resize(size_t width, size_t height) { + // + // Some platforms/bindings may destroy the GL context when resizing the + // window. Go ahead and clean up display lists and texture maps. They'll + // get recreated as needed. + // + this->shutdown(); + if (width < 2) { width = 2; } if (height < 2) { height = 2; } - glViewport(0, 0, GLsizei(width), GLsizei(height)); + glViewport(0, 0, + static_cast<GLsizei>(width), + static_cast<GLsizei>(height)); this->win_width = width; this->win_height = height; } Modified: trunk/src/libopenvrml-gl/openvrml/gl/viewer.h =================================================================== --- trunk/src/libopenvrml-gl/openvrml/gl/viewer.h 2009-04-05 05:12:57 UTC (rev 3883) +++ trunk/src/libopenvrml-gl/openvrml/gl/viewer.h 2009-04-05 05:32:54 UTC (rev 3884) @@ -45,9 +45,11 @@ class OPENVRML_GL_API viewer : public openvrml::viewer { typedef std::map<const node *, GLuint> list_map_t; + struct delete_list; list_map_t list_map_; typedef std::map<const texture_node *, GLuint> texture_map_t; + struct delete_texture; texture_map_t texture_map_; public: @@ -146,8 +148,8 @@ double render_time; double render_time1; - // Initialize OpenGL state void initialize(); + void shutdown(); void begin_geometry(); void end_geometry(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |