2022-08-22 22:16:58 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2022-2022 Sandy Carter. All rights reserved.
|
|
|
|
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "bgfx_utils.h"
|
|
|
|
#include "imgui/imgui.h"
|
|
|
|
|
|
|
|
#include <bx/allocator.h>
|
|
|
|
#include <bx/math.h>
|
|
|
|
|
2022-08-23 22:51:00 +03:00
|
|
|
#include <bimg/decode.h>
|
|
|
|
|
|
|
|
#include <tinystl/string.h>
|
|
|
|
#include <tinystl/vector.h>
|
|
|
|
namespace stl = tinystl;
|
|
|
|
|
2022-08-22 22:16:58 +03:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-08-26 06:07:03 +03:00
|
|
|
constexpr int32_t kCheckerboardSize = 128;
|
2022-08-25 16:51:48 +03:00
|
|
|
constexpr int32_t kFirstUncompressedFormatIndex = bgfx::TextureFormat::Unknown + 1;
|
2022-08-26 06:07:03 +03:00
|
|
|
constexpr int32_t kNumCompressedFormats = bgfx::TextureFormat::Unknown;
|
|
|
|
constexpr int32_t kNumUncompressedFormats = bgfx::TextureFormat::UnknownDepth - kFirstUncompressedFormatIndex;
|
|
|
|
constexpr int32_t kNumFormats = kNumCompressedFormats + kNumUncompressedFormats;
|
|
|
|
const int32_t kNumFormatsInRow = (int32_t)bx::ceil(1.2f * bx::sqrt(kNumFormats) );
|
2022-08-22 22:16:58 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
inline int32_t formatToIndex(bimg::TextureFormat::Enum format)
|
2022-08-23 22:51:00 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
int32_t index = format;
|
|
|
|
if (index >= kFirstUncompressedFormatIndex)
|
|
|
|
{
|
|
|
|
--index;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
2022-08-23 22:51:00 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
inline bimg::TextureFormat::Enum indexToFormat(int32_t index)
|
|
|
|
{
|
|
|
|
if (index < kNumCompressedFormats)
|
|
|
|
{
|
|
|
|
return bimg::TextureFormat::Enum(index);
|
|
|
|
}
|
2023-05-24 08:03:07 +03:00
|
|
|
|
|
|
|
if (index >= kNumCompressedFormats && index < kNumFormats)
|
2022-08-23 22:51:00 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
return bimg::TextureFormat::Enum(index + 1);
|
2022-08-23 22:51:00 +03:00
|
|
|
}
|
2023-05-24 08:03:07 +03:00
|
|
|
|
|
|
|
return bimg::TextureFormat::Unknown;
|
2022-08-25 16:51:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TextureStatus
|
|
|
|
{
|
|
|
|
enum Enum
|
|
|
|
{
|
|
|
|
Ok,
|
|
|
|
NotInitialized,
|
|
|
|
FormatNotSupported,
|
|
|
|
ConversionNotSupported,
|
|
|
|
FormatIgnored
|
|
|
|
};
|
|
|
|
|
|
|
|
inline static const char* getDescription(Enum value)
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
2023-05-24 08:03:07 +03:00
|
|
|
case Ok: return "Ok";
|
|
|
|
case NotInitialized: return "Texture was not initialized";
|
|
|
|
case FormatNotSupported: return "Format not supported by GPU/backend";
|
2022-08-25 16:51:48 +03:00
|
|
|
case ConversionNotSupported: return "Conversion from RGBA8 not supported";
|
2023-05-24 08:03:07 +03:00
|
|
|
case FormatIgnored: return "Format is ignored by this example";
|
2022-08-25 16:51:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool isError(Enum value)
|
|
|
|
{
|
|
|
|
return value == FormatNotSupported
|
|
|
|
|| value == ConversionNotSupported
|
|
|
|
;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Texture
|
|
|
|
{
|
2023-05-24 08:03:07 +03:00
|
|
|
uint16_t m_width = 0;
|
2022-08-25 16:51:48 +03:00
|
|
|
uint16_t m_height = 0;
|
|
|
|
TextureStatus::Enum m_status = TextureStatus::NotInitialized;
|
|
|
|
bgfx::TextureHandle m_texture = BGFX_INVALID_HANDLE;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextureSet
|
|
|
|
{
|
|
|
|
stl::string m_name;
|
2023-05-24 08:03:07 +03:00
|
|
|
uint16_t m_maxWidth = 0;
|
2022-08-25 16:51:48 +03:00
|
|
|
uint16_t m_maxHeight = 0;
|
|
|
|
bool m_hasCompressedTextures = false;
|
|
|
|
Texture m_textures[kNumFormats];
|
2022-08-23 22:51:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static bimg::ImageContainer* generateHueWheelImage()
|
|
|
|
{
|
|
|
|
constexpr int32_t kTextureSize = 256;
|
|
|
|
constexpr int32_t kHalfTextureSize = kTextureSize / 2;
|
|
|
|
|
|
|
|
bimg::ImageContainer* image = bimg::imageAlloc(
|
|
|
|
entry::getAllocator(),
|
|
|
|
bimg::TextureFormat::RGBA32F,
|
|
|
|
kTextureSize,
|
|
|
|
kTextureSize,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (NULL == image)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
float* rgbaf32Pixels = (float*)image->m_data;
|
|
|
|
|
|
|
|
for (int32_t y = 0 ; y < kTextureSize; ++y)
|
|
|
|
{
|
|
|
|
for (int32_t x = 0; x < kTextureSize; ++x)
|
|
|
|
{
|
|
|
|
float relX = (x - kHalfTextureSize) / (float) kHalfTextureSize;
|
|
|
|
float relY = (y - kHalfTextureSize) / (float) kHalfTextureSize;
|
|
|
|
float distance = bx::min(1.0f, bx::sqrt(relX * relX + relY * relY) );
|
|
|
|
float angle = bx::atan2(relY, relX);
|
|
|
|
float* pixel = &rgbaf32Pixels[(x + y * kTextureSize) * 4];
|
|
|
|
float hsv[3] = {angle / (2.0f * bx::kPi), 1.0f, 1.0f - distance};
|
|
|
|
bx::hsvToRgb(pixel, hsv);
|
|
|
|
pixel[3] = 1.0f - distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t y = 0; y < 16; ++y)
|
|
|
|
{
|
|
|
|
for (int32_t x = 0; x < 16; ++x)
|
|
|
|
{
|
|
|
|
float* r = &rgbaf32Pixels[(x + (kTextureSize - 36 + y) * kTextureSize) * 4];
|
|
|
|
r[0] = 1.0f;
|
|
|
|
r[1] = 0.0f;
|
|
|
|
r[2] = 0.0f;
|
|
|
|
r[3] = 1.0f;
|
|
|
|
|
|
|
|
float* g = &rgbaf32Pixels[(x + 16 + (kTextureSize - 36 + y) * kTextureSize) * 4];
|
|
|
|
g[0] = 0.0f;
|
|
|
|
g[1] = 1.0f;
|
|
|
|
g[2] = 0.0f;
|
|
|
|
g[3] = 1.0f;
|
|
|
|
|
|
|
|
float* b = &rgbaf32Pixels[(x + 32 + (kTextureSize - 36 + y) * kTextureSize) * 4];
|
|
|
|
b[0] = 0.0f;
|
|
|
|
b[1] = 0.0f;
|
|
|
|
b[2] = 1.0f;
|
|
|
|
b[3] = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t y = 0; y < 16; ++y)
|
|
|
|
{
|
|
|
|
for (int32_t x = 0; x < 48; ++x)
|
|
|
|
{
|
|
|
|
float* a = &rgbaf32Pixels[(x + (kTextureSize - 20 + y) * kTextureSize) * 4];
|
|
|
|
a[0] = 1.0f;
|
|
|
|
a[1] = 1.0f;
|
|
|
|
a[2] = 1.0f;
|
|
|
|
a[3] = 1.0f - (float)x / 48.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
static void textureSetPopulateCompressedFormat(TextureSet& textureSet, bimg::ImageContainer* source, bool freeImage = true)
|
2022-08-23 22:51:00 +03:00
|
|
|
{
|
|
|
|
if (NULL == source)
|
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t textureIndex = indexToFormat(source->m_format);
|
|
|
|
Texture& texture = textureSet.m_textures[textureIndex];
|
|
|
|
|
|
|
|
if (bgfx::isValid(texture.m_texture) || texture.m_status == TextureStatus::FormatNotSupported)
|
|
|
|
{
|
|
|
|
if (freeImage)
|
|
|
|
{
|
|
|
|
bimg::imageFree(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2022-08-23 22:51:00 +03:00
|
|
|
}
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
bimg::ImageMip mip0;
|
|
|
|
bimg::imageGetRawData(
|
|
|
|
*source
|
|
|
|
, 0
|
|
|
|
, 0
|
|
|
|
, source->m_data
|
|
|
|
, source->m_size
|
|
|
|
, mip0
|
|
|
|
);
|
|
|
|
|
|
|
|
texture.m_width = uint16_t(mip0.m_width);
|
|
|
|
texture.m_height = uint16_t(mip0.m_height);
|
|
|
|
texture.m_status = TextureStatus::Ok;
|
|
|
|
texture.m_texture = bgfx::createTexture2D(
|
|
|
|
uint16_t(mip0.m_width)
|
|
|
|
, uint16_t(mip0.m_height)
|
|
|
|
, false
|
|
|
|
, 1
|
|
|
|
, bgfx::TextureFormat::Enum(mip0.m_format)
|
|
|
|
, BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT
|
|
|
|
, bgfx::copy(mip0.m_data, mip0.m_size)
|
|
|
|
);
|
|
|
|
|
|
|
|
bgfx::setName(texture.m_texture, bimg::getName(source->m_format) );
|
|
|
|
|
|
|
|
if (freeImage)
|
|
|
|
{
|
|
|
|
bimg::imageFree(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
textureSet.m_maxWidth = bx::max(textureSet.m_maxWidth, texture.m_width);
|
|
|
|
textureSet.m_maxHeight = bx::max(textureSet.m_maxHeight, texture.m_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void textureSetPopulateUncompressedFormats(TextureSet& textureSet, bimg::ImageContainer* source, bool freeImage = true)
|
|
|
|
{
|
|
|
|
if (NULL == source)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-08-23 22:51:00 +03:00
|
|
|
|
|
|
|
const uint32_t flags = 0
|
|
|
|
| BGFX_SAMPLER_MIN_POINT
|
|
|
|
| BGFX_SAMPLER_MAG_POINT
|
|
|
|
;
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
for (int32_t i = 0; i < kNumUncompressedFormats; ++i)
|
2022-08-23 22:51:00 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
int32_t textureIndex = kNumCompressedFormats + i;
|
|
|
|
|
|
|
|
Texture& texture = textureSet.m_textures[textureIndex];
|
|
|
|
|
|
|
|
if (bgfx::isValid(texture.m_texture) || texture.m_status == TextureStatus::FormatNotSupported)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bimg::TextureFormat::Enum format = indexToFormat(textureIndex);
|
|
|
|
const char* formatName = bimg::getName(format);
|
2022-08-23 22:51:00 +03:00
|
|
|
int32_t formatNameLen = bx::strLen(formatName);
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
if (!bimg::imageConvert(format, source->m_format) )
|
|
|
|
{
|
|
|
|
texture.m_status = TextureStatus::ConversionNotSupported;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-05-24 08:03:07 +03:00
|
|
|
if (formatName[formatNameLen - 1] == 'I'
|
|
|
|
|| formatName[formatNameLen - 1] == 'U')
|
2022-08-23 22:51:00 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
texture.m_status = TextureStatus::FormatIgnored;
|
2022-08-23 22:51:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bimg::TextureInfo info;
|
|
|
|
bimg::imageGetSize(
|
2022-08-25 16:51:48 +03:00
|
|
|
&info
|
2022-08-23 22:51:00 +03:00
|
|
|
, uint16_t(source->m_width)
|
|
|
|
, uint16_t(source->m_height)
|
|
|
|
, 1
|
|
|
|
, false
|
|
|
|
, false
|
|
|
|
, 1
|
2022-08-25 16:51:48 +03:00
|
|
|
, format
|
2023-05-24 08:03:07 +03:00
|
|
|
);
|
2022-08-23 22:51:00 +03:00
|
|
|
|
|
|
|
const bgfx::Memory* mem = bgfx::alloc(info.storageSize);
|
|
|
|
bimg::imageConvert(
|
2022-08-25 16:51:48 +03:00
|
|
|
entry::getAllocator()
|
2022-08-23 22:51:00 +03:00
|
|
|
, mem->data
|
|
|
|
, info.format
|
|
|
|
, source->m_data
|
|
|
|
, source->m_format
|
|
|
|
, source->m_width
|
|
|
|
, source->m_height
|
|
|
|
, 1
|
2023-05-24 08:03:07 +03:00
|
|
|
);
|
2022-08-23 22:51:00 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
texture.m_width = info.width;
|
|
|
|
texture.m_height = info.height;
|
|
|
|
texture.m_status = TextureStatus::Ok;
|
|
|
|
texture.m_texture = bgfx::createTexture2D(
|
|
|
|
info.width
|
2022-08-23 22:51:00 +03:00
|
|
|
, info.height
|
|
|
|
, info.numMips > 1
|
|
|
|
, info.numLayers
|
|
|
|
, bgfx::TextureFormat::Enum(info.format)
|
|
|
|
, flags
|
|
|
|
, mem
|
2023-05-24 08:03:07 +03:00
|
|
|
);
|
2022-08-23 22:51:00 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
bgfx::setName(texture.m_texture, formatName);
|
|
|
|
|
|
|
|
textureSet.m_maxWidth = bx::max(textureSet.m_maxWidth, texture.m_width);
|
|
|
|
textureSet.m_maxHeight = bx::max(textureSet.m_maxHeight, texture.m_height);
|
2022-08-23 22:51:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (freeImage)
|
|
|
|
{
|
|
|
|
bimg::imageFree(source);
|
|
|
|
}
|
2022-08-25 16:51:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static TextureSet makeEmptyTextureSet(const char* name)
|
|
|
|
{
|
|
|
|
TextureSet textureSet;
|
|
|
|
textureSet.m_name = name;
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < kNumFormats; ++i)
|
|
|
|
{
|
|
|
|
bimg::TextureFormat::Enum format = indexToFormat(i);
|
|
|
|
|
|
|
|
if (!bgfx::isTextureValid(
|
|
|
|
1
|
|
|
|
, false
|
|
|
|
, 1
|
|
|
|
, bgfx::TextureFormat::Enum(format)
|
|
|
|
, BGFX_TEXTURE_NONE
|
|
|
|
) )
|
|
|
|
{
|
|
|
|
textureSet.m_textures[i].m_status = TextureStatus::FormatNotSupported;
|
|
|
|
}
|
|
|
|
}
|
2022-08-23 22:51:00 +03:00
|
|
|
|
|
|
|
return textureSet;
|
|
|
|
}
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
static TextureSet generateTextureSetFromImage(const char* name, bimg::ImageContainer* source, bool freeImage = true)
|
2022-08-23 22:51:00 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
TextureSet textureSet = makeEmptyTextureSet(name);
|
2022-08-23 22:51:00 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
if (NULL == source)
|
2022-08-23 22:51:00 +03:00
|
|
|
{
|
|
|
|
return textureSet;
|
|
|
|
}
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
textureSetPopulateUncompressedFormats(textureSet, source, freeImage);
|
|
|
|
|
|
|
|
return textureSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TextureSet generateTextureSetFromFileSet(const char* name, const char* filePaths[])
|
|
|
|
{
|
|
|
|
TextureSet textureSet = makeEmptyTextureSet(name);
|
|
|
|
|
|
|
|
while (NULL != *filePaths)
|
|
|
|
{
|
|
|
|
const char* filePath = *filePaths++;
|
|
|
|
|
|
|
|
uint32_t size;
|
|
|
|
void* data = load(filePath, &size);
|
|
|
|
if (NULL == data)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bimg::ImageContainer* image = bimg::imageParse(entry::getAllocator(), data, size);
|
|
|
|
if (NULL == image)
|
|
|
|
{
|
|
|
|
unload(data);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bimg::isCompressed(image->m_format) )
|
|
|
|
{
|
|
|
|
textureSet.m_hasCompressedTextures = true;
|
|
|
|
|
|
|
|
textureSetPopulateCompressedFormat(textureSet, image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textureSetPopulateUncompressedFormats(textureSet, image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return textureSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TextureSet generateTextureSetFromFile(const char* filePath)
|
|
|
|
{
|
|
|
|
const char* filePaths[] =
|
|
|
|
{
|
|
|
|
filePath,
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
return generateTextureSetFromFileSet(bx::FilePath(filePath).getFileName().getPtr(), filePaths);
|
2022-08-23 22:51:00 +03:00
|
|
|
}
|
|
|
|
|
2022-08-22 22:16:58 +03:00
|
|
|
class ExamplePixelFormats : public entry::AppI
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ExamplePixelFormats(const char* _name, const char* _description, const char* _url)
|
|
|
|
: entry::AppI(_name, _description, _url)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) override
|
|
|
|
{
|
|
|
|
Args args(_argc, _argv);
|
|
|
|
|
|
|
|
m_width = _width;
|
|
|
|
m_height = _height;
|
|
|
|
m_debug = BGFX_DEBUG_TEXT;
|
|
|
|
m_reset = BGFX_RESET_VSYNC;
|
|
|
|
|
|
|
|
bgfx::Init init;
|
|
|
|
init.type = args.m_type;
|
|
|
|
init.vendorId = args.m_pciId;
|
2022-08-26 06:07:03 +03:00
|
|
|
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
|
|
|
|
init.platformData.ndt = entry::getNativeDisplayHandle();
|
2023-11-04 07:36:00 +03:00
|
|
|
init.platformData.type = entry::getNativeWindowHandleType();
|
2022-08-22 22:16:58 +03:00
|
|
|
init.resolution.width = m_width;
|
|
|
|
init.resolution.height = m_height;
|
|
|
|
init.resolution.reset = m_reset;
|
|
|
|
bgfx::init(init);
|
|
|
|
|
|
|
|
// Enable debug text.
|
|
|
|
bgfx::setDebug(m_debug);
|
|
|
|
|
|
|
|
// Set view 0 clear state.
|
|
|
|
bgfx::setViewClear(0
|
2022-08-23 06:45:14 +03:00
|
|
|
, BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
|
|
|
|
, 0x303030ff
|
|
|
|
, 1.0f
|
|
|
|
, 0
|
|
|
|
);
|
2022-08-22 22:16:58 +03:00
|
|
|
|
2022-08-23 22:51:00 +03:00
|
|
|
const bgfx::Memory* checkerboardImageMemory = bgfx::alloc(kCheckerboardSize * kCheckerboardSize * 4);
|
2022-08-23 06:41:35 +03:00
|
|
|
bimg::imageCheckerboard(
|
|
|
|
checkerboardImageMemory->data
|
2022-08-23 22:51:00 +03:00
|
|
|
, kCheckerboardSize
|
|
|
|
, kCheckerboardSize
|
2022-08-23 06:41:35 +03:00
|
|
|
, 16
|
|
|
|
, 0xFF909090
|
|
|
|
, 0xFF707070
|
|
|
|
);
|
|
|
|
m_checkerboard = bgfx::createTexture2D(
|
2022-08-23 22:51:00 +03:00
|
|
|
kCheckerboardSize
|
|
|
|
, kCheckerboardSize
|
2022-08-23 06:41:35 +03:00
|
|
|
, false
|
|
|
|
, 1
|
|
|
|
, bgfx::TextureFormat::RGBA8
|
2022-08-23 22:51:00 +03:00
|
|
|
, BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT
|
2022-08-23 06:41:35 +03:00
|
|
|
, checkerboardImageMemory
|
|
|
|
);
|
2022-08-22 22:16:58 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
m_textureSets.push_back(generateTextureSetFromImage("Hue Wheel", generateHueWheelImage() ) );
|
2022-08-23 22:51:00 +03:00
|
|
|
m_textureSets.push_back(generateTextureSetFromFile("textures/pf_alpha_test.dds") );
|
|
|
|
m_textureSets.push_back(generateTextureSetFromFile("textures/pf_uv_filtering_test.dds") );
|
2022-08-25 16:51:48 +03:00
|
|
|
const char* textureCompressionSetFiles[] =
|
|
|
|
{
|
2022-10-26 03:03:40 +03:00
|
|
|
"textures/texture_compression_astc_4x4.dds",
|
|
|
|
"textures/texture_compression_astc_5x4.dds",
|
|
|
|
"textures/texture_compression_astc_5x5.dds",
|
|
|
|
"textures/texture_compression_astc_6x5.dds",
|
|
|
|
"textures/texture_compression_astc_6x6.dds",
|
|
|
|
"textures/texture_compression_astc_8x5.dds",
|
|
|
|
"textures/texture_compression_astc_8x6.dds",
|
|
|
|
"textures/texture_compression_astc_8x8.dds",
|
|
|
|
"textures/texture_compression_astc_10x5.dds",
|
|
|
|
"textures/texture_compression_astc_10x6.dds",
|
|
|
|
"textures/texture_compression_astc_10x8.dds",
|
|
|
|
"textures/texture_compression_astc_10x10.dds",
|
|
|
|
"textures/texture_compression_astc_12x10.dds",
|
|
|
|
"textures/texture_compression_astc_12x12.dds",
|
|
|
|
"textures/texture_compression_atc.dds",
|
|
|
|
"textures/texture_compression_atce.dds",
|
|
|
|
"textures/texture_compression_atci.dds",
|
|
|
|
"textures/texture_compression_bc1.ktx",
|
|
|
|
"textures/texture_compression_bc2.ktx",
|
|
|
|
"textures/texture_compression_bc3.ktx",
|
|
|
|
"textures/texture_compression_bc7.ktx",
|
|
|
|
"textures/texture_compression_etc1.ktx",
|
|
|
|
"textures/texture_compression_etc2.ktx",
|
|
|
|
"textures/texture_compression_ptc12.pvr",
|
|
|
|
"textures/texture_compression_ptc14.pvr",
|
|
|
|
"textures/texture_compression_ptc22.pvr",
|
|
|
|
"textures/texture_compression_ptc24.pvr",
|
|
|
|
"textures/texture_compression_rgba8.dds",
|
|
|
|
nullptr
|
2022-08-25 16:51:48 +03:00
|
|
|
};
|
|
|
|
m_textureSets.push_back(generateTextureSetFromFileSet("texture_compression_* set", textureCompressionSetFiles));
|
2022-08-23 22:51:00 +03:00
|
|
|
|
|
|
|
m_currentTextureSet = &m_textureSets[0];
|
|
|
|
|
|
|
|
for (auto& textureSet : m_textureSets)
|
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
m_largestTextureSize = bx::max(m_largestTextureSize, float(bx::max(textureSet.m_maxWidth, textureSet.m_maxHeight)));
|
2022-08-23 22:51:00 +03:00
|
|
|
}
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
imguiCreate();
|
|
|
|
}
|
|
|
|
|
2022-08-23 06:41:35 +03:00
|
|
|
int32_t shutdown() override
|
2022-08-22 22:16:58 +03:00
|
|
|
{
|
|
|
|
imguiDestroy();
|
|
|
|
|
2022-08-23 22:51:00 +03:00
|
|
|
for (auto& textureSet : m_textureSets)
|
2022-08-22 22:16:58 +03:00
|
|
|
{
|
2022-08-23 22:51:00 +03:00
|
|
|
for (auto texture : textureSet.m_textures)
|
2022-08-23 06:45:14 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
if (bgfx::isValid(texture.m_texture) )
|
2022-08-23 22:51:00 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
bgfx::destroy(texture.m_texture);
|
2022-08-23 22:51:00 +03:00
|
|
|
}
|
2022-08-23 06:45:14 +03:00
|
|
|
}
|
2022-08-22 22:16:58 +03:00
|
|
|
}
|
|
|
|
|
2022-08-23 06:41:35 +03:00
|
|
|
if (bgfx::isValid(m_checkerboard) )
|
2022-08-23 06:45:14 +03:00
|
|
|
{
|
2022-08-22 22:16:58 +03:00
|
|
|
bgfx::destroy(m_checkerboard);
|
2022-08-23 06:45:14 +03:00
|
|
|
}
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
// Shutdown bgfx.
|
|
|
|
bgfx::shutdown();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void imguiTextBoxUnformatted(const ImVec2& size, const char* text) const
|
|
|
|
{
|
|
|
|
ImVec2 textSize = ImGui::CalcTextSize(text);
|
|
|
|
ImVec2 textOffset = ImVec2(
|
2022-08-23 06:41:35 +03:00
|
|
|
size.x >= 0.0f ? bx::max( (size.x - textSize.x) / 2, 0.0f) : 0.0f
|
|
|
|
, size.y >= 0.0f ? bx::max( (size.y - textSize.y) / 2, 0.0f) : 0.0f
|
|
|
|
);
|
|
|
|
ImGui::SetCursorPos(ImVec2(
|
|
|
|
ImGui::GetCursorPosX() + textOffset.x
|
|
|
|
, ImGui::GetCursorPosY() + textOffset.y
|
|
|
|
) );
|
2022-08-22 22:16:58 +03:00
|
|
|
ImGui::TextUnformatted(text);
|
|
|
|
};
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
void imguiStrikethroughItem()
|
|
|
|
{
|
|
|
|
ImVec2 itemSize = ImGui::GetItemRectSize();
|
|
|
|
if (itemSize.x <= 0.0f || itemSize.y <= 0.0f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ImVec2 p0 = ImGui::GetItemRectMin();
|
|
|
|
ImVec2 p1 = ImGui::GetItemRectMax();
|
|
|
|
p0.y = p1.y = p0.y + itemSize.y * 0.5f;
|
|
|
|
|
|
|
|
ImGui::GetWindowDrawList()->AddLine(p0, p1, ImGui::GetColorU32(ImGuiCol_Text) );
|
|
|
|
}
|
|
|
|
|
2022-08-23 06:41:35 +03:00
|
|
|
void imguiTexturePreview(const ImVec2& size, bgfx::TextureHandle texture, const ImVec2& previewSizeHint = ImVec2(-1.0f, -1.0f) ) const
|
2022-08-22 22:16:58 +03:00
|
|
|
{
|
|
|
|
ImVec2 origin = ImGui::GetCursorScreenPos();
|
|
|
|
|
|
|
|
ImVec2 previewSize = ImVec2(
|
2022-08-23 06:41:35 +03:00
|
|
|
previewSizeHint.x >= 0.0f ? previewSizeHint.x : size.x
|
|
|
|
, previewSizeHint.y >= 0.0f ? previewSizeHint.y : size.y
|
|
|
|
);
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
ImVec2 previewPos = ImVec2(
|
2022-08-23 06:41:35 +03:00
|
|
|
origin.x + bx::max(0.0f, (size.x - previewSize.x) / 2)
|
|
|
|
, origin.y + bx::max(0.0f, (size.y - previewSize.y) / 2)
|
|
|
|
);
|
2022-08-22 22:16:58 +03:00
|
|
|
|
2022-08-23 06:41:35 +03:00
|
|
|
if (bgfx::isValid(texture) )
|
2022-08-22 22:16:58 +03:00
|
|
|
{
|
2022-08-23 06:41:35 +03:00
|
|
|
if (bgfx::isValid(m_checkerboard) )
|
2022-08-22 22:16:58 +03:00
|
|
|
{
|
2022-08-23 07:49:26 +03:00
|
|
|
static int64_t timeOffset = bx::getHPCounter();
|
2022-08-26 07:12:09 +03:00
|
|
|
const float time = float( (bx::getHPCounter()-timeOffset)/double(bx::getHPFrequency() ) );
|
|
|
|
const float animate = float(m_animate)*0.5f;
|
|
|
|
const float xx = bx::sin(time * 0.37f) * animate;
|
|
|
|
const float yy = bx::cos(time * 0.43f) * animate;
|
|
|
|
|
2022-08-23 22:51:00 +03:00
|
|
|
const float uTile = bx::max(1.0f, previewSize.x / kCheckerboardSize);
|
|
|
|
const float vTile = bx::max(1.0f, previewSize.y / kCheckerboardSize);
|
2022-08-23 07:49:26 +03:00
|
|
|
|
2022-08-22 22:16:58 +03:00
|
|
|
ImGui::SetCursorScreenPos(previewPos);
|
2022-08-23 22:51:00 +03:00
|
|
|
ImGui::Image(m_checkerboard, previewSize, ImVec2(xx, yy), ImVec2(xx+uTile, yy+vTile) );
|
2022-08-22 22:16:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetCursorScreenPos(previewPos);
|
2022-08-22 22:50:13 +03:00
|
|
|
ImGui::Image(texture, m_useAlpha ? IMGUI_FLAGS_ALPHA_BLEND : IMGUI_FLAGS_NONE, 0, previewSize);
|
2022-08-22 22:16:58 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
ImU32 color = ImGui::GetColorU32(ImGuiCol_Text, 0.25f);
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
|
|
|
ImVec2 p0 = previewPos;
|
|
|
|
ImVec2 p1 = ImVec2(p0.x + previewSize.x, p0.y + previewSize.y);
|
|
|
|
drawList->AddRect(p0, p1, color);
|
|
|
|
drawList->AddLine(p0, p1, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetCursorScreenPos(origin);
|
|
|
|
ImGui::Dummy(size);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool update() override
|
|
|
|
{
|
|
|
|
if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
|
|
|
|
{
|
|
|
|
imguiBeginFrame(m_mouseState.m_mx
|
|
|
|
, m_mouseState.m_my
|
|
|
|
, (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
|
|
|
|
| (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
|
|
|
|
| (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
|
|
|
|
, m_mouseState.m_mz
|
|
|
|
, uint16_t(m_width)
|
|
|
|
, uint16_t(m_height)
|
|
|
|
);
|
|
|
|
|
|
|
|
showExampleDialog(this);
|
|
|
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(360.0f, 40.0f), ImGuiCond_FirstUseEver);
|
2022-08-23 06:41:35 +03:00
|
|
|
ImGui::Begin("Formats", NULL, ImGuiWindowFlags_AlwaysAutoResize);
|
2022-08-22 22:16:58 +03:00
|
|
|
|
2022-08-23 22:51:00 +03:00
|
|
|
ImVec2 previewSize = ImVec2(m_previewSize, m_previewSize);
|
2022-08-25 16:51:48 +03:00
|
|
|
if (m_currentTextureSet->m_maxWidth > m_currentTextureSet->m_maxHeight)
|
2023-05-24 08:03:07 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
previewSize.y /= float(m_currentTextureSet->m_maxWidth) / m_currentTextureSet->m_maxHeight;
|
2023-05-24 08:03:07 +03:00
|
|
|
}
|
2022-08-25 16:51:48 +03:00
|
|
|
else if (m_currentTextureSet->m_maxWidth < m_currentTextureSet->m_maxHeight)
|
2023-05-24 08:03:07 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
previewSize.x *= float(m_currentTextureSet->m_maxWidth) / m_currentTextureSet->m_maxHeight;
|
2023-05-24 08:03:07 +03:00
|
|
|
}
|
2022-08-23 22:51:00 +03:00
|
|
|
|
|
|
|
float cellWidth = previewSize.x;
|
2022-08-23 06:41:35 +03:00
|
|
|
for (int32_t i = 0; i < kNumFormats; ++i)
|
2022-08-22 22:16:58 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
int32_t format = indexToFormat(i);
|
2022-08-23 06:41:35 +03:00
|
|
|
ImVec2 textSize = ImGui::CalcTextSize(bimg::getName(bimg::TextureFormat::Enum(format) ) );
|
2022-08-22 22:16:58 +03:00
|
|
|
cellWidth = bx::max(cellWidth, textSize.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImDrawList* drawList = ImGui::GetWindowDrawList();
|
|
|
|
|
2022-08-23 22:51:00 +03:00
|
|
|
if (ImGui::BeginCombo("Sample", m_currentTextureSet ? m_currentTextureSet->m_name.c_str() : nullptr))
|
|
|
|
{
|
|
|
|
for (auto& textureSet : m_textureSets)
|
|
|
|
{
|
|
|
|
bool isSelected = (&textureSet == m_currentTextureSet);
|
|
|
|
if (ImGui::Selectable(textureSet.m_name.c_str(), &isSelected))
|
|
|
|
{
|
|
|
|
m_currentTextureSet = &textureSet;
|
2022-08-25 16:51:48 +03:00
|
|
|
if (!m_currentTextureSet->m_hasCompressedTextures && formatToIndex(m_selectedFormat) < kNumCompressedFormats)
|
2023-05-24 08:03:07 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
m_selectedFormat = bimg::TextureFormat::RGBA8;
|
2023-05-24 08:03:07 +03:00
|
|
|
}
|
2022-08-23 22:51:00 +03:00
|
|
|
}
|
|
|
|
}
|
2023-05-24 08:03:07 +03:00
|
|
|
|
2022-08-23 22:51:00 +03:00
|
|
|
ImGui::EndCombo();
|
|
|
|
}
|
2023-05-24 08:03:07 +03:00
|
|
|
|
2022-08-23 22:51:00 +03:00
|
|
|
ImGui::DragFloat("Preview Size", &m_previewSize, 1.0f, 10.0f, m_largestTextureSize, "%.0f px");
|
2022-08-22 22:32:40 +03:00
|
|
|
ImGui::SameLine();
|
2022-08-22 22:50:13 +03:00
|
|
|
ImGui::Checkbox("Alpha", &m_useAlpha);
|
2022-08-25 16:51:48 +03:00
|
|
|
ImGui::SameLine();
|
2022-08-26 06:07:03 +03:00
|
|
|
ImGui::Checkbox("Animate", &m_animate);
|
2022-08-23 06:41:35 +03:00
|
|
|
ImGui::BeginTable("Formats", kNumFormatsInRow, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit);
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
for (int32_t i = m_currentTextureSet->m_hasCompressedTextures ? 0 : kNumCompressedFormats; i < kNumFormats; ++i)
|
2022-08-22 22:16:58 +03:00
|
|
|
{
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
bimg::TextureFormat::Enum format = indexToFormat(i);
|
|
|
|
const Texture& texture = m_currentTextureSet->m_textures[i];
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
bool isSelected = (m_selectedFormat == format);
|
2022-08-25 16:51:48 +03:00
|
|
|
bool isFormatSupported = texture.m_status == TextureStatus::Ok;
|
|
|
|
bool isError = TextureStatus::isError(texture.m_status);
|
|
|
|
ImU32 labelColor = isError ? IM_COL32(255, 96, 96, 255) : ImGui::GetColorU32(isFormatSupported ? ImGuiCol_Text : ImGuiCol_TextDisabled);
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
ImDrawListSplitter splitter;
|
|
|
|
splitter.Split(drawList, 2);
|
|
|
|
splitter.SetCurrentChannel(drawList, 1);
|
|
|
|
|
|
|
|
ImGui::BeginGroup();
|
|
|
|
ImGuiTextBuffer label;
|
2022-08-23 06:41:35 +03:00
|
|
|
label.append(bimg::getName(bimg::TextureFormat::Enum(format) ) );
|
2022-08-25 16:51:48 +03:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, labelColor);
|
2022-08-23 06:41:35 +03:00
|
|
|
imguiTextBoxUnformatted(ImVec2(cellWidth, 0.0f), label.c_str() );
|
2023-05-24 08:03:07 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
if (TextureStatus::isError(texture.m_status) )
|
|
|
|
{
|
|
|
|
imguiStrikethroughItem();
|
|
|
|
}
|
|
|
|
imguiTexturePreview(ImVec2(cellWidth, previewSize.y), m_currentTextureSet->m_textures[i].m_texture, previewSize );
|
|
|
|
ImGui::PopStyleColor();
|
2022-08-22 22:16:58 +03:00
|
|
|
ImGui::EndGroup();
|
2022-08-25 16:51:48 +03:00
|
|
|
if (!isFormatSupported && ImGui::IsItemHovered() )
|
|
|
|
{
|
|
|
|
ImGui::SetTooltip("%s", TextureStatus::getDescription(texture.m_status) );
|
|
|
|
}
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
splitter.SetCurrentChannel(drawList, 0);
|
2022-08-23 06:41:35 +03:00
|
|
|
ImGui::SetCursorScreenPos(ImGui::GetItemRectMin() );
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
ImGui::PushID(i);
|
2022-08-23 06:41:35 +03:00
|
|
|
|
|
|
|
if (ImGui::Selectable(
|
|
|
|
"##selectable"
|
|
|
|
, &isSelected
|
2023-07-01 18:16:39 +03:00
|
|
|
, ImGuiSelectableFlags_AllowOverlap
|
2022-08-23 06:41:35 +03:00
|
|
|
, ImGui::GetItemRectSize()
|
|
|
|
) )
|
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
m_selectedFormat = format;
|
2022-08-23 06:41:35 +03:00
|
|
|
}
|
|
|
|
|
2022-08-22 22:16:58 +03:00
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
splitter.Merge(drawList);
|
|
|
|
}
|
2022-08-23 06:41:35 +03:00
|
|
|
|
2022-08-22 22:16:58 +03:00
|
|
|
ImGui::EndTable();
|
|
|
|
ImGui::End();
|
|
|
|
|
2022-08-23 06:57:19 +03:00
|
|
|
{
|
2022-08-25 16:51:48 +03:00
|
|
|
int32_t selectedTextureIndex = formatToIndex(m_selectedFormat);
|
|
|
|
const Texture& texture = m_currentTextureSet->m_textures[selectedTextureIndex];
|
|
|
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(10.0f, 280.0f), ImGuiCond_FirstUseEver);
|
2022-08-23 06:57:19 +03:00
|
|
|
ImGui::Begin("Selected Format", NULL, ImGuiWindowFlags_AlwaysAutoResize);
|
|
|
|
ImGui::Text("Format: %s", bimg::getName(m_selectedFormat) );
|
2022-08-25 16:51:48 +03:00
|
|
|
ImGui::Text("Status: %s", TextureStatus::getDescription(texture.m_status) );
|
2022-08-23 06:41:35 +03:00
|
|
|
|
2022-08-23 06:57:19 +03:00
|
|
|
const bgfx::Caps* caps = bgfx::getCaps();
|
2022-08-23 06:41:35 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
const uint32_t formatFlags = caps->formats[m_selectedFormat];
|
2022-08-23 07:40:04 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
{
|
2022-08-23 07:40:04 +03:00
|
|
|
bool emulated = 0 != (formatFlags & (0
|
|
|
|
| BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED
|
|
|
|
| BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED
|
|
|
|
| BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED
|
|
|
|
) );
|
|
|
|
ImGui::PushEnabled(false);
|
|
|
|
ImGui::Checkbox("Emu", &emulated);
|
|
|
|
ImGui::PopEnabled();
|
|
|
|
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
|
|
|
{
|
2022-08-23 09:29:13 +03:00
|
|
|
ImGui::SetTooltip("Texture format is%s emulated.", emulated ? "" : " not");
|
2022-08-23 07:40:04 +03:00
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
bool framebuffer = 0 != (formatFlags & BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER);
|
|
|
|
ImGui::PushEnabled(false);
|
|
|
|
ImGui::Checkbox("FB", &framebuffer);
|
|
|
|
ImGui::PopEnabled();
|
|
|
|
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
|
|
|
{
|
2022-08-23 09:29:13 +03:00
|
|
|
ImGui::SetTooltip("Texture format can%s be used as frame buffer.", framebuffer ? "" : "not");
|
2022-08-23 07:40:04 +03:00
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
bool msaa = 0 != (formatFlags & BGFX_CAPS_FORMAT_TEXTURE_MSAA);
|
|
|
|
ImGui::PushEnabled(false);
|
|
|
|
ImGui::Checkbox("MSAA", &msaa);
|
|
|
|
ImGui::PopEnabled();
|
|
|
|
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
|
|
|
|
{
|
2022-08-23 09:29:13 +03:00
|
|
|
ImGui::SetTooltip("Texture can%s be sampled as MSAA.", msaa ? "" : "not");
|
2022-08-23 07:40:04 +03:00
|
|
|
}
|
|
|
|
}
|
2022-08-23 06:57:19 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
ImVec2 size = ImVec2(float(m_currentTextureSet->m_maxWidth), float(m_currentTextureSet->m_maxHeight) );
|
|
|
|
ImVec2 selectedPreviewSize = bgfx::isValid(texture.m_texture) ? ImVec2(float(texture.m_width), float(texture.m_height) ) : size;
|
2022-08-23 06:57:19 +03:00
|
|
|
|
2022-08-25 16:51:48 +03:00
|
|
|
imguiTexturePreview(size, texture.m_texture, selectedPreviewSize);
|
2022-08-23 06:57:19 +03:00
|
|
|
ImGui::End();
|
|
|
|
}
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
imguiEndFrame();
|
2022-08-23 06:41:35 +03:00
|
|
|
|
2022-08-22 22:16:58 +03:00
|
|
|
// Set view 0 default viewport.
|
|
|
|
bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
|
|
|
|
|
|
|
// This dummy draw call is here to make sure that view 0 is cleared
|
|
|
|
// if no other draw calls are submitted to viewZ 0.
|
|
|
|
bgfx::touch(0);
|
|
|
|
|
|
|
|
// Advance to next frame. Rendering thread will be kicked to
|
|
|
|
// process submitted rendering primitives.
|
|
|
|
bgfx::frame();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry::MouseState m_mouseState;
|
|
|
|
|
|
|
|
uint32_t m_width;
|
|
|
|
uint32_t m_height;
|
|
|
|
uint32_t m_debug;
|
|
|
|
uint32_t m_reset;
|
2022-08-23 22:51:00 +03:00
|
|
|
float m_largestTextureSize = 256.0f;
|
2022-08-22 22:16:58 +03:00
|
|
|
float m_previewSize = 50.0f;
|
2022-08-22 22:50:13 +03:00
|
|
|
bool m_useAlpha = true;
|
2022-08-26 06:07:03 +03:00
|
|
|
bool m_animate = true;
|
2022-08-22 22:32:40 +03:00
|
|
|
bimg::TextureFormat::Enum m_selectedFormat = bimg::TextureFormat::RGBA8;
|
2022-08-22 22:16:58 +03:00
|
|
|
|
|
|
|
bgfx::TextureHandle m_checkerboard = BGFX_INVALID_HANDLE;
|
2022-08-23 22:51:00 +03:00
|
|
|
stl::vector<TextureSet> m_textureSets;
|
|
|
|
TextureSet* m_currentTextureSet = NULL;
|
2022-08-22 22:16:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ENTRY_IMPLEMENT_MAIN(
|
|
|
|
ExamplePixelFormats
|
|
|
|
, "47-pixelformats"
|
|
|
|
, "Texture formats."
|
|
|
|
, "https://bkaradzic.github.io/bgfx/examples.html#pixelformats"
|
|
|
|
);
|