00001 #ifndef GLUTIL_BITARRAY_INCLUDED
00002 #define GLUTIL_BITARRAY_INCLUDED
00003
00004
00005
00006
00007
00008
00009 #include "gltypes.h"
00010
00011 template< int WIDTH, int HEIGHT >
00012 class GlBitArrayT
00013 {
00014 public:
00015 enum {
00016 ROW_WIDTH = ( ( WIDTH+31 ) / 32 ),
00017 WORDSIZE = ROW_WIDTH * HEIGHT
00018 };
00019
00020 GlBitArrayT() { memset( array, 0, WORDSIZE*4 ); }
00021
00022 U32 IsSet( int x, int y ) { return array[ y*ROW_WIDTH + (x/32) ] & ( 0x1 << (x & 31)); }
00023 void Set( int x, int y ) { array[ y*ROW_WIDTH + (x/32) ] |= ( 0x1 << ( x & 31 ) ); }
00024 void Clear( int x, int y ) { array[ y*ROW_WIDTH + (x/32) ] &= (~( 0x1 << ( x & 31 ) ) ); }
00025
00026 void ClearAll() { memset( array, 0, WORDSIZE*4 ); }
00027 void SetAll() { memset( array, 0xff, WORDSIZE*4 ); }
00028
00029
00030 U32 array[ WORDSIZE ];
00031 };
00032
00033
00034 template< int WIDTH, int HEIGHT >
00035 class GlBitArrayTRowIt
00036 {
00037 public:
00038 GlBitArrayTRowIt( const GlBitArrayT<WIDTH, HEIGHT>& _array ) : bitArray( _array ), mask( 0 ), loc( 0 ) {}
00039
00040 void Begin( int x, int y) { loc = &bitArray.array[ y*bitArray.ROW_WIDTH + (x/32) ];
00041 U32 bit = x & 31;
00042 mask = 0x01 << bit;
00043 }
00044 void Next() { mask <<= 1;
00045 if ( !mask ) {
00046 mask = 0x01;
00047 ++loc;
00048 }
00049 }
00050 U32 IsSet() { return ( *loc ) & ( mask ); }
00051 bool WordEmpty() { return !(*loc); }
00052
00053 private:
00054 const GlBitArrayT<WIDTH, HEIGHT>& bitArray;
00055 U32 mask;
00056 const U32 *loc;
00057 };
00058
00059
00060
00061 #endif