diff options
Diffstat (limited to '3rdparty/bgfx/tools/texturev/texturev.cpp')
-rw-r--r-- | 3rdparty/bgfx/tools/texturev/texturev.cpp | 414 |
1 files changed, 299 insertions, 115 deletions
diff --git a/3rdparty/bgfx/tools/texturev/texturev.cpp b/3rdparty/bgfx/tools/texturev/texturev.cpp index edd3b9b1a6b..5a26388c8a0 100644 --- a/3rdparty/bgfx/tools/texturev/texturev.cpp +++ b/3rdparty/bgfx/tools/texturev/texturev.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "common.h" @@ -20,11 +20,10 @@ #include <entry/entry.h> #include <entry/input.h> #include <entry/cmd.h> +#include <entry/dialog.h> #include <imgui/imgui.h> #include <bgfx_utils.h> -#include <dirent.h> - #include <tinystl/allocator.h> #include <tinystl/vector.h> namespace stl = tinystl; @@ -114,6 +113,18 @@ struct Geometry }; }; +struct Output +{ + enum Enum + { + sRGB, + scRGB, + HDR10, + + Count + }; +}; + static const InputBinding s_bindingApp[] = { { entry::Key::KeyQ, entry::Modifier::None, 1, NULL, "exit" }, @@ -213,10 +224,50 @@ static const InputBinding* s_binding[] = }; BX_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) | *.bmp *.dds *.exr *.gif *.gnf *.jpg *.jpeg *.hdr *.ktx *.pgm *.png *.ppm *.psd *.pvr *.tga\n" + "Windows Bitmap (bmp) | *.bmp\n" + "Direct Draw Surface (dds) | *.dds\n" + "OpenEXR (exr) | *.exr\n" + "Graphics Interchange Format (gif) | *.gif\n" + "JPEG Interchange Format (jpg, jpeg) | *.jpg *.jpeg\n" + "Radiance RGBE (hdr) | *.hdr\n" + "Khronos Texture (ktx) | *.ktx\n" + "Portable Graymap/Pixmap Format (pgm, ppm) | *.pgm *.ppm\n" + "Portable Network Graphics (png) | *.png\n" + "Photoshop Document (psd) | *.psd\n" + "PowerVR (pvr) | *.pvr\n" + "Truevision TGA (tga) | *.tga\n" + ; + +#if BX_PLATFORM_WINDOWS + +extern "C" void* __stdcall GetModuleHandleA(const char* _moduleName); +extern "C" uint32_t __stdcall GetModuleFileNameA(void* _module, char* _outFilePath, uint32_t _size); + +#endif // BX_PLATFORM_WINDOWS + +struct RendererTypeRemap +{ + bx::StringView name; + bgfx::RendererType::Enum type; +}; + +static RendererTypeRemap s_rendererTypeRemap[] = +{ + { "gl", bgfx::RendererType::OpenGL }, + { "d3d11", bgfx::RendererType::Direct3D11 }, + { "d3d11", bgfx::RendererType::Direct3D12 }, + { "vk", bgfx::RendererType::Vulkan }, + { "mtl", bgfx::RendererType::Metal }, +}; + struct View { View() - : m_cubeMapGeo(Geometry::Quad) + : m_rendererType(bgfx::RendererType::Count) + , m_cubeMapGeo(Geometry::Quad) + , m_outputFormat(Output::sRGB) , m_fileIndex(0) , m_scaleFn(0) , m_mip(0) @@ -586,6 +637,46 @@ struct View m_cubeMapGeo = Geometry::Enum( (m_cubeMapGeo + 1) % Geometry::Count); } } + else if (0 == bx::strCmp(_argv[1], "output") ) + { + Output::Enum outputPrev = m_outputFormat; + if (_argc >= 3) + { + if (0 == bx::strCmp(_argv[2], "srgb") ) + { + m_outputFormat = Output::sRGB; + } + else if (0 == bx::strCmp(_argv[2], "scrgb") ) + { + m_outputFormat = Output::scRGB; + } + else if (0 == bx::strCmp(_argv[2], "hdr10") ) + { + m_outputFormat = Output::HDR10; + } + } + else + { + m_outputFormat = Output::Enum( (m_outputFormat + 1) % Output::Count); + } + + if (outputPrev != m_outputFormat) + { + bgfx::TextureFormat::Enum format = bgfx::TextureFormat::RGBA8; + uint32_t formatFlag = 0; + if (Output::scRGB == m_outputFormat) + { + format = bgfx::TextureFormat::RGBA16F; + } + else if (Output::HDR10 == m_outputFormat) + { + format = bgfx::TextureFormat::RGB10A2; + formatFlag = BGFX_RESET_HDR10; + } + + bgfx::reset(m_width, m_height, BGFX_RESET_VSYNC | formatFlag, format); + } + } else if (0 == bx::strCmp(_argv[1], "help") ) { m_help ^= true; @@ -618,68 +709,84 @@ struct View void updateFileList(const bx::FilePath& _filePath) { - DIR* dir = opendir(_filePath.get() ); + bx::DirectoryReader dr; - if (NULL == dir) + if (bx::open(&dr, _filePath) ) + { + m_path = _filePath; + } + else if (bx::open(&dr, _filePath.getPath() ) ) { m_path = _filePath.getPath(); - dir = opendir(m_path.get() ); } else { - m_path = _filePath; + DBG("File path `%s` not found.", _filePath.getCPtr() ); + return; } - if (NULL != dir) + bx::Error err; + + m_fileList.clear(); + + while (err.isOk() ) { - for (dirent* item = readdir(dir); NULL != item; item = readdir(dir) ) + bx::FileInfo fi; + bx::read(&dr, fi, &err); + + if (err.isOk() + && bx::FileType::File == fi.type) { - if (0 == (item->d_type & DT_DIR) ) + bx::StringView ext = fi.filePath.getExt(); + + if (!ext.isEmpty() ) { - const bx::StringView fileName(item->d_name); - bx::StringView ext = bx::strRFind(fileName, '.'); - if (!ext.isEmpty() ) + ext.set(ext.getPtr()+1, ext.getTerm() ); + + bool supported = false; + for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii) { - ext.set(ext.getPtr()+1, fileName.getTerm() ); - bool supported = false; - for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii) - { - if (0 == bx::strCmpI(ext, s_supportedExt[ii]) ) - { - supported = true; - break; - } - } + const bx::StringView supportedExt(s_supportedExt[ii]); - if (supported) + if (0 == bx::strCmpI(bx::max(ext.getPtr(), ext.getTerm() - supportedExt.getLength() ), supportedExt) ) { - m_fileList.push_back(item->d_name); + supported = true; + break; } } + + if (supported) + { + const bx::StringView fileName = fi.filePath.getFileName(); + m_fileList.push_back(std::string(fileName.getPtr(), fileName.getTerm() ) ); + } } } + } + + bx::close(&dr); + + std::sort(m_fileList.begin(), m_fileList.end(), sortNameAscending); - std::sort(m_fileList.begin(), m_fileList.end(), sortNameAscending); + m_fileIndex = 0; + uint32_t idx = 0; - m_fileIndex = 0; - uint32_t idx = 0; - for (FileList::const_iterator it = m_fileList.begin(); it != m_fileList.end(); ++it, ++idx) + const bx::StringView fileName = _filePath.getFileName(); + + for (FileList::const_iterator it = m_fileList.begin(); it != m_fileList.end(); ++it, ++idx) + { + if (0 == bx::strCmpI(it->c_str(), fileName) ) { - if (0 == bx::strCmpI(it->c_str(), _filePath.getFileName() ) ) - { - // If it is case-insensitive match then might be correct one, but keep - // searching. - m_fileIndex = idx; + // If it is case-insensitive match then might be correct one, but keep + // searching. + m_fileIndex = idx; - if (0 == bx::strCmp(it->c_str(), _filePath.getFileName() ) ) - { - // If it is exact match we're done. - break; - } + if (0 == bx::strCmp(it->c_str(), fileName) ) + { + // If it is exact match we're done. + break; } } - - closedir(dir); } } @@ -693,7 +800,7 @@ struct View bx::FileReader reader; if (bx::open(&reader, filePath) ) { - bx::read(&reader, settings); + bx::read(&reader, settings, bx::ErrorAssert{}); bx::close(&reader); if (!bx::fromString(&m_transitionTime, settings.get("view/transition") ) ) @@ -710,6 +817,8 @@ struct View { m_height = 720; } + + m_rendererType = getType(settings.get("view/renderer") ); } } @@ -732,10 +841,15 @@ struct View bx::toString(tmp, sizeof(tmp), m_height); settings.set("view/height", tmp); + if (m_rendererType != bgfx::RendererType::Count) + { + settings.set("view/renderer", getName(m_rendererType) ); + } + bx::FileWriter writer; if (bx::open(&writer, filePath) ) { - bx::write(&writer, settings); + bx::write(&writer, settings, bx::ErrorAssert{}); bx::close(&writer); } } @@ -746,8 +860,10 @@ struct View typedef stl::vector<std::string> FileList; FileList m_fileList; + bgfx::RendererType::Enum m_rendererType; bgfx::TextureInfo m_textureInfo; Geometry::Enum m_cubeMapGeo; + Output::Enum m_outputFormat; uint32_t m_fileIndex; uint32_t m_scaleFn; uint32_t m_mip; @@ -796,7 +912,7 @@ struct PosUvwColorVertex static void init() { - ms_decl + ms_layout .begin() .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) .add(bgfx::Attrib::TexCoord0, 3, bgfx::AttribType::Float) @@ -814,10 +930,10 @@ struct PosUvwColorVertex m_abgr = _abgr; } - static bgfx::VertexDecl ms_decl; + static bgfx::VertexLayout ms_layout; }; -bgfx::VertexDecl PosUvwColorVertex::ms_decl; +bgfx::VertexLayout PosUvwColorVertex::ms_layout; static uint32_t addQuad(uint16_t* _indices, uint16_t _idx0, uint16_t _idx1, uint16_t _idx2, uint16_t _idx3) { @@ -845,10 +961,10 @@ void setGeometry( { if (Geometry::Quad == _type) { - if (6 == bgfx::getAvailTransientVertexBuffer(6, PosUvwColorVertex::ms_decl) ) + if (6 == bgfx::getAvailTransientVertexBuffer(6, PosUvwColorVertex::ms_layout) ) { bgfx::TransientVertexBuffer vb; - bgfx::allocTransientVertexBuffer(&vb, 6, PosUvwColorVertex::ms_decl); + bgfx::allocTransientVertexBuffer(&vb, 6, PosUvwColorVertex::ms_layout); PosUvwColorVertex* vertex = (PosUvwColorVertex*)vb.data; const float widthf = float(_width); @@ -879,10 +995,10 @@ void setGeometry( { const uint32_t numVertices = 14; const uint32_t numIndices = 36; - if (checkAvailTransientBuffers(numVertices, PosUvwColorVertex::ms_decl, numIndices) ) + if (checkAvailTransientBuffers(numVertices, PosUvwColorVertex::ms_layout, numIndices) ) { bgfx::TransientVertexBuffer tvb; - bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosUvwColorVertex::ms_decl); + bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosUvwColorVertex::ms_layout); bgfx::TransientIndexBuffer tib; bgfx::allocTransientIndexBuffer(&tib, numIndices); @@ -981,7 +1097,7 @@ struct InterpolatorT { from = _value; to = _value; - duration = 0.0; + duration = 0.0f; offset = bx::getHPCounter(); } @@ -1003,7 +1119,7 @@ struct InterpolatorT const double freq = double(bx::getHPFrequency() ); int64_t now = bx::getHPCounter(); float time = (float)(double(now - offset) / freq); - float lerp = bx::clamp(time, 0.0f, duration) / duration; + float lerp = duration != 0.0f ? bx::clamp(time, 0.0f, duration) / duration : 0.0f; return lerpT(from, to, easeT(lerp) ); } @@ -1012,11 +1128,16 @@ struct InterpolatorT bool isActive() const { - const double freq = double(bx::getHPFrequency() ); - int64_t now = bx::getHPCounter(); - float time = (float)(double(now - offset) / freq); - float lerp = bx::clamp(time, 0.0f, duration) / duration; - return lerp < 1.0f; + if (0.0f < duration) + { + const double freq = double(bx::getHPFrequency() ); + int64_t now = bx::getHPCounter(); + float time = (float)(double(now - offset) / freq); + float lerp = bx::clamp(time, 0.0f, duration) / duration; + return lerp < 1.0f; + } + + return false; } }; @@ -1026,9 +1147,24 @@ typedef InterpolatorT<bx::lerp, bx::easeLinear> InterpolatorLinear; void keyBindingHelp(const char* _bindings, const char* _description) { - ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), _bindings); + ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "%s", _bindings); ImGui::SameLine(100); - ImGui::Text(_description); + ImGui::Text("%s", _description); +} + +inline std::string replaceAll(const char* _str, const char* _from, const char* _to) +{ + std::string str = _str; + size_t startPos = 0; + const size_t fromLen = bx::strLen(_from); + const size_t toLen = bx::strLen(_to); + while ( (startPos = str.find(_from, startPos) ) != std::string::npos) + { + str.replace(startPos, fromLen, _to); + startPos += toLen; + } + + return str; } void associate() @@ -1036,10 +1172,10 @@ void associate() #if BX_PLATFORM_WINDOWS std::string str; - char exec[MAX_PATH]; - GetModuleFileNameA(GetModuleHandleA(NULL), exec, MAX_PATH); + char exec[bx::kMaxFilePath]; + GetModuleFileNameA(GetModuleHandleA(NULL), exec, sizeof(exec) ); - std::string strExec = bx::replaceAll<std::string>(exec, "\\", "\\\\"); + std::string strExec = replaceAll(exec, "\\", "\\\\"); std::string value; bx::stringPrintf(value, "@=\"\\\"%s\\\" \\\"%%1\\\"\"\r\n\r\n", strExec.c_str() ); @@ -1076,7 +1212,7 @@ void associate() if (err.isOk() ) { std::string cmd; - bx::stringPrintf(cmd, "/s %s", filePath.get() ); + bx::stringPrintf(cmd, "/s %s", filePath.getCPtr() ); bx::ProcessReader reader; if (bx::open(&reader, "regedit.exe", cmd.c_str(), &err) ) @@ -1122,31 +1258,31 @@ void help(const char* _error = NULL) { if (NULL != _error) { - fprintf(stderr, "Error:\n%s\n\n", _error); + bx::printf("Error:\n%s\n\n", _error); } - fprintf(stderr - , "texturev, bgfx texture viewer tool, version %d.%d.%d.\n" - "Copyright 2011-2018 Branimir Karadzic. All rights reserved.\n" - "License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n\n" + bx::printf( + "texturev, bgfx texture viewer tool, version %d.%d.%d.\n" + "Copyright 2011-2022 Branimir Karadzic. All rights reserved.\n" + "License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE\n\n" , BGFX_TEXTUREV_VERSION_MAJOR , BGFX_TEXTUREV_VERSION_MINOR , BGFX_API_VERSION ); - fprintf(stderr - , "Usage: texturev <file path>\n" + bx::printf( + "Usage: texturev <file path>\n" "\n" "Supported input file types:\n" ); for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii) { - fprintf(stderr, " *.%s\n", s_supportedExt[ii]); + bx::printf(" *.%s\n", s_supportedExt[ii]); } - fprintf(stderr - , "\n" + bx::printf( + "\n" "Options:\n" " -h, --help Help.\n" " -v, --version Version information only.\n" @@ -1162,8 +1298,8 @@ int _main_(int _argc, char** _argv) if (cmdLine.hasArg('v', "version") ) { - fprintf(stderr - , "texturev, bgfx texture viewer tool, version %d.%d.%d.\n" + bx::printf( + "texturev, bgfx texture viewer tool, version %d.%d.%d.\n" , BGFX_TEXTUREV_VERSION_MAJOR , BGFX_TEXTUREV_VERSION_MINOR , BGFX_API_VERSION @@ -1190,13 +1326,16 @@ int _main_(int _argc, char** _argv) View view; cmdAdd("view", cmdView, &view); - entry::setWindowFlags(entry::WindowHandle{0}, ENTRY_WINDOW_FLAG_ASPECT_RATIO, false); - entry::setWindowSize(entry::WindowHandle{0}, view.m_width, view.m_height); + entry::setWindowFlags(entry::kDefaultWindowHandle, ENTRY_WINDOW_FLAG_ASPECT_RATIO, false); + entry::setWindowSize(entry::kDefaultWindowHandle, view.m_width, view.m_height); bgfx::Init init; - init.resolution.width = view.m_width; - init.resolution.width = view.m_height; - init.resolution.reset = BGFX_RESET_VSYNC; + init.type = view.m_rendererType; + init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle); + init.platformData.ndt = entry::getNativeDisplayHandle(); + init.resolution.width = view.m_width; + init.resolution.height = view.m_height; + init.resolution.reset = BGFX_RESET_VSYNC; bgfx::init(init); @@ -1215,9 +1354,10 @@ int _main_(int _argc, char** _argv) const bgfx::Caps* caps = bgfx::getCaps(); bgfx::RendererType::Enum type = caps->rendererType; - bgfx::UniformHandle s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1); + bgfx::UniformHandle s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler); bgfx::UniformHandle u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Mat4); - bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4); + bgfx::UniformHandle u_params0 = bgfx::createUniform("u_params0", bgfx::UniformType::Vec4); + bgfx::UniformHandle u_params1 = bgfx::createUniform("u_params1", bgfx::UniformType::Vec4); bgfx::ShaderHandle vsTexture = bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_texture"); bgfx::ShaderHandle fsTexture = bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture"); @@ -1381,6 +1521,20 @@ int _main_(int _argc, char** _argv) { if (ImGui::BeginMenu("File")) { + if (ImGui::MenuItem("Open File") ) + { + bx::FilePath tmp = view.m_path; + if (openFileSelectionDialog( + tmp + , FileSelectionDialogType::Open + , "texturev: Open File" + , s_filter + ) ) + { + view.updateFileList(tmp); + } + } + if (ImGui::MenuItem("Show File List", NULL, view.m_files) ) { cmdExec("view files"); @@ -1440,6 +1594,31 @@ int _main_(int _argc, char** _argv) ImGui::EndMenu(); } + if (ImGui::BeginMenu("Output") ) + { + const bool hdrCap = (bgfx::getCaps()->supported & BGFX_CAPS_HDR10); + + if (ImGui::MenuItem("sRGB", NULL, Output::sRGB == view.m_outputFormat) ) + { + cmdExec("view output srgb"); + } + + if (hdrCap) + { + if (ImGui::MenuItem("scRGB", NULL, Output::scRGB == view.m_outputFormat) ) + { + cmdExec("view output scrgb"); + } + + if (ImGui::MenuItem("HDR10", NULL, Output::HDR10 == view.m_outputFormat) ) + { + cmdExec("view output hdr10"); + } + } + + ImGui::EndMenu(); + } + bool sdf = view.m_sdf; if (ImGui::MenuItem("SDF", NULL, &sdf) ) { @@ -1501,6 +1680,7 @@ int _main_(int _argc, char** _argv) ImGui::Separator(); ImGui::TextColored( ImVec4(0.0f, 1.0f, 1.0f, 1.0f) + , "%s" , view.m_fileList[view.m_fileIndex].c_str() ); @@ -1675,7 +1855,7 @@ int _main_(int _argc, char** _argv) if (view.m_files) { char temp[bx::kMaxFilePath]; - bx::snprintf(temp, BX_COUNTOF(temp), "%s##File", view.m_path.get() ); + bx::snprintf(temp, BX_COUNTOF(temp), "%s##File", view.m_path.getCPtr() ); ImGui::SetNextWindowSize( ImVec2(400.0f, 400.0f) @@ -1694,12 +1874,15 @@ int _main_(int _argc, char** _argv) ; ImGui::PushItemWidth(-1); - if (ImGui::ListBoxHeader("##empty", ImVec2(0.0f, listHeight) ) ) + if (ImGui::BeginListBox("##empty", ImVec2(0.0f, listHeight) ) ) { const int32_t itemCount = int32_t(view.m_fileList.size() ); - int32_t start, end; - ImGui::CalcListClipping(itemCount, itemHeight, &start, &end); + ImGuiListClipper clipper; + clipper.Begin(itemCount, itemHeight); + + int32_t start = clipper.DisplayStart; + int32_t end = clipper.DisplayEnd; const int32_t index = int32_t(view.m_fileIndex); if (index <= start) @@ -1711,24 +1894,25 @@ int _main_(int _argc, char** _argv) ImGui::SetScrollY(ImGui::GetScrollY() + (index-end+1)*itemHeight); } - ImGuiListClipper clipper(itemCount, itemHeight); - - for (int32_t pos = clipper.DisplayStart; pos < clipper.DisplayEnd; ++pos) + while (clipper.Step() ) { - ImGui::PushID(pos); - - bool isSelected = uint32_t(pos) == view.m_fileIndex; - if (ImGui::Selectable(view.m_fileList[pos].c_str(), &isSelected) ) + for (int32_t pos = clipper.DisplayStart; pos < clipper.DisplayEnd; ++pos) { - view.m_fileIndex = pos; - } + ImGui::PushID(pos); + + bool isSelected = uint32_t(pos) == view.m_fileIndex; + if (ImGui::Selectable(view.m_fileList[pos].c_str(), &isSelected) ) + { + view.m_fileIndex = pos; + } - ImGui::PopID(); + ImGui::PopID(); + } } clipper.End(); - ImGui::ListBoxFooter(); + ImGui::EndListBox(); } ImGui::PopFont(); @@ -1745,8 +1929,8 @@ int _main_(int _argc, char** _argv) ImGui::Text( "texturev, bgfx texture viewer tool " ICON_KI_WRENCH ", version %d.%d.%d.\n" - "Copyright 2011-2018 Branimir Karadzic. All rights reserved.\n" - "License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n" + "Copyright 2011-2022 Branimir Karadzic. All rights reserved.\n" + "License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE\n" , BGFX_TEXTUREV_VERSION_MAJOR , BGFX_TEXTUREV_VERSION_MINOR , BGFX_API_VERSION @@ -1834,7 +2018,7 @@ int _main_(int _argc, char** _argv) fp.join(view.m_fileList[view.m_fileIndex].c_str() ); bimg::Orientation::Enum orientation; - texture = loadTexture(fp.get() + texture = loadTexture(fp.getCPtr() , 0 | BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP @@ -1883,7 +2067,7 @@ int _main_(int _argc, char** _argv) } bx::stringPrintf(title, "%s (%d x %d%s, mips: %d, layers %d, %s)" - , fp.get() + , fp.getCPtr() , view.m_textureInfo.width , view.m_textureInfo.height , name @@ -1897,8 +2081,7 @@ int _main_(int _argc, char** _argv) bx::stringPrintf(title, "Failed to load %s!", filePath); } - entry::WindowHandle handle = { 0 }; - entry::setWindowTitle(handle, title.c_str() ); + entry::setWindowTitle(entry::kDefaultWindowHandle, title.c_str() ); } int64_t now = bx::getHPCounter(); @@ -1974,14 +2157,11 @@ int _main_(int _argc, char** _argv) if (view.m_fit) { - float wh[3] = { float(view.m_textureInfo.width), float(view.m_textureInfo.height), 0.0f }; - float result[3]; - bx::vec3MulMtx(result, wh, orientation); - result[0] = bx::round(bx::abs(result[0]) ); - result[1] = bx::round(bx::abs(result[1]) ); - - scale.set(bx::min(float(view.m_width) / result[0] - , float(view.m_height) / result[1]) + const bx::Vec3 wh = { float(view.m_textureInfo.width), float(view.m_textureInfo.height), 0.0f }; + const bx::Vec3 result = bx::round(bx::abs(bx::mul(wh, orientation) ) ); + + scale.set(bx::min(float(view.m_width) / result.x + , float(view.m_height) / result.y) , 0.1f*view.m_transitionTime ); } @@ -2023,7 +2203,10 @@ int _main_(int _argc, char** _argv) params[1] = layer.getValue()/float(bx::max(1, view.m_textureInfo.depth >> view.m_mip) ); } - bgfx::setUniform(u_params, params); + bgfx::setUniform(u_params0, params); + + float params1[4] = { float(view.m_outputFormat), 80.0f, 0.0, 0.0f }; + bgfx::setUniform(u_params1, params1); const uint32_t textureFlags = 0 | BGFX_SAMPLER_U_CLAMP @@ -2103,7 +2286,8 @@ int _main_(int _argc, char** _argv) bgfx::destroy(checkerBoard); bgfx::destroy(s_texColor); bgfx::destroy(u_mtx); - bgfx::destroy(u_params); + bgfx::destroy(u_params0); + bgfx::destroy(u_params1); bgfx::destroy(textureProgram); bgfx::destroy(textureArrayProgram); bgfx::destroy(textureCubeProgram); |