Name

bitfieldInsert - returns an extracted range of bits from a bitfield.

Synopsis

int  bitfieldInsert(int  a, int b, int c, int d)
int2 bitfieldInsert(int2 a, int b, int c, int d)
int3 bitfieldInsert(int3 a, int b, int c, int d)
int4 bitfieldInsert(int4 a, int b, int c, int d)

uint  bitfieldInsert(uint  a, uint b, int c, int d)
uint2 bitfieldInsert(uint2 a, uint b, int c, int d)
uint3 bitfieldInsert(uint3 a, uint b, int c, int d)
uint4 bitfieldInsert(uint4 a, uint b, int c, int d)

Parameters

a
Bitfield to insert bits into.
b
Bit pattern to insert.
c
Bit offset number.
d
Number of bits to insert.

Description

Returns the result of inserting bits B at offset C of length D in the bitfield A.

Reference Implementation

bitfieldInsert for an int bitfield can be implemented like this:

int bitfieldInsert(int a, int b, int c, int d)
{
  uint mask = ~(0xffffffff << d) << c;
  mask ~= mask;
  a &= mask;
  return a | (b << c);
}

Profile Support

bitfieldInsert is supported in gp5 profiles.

See Also

  http://www.opengl.org/registry/specs/ARB/gpu_shader5.txt

bitfieldExtract, bitfieldReverse, bitCount, findLSB and findMSB