c++ - What do "Non-Power-Of-Two Textures" mean? -


what "non-power-of-two textures" mean? read this tutorial , meet binaries operations("<<", ">>", "^", "~"), don't understand doing. example following code:

gluint ltexture::poweroftwo(gluint num) {     if (num != 0)     {         num--;         num |= (num >> 1); //or first 2 bits         num |= (num >> 2); //or next 2 bits         num |= (num >> 4); //or next 4 bits         num |= (num >> 8); //or next 8 bits         num |= (num >> 16); //or next 16 bits         num++;     }     return num; } 

i want understand operations. well, read this. short article. want see examples of using, not found. did test:

int = 5; <<= 1; //a = 10 = 5; <<= 2; //a = 20 = 5; <<= 3; //a = 40 

okay, multiply on two, but

int = 5; >>= 1; // = 2 whaat?? 

in c++, <<= "left binary shift" assignment operator; operand on left treated binary number, bits moved left, , 0 bits inserted on right.

the >>= right binary shift; bits moved right , "fall off" right end, it's division 2 (for each bit) truncation. negative signed integers, way, additional 1 bits shifted in @ left end ("arithmetic right shift"), may surprising; positive signed integers, or unsigned integers, 0 bits shifted in @ left ("logical right shift").

"powers of two" numbers created successive doublings of 1: 2, 4, 8, 16, 32… graphics hardware prefers work texture maps powers of 2 in size.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -