diff --git a/examples/common/bgfx_utils.cpp b/examples/common/bgfx_utils.cpp index 7f48cdb07..5bdbff647 100644 --- a/examples/common/bgfx_utils.cpp +++ b/examples/common/bgfx_utils.cpp @@ -160,16 +160,29 @@ static void imageReleaseCb(void* _ptr, void* _userData) bimg::imageFree(imageContainer); } -bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const bx::FilePath& _filePath, uint64_t _flags, uint8_t _skip, bgfx::TextureInfo* _info, bimg::Orientation::Enum* _orientation) +bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const bx::FilePath& _filePath, uint64_t _flags, uint8_t _skip, bgfx::TextureInfo* _info, bimg::Orientation::Enum* _orientation, bx::Error* _err) { BX_UNUSED(_skip); bgfx::TextureHandle handle = BGFX_INVALID_HANDLE; + if (NULL != _info) + { + bx::memSet(_info, 0, sizeof(*_info) ); + _info->format = bgfx::TextureFormat::Unknown; + } + + if (NULL != _orientation) + { + *_orientation = bimg::Orientation::R0; + } + uint32_t size; void* data = load(_reader, entry::getAllocator(), _filePath, &size); if (NULL != data) { - bimg::ImageContainer* imageContainer = bimg::imageParse(entry::getAllocator(), data, size, bimg::TextureFormat::Count, bx::ErrorIgnore{}); + bx::Error localErr; + bx::Error* err = (NULL != _err) ? _err : &localErr; + bimg::ImageContainer* imageContainer = bimg::imageParse(entry::getAllocator(), data, size, bimg::TextureFormat::Count, err); if (NULL != imageContainer) { @@ -247,9 +260,9 @@ bgfx::TextureHandle loadTexture(bx::FileReaderI* _reader, const bx::FilePath& _f return handle; } -bgfx::TextureHandle loadTexture(const bx::FilePath& _filePath, uint64_t _flags, uint8_t _skip, bgfx::TextureInfo* _info, bimg::Orientation::Enum* _orientation) +bgfx::TextureHandle loadTexture(const bx::FilePath& _filePath, uint64_t _flags, uint8_t _skip, bgfx::TextureInfo* _info, bimg::Orientation::Enum* _orientation, bx::Error* _err) { - return loadTexture(entry::getFileReader(), _filePath, _flags, _skip, _info, _orientation); + return loadTexture(entry::getFileReader(), _filePath, _flags, _skip, _info, _orientation, _err); } bimg::ImageContainer* imageLoad(const bx::FilePath& _filePath, bgfx::TextureFormat::Enum _dstFormat) diff --git a/examples/common/bgfx_utils.h b/examples/common/bgfx_utils.h index 32a500492..fee09c037 100644 --- a/examples/common/bgfx_utils.h +++ b/examples/common/bgfx_utils.h @@ -60,7 +60,7 @@ bgfx::ProgramHandle loadProgram(const bx::StringView& _vsName, const bx::StringV /// /// @returns Texture handle. /// -bgfx::TextureHandle loadTexture(const bx::FilePath& _filePath, uint64_t _flags = BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL, bimg::Orientation::Enum* _orientation = NULL); +bgfx::TextureHandle loadTexture(const bx::FilePath& _filePath, uint64_t _flags = BGFX_TEXTURE_NONE|BGFX_SAMPLER_NONE, uint8_t _skip = 0, bgfx::TextureInfo* _info = NULL, bimg::Orientation::Enum* _orientation = NULL, bx::Error* _err = NULL); /// Load image container from file. /// diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index b0f30ee74..23ea37a5d 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -80,6 +80,7 @@ static const char* s_supportedExt[] = "jpeg", "jpg", "ktx", + "ktx2", "pgm", "png", "ppm", @@ -231,7 +232,7 @@ static const InputBinding* s_binding[] = static_assert(Binding::Count == BX_COUNTOF(s_binding) ); static const char* s_filter = "" - "All Image Formats (bmp, dds, exr, gif, gnf, jpg, jpeg, hdr, ktx, pgm, png, ppm, psd, pvr, tga, webp) | *.bmp *.dds *.exr *.gif *.gnf *.jpg *.jpeg *.hdr *.ktx *.pgm *.png *.ppm *.psd *.pvr *.tga *.webp\n" + "All Image Formats (bmp, dds, exr, gif, gnf, jpg, jpeg, hdr, ktx, ktx2, pgm, png, ppm, psd, pvr, tga, webp) | *.bmp *.dds *.exr *.gif *.gnf *.jpg *.jpeg *.hdr *.ktx *.ktx2 *.pgm *.png *.ppm *.psd *.pvr *.tga *.webp\n" "Windows Bitmap (bmp) | *.bmp\n" "Direct Draw Surface (dds) | *.dds\n" "OpenEXR (exr) | *.exr\n" @@ -239,6 +240,7 @@ static const char* s_filter = "" "JPEG Interchange Format (jpg, jpeg) | *.jpg *.jpeg\n" "Radiance RGBE (hdr) | *.hdr\n" "Khronos Texture (ktx) | *.ktx\n" + "Khronos Texture 2 (ktx2) | *.ktx2\n" "Portable Graymap/Pixmap Format (pgm, ppm) | *.pgm *.ppm\n" "Portable Network Graphics (png) | *.png\n" "Photoshop Document (psd) | *.psd\n" @@ -1499,7 +1501,7 @@ int _main_(int _argc, char** _argv) bgfx::TextureHandle texture = BGFX_INVALID_HANDLE; { - uint32_t fileIndex = 0; + uint32_t fileIndex = UINT32_MAX; bool dragging = false; entry::WindowState windowState; @@ -2041,7 +2043,7 @@ int _main_(int _argc, char** _argv) imguiEndFrame(); - if ( (!bgfx::isValid(texture) || view.m_fileIndex != fileIndex) + if (view.m_fileIndex != fileIndex && 0 != view.m_fileList.size() ) { if (bgfx::isValid(texture) ) @@ -2055,6 +2057,7 @@ int _main_(int _argc, char** _argv) fp.join(view.m_fileList[view.m_fileIndex].c_str() ); bimg::Orientation::Enum orientation; + bx::Error loadErr; texture = loadTexture(fp.getCPtr() , 0 | BGFX_SAMPLER_U_CLAMP @@ -2063,6 +2066,7 @@ int _main_(int _argc, char** _argv) , 0 , &view.m_textureInfo , &orientation + , &loadErr ); bimg::TextureFormat::Enum format = bimg::TextureFormat::Enum(view.m_textureInfo.format); @@ -2115,7 +2119,16 @@ int _main_(int _argc, char** _argv) } else { - bx::stringPrintf(title, "Failed to load %s!", filePath); + if (!loadErr.isOk() ) + { + const bx::StringView& msg = loadErr.getMessage(); + bx::stringPrintf(title, "Failed to load %s: %S", filePath, &msg); + bx::printf("Failed to load %s: %S\n", filePath, &msg); + } + else + { + bx::stringPrintf(title, "Failed to load %s!", filePath); + } } entry::setWindowTitle(entry::kDefaultWindowHandle, title.c_str() );