Little Help

Hi,

I would really appreciate if someone could help me understand some code here:
Any kind of suggestions will be much appreciated.

1.
1
2
3
4
5
6
7
8
9
		const tunPass	PrimitivesTraverser::EnabledPassDefault = 
		{ 
			1 << 0 |	// biClearPass
			1 << 1 |	// biEmissivePass	
			1 << 2 |	// biAmbientPass	
			1 << 3 | 	// biDiffusePass	
			1 << 4 |	// biSpecularPass	
			1 << 5  	// biEnvironmentPass
		};





Last edited on
The first set is a nice way of writing numbers in which only a single bit is set to 1.

<< is the left shift operator. It serves to move every bit in the value to the left by the amount indicated.

So, 1 is the same as 00000001. I'm using 8 bits here, but it's just a demonstration.

1 << 0 is 00000001<<0, which comes out as 0000001
1 << 1 is 00000001<<1, which comes out as 0000010
1 << 2 is 00000001<<2, which comes out as 0000100
1 << 3 is 00000001<<3, which comes out as 0001000

and so on. It is common to use single bits in this way as flags; to indicate some status is on or off depending on the value of the bit. Looks like the LSB (least significant bit) is being used to indicate biClearPass, and the next one to indicate biEmissivePass, and so on.

As for section 2, what's the first line you don't understand?
Last edited on
Topic archived. No new replies allowed.