C ++ cocos2d-x OpenGL
Today, I saw the cocos2d rendering mechanism and saw a god-like thing ccnextpot.
Preface: Cocos2d is based on OpenGL. Some graphics cards of OpenGL on npot support some unsupported ones. npot indicates whether the power is a multiple of 2 because during rendering, it seems that Fourier transformation is used at the underlying layer for two idempotence. [This is not an investigation]
Source code : Cocos2d-x 3.1.1crendertexture class if (configuration: getinstance ()-> supportsnpot () {poww = W; powh = H;} else {poww = ccnextpot (w ); powh = ccnextpot (h );}
Int ccnextpot (int x) {x = x-1; X = x | (x> 1); X = x | (x> 2 ); X = x | (x> 4); X = x | (x> 8); X = x | (x> 16); Return x + 1 ;}
Find the minimum two power numbers greater than X, that is, the number of digits after the highest bit is changed to 1 plus 1. For example: 1011 0011 first to 1111 1111 0000 will only + 1 equals 1 0000
Parse source code: [for 32-bit integers] the image is not that big X = x-1; // 32: the answer is 32. So here we need to subtract 1 from the power of 2 to be greater than or equal to X = x | (x> 1 ); change the 2nd High to 1 x = x | (x> 2); change the high to 1 x = x | (x> 4); change the high to 1 x = x, 7, 8 high to 1 x = x | (x> 8); converts the 9,10, 11,12, 13,14, 15,16 high to 1 x = x | (x> 16 ); set 17,18, 19 ........ 32 high to 1
During cocos2d rendering, some graphics cards require two power ccnextpot images.