During cocos2d rendering, some graphics cards require two power ccnextpot images.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.