PrevUpHomeNext

Bitfield

#include <oglplus/bitfield.hpp>

The Bitfield template serves as a wrapper for OpenGL bitfields. It allows to combine strongly-typed enumerated values into a single bitfield value.

Library end-user applications rarely need to use this class directly. Instantiations of this template are used as types for parameters in functions taking bitfields based on strongly-type enumerations. When constructing a bitfield the application simply passes the enumerated value or a combination of enumerated values using the bitwise-or operator or initializer list.

template <typename Bits>
class Bitfield
{
public:
	Bitfield(void); 1
	Bitfield(Bits _bit); 2
	Bitfield(Bits _bit_a, Bits _bit_b); 3

#if !OGLPLUS_NO_INITIALIZER_LISTS
	Bitfield(const std::initializer_list<Bits>& bits); 4
#endif
	template <typename Iter>
	Bitfield(Iter pos, Iter end); 5

	friend Bitfield operator | (Bitfield bf, Bits b); 6
	Bitfield& operator |= (Bits b); 7

	bool Test(Bits b) const; 8
	bool Has(Bits b) const;
};

template <typename Bits>
Bitfield<Bits> operator | (Bits b1, Bits b2);

1

Constructs an empty (zero) bitfield.

2

Construct a bitfield from a single value of Bits.

3

Construct a bitfield from a pair of Bits.

4

Construct a bitfield from an initializer list of Bits.

5

Construction from a pair of iterators through Bits.

6

Bitwise-or operator for combining Bits into a bitfield.

7

Bitwise-or operator for combining Bits into a bitfield.

8

These functions test if a specified bit is set.

Examples of usage

Context gl;

gl.Clear(ClearBit::ColorBuffer); 1

gl.Clear(
	ClearBit::ColorBuffer|
	ClearBit::DepthBuffer|
	ClearBit::StencilBuffer
); 2

gl.Clear({
	ClearBit::ColorBuffer,
	ClearBit::DepthBuffer,
	ClearBit::StencilBuffer
}); 3

if(gl.ProfileMask().Has(ContextProfileBit::Compatibility)) 4
{
	/* ... */
}

1

Initialization of a Bitfield from a single enumeration value.

2

Initialization from a set of enumeration values.

3

Initialization from an std::initializer_list of enumeration values.

4

Testing if a particular bit is set


PrevUpHomeNext