What does |= mean?

I saw |= used in an example for creating a vertex shader.

1
2
3
#if defined( DEBUG ) || defined( _DEBUG )
     shaderFlags |= D3DCOMPILE_DEBUG;
#endif 
Just a shorter way of writing the following:
1
2
 
  shaderFlags = shaderFlags | D3DCOMPILE_DEBUG;

Its an operator called Bitwise OR assignment. Not sure what it does though, try googling that.
In that case it means you're adding the debug flag to the list of flags you have already, it does something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
unsigned char current flag = 0;  //0000 0000

current flag |= 4;

//current flag = 0000 0010 or (4)

current flag |= 32

//current flag = 0001 0010 or (36)

current flag |= 4

//current flag = 0001 0010 or (36)

current flag |= 255

//current flag = 1111 1111 or (255) 


etc. etc. ad naseum.
Last edited on
Topic archived. No new replies allowed.