Index: /trunk/nv/flags.hh
===================================================================
--- /trunk/nv/flags.hh	(revision 309)
+++ /trunk/nv/flags.hh	(revision 310)
@@ -16,32 +16,12 @@
 #include <nv/common.hh>
 #include <nv/type_traits.hh>
-#include <bitset>
+#include <nv/array.hh>
 
 namespace nv
 {
-	template< typename T, typename IS_ENUM >
-	struct base_underlying_type_helper
-	{
-		typedef T type;
-	};
-
-	template< typename T >
-	struct base_underlying_type_helper< T, std::true_type >
-	{
-		typedef typename nv::underlying_type<T>::type type;
-	};
-
-
-	template< typename T >
-	struct base_underlying_type
-	{
-		typedef typename base_underlying_type_helper< T, typename std::is_enum<T>::type >::type type;
-	};
-
 	template < uint32 SIZE, typename T = uint32 >
 	class flags
 	{
 	public:
-
 		class reference
 		{
@@ -67,5 +47,5 @@
 
 		private:
-			reference() : m_flags( nullptr ), m_index( 0 ) {}
+			reference() : m_flags( nullptr ), m_index( index_type(0) ) {}
 
 			reference( flags<SIZE,T>* a_flags, index_type a_index )
@@ -79,7 +59,64 @@
 		};
 
-		typedef uint8  data_type;
-		typedef bool   value_type;
-		typedef T      index_type;
+		class enumerator
+		{
+			friend class flags<SIZE,T>;
+		public:
+			typedef T              index_type;
+			typedef T              value_type;
+			typedef T*             iterator;
+			typedef const T*       const_iterator;
+			typedef T&             reference;
+			typedef const T&       const_reference;
+			typedef std::size_t    size_type;
+			typedef std::ptrdiff_t difference_type;
+
+			T operator* () const { return m_index; }
+			T const* operator-> () const { return &m_index; }
+			bool operator== ( const enumerator& rhs ) const
+			{
+				return ( m_index == rhs.m_index ) && ( m_flags == rhs.m_flags );
+			}
+			bool operator!= ( const enumerator& rhs ) const
+			{
+				return !( *this == rhs );
+			}
+			
+			enumerator& operator++ () 
+			{
+				next();
+				return *this; 
+			}
+			enumerator operator++ (int) 
+			{
+				auto result = *this; 
+				++*this; 
+				return result;
+			}
+		protected:
+			enumerator() : m_flags( nullptr ), m_index( index_type(0) ) {}
+
+			enumerator( const flags<SIZE,T>* a_flags, index_type a_index )
+				: m_flags( a_flags ), m_index( a_index )
+			{	
+				if ( a_flags && !a_flags->test( a_index ) ) next();
+			}
+
+			void next()
+			{
+				if ( m_flags )
+				do 
+				{
+					if ( raw_index_type(m_index) >= SIZE ) { m_flags = nullptr; m_index = index_type(0); return; }
+					m_index = index_type((raw_index_type)m_index + 1);
+				} while ( !m_flags->test( m_index ) );
+			}
+
+			const flags<SIZE,T>* m_flags;
+			index_type           m_index;
+		};
+
+		typedef uint8     data_type;
+		typedef T         index_type;
 		typedef uint32 size_type;
 		typedef typename base_underlying_type<T>::type raw_index_type;
@@ -89,4 +126,10 @@
 		static const size_type data_size      = (SIZE+data_type_size-1) / data_type_size;
 
+		enumerator begin()  const { return enumerator( this, index_type(0) ); }
+		enumerator cbegin() const { return enumerator( this, index_type(0) ); }
+
+		enumerator end()  const { return enumerator(); }
+		enumerator cend() const { return enumerator(); }
+
 		flags()
 		{
@@ -123,5 +166,5 @@
 		}
 
-		void set( index_type i, value_type value )
+		void set( index_type i, bool value )
 		{
 			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
Index: /trunk/nv/lib/wx.hh
===================================================================
--- /trunk/nv/lib/wx.hh	(revision 309)
+++ /trunk/nv/lib/wx.hh	(revision 310)
@@ -32,6 +32,24 @@
 		explicit gl_canvas( wxWindow *parent );
 		virtual void OnUpdate() = 0;
-		virtual void Stop() { m_update_timer->Stop(); }
-		virtual void Start() { m_update_timer->Start(10); }
+// 		virtual void Stop() { m_update_timer->Stop(); }
+// 		virtual void Start() { m_update_timer->Start(20); }
+		virtual void Stop() 
+		{
+			Disconnect( wxEVT_IDLE, wxIdleEventHandler(gl_canvas::OnIdle) );
+			//m_update_timer->Stop();
+		}
+		virtual void Start() 
+		{ 
+			Connect( wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(gl_canvas::OnIdle) );
+			//m_update_timer->Start(20);
+		}
+		void OnIdle(wxIdleEvent& evt)
+		{
+			if(m_render)
+			{
+				OnUpdate();
+				evt.RequestMore(); // render continuously, not only once on idle
+			}
+		}
 		~gl_canvas();
 	protected:
@@ -42,4 +60,5 @@
 		nv::window*  m_window;
 		wxTimer*     m_update_timer;
+		bool         m_render;
 		wxDECLARE_EVENT_TABLE();
 	};
@@ -68,10 +87,8 @@
 		m_window = m_device->adopt_window( GetHWND(), dc.GetHDC() );
 		m_context = m_window->get_context();
-		m_update_timer = new gl_update_timer( this );
 	}
 
 	inline gl_canvas::~gl_canvas()
 	{
-		delete m_update_timer;
 		delete m_window;
 		delete m_device;
Index: /trunk/nv/range.hh
===================================================================
--- /trunk/nv/range.hh	(revision 309)
+++ /trunk/nv/range.hh	(revision 310)
@@ -89,4 +89,41 @@
 		};
 
+		template < typename T >
+		class bits_iterator_base : public forward_iterator_base< T >
+		{
+		public:
+			typedef typename base_underlying_type<T>::type base_type;
+			static const T invalid = T( 0 );
+
+			bits_iterator_base( T value, T current ) : forward_iterator_base( current ), m_full( value )
+			{
+				if( !( (base_type)value & (base_type)current ) )
+					next();
+			}
+			bits_iterator_base& operator++ () 
+			{
+				next();
+				return *this; 
+			}
+			bits_iterator_base operator++ (int) 
+			{
+				auto result = *this; 
+				++*this; 
+				return result;
+			}
+		private:
+			void next()
+			{
+				do
+				{
+					if ( m_value == invalid || m_full <= m_value ) { m_value = invalid; m_full = invalid; break; }
+					m_value = T((base_type)m_value << 1);
+				} while ( !( (base_type)m_full & (base_type)m_value ) );
+			}
+
+			T m_full;
+		};
+
+
 	} // namespace detail
 
@@ -134,4 +171,20 @@
 
 	template < typename T >
+	class bits_iterator_provider
+	{
+	public:
+		typedef typename base_underlying_type<T>::type base_type;
+		typedef detail::bits_iterator_base<T> iterator;
+		static const T invalid = T( 0 );
+
+		bits_iterator_provider( T value ) : m_value( value ) {}
+		iterator begin() { return iterator( m_value, T(1) ); }
+		iterator end() { return iterator( m_value, invalid ); }
+
+	protected:
+		T m_value;
+	};
+
+	template < typename T >
 	range_iterator_provider<T> range( T begin, T end )
 	{
@@ -163,4 +216,11 @@
 	}
 
+	template < typename T >
+	bits_iterator_provider<T> bits( T value )
+	{
+		return bits_iterator_provider<T>( value );
+	}
+
+
 }
 
Index: /trunk/nv/type_traits.hh
===================================================================
--- /trunk/nv/type_traits.hh	(revision 309)
+++ /trunk/nv/type_traits.hh	(revision 310)
@@ -207,4 +207,25 @@
 		((TYPE*)object)->TYPE::~TYPE();
 	}
+
+	template< typename T, typename IS_ENUM >
+	struct base_underlying_type_helper
+	{
+		typedef T type;
+	};
+
+	template< typename T >
+	struct base_underlying_type_helper< T, std::true_type >
+	{
+		typedef typename nv::underlying_type<T>::type type;
+	};
+
+
+	template< typename T >
+	struct base_underlying_type
+	{
+		typedef typename base_underlying_type_helper< T, typename std::is_enum<T>::type >::type type;
+	};
+
+
 }
 
Index: /trunk/src/gl/gl_window.cc
===================================================================
--- /trunk/src/gl/gl_window.cc	(revision 309)
+++ /trunk/src/gl/gl_window.cc	(revision 310)
@@ -350,5 +350,4 @@
 #if NV_PLATFORM == NV_WINDOWS
 #if NV_SDL_VERSION == NV_SDL_20
-	nv::load_gl_no_context();
 	m_context = new native_gl_context( m_device, dc );
 	SDL_Window* window = SDL_CreateWindowFrom( handle );
