diff --git a/src/main.c b/src/main.c index a147d2598..384d5736a 100644 --- a/src/main.c +++ b/src/main.c @@ -8273,6 +8273,18 @@ static bool se_load_theme_from_image_format_mini(uint8_t* im, uint32_t im_w, uin } return true; } +static uint8_t * se_pad_image_to_size(uint8_t* im, uint32_t im_w, uint32_t im_h, uint32_t new_w, uint32_t new_h){ + uint8_t * new_image = malloc(new_w*new_h*4); + memset(new_image,0,new_w*new_h*4); + for(int y = 0; y< im_h;++y) + for(int x = 0; x< im_w;++x){ + new_image[(y*new_w + x)*4+0] = im[(y*im_w+x)*4+0]; + new_image[(y*new_w + x)*4+1] = im[(y*im_w+x)*4+1]; + new_image[(y*new_w + x)*4+2] = im[(y*im_w+x)*4+2]; + new_image[(y*new_w + x)*4+3] = im[(y*im_w+x)*4+3]; + } + return new_image; +} static bool se_load_theme_from_image(uint8_t* im, uint32_t im_w, uint32_t im_h, bool invert){ if(!im){return false; } bool loaded = false; @@ -8413,6 +8425,22 @@ static bool se_load_theme_from_image(uint8_t* im, uint32_t im_w, uint32_t im_h, theme->palettes[i*4+2]= 255-theme->palettes[i*4+2]; } } + //WebGL doesn't support mip mapping of NPOT, so pad them to a power of two. + bool free_mip0 = false; + //#if defined(EMSCRIPTEN) + int pad_pow2 = 1; + while(pad_pow2 < im_w ||pad_pow2 {%d %d}\n",im_w,im_h,pad_pow2,pad_pow2); + im_w = pad_pow2; + im_h = pad_pow2; + free_mip0 = true; + } + //#endif + theme->im_h=im_h; + theme->im_w=im_w; sg_image_data im_data={0}; im_data.subimage[0][0].ptr = im; @@ -8437,11 +8465,24 @@ static bool se_load_theme_from_image(uint8_t* im, uint32_t im_w, uint32_t im_h, } } } + int drop_mips=0; + //#if defined(EMSCRIPTEN) + while((im_h>>drop_mips)>2048)drop_mips++; + printf("Dropping %d mip layers\n",drop_mips); + for(int i=0;i