[edit] actually I cant compare bits using bitfields with more then one bit, so no need to bother reading further..[/edit]
Say you have those flags in a bitfield:
setViewport 1 bit (on off)
setCbuffer 4 bits (slots 0 to 15)
setTexture 4 bits (slots 0 to 15)
setBlendSate 1 bit (on off)
...
(totally based on Hodgman pseudo codes I found around graphics forum)
You need to put it on a state:
uint64 stateMask;
So that you can check witch flags are set, set new flags, and so on..
stateMask &= command[it].stateBits; if( stateMask & command[it].stateBits) ...
How do you define all possible values? How do you assign the command.stateBits a value?
I tried a enum, but VS complains about it being > than 32, and says its undefined behavior('<<' : shift count negative or too big, undefined behavior.), if Id define in hexa maybe it would work(a quick search and I found that enums can fit in any integral type theyd need, not sure), but godam, too fancy. Defining the values for the enums is a pain in the ass.
Than I created a union between a struct bitfield and a uint64...seens nice but thats a type, not a value..Its kinda stupid but I dont know how to do it elegantly.
If I use the struct bitfield, each state value will need to be initialized in the constructor of the command objects:
union Bitfield{
uint64 asInt64;
struct{
bool Viewport : 1;
uint CBuffer : 4;
uint Texture : 4;
bool BlendState : 1;
...
}
}
struct SetCBuffer4Command{
Bitfield stateBits;
SetCBuffer4Command(){
stateBits.CBuffer = 4; // intead of stateBits = 4<<1, where id need to remind of the bits position;
}
}
...
stateMask &= command[it].stateBits.asInt64;
Any suggestion? Ive heard bitfields arent guaranteed of preserving its order, with means I just cant do that...
Edited by Icebone1000, 13 March 2013 - 02:27 PM.






