2016-04-22 08:12:35 +03:00
|
|
|
/*
|
2017-01-01 11:18:41 +03:00
|
|
|
* Copyright 2011-2017 Branimir Karadzic. All rights reserved.
|
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
2016-04-22 08:12:35 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include <bgfx/bgfx.h>
|
2016-05-06 02:22:48 +03:00
|
|
|
#include <bx/commandline.h>
|
2016-04-22 08:12:35 +03:00
|
|
|
#include <bx/os.h>
|
2017-07-14 10:10:33 +03:00
|
|
|
#include <bx/filepath.h>
|
2016-04-22 08:12:35 +03:00
|
|
|
#include <bx/uint32_t.h>
|
2017-07-16 07:01:08 +03:00
|
|
|
#include <bx/math.h>
|
2017-06-03 23:18:12 +03:00
|
|
|
#include <bx/easing.h>
|
2016-04-22 08:12:35 +03:00
|
|
|
#include <entry/entry.h>
|
|
|
|
#include <entry/input.h>
|
|
|
|
#include <entry/cmd.h>
|
2016-04-24 18:49:49 +03:00
|
|
|
#include <imgui/imgui.h>
|
2016-04-22 08:12:35 +03:00
|
|
|
#include <bgfx_utils.h>
|
|
|
|
|
2016-04-23 21:07:20 +03:00
|
|
|
#include <dirent.h>
|
|
|
|
|
2017-07-16 07:01:08 +03:00
|
|
|
#include <bx/file.h>
|
|
|
|
#include <bx/process.h>
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2016-04-23 21:07:20 +03:00
|
|
|
#include <tinystl/allocator.h>
|
|
|
|
#include <tinystl/vector.h>
|
|
|
|
#include <string>
|
|
|
|
namespace stl = tinystl;
|
|
|
|
|
2017-04-04 08:42:27 +03:00
|
|
|
#include <bimg/decode.h>
|
2016-04-23 22:25:05 +03:00
|
|
|
|
2016-12-06 07:59:32 +03:00
|
|
|
#include <bgfx/embedded_shader.h>
|
|
|
|
|
|
|
|
#include "vs_texture.bin.h"
|
2017-06-20 23:31:22 +03:00
|
|
|
#include "vs_texture_cube.bin.h"
|
|
|
|
|
2016-12-06 07:59:32 +03:00
|
|
|
#include "fs_texture.bin.h"
|
|
|
|
#include "fs_texture_array.bin.h"
|
|
|
|
#include "fs_texture_cube.bin.h"
|
2017-07-09 21:47:13 +03:00
|
|
|
#include "fs_texture_cube2.bin.h"
|
2016-12-27 21:11:33 +03:00
|
|
|
#include "fs_texture_sdf.bin.h"
|
2017-06-20 23:31:22 +03:00
|
|
|
#include "fs_texture_3d.bin.h"
|
2016-12-06 07:59:32 +03:00
|
|
|
|
2017-05-30 02:18:30 +03:00
|
|
|
#define BACKGROUND_VIEW_ID 0
|
|
|
|
#define IMAGE_VIEW_ID 1
|
|
|
|
|
2017-05-11 06:55:31 +03:00
|
|
|
#define BGFX_TEXTUREV_VERSION_MAJOR 1
|
|
|
|
#define BGFX_TEXTUREV_VERSION_MINOR 0
|
|
|
|
|
2016-12-06 07:59:32 +03:00
|
|
|
static const bgfx::EmbeddedShader s_embeddedShaders[] =
|
|
|
|
{
|
|
|
|
BGFX_EMBEDDED_SHADER(vs_texture),
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_texture),
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_texture_array),
|
|
|
|
BGFX_EMBEDDED_SHADER(vs_texture_cube),
|
|
|
|
BGFX_EMBEDDED_SHADER(fs_texture_cube),
|
2017-07-09 21:47:13 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(fs_texture_cube2),
|
2016-12-27 21:11:33 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(fs_texture_sdf),
|
2017-06-20 23:31:22 +03:00
|
|
|
BGFX_EMBEDDED_SHADER(fs_texture_3d),
|
2016-12-06 07:59:32 +03:00
|
|
|
|
|
|
|
BGFX_EMBEDDED_SHADER_END()
|
|
|
|
};
|
|
|
|
|
2016-05-06 02:22:48 +03:00
|
|
|
static const char* s_supportedExt[] =
|
|
|
|
{
|
2016-06-17 08:10:33 +03:00
|
|
|
"bmp",
|
2016-05-06 02:22:48 +03:00
|
|
|
"dds",
|
2016-12-19 04:02:20 +03:00
|
|
|
"exr",
|
2016-12-19 07:50:15 +03:00
|
|
|
"gif",
|
2016-05-06 02:22:48 +03:00
|
|
|
"jpg",
|
|
|
|
"jpeg",
|
|
|
|
"hdr",
|
|
|
|
"ktx",
|
|
|
|
"png",
|
2016-06-18 05:19:51 +03:00
|
|
|
"psd",
|
2016-05-06 02:22:48 +03:00
|
|
|
"pvr",
|
|
|
|
"tga",
|
|
|
|
};
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
struct Binding
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
App,
|
|
|
|
View,
|
2017-07-11 07:42:50 +03:00
|
|
|
Help,
|
2016-04-22 08:12:35 +03:00
|
|
|
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
struct Geometry
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Quad,
|
|
|
|
Cross,
|
|
|
|
Hexagon,
|
|
|
|
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
static const InputBinding s_bindingApp[] =
|
|
|
|
{
|
2017-05-27 19:40:25 +03:00
|
|
|
{ entry::Key::KeyQ, entry::Modifier::None, 1, NULL, "exit" },
|
2016-04-24 18:49:49 +03:00
|
|
|
{ entry::Key::KeyF, entry::Modifier::None, 1, NULL, "graphics fullscreen" },
|
2016-04-22 08:12:35 +03:00
|
|
|
|
|
|
|
INPUT_BINDING_END
|
|
|
|
};
|
|
|
|
|
2017-07-10 03:11:59 +03:00
|
|
|
const char* s_resetCmd =
|
|
|
|
"view zoom 1.0\n"
|
|
|
|
"view rotate 0\n"
|
|
|
|
"view cubemap\n"
|
|
|
|
"view pan\n"
|
|
|
|
;
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
static const InputBinding s_bindingView[] =
|
|
|
|
{
|
2017-07-11 07:42:50 +03:00
|
|
|
{ entry::Key::Esc, entry::Modifier::None, 1, NULL, "exit" },
|
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
{ entry::Key::Comma, entry::Modifier::None, 1, NULL, "view mip prev" },
|
|
|
|
{ entry::Key::Period, entry::Modifier::None, 1, NULL, "view mip next" },
|
|
|
|
{ entry::Key::Comma, entry::Modifier::LeftShift, 1, NULL, "view mip" },
|
|
|
|
{ entry::Key::Comma, entry::Modifier::RightShift, 1, NULL, "view mip" },
|
2016-04-23 21:07:20 +03:00
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
{ entry::Key::Slash, entry::Modifier::None, 1, NULL, "view filter" },
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-06-10 05:40:20 +03:00
|
|
|
{ entry::Key::Key1, entry::Modifier::None, 1, NULL, "view zoom 1.0\n"
|
|
|
|
"view fit\n" },
|
|
|
|
|
2017-07-10 03:11:59 +03:00
|
|
|
{ entry::Key::Key0, entry::Modifier::None, 1, NULL, s_resetCmd },
|
2017-05-26 01:12:07 +03:00
|
|
|
{ entry::Key::Plus, entry::Modifier::None, 1, NULL, "view zoom +0.1" },
|
|
|
|
{ entry::Key::Minus, entry::Modifier::None, 1, NULL, "view zoom -0.1" },
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-06-03 23:18:12 +03:00
|
|
|
{ entry::Key::KeyZ, entry::Modifier::None, 1, NULL, "view rotate -90" },
|
|
|
|
{ entry::Key::KeyZ, entry::Modifier::LeftShift, 1, NULL, "view rotate +90" },
|
|
|
|
|
2017-07-06 08:36:08 +03:00
|
|
|
{ entry::Key::Up, entry::Modifier::None, 1, NULL, "view pan\n"
|
|
|
|
"view file-up" },
|
|
|
|
{ entry::Key::Down, entry::Modifier::None, 1, NULL, "view pan\n"
|
|
|
|
"view file-down" },
|
|
|
|
{ entry::Key::PageUp, entry::Modifier::None, 1, NULL, "view pan\n"
|
|
|
|
"view file-pgup" },
|
|
|
|
{ entry::Key::PageDown, entry::Modifier::None, 1, NULL, "view pan\n"
|
|
|
|
"view file-pgdown" },
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
{ entry::Key::Left, entry::Modifier::None, 1, NULL, "view layer prev" },
|
|
|
|
{ entry::Key::Right, entry::Modifier::None, 1, NULL, "view layer next" },
|
2016-08-24 08:06:50 +03:00
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
{ entry::Key::KeyR, entry::Modifier::None, 1, NULL, "view rgb r" },
|
|
|
|
{ entry::Key::KeyG, entry::Modifier::None, 1, NULL, "view rgb g" },
|
|
|
|
{ entry::Key::KeyB, entry::Modifier::None, 1, NULL, "view rgb b" },
|
|
|
|
{ entry::Key::KeyA, entry::Modifier::None, 1, NULL, "view rgb a" },
|
2016-05-18 19:10:02 +03:00
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
{ entry::Key::KeyH, entry::Modifier::None, 1, NULL, "view help" },
|
2016-04-24 18:49:49 +03:00
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
{ entry::Key::KeyS, entry::Modifier::None, 1, NULL, "view sdf" },
|
2016-12-27 21:11:33 +03:00
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
{ entry::Key::Space, entry::Modifier::None, 1, NULL, "view geo\n"
|
|
|
|
"view pan\n" },
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
INPUT_BINDING_END
|
|
|
|
};
|
|
|
|
|
2017-07-11 07:42:50 +03:00
|
|
|
static const InputBinding s_bindingHelp[] =
|
|
|
|
{
|
|
|
|
{ entry::Key::Esc, entry::Modifier::None, 1, NULL, "view help" },
|
|
|
|
{ entry::Key::KeyH, entry::Modifier::None, 1, NULL, "view help" },
|
|
|
|
INPUT_BINDING_END
|
|
|
|
};
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
static const char* s_bindingName[] =
|
|
|
|
{
|
|
|
|
"App",
|
|
|
|
"View",
|
2017-07-11 07:42:50 +03:00
|
|
|
"Help",
|
2016-04-22 08:12:35 +03:00
|
|
|
};
|
|
|
|
BX_STATIC_ASSERT(Binding::Count == BX_COUNTOF(s_bindingName) );
|
|
|
|
|
|
|
|
static const InputBinding* s_binding[] =
|
|
|
|
{
|
|
|
|
s_bindingApp,
|
|
|
|
s_bindingView,
|
2017-07-11 07:42:50 +03:00
|
|
|
s_bindingHelp,
|
2016-04-22 08:12:35 +03:00
|
|
|
};
|
|
|
|
BX_STATIC_ASSERT(Binding::Count == BX_COUNTOF(s_binding) );
|
|
|
|
|
|
|
|
struct View
|
|
|
|
{
|
|
|
|
View()
|
2017-07-09 21:47:13 +03:00
|
|
|
: m_cubeMapGeo(Geometry::Quad)
|
|
|
|
, m_fileIndex(0)
|
2016-04-23 21:07:20 +03:00
|
|
|
, m_scaleFn(0)
|
2016-04-22 08:12:35 +03:00
|
|
|
, m_mip(0)
|
2016-08-24 08:06:50 +03:00
|
|
|
, m_layer(0)
|
2016-05-18 19:10:02 +03:00
|
|
|
, m_abgr(UINT32_MAX)
|
2017-05-26 01:12:07 +03:00
|
|
|
, m_posx(0.0f)
|
|
|
|
, m_posy(0.0f)
|
2017-07-06 08:36:08 +03:00
|
|
|
, m_angx(0.0f)
|
|
|
|
, m_angy(0.0f)
|
2016-04-22 08:12:35 +03:00
|
|
|
, m_zoom(1.0f)
|
2017-06-03 23:18:12 +03:00
|
|
|
, m_angle(0.0f)
|
2016-04-22 08:12:35 +03:00
|
|
|
, m_filter(true)
|
2017-06-10 05:40:20 +03:00
|
|
|
, m_fit(true)
|
2016-05-18 19:10:02 +03:00
|
|
|
, m_alpha(false)
|
2016-04-24 18:49:49 +03:00
|
|
|
, m_help(false)
|
2016-12-27 21:11:33 +03:00
|
|
|
, m_sdf(false)
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~View()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
int32_t cmd(int32_t _argc, char const* const* _argv)
|
|
|
|
{
|
|
|
|
if (_argc >= 2)
|
|
|
|
{
|
2017-05-26 01:12:07 +03:00
|
|
|
if (0 == bx::strCmp(_argv[1], "mip") )
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
|
|
|
uint32_t mip = m_mip;
|
2017-05-26 01:12:07 +03:00
|
|
|
if (0 == bx::strCmp(_argv[2], "next") )
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
++mip;
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[2], "prev") )
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
--mip;
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[2], "last") )
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
mip = INT32_MAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mip = atoi(_argv[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mip = bx::uint32_iclamp(mip, 0, m_info.numMips-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_mip = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
if (0 == bx::strCmp(_argv[1], "layer") )
|
2016-08-24 08:06:50 +03:00
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
|
|
|
uint32_t layer = m_layer;
|
2017-05-26 01:12:07 +03:00
|
|
|
if (0 == bx::strCmp(_argv[2], "next") )
|
2016-08-24 08:06:50 +03:00
|
|
|
{
|
|
|
|
++layer;
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[2], "prev") )
|
2016-08-24 08:06:50 +03:00
|
|
|
{
|
|
|
|
--layer;
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[2], "last") )
|
2016-08-24 08:06:50 +03:00
|
|
|
{
|
|
|
|
layer = INT32_MAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
layer = atoi(_argv[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_layer = bx::uint32_iclamp(layer, 0, m_info.numLayers-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_layer = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "pan") )
|
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
|
|
|
if (_argc >= 4)
|
|
|
|
{
|
2017-06-18 03:03:02 +03:00
|
|
|
float yy;
|
|
|
|
bx::fromString(&yy, _argv[3]);
|
2017-05-26 01:12:07 +03:00
|
|
|
if (_argv[3][0] == '+'
|
|
|
|
|| _argv[3][0] == '-')
|
|
|
|
{
|
|
|
|
m_posy += yy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_posy = yy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-18 03:03:02 +03:00
|
|
|
float xx;
|
|
|
|
bx::fromString(&xx, _argv[2]);
|
2017-05-26 01:12:07 +03:00
|
|
|
if (_argv[2][0] == '+'
|
|
|
|
|| _argv[2][0] == '-')
|
|
|
|
{
|
|
|
|
m_posx += xx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_posx = xx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_posx = 0.0f;
|
|
|
|
m_posy = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 08:36:08 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "cubemap") )
|
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
|
|
|
if (_argc >= 4)
|
|
|
|
{
|
|
|
|
float yy;
|
|
|
|
bx::fromString(&yy, _argv[3]);
|
|
|
|
if (_argv[3][0] == '+'
|
|
|
|
|| _argv[3][0] == '-')
|
|
|
|
{
|
|
|
|
m_angy += bx::toRad(yy);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_angy = bx::toRad(yy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float xx;
|
|
|
|
bx::fromString(&xx, _argv[2]);
|
|
|
|
if (_argv[2][0] == '+'
|
|
|
|
|| _argv[2][0] == '-')
|
|
|
|
{
|
|
|
|
m_angx += bx::toRad(xx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_angx = bx::toRad(xx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_angx = 0.0f;
|
|
|
|
m_angy = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "zoom") )
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
2017-06-18 03:03:02 +03:00
|
|
|
float zoom;
|
|
|
|
bx::fromString(&zoom, _argv[2]);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
|
|
|
if (_argv[2][0] == '+'
|
|
|
|
|| _argv[2][0] == '-')
|
|
|
|
{
|
|
|
|
m_zoom += zoom;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_zoom = zoom;
|
|
|
|
}
|
|
|
|
|
2017-05-25 07:12:30 +03:00
|
|
|
m_zoom = bx::fclamp(m_zoom, 0.01f, 10.0f);
|
2016-04-22 08:12:35 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_zoom = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
2017-06-03 23:18:12 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "rotate") )
|
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
2017-06-18 03:03:02 +03:00
|
|
|
float angle;
|
|
|
|
bx::fromString(&angle, _argv[2]);
|
2017-06-03 23:18:12 +03:00
|
|
|
|
|
|
|
if (_argv[2][0] == '+'
|
|
|
|
|| _argv[2][0] == '-')
|
|
|
|
{
|
|
|
|
m_angle += bx::toRad(angle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_angle = bx::toRad(angle);
|
|
|
|
}
|
|
|
|
|
2017-06-10 06:08:52 +03:00
|
|
|
m_angle = bx::fwrap(m_angle, bx::kPi*2.0f);
|
2017-06-03 23:18:12 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_angle = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "filter") )
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
|
|
|
m_filter = bx::toBool(_argv[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_filter ^= true;
|
|
|
|
}
|
|
|
|
}
|
2017-06-10 05:40:20 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "fit") )
|
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
|
|
|
m_fit = bx::toBool(_argv[2]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fit ^= true;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "file-up") )
|
2016-04-23 21:07:20 +03:00
|
|
|
{
|
|
|
|
m_fileIndex = bx::uint32_satsub(m_fileIndex, 1);
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "file-down") )
|
2016-04-23 21:07:20 +03:00
|
|
|
{
|
|
|
|
uint32_t numFiles = bx::uint32_satsub(uint32_t(m_fileList.size() ), 1);
|
|
|
|
++m_fileIndex;
|
|
|
|
m_fileIndex = bx::uint32_min(m_fileIndex, numFiles);
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "rgb") )
|
2016-05-18 19:10:02 +03:00
|
|
|
{
|
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
|
|
|
if (_argv[2][0] == 'r')
|
|
|
|
{
|
|
|
|
m_abgr ^= 0x000000ff;
|
|
|
|
}
|
|
|
|
else if (_argv[2][0] == 'g')
|
|
|
|
{
|
|
|
|
m_abgr ^= 0x0000ff00;
|
|
|
|
}
|
|
|
|
else if (_argv[2][0] == 'b')
|
|
|
|
{
|
|
|
|
m_abgr ^= 0x00ff0000;
|
|
|
|
}
|
|
|
|
else if (_argv[2][0] == 'a')
|
|
|
|
{
|
|
|
|
m_alpha ^= true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_abgr = UINT32_MAX;
|
|
|
|
m_alpha = false;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "sdf") )
|
2016-12-27 21:11:33 +03:00
|
|
|
{
|
|
|
|
m_sdf ^= true;
|
|
|
|
}
|
2017-07-09 21:47:13 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "geo") )
|
|
|
|
{
|
2017-07-10 03:11:59 +03:00
|
|
|
if (_argc >= 3)
|
|
|
|
{
|
|
|
|
if (bx::toLower(_argv[2][0]) == 'c')
|
|
|
|
{
|
|
|
|
m_cubeMapGeo = Geometry::Cross;
|
|
|
|
}
|
|
|
|
else if (bx::toLower(_argv[2][0]) == 'h')
|
|
|
|
{
|
|
|
|
m_cubeMapGeo = Geometry::Hexagon;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_cubeMapGeo = Geometry::Quad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_cubeMapGeo = Geometry::Enum( (m_cubeMapGeo + 1) % Geometry::Count);
|
|
|
|
}
|
2017-07-09 21:47:13 +03:00
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
else if (0 == bx::strCmp(_argv[1], "help") )
|
2016-04-24 18:49:49 +03:00
|
|
|
{
|
|
|
|
m_help ^= true;
|
|
|
|
}
|
2016-04-22 08:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-14 10:10:33 +03:00
|
|
|
void updateFileList(const char* _path, const bx::StringView& _fileName)
|
2016-04-23 21:07:20 +03:00
|
|
|
{
|
|
|
|
std::string path = _path;
|
|
|
|
|
|
|
|
DIR* dir = opendir(_path);
|
|
|
|
|
|
|
|
if (NULL == dir)
|
|
|
|
{
|
|
|
|
path = ".";
|
|
|
|
}
|
|
|
|
|
|
|
|
dir = opendir(path.c_str() );
|
|
|
|
if (NULL != dir)
|
|
|
|
{
|
|
|
|
for (dirent* item = readdir(dir); NULL != item; item = readdir(dir) )
|
|
|
|
{
|
|
|
|
if (0 == (item->d_type & DT_DIR) )
|
|
|
|
{
|
2017-04-23 00:47:02 +03:00
|
|
|
const char* ext = bx::strRFind(item->d_name, '.');
|
2016-04-23 21:07:20 +03:00
|
|
|
if (NULL != ext)
|
|
|
|
{
|
2016-05-06 03:24:28 +03:00
|
|
|
ext += 1;
|
2016-05-06 02:22:48 +03:00
|
|
|
bool supported = false;
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
|
|
|
|
{
|
2017-04-23 00:47:02 +03:00
|
|
|
if (0 == bx::strCmpI(ext, s_supportedExt[ii]) )
|
2016-05-06 02:22:48 +03:00
|
|
|
{
|
|
|
|
supported = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (supported)
|
2016-04-23 21:07:20 +03:00
|
|
|
{
|
2017-07-14 10:10:33 +03:00
|
|
|
if (0 == bx::strCmp(item->d_name, _fileName) )
|
2016-04-23 21:07:20 +03:00
|
|
|
{
|
|
|
|
m_fileIndex = uint32_t(m_fileList.size() );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string name = path;
|
2016-04-30 21:08:56 +03:00
|
|
|
char ch = name[name.size()-1];
|
2016-04-23 21:07:20 +03:00
|
|
|
name += '/' == ch || '\\' == ch ? "" : "/";
|
|
|
|
name += item->d_name;
|
|
|
|
m_fileList.push_back(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef stl::vector<std::string> FileList;
|
|
|
|
FileList m_fileList;
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::TextureInfo m_info;
|
2017-07-09 21:47:13 +03:00
|
|
|
Geometry::Enum m_cubeMapGeo;
|
2016-04-23 21:07:20 +03:00
|
|
|
uint32_t m_fileIndex;
|
2016-04-22 08:12:35 +03:00
|
|
|
uint32_t m_scaleFn;
|
|
|
|
uint32_t m_mip;
|
2016-08-24 08:06:50 +03:00
|
|
|
uint32_t m_layer;
|
2016-05-18 19:10:02 +03:00
|
|
|
uint32_t m_abgr;
|
2017-05-26 01:12:07 +03:00
|
|
|
float m_posx;
|
|
|
|
float m_posy;
|
2017-07-06 08:36:08 +03:00
|
|
|
float m_angx;
|
|
|
|
float m_angy;
|
2016-04-22 08:12:35 +03:00
|
|
|
float m_zoom;
|
2017-06-03 23:18:12 +03:00
|
|
|
float m_angle;
|
2016-04-22 08:12:35 +03:00
|
|
|
bool m_filter;
|
2017-06-10 05:40:20 +03:00
|
|
|
bool m_fit;
|
2016-05-18 19:10:02 +03:00
|
|
|
bool m_alpha;
|
2016-04-24 18:49:49 +03:00
|
|
|
bool m_help;
|
2016-12-27 21:11:33 +03:00
|
|
|
bool m_sdf;
|
2016-04-22 08:12:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
int cmdView(CmdContext* /*_context*/, void* _userData, int _argc, char const* const* _argv)
|
|
|
|
{
|
|
|
|
View* view = static_cast<View*>(_userData);
|
|
|
|
return view->cmd(_argc, _argv);
|
|
|
|
}
|
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
struct PosUvwColorVertex
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
float m_x;
|
|
|
|
float m_y;
|
|
|
|
float m_u;
|
|
|
|
float m_v;
|
2017-07-09 21:47:13 +03:00
|
|
|
float m_w;
|
2016-04-22 08:12:35 +03:00
|
|
|
uint32_t m_abgr;
|
|
|
|
|
|
|
|
static void init()
|
|
|
|
{
|
|
|
|
ms_decl
|
|
|
|
.begin()
|
|
|
|
.add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
|
2017-07-09 21:47:13 +03:00
|
|
|
.add(bgfx::Attrib::TexCoord0, 3, bgfx::AttribType::Float)
|
2016-04-22 08:12:35 +03:00
|
|
|
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
|
|
|
|
.end();
|
|
|
|
}
|
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
void set(float _x, float _y, float _u, float _v, float _w, uint32_t _abgr)
|
|
|
|
{
|
|
|
|
m_x = _x;
|
|
|
|
m_y = _y;
|
|
|
|
m_u = _u;
|
|
|
|
m_v = _v;
|
|
|
|
m_w = _w;
|
|
|
|
m_abgr = _abgr;
|
|
|
|
}
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
static bgfx::VertexDecl ms_decl;
|
|
|
|
};
|
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
bgfx::VertexDecl PosUvwColorVertex::ms_decl;
|
|
|
|
|
|
|
|
static uint32_t addQuad(uint16_t* _indices, uint16_t _idx0, uint16_t _idx1, uint16_t _idx2, uint16_t _idx3)
|
|
|
|
{
|
|
|
|
_indices[0] = _idx0;
|
|
|
|
_indices[1] = _idx3;
|
|
|
|
_indices[2] = _idx1;
|
|
|
|
|
|
|
|
_indices[3] = _idx1;
|
|
|
|
_indices[4] = _idx3;
|
|
|
|
_indices[5] = _idx2;
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setGeometry(
|
|
|
|
Geometry::Enum _type
|
|
|
|
, int32_t _x
|
|
|
|
, int32_t _y
|
|
|
|
, int32_t _width
|
|
|
|
, uint32_t _height
|
|
|
|
, uint32_t _abgr
|
|
|
|
, float _maxu = 1.0f
|
|
|
|
, float _maxv = 1.0f
|
|
|
|
)
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
2017-07-09 21:47:13 +03:00
|
|
|
if (Geometry::Quad == _type)
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
2017-07-09 21:47:13 +03:00
|
|
|
if (6 == bgfx::getAvailTransientVertexBuffer(6, PosUvwColorVertex::ms_decl) )
|
|
|
|
{
|
|
|
|
bgfx::TransientVertexBuffer vb;
|
|
|
|
bgfx::allocTransientVertexBuffer(&vb, 6, PosUvwColorVertex::ms_decl);
|
|
|
|
PosUvwColorVertex* vertex = (PosUvwColorVertex*)vb.data;
|
|
|
|
|
|
|
|
const float widthf = float(_width);
|
|
|
|
const float heightf = float(_height);
|
|
|
|
|
|
|
|
const float minx = float(_x);
|
|
|
|
const float miny = float(_y);
|
|
|
|
const float maxx = minx+widthf;
|
|
|
|
const float maxy = miny+heightf;
|
|
|
|
|
|
|
|
const float minu = 0.0f;
|
|
|
|
const float maxu = _maxu;
|
|
|
|
const float minv = 0.0f;
|
|
|
|
const float maxv = _maxv;
|
|
|
|
|
|
|
|
vertex->set(minx, miny, minu, minv, 0.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(maxx, miny, maxu, minv, 0.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(maxx, maxy, maxu, maxv, 0.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(maxx, maxy, maxu, maxv, 0.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(minx, maxy, minu, maxv, 0.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(minx, miny, minu, minv, 0.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
bgfx::setVertexBuffer(0, &vb);
|
|
|
|
}
|
2016-04-22 08:12:35 +03:00
|
|
|
}
|
2017-07-09 21:47:13 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const uint32_t numVertices = 14;
|
|
|
|
const uint32_t numIndices = 36;
|
|
|
|
if (checkAvailTransientBuffers(numVertices, PosUvwColorVertex::ms_decl, numIndices) )
|
|
|
|
{
|
|
|
|
bgfx::TransientVertexBuffer tvb;
|
|
|
|
bgfx::allocTransientVertexBuffer(&tvb, numVertices, PosUvwColorVertex::ms_decl);
|
|
|
|
|
|
|
|
bgfx::TransientIndexBuffer tib;
|
|
|
|
bgfx::allocTransientIndexBuffer(&tib, numIndices);
|
|
|
|
|
|
|
|
PosUvwColorVertex* vertex = (PosUvwColorVertex*)tvb.data;
|
|
|
|
uint16_t* indices = (uint16_t*)tib.data;
|
|
|
|
|
|
|
|
if (Geometry::Cross == _type)
|
|
|
|
{
|
|
|
|
const float sx = _width /1.5f;
|
|
|
|
const float sy = _height/1.5f;
|
|
|
|
const float px = float(_x)-sx/4.0f;
|
|
|
|
const float py = float(_y);
|
|
|
|
|
|
|
|
vertex->set(0.0f*sx+px, 0.5f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(0.0f*sx+px, 1.0f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(0.5f*sx+px, 0.0f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(0.5f*sx+px, 0.5f*sy+py, -1.0f, 1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(0.5f*sx+px, 1.0f*sy+py, -1.0f, -1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(0.5f*sx+px, 1.5f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(1.0f*sx+px, 0.0f*sy+py, 1.0f, 1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(1.0f*sx+px, 0.5f*sy+py, 1.0f, 1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(1.0f*sx+px, 1.0f*sy+py, 1.0f, -1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(1.0f*sx+px, 1.5f*sy+py, 1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(1.5f*sx+px, 0.5f*sy+py, 1.0f, 1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(1.5f*sx+px, 1.0f*sy+py, 1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(2.0f*sx+px, 0.5f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(2.0f*sx+px, 1.0f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
indices += addQuad(indices, 0, 3, 4, 1);
|
|
|
|
indices += addQuad(indices, 2, 6, 7, 3);
|
|
|
|
indices += addQuad(indices, 3, 7, 8, 4);
|
|
|
|
indices += addQuad(indices, 4, 8, 9, 5);
|
|
|
|
indices += addQuad(indices, 7, 10, 11, 8);
|
|
|
|
indices += addQuad(indices, 10, 12, 13, 11);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-15 09:38:45 +03:00
|
|
|
const float sx = float(_width);
|
|
|
|
const float sy = float(_height);
|
2017-07-09 21:47:13 +03:00
|
|
|
const float px = float(_x) - sx/2.0f;
|
|
|
|
const float py = float(_y);
|
|
|
|
|
|
|
|
vertex->set(0.0f*sx+px, 0.25f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(0.0f*sx+px, 0.75f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(0.5f*sx+px, 0.00f*sy+py, -1.0f, 1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(0.5f*sx+px, 0.50f*sy+py, -1.0f, -1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(0.5f*sx+px, 1.00f*sy+py, 1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(1.0f*sx+px, 0.25f*sy+py, 1.0f, 1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(1.0f*sx+px, 0.75f*sy+py, 1.0f, -1.0f, 1.0f, _abgr); ++vertex;
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
vertex->set(1.0f*sx+px, 0.25f*sy+py, 1.0f, 1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(1.0f*sx+px, 0.75f*sy+py, 1.0f, -1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(1.5f*sx+px, 0.00f*sy+py, -1.0f, 1.0f, 1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(1.5f*sx+px, 0.50f*sy+py, 1.0f, 1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(1.5f*sx+px, 1.00f*sy+py, 1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
vertex->set(2.0f*sx+px, 0.25f*sy+py, -1.0f, 1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
vertex->set(2.0f*sx+px, 0.75f*sy+py, -1.0f, -1.0f, -1.0f, _abgr); ++vertex;
|
|
|
|
|
|
|
|
indices += addQuad(indices, 0, 2, 3, 1);
|
|
|
|
indices += addQuad(indices, 1, 3, 6, 4);
|
|
|
|
indices += addQuad(indices, 2, 5, 6, 3);
|
|
|
|
indices += addQuad(indices, 7, 9, 12, 10);
|
|
|
|
indices += addQuad(indices, 7, 10, 11, 8);
|
|
|
|
indices += addQuad(indices, 10, 12, 13, 11);
|
|
|
|
}
|
|
|
|
|
|
|
|
bgfx::setVertexBuffer(0, &tvb);
|
|
|
|
bgfx::setIndexBuffer(&tib);
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 08:12:35 +03:00
|
|
|
}
|
|
|
|
|
2017-06-03 23:18:12 +03:00
|
|
|
template<bx::LerpFn lerpT, bx::EaseFn easeT>
|
|
|
|
struct InterpolatorT
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
float from;
|
|
|
|
float to;
|
|
|
|
float duration;
|
|
|
|
int64_t offset;
|
|
|
|
|
2017-06-03 23:18:12 +03:00
|
|
|
InterpolatorT(float _value)
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
|
|
|
reset(_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset(float _value)
|
|
|
|
{
|
|
|
|
from = _value;
|
|
|
|
to = _value;
|
|
|
|
duration = 0.0;
|
|
|
|
offset = bx::getHPCounter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set(float _value, float _duration)
|
|
|
|
{
|
|
|
|
if (_value != to)
|
|
|
|
{
|
|
|
|
from = getValue();
|
|
|
|
to = _value;
|
|
|
|
duration = _duration;
|
|
|
|
offset = bx::getHPCounter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float getValue()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (duration > 0.0)
|
|
|
|
{
|
|
|
|
const double freq = double(bx::getHPFrequency() );
|
|
|
|
int64_t now = bx::getHPCounter();
|
|
|
|
float time = (float)(double(now - offset) / freq);
|
|
|
|
float lerp = bx::fclamp(time, 0.0, duration) / duration;
|
2017-06-03 23:18:12 +03:00
|
|
|
return lerpT(from, to, easeT(lerp) );
|
2016-04-22 08:12:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-03 23:18:12 +03:00
|
|
|
typedef InterpolatorT<bx::flerp, bx::easeInOutQuad> Interpolator;
|
|
|
|
typedef InterpolatorT<bx::angleLerp, bx::easeInOutCubic> InterpolatorAngle;
|
|
|
|
|
2017-06-04 01:38:03 +03:00
|
|
|
void keyBindingHelp(const char* _bindings, const char* _description)
|
|
|
|
{
|
|
|
|
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), _bindings);
|
|
|
|
ImGui::SameLine(100);
|
|
|
|
ImGui::Text(_description);
|
|
|
|
}
|
|
|
|
|
2016-05-06 02:22:48 +03:00
|
|
|
void associate()
|
|
|
|
{
|
|
|
|
#if BX_PLATFORM_WINDOWS
|
|
|
|
std::string str;
|
|
|
|
|
|
|
|
char exec[MAX_PATH];
|
|
|
|
GetModuleFileNameA(GetModuleHandleA(NULL), exec, MAX_PATH);
|
|
|
|
|
2016-05-06 20:55:41 +03:00
|
|
|
std::string strExec = bx::replaceAll<std::string>(exec, "\\", "\\\\");
|
2016-05-06 03:24:28 +03:00
|
|
|
|
2016-05-06 02:22:48 +03:00
|
|
|
std::string value;
|
2016-05-06 06:18:20 +03:00
|
|
|
bx::stringPrintf(value, "@=\"\\\"%s\\\" \\\"%%1\\\"\"\r\n\r\n", strExec.c_str() );
|
2016-05-06 02:22:48 +03:00
|
|
|
|
2016-05-06 03:24:28 +03:00
|
|
|
str += "Windows Registry Editor Version 5.00\r\n\r\n";
|
2016-05-06 02:22:48 +03:00
|
|
|
|
2016-05-06 03:24:28 +03:00
|
|
|
str += "[HKEY_CLASSES_ROOT\\texturev\\shell\\open\\command]\r\n";
|
2016-05-06 02:22:48 +03:00
|
|
|
str += value;
|
|
|
|
|
2016-05-06 03:24:28 +03:00
|
|
|
str += "[HKEY_CLASSES_ROOT\\Applications\\texturev.exe\\shell\\open\\command]\r\n";
|
2016-05-06 02:22:48 +03:00
|
|
|
str += value;
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
|
|
|
|
{
|
|
|
|
const char* ext = s_supportedExt[ii];
|
2016-05-06 06:18:20 +03:00
|
|
|
|
|
|
|
bx::stringPrintf(str, "[-HKEY_CLASSES_ROOT\\.%s]\r\n\r\n", ext);
|
|
|
|
bx::stringPrintf(str, "[-HKEY_CURRENT_USER\\Software\\Classes\\.%s]\r\n\r\n", ext);
|
|
|
|
|
|
|
|
bx::stringPrintf(str, "[HKEY_CLASSES_ROOT\\.%s]\r\n@=\"texturev\"\r\n\r\n", ext);
|
|
|
|
bx::stringPrintf(str, "[HKEY_CURRENT_USER\\Software\\Classes\\.%s]\r\n@=\"texturev\"\r\n\r\n", ext);
|
2016-05-06 02:22:48 +03:00
|
|
|
}
|
|
|
|
|
2017-07-16 07:21:31 +03:00
|
|
|
bx::FilePath filePath(bx::TempDir::Tag);
|
|
|
|
filePath.join("texture.reg");
|
2016-05-06 02:22:48 +03:00
|
|
|
|
2017-06-12 07:01:38 +03:00
|
|
|
bx::FileWriter writer;
|
2016-05-06 02:22:48 +03:00
|
|
|
bx::Error err;
|
2017-07-16 07:21:31 +03:00
|
|
|
if (bx::open(&writer, filePath, false, &err) )
|
2016-05-06 02:22:48 +03:00
|
|
|
{
|
2016-08-24 23:16:04 +03:00
|
|
|
bx::write(&writer, str.c_str(), uint32_t(str.length()), &err);
|
2016-05-06 02:22:48 +03:00
|
|
|
bx::close(&writer);
|
|
|
|
|
|
|
|
if (err.isOk() )
|
|
|
|
{
|
|
|
|
std::string cmd;
|
2017-07-16 07:21:31 +03:00
|
|
|
bx::stringPrintf(cmd, "/s %s", filePath.get() );
|
2016-05-06 02:22:48 +03:00
|
|
|
|
|
|
|
bx::ProcessReader reader;
|
2017-07-15 09:38:45 +03:00
|
|
|
if (bx::open(&reader, "regedit.exe", cmd.c_str(), &err) )
|
2016-05-06 02:22:48 +03:00
|
|
|
{
|
|
|
|
bx::close(&reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-06 08:55:38 +03:00
|
|
|
#elif BX_PLATFORM_LINUX
|
|
|
|
std::string str;
|
|
|
|
str += "#/bin/bash\n\n";
|
|
|
|
|
|
|
|
for (uint32_t ii = 0; ii < BX_COUNTOF(s_supportedExt); ++ii)
|
|
|
|
{
|
|
|
|
const char* ext = s_supportedExt[ii];
|
|
|
|
bx::stringPrintf(str, "xdg-mime default texturev.desktop image/%s\n", ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
str += "\n";
|
|
|
|
|
2017-06-12 07:01:38 +03:00
|
|
|
bx::FileWriter writer;
|
2016-05-06 08:55:38 +03:00
|
|
|
bx::Error err;
|
|
|
|
if (bx::open(&writer, "/tmp/texturev.sh", false, &err) )
|
|
|
|
{
|
2016-08-24 23:16:04 +03:00
|
|
|
bx::write(&writer, str.c_str(), uint32_t(str.length()), &err);
|
2016-05-06 08:55:38 +03:00
|
|
|
bx::close(&writer);
|
|
|
|
|
|
|
|
if (err.isOk() )
|
|
|
|
{
|
|
|
|
bx::ProcessReader reader;
|
2017-07-15 09:06:03 +03:00
|
|
|
if (bx::open(&reader, "/bin/bash", "/tmp/texturev.sh", &err) )
|
2016-05-06 08:55:38 +03:00
|
|
|
{
|
|
|
|
bx::close(&reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-06 02:22:48 +03:00
|
|
|
#endif // BX_PLATFORM_WINDOWS
|
|
|
|
}
|
|
|
|
|
2017-05-11 06:55:31 +03:00
|
|
|
void help(const char* _error = NULL)
|
|
|
|
{
|
|
|
|
if (NULL != _error)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error:\n%s\n\n", _error);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr
|
|
|
|
, "texturev, bgfx texture viewer tool, version %d.%d.%d.\n"
|
|
|
|
"Copyright 2011-2017 Branimir Karadzic. All rights reserved.\n"
|
|
|
|
"License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n\n"
|
|
|
|
, BGFX_TEXTUREV_VERSION_MAJOR
|
|
|
|
, BGFX_TEXTUREV_VERSION_MINOR
|
|
|
|
, BGFX_API_VERSION
|
|
|
|
);
|
|
|
|
|
|
|
|
fprintf(stderr
|
|
|
|
, "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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr
|
|
|
|
, "\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -h, --help Help.\n"
|
|
|
|
" -v, --version Version information only.\n"
|
|
|
|
" --associate Associate file extensions with texturev.\n"
|
|
|
|
"\n"
|
|
|
|
"For additional information, see https://github.com/bkaradzic/bgfx\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
int _main_(int _argc, char** _argv)
|
|
|
|
{
|
2016-05-06 02:22:48 +03:00
|
|
|
bx::CommandLine cmdLine(_argc, _argv);
|
|
|
|
|
2017-05-11 06:55:31 +03:00
|
|
|
if (cmdLine.hasArg('v', "version") )
|
|
|
|
{
|
|
|
|
fprintf(stderr
|
|
|
|
, "texturev, bgfx texture viewer tool, version %d.%d.%d.\n"
|
|
|
|
, BGFX_TEXTUREV_VERSION_MAJOR
|
|
|
|
, BGFX_TEXTUREV_VERSION_MINOR
|
|
|
|
, BGFX_API_VERSION
|
|
|
|
);
|
2017-06-21 07:42:23 +03:00
|
|
|
return bx::kExitSuccess;
|
2017-05-11 06:55:31 +03:00
|
|
|
}
|
|
|
|
|
2016-05-06 02:22:48 +03:00
|
|
|
if (cmdLine.hasArg('h', "help") )
|
|
|
|
{
|
|
|
|
help();
|
2017-06-21 07:42:23 +03:00
|
|
|
return bx::kExitFailure;
|
2016-05-06 02:22:48 +03:00
|
|
|
}
|
|
|
|
else if (cmdLine.hasArg("associate") )
|
|
|
|
{
|
|
|
|
associate();
|
2017-06-21 07:42:23 +03:00
|
|
|
return bx::kExitFailure;
|
2016-05-06 02:22:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
uint32_t width = 1280;
|
|
|
|
uint32_t height = 720;
|
|
|
|
uint32_t debug = BGFX_DEBUG_TEXT;
|
|
|
|
uint32_t reset = BGFX_RESET_VSYNC;
|
|
|
|
|
|
|
|
inputAddBindings(s_bindingName[Binding::App], s_binding[Binding::App]);
|
|
|
|
inputAddBindings(s_bindingName[Binding::View], s_binding[Binding::View]);
|
|
|
|
|
|
|
|
View view;
|
|
|
|
cmdAdd("view", cmdView, &view);
|
|
|
|
|
|
|
|
bgfx::init();
|
|
|
|
bgfx::reset(width, height, reset);
|
|
|
|
|
|
|
|
// Set view 0 clear state.
|
2017-05-30 02:18:30 +03:00
|
|
|
bgfx::setViewClear(BACKGROUND_VIEW_ID
|
2016-04-22 08:12:35 +03:00
|
|
|
, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
|
2017-05-30 02:18:30 +03:00
|
|
|
, 0x000000ff
|
2016-04-22 08:12:35 +03:00
|
|
|
, 1.0f
|
|
|
|
, 0
|
|
|
|
);
|
|
|
|
|
2016-04-24 18:49:49 +03:00
|
|
|
imguiCreate();
|
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
PosUvwColorVertex::init();
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-06-13 08:43:07 +03:00
|
|
|
const bgfx::Caps* caps = bgfx::getCaps();
|
|
|
|
bgfx::RendererType::Enum type = caps->rendererType;
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
bgfx::UniformHandle s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1);
|
|
|
|
bgfx::UniformHandle u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Mat4);
|
|
|
|
bgfx::UniformHandle u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4);
|
|
|
|
|
2016-12-06 07:59:32 +03:00
|
|
|
bgfx::ShaderHandle vsTexture = bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_texture");
|
|
|
|
bgfx::ShaderHandle fsTexture = bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture");
|
|
|
|
bgfx::ShaderHandle fsTextureArray = bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_array");
|
2016-08-24 08:06:50 +03:00
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::ProgramHandle textureProgram = bgfx::createProgram(
|
2017-07-09 21:47:13 +03:00
|
|
|
vsTexture
|
|
|
|
, fsTexture
|
|
|
|
, true
|
|
|
|
);
|
|
|
|
|
2016-08-24 08:06:50 +03:00
|
|
|
bgfx::ProgramHandle textureArrayProgram = bgfx::createProgram(
|
2017-07-09 21:47:13 +03:00
|
|
|
vsTexture
|
|
|
|
, bgfx::isValid(fsTextureArray)
|
|
|
|
? fsTextureArray
|
|
|
|
: fsTexture
|
|
|
|
, true
|
|
|
|
);
|
2016-08-24 08:06:50 +03:00
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::ProgramHandle textureCubeProgram = bgfx::createProgram(
|
2017-07-09 21:47:13 +03:00
|
|
|
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_texture_cube")
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_cube")
|
|
|
|
, true
|
|
|
|
);
|
|
|
|
|
|
|
|
bgfx::ProgramHandle textureCube2Program = bgfx::createProgram(
|
|
|
|
vsTexture
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_cube2")
|
|
|
|
, true
|
|
|
|
);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-05-30 00:09:48 +03:00
|
|
|
bgfx::ProgramHandle textureSdfProgram = bgfx::createProgram(
|
2017-07-09 21:47:13 +03:00
|
|
|
vsTexture
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_sdf")
|
|
|
|
, true
|
|
|
|
);
|
2016-12-27 21:11:33 +03:00
|
|
|
|
2017-06-20 23:31:22 +03:00
|
|
|
bgfx::ProgramHandle texture3DProgram = bgfx::createProgram(
|
2017-07-09 21:47:13 +03:00
|
|
|
vsTexture
|
|
|
|
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_texture_3d")
|
|
|
|
, true
|
|
|
|
);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-05-30 02:18:30 +03:00
|
|
|
const uint32_t checkerBoardSize = 64;
|
|
|
|
bgfx::TextureHandle checkerBoard;
|
|
|
|
{
|
|
|
|
const bgfx::Memory* mem = bgfx::alloc(checkerBoardSize*checkerBoardSize*4);
|
|
|
|
bimg::imageCheckerboard(mem->data, checkerBoardSize, checkerBoardSize, 8, 0xff8e8e8e, 0xff5d5d5d);
|
|
|
|
checkerBoard = bgfx::createTexture2D(checkerBoardSize, checkerBoardSize, false, 1
|
|
|
|
, bgfx::TextureFormat::BGRA8
|
|
|
|
, 0
|
|
|
|
| BGFX_TEXTURE_MIN_POINT
|
|
|
|
| BGFX_TEXTURE_MIP_POINT
|
|
|
|
| BGFX_TEXTURE_MAG_POINT
|
|
|
|
, mem
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
float speed = 0.37f;
|
|
|
|
float time = 0.0f;
|
|
|
|
|
2016-08-24 08:06:50 +03:00
|
|
|
Interpolator mip(0.0f);
|
|
|
|
Interpolator layer(0.0f);
|
|
|
|
Interpolator zoom(1.0f);
|
|
|
|
Interpolator scale(1.0f);
|
2017-05-26 01:12:07 +03:00
|
|
|
Interpolator posx(0.0f);
|
|
|
|
Interpolator posy(0.0f);
|
2017-07-06 08:36:08 +03:00
|
|
|
InterpolatorAngle angle(0.0f);
|
|
|
|
InterpolatorAngle angx(0.0f);
|
|
|
|
InterpolatorAngle angy(0.0f);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2016-04-24 18:49:49 +03:00
|
|
|
const char* filePath = _argc < 2 ? "" : _argv[1];
|
2016-04-23 21:07:20 +03:00
|
|
|
bool directory = false;
|
|
|
|
|
|
|
|
bx::FileInfo fi;
|
|
|
|
bx::stat(filePath, fi);
|
|
|
|
directory = bx::FileInfo::Directory == fi.m_type;
|
|
|
|
|
|
|
|
std::string path = filePath;
|
|
|
|
if (!directory)
|
|
|
|
{
|
2017-07-14 10:10:33 +03:00
|
|
|
bx::FilePath fp(filePath);
|
|
|
|
path.assign(fp.getPath().getPtr(), fp.getPath().getTerm() );
|
|
|
|
view.updateFileList(path.c_str(), fp.getFileName() );
|
2016-04-23 21:07:20 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-14 10:10:33 +03:00
|
|
|
view.updateFileList(path.c_str(), "");
|
2016-04-23 21:07:20 +03:00
|
|
|
}
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-06-21 07:42:23 +03:00
|
|
|
int exitcode = bx::kExitSuccess;
|
2016-04-23 21:07:20 +03:00
|
|
|
bgfx::TextureHandle texture = BGFX_INVALID_HANDLE;
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2016-04-23 21:07:20 +03:00
|
|
|
if (view.m_fileList.empty() )
|
2016-04-22 08:12:35 +03:00
|
|
|
{
|
2017-06-21 07:42:23 +03:00
|
|
|
exitcode = bx::kExitFailure;
|
2016-04-24 18:49:49 +03:00
|
|
|
if (2 > _argc)
|
|
|
|
{
|
|
|
|
help("File path is not specified.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unable to load '%s' texture.\n", filePath);
|
|
|
|
}
|
2016-04-22 08:12:35 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-23 21:07:20 +03:00
|
|
|
uint32_t fileIndex = 0;
|
2017-05-26 01:12:07 +03:00
|
|
|
bool dragging = false;
|
2016-04-23 21:07:20 +03:00
|
|
|
|
2017-05-25 07:12:30 +03:00
|
|
|
entry::MouseState mouseStatePrev;
|
2016-04-22 08:12:35 +03:00
|
|
|
entry::MouseState mouseState;
|
|
|
|
while (!entry::processEvents(width, height, debug, reset, &mouseState) )
|
|
|
|
{
|
2016-04-24 18:49:49 +03:00
|
|
|
imguiBeginFrame(mouseState.m_mx
|
2017-05-25 07:12:30 +03:00
|
|
|
, mouseState.m_my
|
2016-04-24 18:49:49 +03:00
|
|
|
, (mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
|
|
|
|
| (mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
|
|
|
|
| (mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
|
2017-05-25 07:12:30 +03:00
|
|
|
, mouseState.m_mz
|
2017-03-12 01:44:00 +03:00
|
|
|
, uint16_t(width)
|
|
|
|
, uint16_t(height)
|
2016-04-24 18:49:49 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
static bool help = false;
|
2017-05-25 07:12:30 +03:00
|
|
|
static bool mouseDelta = false;
|
|
|
|
if (!mouseDelta)
|
|
|
|
{
|
|
|
|
mouseStatePrev = mouseState;
|
|
|
|
mouseDelta = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t zoomDelta = mouseState.m_mz - mouseStatePrev.m_mz;
|
|
|
|
if (zoomDelta != 0)
|
|
|
|
{
|
|
|
|
char exec[64];
|
|
|
|
bx::snprintf(exec, BX_COUNTOF(exec), "view zoom %+f", -zoomDelta*0.1f);
|
|
|
|
cmdExec(exec);
|
|
|
|
}
|
|
|
|
|
2017-07-06 08:36:08 +03:00
|
|
|
const float xDelta = float(mouseStatePrev.m_mx - mouseState.m_mx);
|
|
|
|
const float yDelta = float(mouseStatePrev.m_my - mouseState.m_my);
|
|
|
|
|
|
|
|
if (!ImGui::MouseOverArea()
|
|
|
|
&& !help
|
|
|
|
&& mouseState.m_buttons[entry::MouseButton::Left] != mouseStatePrev.m_buttons[entry::MouseButton::Left])
|
2017-05-26 01:12:07 +03:00
|
|
|
{
|
|
|
|
dragging = !!mouseState.m_buttons[entry::MouseButton::Left];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dragging)
|
|
|
|
{
|
2017-07-09 21:47:13 +03:00
|
|
|
if (view.m_info.cubeMap
|
|
|
|
&& Geometry::Quad == view.m_cubeMapGeo)
|
2017-07-06 08:36:08 +03:00
|
|
|
{
|
|
|
|
char exec[64];
|
|
|
|
bx::snprintf(exec, BX_COUNTOF(exec), "view cubemap %+f %+f", -yDelta, -xDelta);
|
|
|
|
cmdExec(exec);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char exec[64];
|
|
|
|
bx::snprintf(exec, BX_COUNTOF(exec), "view pan %+f %+f", xDelta, yDelta);
|
|
|
|
cmdExec(exec);
|
|
|
|
}
|
2017-05-26 01:12:07 +03:00
|
|
|
}
|
|
|
|
|
2017-05-25 07:12:30 +03:00
|
|
|
mouseStatePrev = mouseState;
|
|
|
|
|
2017-07-06 08:36:08 +03:00
|
|
|
if (ImGui::BeginPopupContextVoid("Menu") )
|
|
|
|
{
|
2017-07-10 03:11:59 +03:00
|
|
|
// if (ImGui::MenuItem("Open") )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (ImGui::MenuItem("Save As") )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("Reset") )
|
2017-07-06 08:36:08 +03:00
|
|
|
{
|
2017-07-10 03:11:59 +03:00
|
|
|
cmdExec(s_resetCmd);
|
2017-07-06 08:36:08 +03:00
|
|
|
}
|
|
|
|
|
2017-07-10 03:11:59 +03:00
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::BeginMenu("Options"))
|
2017-07-06 08:36:08 +03:00
|
|
|
{
|
2017-07-10 03:11:59 +03:00
|
|
|
bool filter = view.m_filter;
|
|
|
|
if (ImGui::MenuItem("Filter", NULL, &filter) )
|
|
|
|
{
|
|
|
|
cmdExec("view filter");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginMenu("Cubemap", view.m_info.cubeMap) )
|
|
|
|
{
|
|
|
|
if (ImGui::MenuItem("Quad", NULL, Geometry::Quad == view.m_cubeMapGeo) )
|
|
|
|
{
|
|
|
|
cmdExec("view geo quad");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("Cross", NULL, Geometry::Cross == view.m_cubeMapGeo) )
|
|
|
|
{
|
|
|
|
cmdExec("view geo cross");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::MenuItem("Hexagon", NULL, Geometry::Hexagon == view.m_cubeMapGeo) )
|
|
|
|
{
|
|
|
|
cmdExec("view geo hexagon");
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rr = 0 != (view.m_abgr & 0x000000ff);
|
|
|
|
if (ImGui::MenuItem("R", NULL, &rr) )
|
|
|
|
{
|
|
|
|
cmdExec("view rgb r");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gg = 0 != (view.m_abgr & 0x0000ff00);
|
|
|
|
if (ImGui::MenuItem("G", NULL, &gg) )
|
|
|
|
{
|
|
|
|
cmdExec("view rgb g");
|
|
|
|
}
|
|
|
|
|
2017-07-10 03:29:51 +03:00
|
|
|
bool bb = 0 != (view.m_abgr & 0x00ff0000);
|
2017-07-10 03:11:59 +03:00
|
|
|
if (ImGui::MenuItem("B", NULL, &bb) )
|
|
|
|
{
|
|
|
|
cmdExec("view rgb b");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool alpha = view.m_alpha;
|
|
|
|
if (ImGui::MenuItem("Checkerboard", NULL, &alpha) )
|
|
|
|
{
|
|
|
|
cmdExec("view rgb a");
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
2017-07-06 08:36:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::MenuItem("Help") )
|
|
|
|
{
|
2017-07-11 07:42:50 +03:00
|
|
|
cmdExec("view help");
|
2017-07-06 08:36:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::MenuItem("Exit") )
|
|
|
|
{
|
|
|
|
cmdExec("exit");
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
if (help != view.m_help)
|
2016-04-24 18:49:49 +03:00
|
|
|
{
|
2017-07-09 21:47:13 +03:00
|
|
|
if (!help)
|
|
|
|
{
|
|
|
|
ImGui::OpenPopup("Help");
|
|
|
|
inputRemoveBindings(s_bindingName[Binding::View]);
|
2017-07-11 07:42:50 +03:00
|
|
|
inputAddBindings(s_bindingName[Binding::Help], s_binding[Binding::Help]);
|
2017-07-09 21:47:13 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-11 07:42:50 +03:00
|
|
|
inputRemoveBindings(s_bindingName[Binding::Help]);
|
2017-07-09 21:47:13 +03:00
|
|
|
inputAddBindings(s_bindingName[Binding::View], s_binding[Binding::View]);
|
|
|
|
}
|
|
|
|
|
|
|
|
help = view.m_help;
|
2016-04-24 18:49:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginPopupModal("Help", NULL, ImGuiWindowFlags_AlwaysAutoResize) )
|
|
|
|
{
|
2016-05-29 02:26:12 +03:00
|
|
|
ImGui::SetWindowFontScale(1.0f);
|
2016-04-24 18:49:49 +03:00
|
|
|
|
|
|
|
ImGui::Text(
|
2017-05-11 06:55:31 +03:00
|
|
|
"texturev, bgfx texture viewer tool " ICON_KI_WRENCH ", version %d.%d.%d.\n"
|
2017-01-01 11:18:41 +03:00
|
|
|
"Copyright 2011-2017 Branimir Karadzic. All rights reserved.\n"
|
2016-04-24 18:49:49 +03:00
|
|
|
"License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause\n"
|
2017-05-11 06:55:31 +03:00
|
|
|
, BGFX_TEXTUREV_VERSION_MAJOR
|
|
|
|
, BGFX_TEXTUREV_VERSION_MINOR
|
|
|
|
, BGFX_API_VERSION
|
2016-04-24 18:49:49 +03:00
|
|
|
);
|
|
|
|
ImGui::Separator();
|
|
|
|
ImGui::NextLine();
|
|
|
|
|
|
|
|
ImGui::Text("Key bindings:\n\n");
|
|
|
|
|
2016-05-29 03:14:19 +03:00
|
|
|
ImGui::PushFont(ImGui::Font::Mono);
|
2017-06-04 01:38:03 +03:00
|
|
|
keyBindingHelp("ESC", "Exit.");
|
|
|
|
keyBindingHelp("h", "Toggle help screen.");
|
|
|
|
keyBindingHelp("f", "Toggle full-screen.");
|
2016-05-18 19:10:02 +03:00
|
|
|
ImGui::NextLine();
|
|
|
|
|
2017-06-04 01:38:03 +03:00
|
|
|
keyBindingHelp("LMB+drag", "Pan.");
|
|
|
|
keyBindingHelp("=/- or MW", "Zoom in/out.");
|
|
|
|
keyBindingHelp("z/Z", "Rotate.");
|
|
|
|
keyBindingHelp("0", "Reset.");
|
2017-06-10 05:40:20 +03:00
|
|
|
keyBindingHelp("1", "Fit to window.");
|
2016-04-24 18:49:49 +03:00
|
|
|
ImGui::NextLine();
|
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
keyBindingHelp("<", "Reset MIP level.");
|
|
|
|
keyBindingHelp(",/,", "MIP level up/down.");
|
|
|
|
keyBindingHelp("/", "Toggle linear/point texture sampling.");
|
|
|
|
keyBindingHelp("[space]", "Change cubemap mode.");
|
2017-06-03 23:37:42 +03:00
|
|
|
ImGui::NextLine();
|
|
|
|
|
2017-06-04 01:38:03 +03:00
|
|
|
keyBindingHelp("left", "Previous layer in texture array.");
|
|
|
|
keyBindingHelp("right", "Next layer in texture array.");
|
2016-04-24 18:49:49 +03:00
|
|
|
ImGui::NextLine();
|
|
|
|
|
2017-06-04 01:38:03 +03:00
|
|
|
keyBindingHelp("up", "Previous texture.");
|
|
|
|
keyBindingHelp("down", "Next texture.");
|
2016-08-24 09:18:41 +03:00
|
|
|
ImGui::NextLine();
|
|
|
|
|
2017-06-04 01:38:03 +03:00
|
|
|
keyBindingHelp("r/g/b", "Toggle R, G, or B color channel.");
|
|
|
|
keyBindingHelp("a", "Toggle alpha blending.");
|
2016-04-24 18:49:49 +03:00
|
|
|
ImGui::NextLine();
|
|
|
|
|
2017-06-04 01:38:03 +03:00
|
|
|
keyBindingHelp("s", "Toggle Multi-channel SDF rendering");
|
2016-12-27 21:11:33 +03:00
|
|
|
ImGui::NextLine();
|
|
|
|
|
2016-05-29 03:14:19 +03:00
|
|
|
ImGui::PopFont();
|
|
|
|
|
2016-04-24 18:49:49 +03:00
|
|
|
ImGui::Dummy(ImVec2(0.0f, 0.0f) );
|
|
|
|
ImGui::SameLine(ImGui::GetWindowWidth() - 136.0f);
|
|
|
|
if (ImGui::Button("Close", ImVec2(128.0f, 0.0f) )
|
|
|
|
|| !view.m_help)
|
|
|
|
{
|
|
|
|
view.m_help = false;
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
imguiEndFrame();
|
2016-04-23 21:07:20 +03:00
|
|
|
|
|
|
|
if (!bgfx::isValid(texture)
|
|
|
|
|| view.m_fileIndex != fileIndex)
|
|
|
|
{
|
|
|
|
if (bgfx::isValid(texture) )
|
|
|
|
{
|
|
|
|
bgfx::destroyTexture(texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileIndex = view.m_fileIndex;
|
|
|
|
|
|
|
|
filePath = view.m_fileList[view.m_fileIndex].c_str();
|
|
|
|
|
|
|
|
texture = loadTexture(filePath
|
2017-07-09 21:47:13 +03:00
|
|
|
, 0
|
|
|
|
| BGFX_TEXTURE_U_CLAMP
|
|
|
|
| BGFX_TEXTURE_V_CLAMP
|
|
|
|
| BGFX_TEXTURE_W_CLAMP
|
|
|
|
, 0
|
|
|
|
, &view.m_info
|
|
|
|
);
|
2016-04-23 22:25:05 +03:00
|
|
|
|
|
|
|
std::string title;
|
2017-03-29 03:35:16 +03:00
|
|
|
if (isValid(texture) )
|
|
|
|
{
|
2017-06-20 23:31:22 +03:00
|
|
|
const char* name = "";
|
|
|
|
if (view.m_info.cubeMap)
|
|
|
|
{
|
|
|
|
name = " CubeMap";
|
|
|
|
}
|
|
|
|
else if (1 < view.m_info.depth)
|
|
|
|
{
|
|
|
|
name = " 3D";
|
|
|
|
view.m_info.numLayers = view.m_info.depth;
|
|
|
|
}
|
|
|
|
else if (1 < view.m_info.numLayers)
|
|
|
|
{
|
|
|
|
name = " 2D Array";
|
|
|
|
}
|
|
|
|
|
2017-04-28 07:09:44 +03:00
|
|
|
bx::stringPrintf(title, "%s (%d x %d%s, mips: %d, layers %d, %s)"
|
2017-03-29 03:35:16 +03:00
|
|
|
, filePath
|
|
|
|
, view.m_info.width
|
|
|
|
, view.m_info.height
|
2017-06-20 23:31:22 +03:00
|
|
|
, name
|
2017-04-28 07:09:44 +03:00
|
|
|
, view.m_info.numMips
|
|
|
|
, view.m_info.numLayers
|
2017-04-04 08:42:27 +03:00
|
|
|
, bimg::getName(bimg::TextureFormat::Enum(view.m_info.format) )
|
2017-03-29 03:35:16 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bx::stringPrintf(title, "Failed to load %s!", filePath);
|
|
|
|
}
|
2016-04-23 22:25:05 +03:00
|
|
|
entry::WindowHandle handle = { 0 };
|
|
|
|
entry::setWindowTitle(handle, title.c_str() );
|
2016-04-23 21:07:20 +03:00
|
|
|
}
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
int64_t now = bx::getHPCounter();
|
|
|
|
static int64_t last = now;
|
|
|
|
const int64_t frameTime = now - last;
|
|
|
|
last = now;
|
|
|
|
const double freq = double(bx::getHPFrequency() );
|
|
|
|
|
|
|
|
time += (float)(frameTime*speed/freq);
|
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
float transitionTime = dragging ? 0.0f : 0.25f;
|
|
|
|
|
|
|
|
posx.set(view.m_posx, transitionTime);
|
|
|
|
posy.set(view.m_posy, transitionTime);
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
float ortho[16];
|
2017-05-30 02:18:30 +03:00
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
bx::mtxOrtho(
|
|
|
|
ortho
|
|
|
|
, 0.0f
|
|
|
|
, float(width)
|
|
|
|
, float(height)
|
|
|
|
, 0.0f
|
|
|
|
, 0.0f
|
|
|
|
, 1000.0f
|
|
|
|
, 0.0f
|
|
|
|
, caps->homogeneousDepth
|
|
|
|
);
|
2017-05-30 02:18:30 +03:00
|
|
|
bgfx::setViewTransform(BACKGROUND_VIEW_ID, NULL, ortho);
|
|
|
|
bgfx::setViewRect(BACKGROUND_VIEW_ID, 0, 0, uint16_t(width), uint16_t(height) );
|
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
setGeometry(Geometry::Quad
|
|
|
|
, 0
|
2017-05-30 02:18:30 +03:00
|
|
|
, 0
|
|
|
|
, width
|
|
|
|
, height
|
|
|
|
, view.m_alpha ? UINT32_MAX : 0
|
|
|
|
, float(width )/float(checkerBoardSize)
|
|
|
|
, float(height)/float(checkerBoardSize)
|
|
|
|
);
|
|
|
|
bgfx::setTexture(0
|
|
|
|
, s_texColor
|
|
|
|
, checkerBoard
|
|
|
|
);
|
|
|
|
bgfx::setState(0
|
|
|
|
| BGFX_STATE_RGB_WRITE
|
|
|
|
| BGFX_STATE_ALPHA_WRITE
|
|
|
|
);
|
|
|
|
bgfx::submit(BACKGROUND_VIEW_ID
|
2017-07-09 21:47:13 +03:00
|
|
|
, textureProgram
|
|
|
|
);
|
2017-05-30 02:18:30 +03:00
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
float px = posx.getValue();
|
|
|
|
float py = posy.getValue();
|
2017-07-09 21:47:13 +03:00
|
|
|
bx::mtxOrtho(
|
|
|
|
ortho
|
|
|
|
, px-width/2.0f
|
|
|
|
, px+width/2.0f
|
|
|
|
, py+height/2.0f
|
|
|
|
, py-height/2.0f
|
|
|
|
, 0.0f
|
|
|
|
, 1000.0f
|
|
|
|
, 0.0f
|
|
|
|
, caps->homogeneousDepth
|
|
|
|
);
|
2017-05-30 02:18:30 +03:00
|
|
|
bgfx::setViewTransform(IMAGE_VIEW_ID, NULL, ortho);
|
|
|
|
bgfx::setViewRect(IMAGE_VIEW_ID, 0, 0, uint16_t(width), uint16_t(height) );
|
2016-04-22 08:12:35 +03:00
|
|
|
|
|
|
|
bgfx::dbgTextClear();
|
|
|
|
|
2017-06-10 05:40:20 +03:00
|
|
|
if (view.m_fit)
|
|
|
|
{
|
2017-07-06 08:36:08 +03:00
|
|
|
scale.set(bx::fmin(float(width) / float(view.m_info.width)
|
|
|
|
, float(height) / float(view.m_info.height) )
|
2017-06-10 05:40:20 +03:00
|
|
|
, 0.1f
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scale.set(1.0f, 0.1f);
|
|
|
|
}
|
|
|
|
|
2017-05-26 01:12:07 +03:00
|
|
|
zoom.set(view.m_zoom, transitionTime);
|
2017-06-03 23:18:12 +03:00
|
|
|
angle.set(view.m_angle, transitionTime);
|
2017-07-06 08:36:08 +03:00
|
|
|
angx.set(view.m_angx, transitionTime);
|
|
|
|
angy.set(view.m_angy, transitionTime);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-05-26 06:24:02 +03:00
|
|
|
float ss = scale.getValue()
|
|
|
|
* zoom.getValue()
|
|
|
|
;
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-07-09 21:47:13 +03:00
|
|
|
setGeometry(view.m_info.cubeMap ? view.m_cubeMapGeo : Geometry::Quad
|
|
|
|
, -int(view.m_info.width * ss)/2
|
2017-06-03 23:18:12 +03:00
|
|
|
, -int(view.m_info.height * ss)/2
|
|
|
|
, int(view.m_info.width * ss)
|
|
|
|
, int(view.m_info.height * ss)
|
2016-05-18 19:10:02 +03:00
|
|
|
, view.m_abgr
|
2016-04-23 21:07:20 +03:00
|
|
|
);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2017-06-03 23:18:12 +03:00
|
|
|
float rotz[16];
|
|
|
|
bx::mtxRotateZ(rotz, angle.getValue() );
|
|
|
|
bgfx::setTransform(rotz);
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
float mtx[16];
|
2017-07-06 08:36:08 +03:00
|
|
|
bx::mtxRotateXY(mtx, angx.getValue(), angy.getValue() );
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::setUniform(u_mtx, mtx);
|
|
|
|
|
2016-08-24 08:06:50 +03:00
|
|
|
mip.set(float(view.m_mip), 0.5f);
|
|
|
|
layer.set(float(view.m_layer), 0.25f);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2016-08-24 08:06:50 +03:00
|
|
|
float params[4] = { mip.getValue(), layer.getValue(), 0.0f, 0.0f };
|
2017-06-20 23:31:22 +03:00
|
|
|
if (1 < view.m_info.depth)
|
|
|
|
{
|
|
|
|
params[1] = layer.getValue()/view.m_info.depth;
|
|
|
|
}
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::setUniform(u_params, params);
|
|
|
|
|
2017-05-25 08:40:53 +03:00
|
|
|
const uint32_t textureFlags = 0
|
|
|
|
| BGFX_TEXTURE_U_CLAMP
|
|
|
|
| BGFX_TEXTURE_V_CLAMP
|
|
|
|
| BGFX_TEXTURE_W_CLAMP
|
|
|
|
| (view.m_filter ? 0 : 0
|
2016-04-23 21:07:20 +03:00
|
|
|
| BGFX_TEXTURE_MIN_POINT
|
|
|
|
| BGFX_TEXTURE_MIP_POINT
|
|
|
|
| BGFX_TEXTURE_MAG_POINT
|
2017-05-25 08:40:53 +03:00
|
|
|
)
|
|
|
|
;
|
|
|
|
|
|
|
|
bgfx::setTexture(0
|
|
|
|
, s_texColor
|
|
|
|
, texture
|
|
|
|
, textureFlags
|
2016-04-23 21:07:20 +03:00
|
|
|
);
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::setState(0
|
2016-04-23 21:07:20 +03:00
|
|
|
| BGFX_STATE_RGB_WRITE
|
|
|
|
| BGFX_STATE_ALPHA_WRITE
|
2016-05-18 19:10:02 +03:00
|
|
|
| (view.m_alpha ? BGFX_STATE_BLEND_ALPHA : BGFX_STATE_NONE)
|
2016-04-23 21:07:20 +03:00
|
|
|
);
|
2017-06-20 23:31:22 +03:00
|
|
|
|
|
|
|
bgfx:: ProgramHandle program = textureProgram;
|
|
|
|
if (1 < view.m_info.depth)
|
|
|
|
{
|
|
|
|
program = texture3DProgram;
|
|
|
|
}
|
|
|
|
else if (view.m_info.cubeMap)
|
|
|
|
{
|
2017-07-09 21:47:13 +03:00
|
|
|
program = Geometry::Quad == view.m_cubeMapGeo
|
|
|
|
? textureCubeProgram
|
|
|
|
: textureCube2Program
|
|
|
|
;
|
2017-06-20 23:31:22 +03:00
|
|
|
}
|
|
|
|
else if (1 < view.m_info.numLayers)
|
|
|
|
{
|
|
|
|
program = textureArrayProgram;
|
|
|
|
}
|
|
|
|
else if (view.m_sdf)
|
|
|
|
{
|
|
|
|
program = textureSdfProgram;
|
|
|
|
}
|
|
|
|
|
|
|
|
bgfx::submit(IMAGE_VIEW_ID, program);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
|
|
|
bgfx::frame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bgfx::isValid(texture) )
|
|
|
|
{
|
|
|
|
bgfx::destroyTexture(texture);
|
|
|
|
}
|
2017-07-09 21:47:13 +03:00
|
|
|
|
2017-05-30 02:18:30 +03:00
|
|
|
bgfx::destroyTexture(checkerBoard);
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::destroyUniform(s_texColor);
|
|
|
|
bgfx::destroyUniform(u_mtx);
|
|
|
|
bgfx::destroyUniform(u_params);
|
|
|
|
bgfx::destroyProgram(textureProgram);
|
2016-08-24 08:06:50 +03:00
|
|
|
bgfx::destroyProgram(textureArrayProgram);
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::destroyProgram(textureCubeProgram);
|
2017-07-09 21:47:13 +03:00
|
|
|
bgfx::destroyProgram(textureCube2Program);
|
2017-05-30 00:09:48 +03:00
|
|
|
bgfx::destroyProgram(textureSdfProgram);
|
2017-07-09 21:47:13 +03:00
|
|
|
bgfx::destroyProgram(texture3DProgram);
|
2016-04-22 08:12:35 +03:00
|
|
|
|
2016-04-24 18:49:49 +03:00
|
|
|
imguiDestroy();
|
|
|
|
|
2016-04-22 08:12:35 +03:00
|
|
|
bgfx::shutdown();
|
|
|
|
|
|
|
|
return exitcode;
|
|
|
|
}
|