diff --git a/3rdparty/stb_image/stb_image.c b/3rdparty/stb_image/stb_image.c index be2f2141b..f258d9c1f 100644 --- a/3rdparty/stb_image/stb_image.c +++ b/3rdparty/stb_image/stb_image.c @@ -2951,7 +2951,7 @@ static int shiftsigned(int v, int shift, int bits) static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp) { uint8 *out; - unsigned int mr=0,mg=0,mb=0,ma=0, fake_a=0; + unsigned int mr=0,mg=0,mb=0,ma=0; stbi_uc pal[256][4]; int psize=0,i,j,compress=0,width; int bpp, flip_vertically, pad, target, offset, hsz; @@ -3000,7 +3000,6 @@ static stbi_uc *bmp_load(stbi *s, int *x, int *y, int *comp, int req_comp) mg = 0xffu << 8; mb = 0xffu << 0; ma = 0xffu << 24; - fake_a = 1; // @TODO: check for cases like alpha value is all 0 and switch it to 255 } else { mr = 31u << 10; mg = 31u << 5; diff --git a/examples/common/entry_emscripten.cpp b/examples/common/entry_emscripten.cpp index a6ff26f69..f1cc225d7 100644 --- a/examples/common/entry_emscripten.cpp +++ b/examples/common/entry_emscripten.cpp @@ -8,13 +8,13 @@ #if BX_PLATFORM_EMSCRIPTEN #include -#include +#include +#include extern int _main_(int _argc, char** _argv); -#include -jmp_buf s_main; -jmp_buf s_loop; +static jmp_buf s_main; +static jmp_buf s_loop; void emscripten_yield() { @@ -36,6 +36,7 @@ int main(int _argc, char** _argv) { if (!setjmp(s_loop) ) { + alloca(16<<10); _main_(_argc, _argv); } diff --git a/premake/ddsdump.lua b/premake/ddsdump.lua index 7ec2f5f4b..9c9917b4d 100644 --- a/premake/ddsdump.lua +++ b/premake/ddsdump.lua @@ -14,5 +14,5 @@ project "ddsdump" } links { - "bgfx", +-- "bgfx", } diff --git a/tools/ddsdump.cpp b/tools/ddsdump.cpp index f59138ea5..351c282d9 100644 --- a/tools/ddsdump.cpp +++ b/tools/ddsdump.cpp @@ -7,6 +7,7 @@ #include #include +// Just hacking DDS loading code in here. #include "bgfx_p.h" using namespace bgfx; @@ -21,6 +22,68 @@ using namespace bgfx; #include #include +namespace bgfx +{ + const Memory* alloc(uint32_t _size) + { + Memory* mem = (Memory*)::realloc(NULL, sizeof(Memory) + _size); + mem->size = _size; + mem->data = (uint8_t*)mem + sizeof(Memory); + return mem; + } + + void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, bool _grayscale, bool _yflip) + { + FILE* file = fopen(_filePath, "wb"); + if ( NULL != file ) + { + uint8_t type = _grayscale ? 3 : 2; + uint8_t bpp = _grayscale ? 8 : 32; + + putc(0, file); + putc(0, file); + putc(type, file); + putc(0, file); + putc(0, file); + putc(0, file); + putc(0, file); + putc(0, file); + putc(0, file); + putc(0, file); + putc(0, file); + putc(0, file); + putc(_width&0xff, file); + putc( (_width>>8)&0xff, file); + putc(_height&0xff, file); + putc( (_height>>8)&0xff, file); + putc(bpp, file); + putc(32, file); + + uint32_t dstPitch = _width*bpp/8; + if (_yflip) + { + uint8_t* data = (uint8_t*)_src + dstPitch*_height - _srcPitch; + for (uint32_t yy = 0; yy < _height; ++yy) + { + fwrite(data, dstPitch, 1, file); + data -= _srcPitch; + } + } + else + { + uint8_t* data = (uint8_t*)_src; + for (uint32_t yy = 0; yy < _height; ++yy) + { + fwrite(data, dstPitch, 1, file); + data += _srcPitch; + } + } + + fclose(file); + } + } +} + long int fsize(FILE* _file) { long int pos = ftell(_file); @@ -36,8 +99,9 @@ int main(int _argc, const char* _argv[]) FILE* file = fopen(_argv[1], "rb"); uint32_t size = fsize(file); - const Memory* mem = bgfx::alloc(size); - fread(mem->data, 1, size, file); + const Memory* mem = alloc(size); + size_t readSize = fread(mem->data, 1, size, file); + BX_UNUSED(readSize); fclose(file); Dds dds; @@ -95,7 +159,7 @@ int main(int _argc, const char* _argv[]) char filePath[256]; _snprintf(filePath, sizeof(filePath), "mip%d_%d.tga", side, lod); - bgfx::saveTga(filePath, width, height, dstpitch, bits); + saveTga(filePath, width, height, dstpitch, bits); free(bits); }