Add ktx
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
/* -*- tab-width: 4; -*- */
|
||||
/* vi: set sw=2 ts=4 expandtab: */
|
||||
|
||||
/*
|
||||
* Copyright 2010-2020 Mark Callow.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @file
|
||||
* @~English
|
||||
*
|
||||
* @brief Tests of internal API functions.
|
||||
*
|
||||
* @author Mark Callow, github.com/MarkCallow
|
||||
*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#if _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "image.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
////////////////////////
|
||||
// normalisation tests
|
||||
////////////////////////
|
||||
|
||||
template<typename ColorType>
|
||||
void test_color(ColorType input, ColorType output) {
|
||||
ColorType color;
|
||||
for (uint32_t i = 0; i < color.comps_count(); ++i) {
|
||||
color.set(i, static_cast<typename ColorType::value_type>(input[i]));
|
||||
}
|
||||
|
||||
// Verify color components were set correctly
|
||||
for (uint32_t i = 0; i < color.comps_count(); ++i) {
|
||||
EXPECT_EQ(color[i], static_cast<typename ColorType::value_type>(input[i]));
|
||||
}
|
||||
|
||||
color.normalize();
|
||||
|
||||
for (uint32_t i = 0; i < color.comps_count(); ++i) {
|
||||
EXPECT_EQ(color[i], static_cast<typename ColorType::value_type>(output[i]));
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr uint32_t min_val{0};
|
||||
static constexpr uint32_t max_val[3]={255, 65535, 4294967295};
|
||||
static constexpr uint32_t some_val[3]={31, 191, 178};
|
||||
|
||||
template<uint32_t componentCount>
|
||||
void test_by_channel( const uint32_t min_res[], const uint32_t max_res[],
|
||||
const uint32_t some_res8[], const uint32_t some_res16[], const uint32_t some_res32[]) {
|
||||
{
|
||||
color<uint8_t, componentCount> c8i{(uint8_t)min_val, (uint8_t)min_val, (uint8_t)min_val, (uint8_t)min_val};
|
||||
color<uint8_t, componentCount> c8o{(uint8_t)min_res[0], (uint8_t)min_res[0], (uint8_t)min_res[0], 0};
|
||||
test_color(c8i, c8o);
|
||||
}
|
||||
{
|
||||
color<uint8_t, componentCount> c8i{(uint8_t)max_val[0], (uint8_t)max_val[0], (uint8_t)max_val[0], (uint8_t)max_val[0]};
|
||||
color<uint8_t, componentCount> c8o{(uint8_t)max_res[0], (uint8_t)max_res[0], (uint8_t)max_res[0], (uint8_t)max_val[0]};
|
||||
test_color(c8i, c8o);
|
||||
}
|
||||
{
|
||||
color<uint8_t, componentCount> c8i{(uint8_t)some_val[0], (uint8_t)some_val[1], (uint8_t)some_val[2], 0};
|
||||
color<uint8_t, componentCount> c8o{(uint8_t)some_res8[0], (uint8_t)some_res8[1], (uint8_t)some_res8[2], 0};
|
||||
test_color(c8i, c8o);
|
||||
}
|
||||
{
|
||||
color<uint16_t, componentCount> c16i{(uint16_t)min_val, (uint16_t)min_val, (uint16_t)min_val, (uint16_t)min_val};
|
||||
color<uint16_t, componentCount> c16o{(uint16_t)min_res[1], (uint16_t)min_res[1], (uint16_t)min_res[1], 0};
|
||||
test_color(c16i, c16o);
|
||||
}
|
||||
{
|
||||
color<uint16_t, componentCount> c16i{(uint16_t)max_val[1], (uint16_t)max_val[1], (uint16_t)max_val[1], (uint16_t)max_val[1]};
|
||||
color<uint16_t, componentCount> c16o{(uint16_t)max_res[1], (uint16_t)max_res[1], (uint16_t)max_res[1], (uint16_t)max_val[1]};
|
||||
test_color(c16i, c16o);
|
||||
}
|
||||
{
|
||||
color<uint16_t, componentCount> c16i{(uint16_t)some_val[0], (uint16_t)some_val[1], (uint16_t)some_val[2], 0};
|
||||
color<uint16_t, componentCount> c16o{(uint16_t)some_res16[0], (uint16_t)some_res16[1], (uint16_t)some_res16[2], 0};
|
||||
test_color(c16i, c16o);
|
||||
}
|
||||
{
|
||||
color<uint32_t, componentCount> c32i{(uint32_t)min_val, (uint32_t)min_val, (uint32_t)min_val, (uint32_t)min_val};
|
||||
color<uint32_t, componentCount> c32o{(uint32_t)min_res[2], (uint32_t)min_res[2], (uint32_t)min_res[2], 0};
|
||||
test_color(c32i, c32o);
|
||||
}
|
||||
{
|
||||
color<uint32_t, componentCount> c32i{(uint32_t)max_val[2], (uint32_t)max_val[2], (uint32_t)max_val[2], (uint32_t)max_val[2]};
|
||||
color<uint32_t, componentCount> c32o{(uint32_t)max_res[2], (uint32_t)max_res[2], (uint32_t)max_res[2], (uint32_t)max_val[2]};
|
||||
test_color(c32i, c32o);
|
||||
}
|
||||
{
|
||||
color<uint32_t, componentCount> c32i{(uint32_t)some_val[0], (uint32_t)some_val[1], (uint32_t)some_val[2], 0};
|
||||
color<uint32_t, componentCount> c32o{(uint32_t)some_res32[0], (uint32_t)some_res32[1], (uint32_t)some_res32[2], 0};
|
||||
test_color(c32i, c32o);
|
||||
}
|
||||
}
|
||||
|
||||
// Hand tested vectors and their normalised results in GeoGebra
|
||||
static constexpr uint32_t min_res[3]={54, 13849, 907633408}; // These are -0.577350 float in 8bit-UNORM, 16bit-UNORM and 32bit-UNORM values
|
||||
static constexpr uint32_t max_res[3]={201, 51686, 3387333888};
|
||||
|
||||
static constexpr uint32_t some_res8[3]={30, 192, 179};
|
||||
static constexpr uint32_t some_res16[3]={13790, 13883, 13875};
|
||||
static constexpr uint32_t some_res32[3]={907633408, 907633408, 907633408};
|
||||
|
||||
static constexpr uint32_t min_res2[3]={37, 9597, 628983424};
|
||||
static constexpr uint32_t max_res2[3]={218, 55938, 3665984000};
|
||||
static constexpr uint32_t some_res8_2[3]={21, 198, 128};
|
||||
static constexpr uint32_t some_res16_2[3]={9541, 9654, 32768};
|
||||
static constexpr uint32_t some_res32_2[3]={628983424, 628983424, 2147483648};
|
||||
|
||||
static constexpr uint32_t min_res1[3]={0, 0, 0};
|
||||
static constexpr uint32_t max_res1[3]={255, 65535, 4294967295};
|
||||
static constexpr uint32_t some_res8_1[3]={255, 0, 0}; // Second and third values are unused because its single channel image result
|
||||
static constexpr uint32_t some_res16_1[3]={65535, 0, 0}; // Same as above
|
||||
static constexpr uint32_t some_res32_1[3]={4294967295, 0, 0}; // Same as above
|
||||
|
||||
TEST(NormaliseColorTest, multi_channel_test) {
|
||||
test_by_channel<4>(min_res, max_res, some_res8, some_res16, some_res32);
|
||||
test_by_channel<3>(min_res, max_res, some_res8, some_res16, some_res32);
|
||||
test_by_channel<2>(min_res2, max_res2, some_res8_2, some_res16_2, some_res32_2);
|
||||
test_by_channel<1>(min_res1, max_res1, some_res8_1, some_res16_1, some_res32_1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -0,0 +1,116 @@
|
||||
/* -*- tab-width: 4; -*- */
|
||||
/* vi: set sw=2 ts=4 expandtab: */
|
||||
// Copyright 2022-2023 The Khronos Group Inc.
|
||||
// Copyright 2022-2023 RasterGrid Kft.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include <ktx/fragment_uri.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
class FragmentURITest : public ::testing::Test {
|
||||
protected:
|
||||
FragmentURITest() {}
|
||||
};
|
||||
|
||||
TEST_F(FragmentURITest, ParseWholeRange) {
|
||||
EXPECT_EQ(ktx::parseFragmentURI("").mip, ktx::SelectorRange{});
|
||||
EXPECT_EQ(ktx::parseFragmentURI("").facial, ktx::SelectorRange{});
|
||||
EXPECT_EQ(ktx::parseFragmentURI("").stratal, ktx::SelectorRange{});
|
||||
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m").mip, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m").stratal, ktx::SelectorRange{});
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m").facial, ktx::SelectorRange{});
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a").mip, ktx::SelectorRange{});
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a").stratal, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a").facial, ktx::SelectorRange{});
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f").mip, ktx::SelectorRange{});
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f").stratal, ktx::SelectorRange{});
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f").facial, ktx::SelectorRange(ktx::all));
|
||||
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m&a").mip, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m&a").stratal, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a&f").stratal, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a&f").facial, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f&m").mip, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f&m").facial, ktx::SelectorRange(ktx::all));
|
||||
}
|
||||
|
||||
TEST_F(FragmentURITest, ParseRangeEmpty) {
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=").mip, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=").stratal, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=").facial, ktx::SelectorRange(ktx::all));
|
||||
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=,").mip, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=,").stratal, ktx::SelectorRange(ktx::all));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=,").facial, ktx::SelectorRange(ktx::all));
|
||||
}
|
||||
|
||||
TEST_F(FragmentURITest, ParseRangeBegin) {
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=0").mip, ktx::SelectorRange(0, ktx::RangeEnd));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=0").stratal, ktx::SelectorRange(0, ktx::RangeEnd));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=0").facial, ktx::SelectorRange(0, ktx::RangeEnd));
|
||||
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=1").mip, ktx::SelectorRange(1, ktx::RangeEnd));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=1").stratal, ktx::SelectorRange(1, ktx::RangeEnd));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=1").facial, ktx::SelectorRange(1, ktx::RangeEnd));
|
||||
}
|
||||
|
||||
TEST_F(FragmentURITest, ParseRangeEnd) {
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=,0").mip, ktx::SelectorRange(0, 1));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=,0").stratal, ktx::SelectorRange(0, 1));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=,0").facial, ktx::SelectorRange(0, 1));
|
||||
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=,1").mip, ktx::SelectorRange(0, 2));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=,1").stratal, ktx::SelectorRange(0, 2));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=,1").facial, ktx::SelectorRange(0, 2));
|
||||
}
|
||||
|
||||
TEST_F(FragmentURITest, ParseRangeBeginEnd) {
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=0,0").mip, ktx::SelectorRange(0, 1));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=0,0").stratal, ktx::SelectorRange(0, 1));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=0,0").facial, ktx::SelectorRange(0, 1));
|
||||
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=0,1").mip, ktx::SelectorRange(0, 2));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=0,1").stratal, ktx::SelectorRange(0, 2));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=0,1").facial, ktx::SelectorRange(0, 2));
|
||||
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=1,3").mip, ktx::SelectorRange(1, 4));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=1,3").stratal, ktx::SelectorRange(1, 4));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=1,3").facial, ktx::SelectorRange(1, 4));
|
||||
}
|
||||
|
||||
TEST_F(FragmentURITest, ParseMultipleRange) {
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=0,0&a=1,1").mip, ktx::SelectorRange(0, 1));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("m=0,0&a=1,1").stratal, ktx::SelectorRange(1, 2));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=0,0&f=1,1").stratal, ktx::SelectorRange(0, 1));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("a=0,0&f=1,1").facial, ktx::SelectorRange(1, 2));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=0,0&m=1,1").facial, ktx::SelectorRange(0, 1));
|
||||
EXPECT_EQ(ktx::parseFragmentURI("f=0,0&m=1,1").mip, ktx::SelectorRange(1, 2));
|
||||
}
|
||||
|
||||
TEST_F(FragmentURITest, ParseMultiRange) {
|
||||
EXPECT_EQ(fmt::format("{}", ktx::parseFragmentURI("m=10,15&m=20,").mip), "10..15,20..last");
|
||||
EXPECT_EQ(fmt::format("{}", ktx::parseFragmentURI("m=0,0&m=1,1&m=10,15&m=20,").mip), "0,1,10..15,20..last");
|
||||
}
|
||||
|
||||
TEST_F(FragmentURITest, Validate) {
|
||||
EXPECT_TRUE(ktx::parseFragmentURI("m=0,0&a=1,1").validate(1, 2, 1));
|
||||
EXPECT_FALSE(ktx::parseFragmentURI("m=0,0&a=1,1").validate(1, 1, 1));
|
||||
EXPECT_FALSE(ktx::parseFragmentURI("m=0,0&a=1,1").validate(0, 0, 0));
|
||||
}
|
||||
|
||||
TEST_F(FragmentURITest, SelectorRangeToString) {
|
||||
EXPECT_EQ(fmt::format("{}", ktx::SelectorRange{0, 0}), "none");
|
||||
EXPECT_EQ(fmt::format("{}", ktx::SelectorRange{0, 1}), "0");
|
||||
EXPECT_EQ(fmt::format("{}", ktx::SelectorRange{10, 11}), "10");
|
||||
EXPECT_EQ(fmt::format("{}", ktx::SelectorRange{0, 2}), "0..1");
|
||||
EXPECT_EQ(fmt::format("{}", ktx::SelectorRange{10, 12}), "10..11");
|
||||
EXPECT_EQ(fmt::format("{}", ktx::SelectorRange{0, ktx::RangeEnd}), "all");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -0,0 +1,54 @@
|
||||
/* -*- tab-width: 4; -*- */
|
||||
/* vi: set sw=2 ts=4 expandtab: */
|
||||
// Copyright 2022-2023 The Khronos Group Inc.
|
||||
// Copyright 2022-2023 RasterGrid Kft.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include "vkformat_enum.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
extern "C" {
|
||||
VkFormat stringToVkFormat(const char* str);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
class StringToVkFormatTest : public ::testing::Test {
|
||||
protected:
|
||||
StringToVkFormatTest() {}
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
|
||||
TEST_F(StringToVkFormatTest, stringToVkFormat) {
|
||||
EXPECT_EQ(stringToVkFormat("UNDEFINED"), VK_FORMAT_UNDEFINED);
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_UNDEFINED"), VK_FORMAT_UNDEFINED);
|
||||
EXPECT_EQ(stringToVkFormat("Not a format"), VK_FORMAT_UNDEFINED);
|
||||
|
||||
EXPECT_EQ(stringToVkFormat("R4G4_UNORM_PACK8"), VK_FORMAT_R4G4_UNORM_PACK8);
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_R4G4_UNORM_PACK8"), VK_FORMAT_R4G4_UNORM_PACK8);
|
||||
|
||||
EXPECT_EQ(stringToVkFormat("R8G8B8_UNORM"), VK_FORMAT_R8G8B8_UNORM);
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_R8G8B8_UNORM"), VK_FORMAT_R8G8B8_UNORM);
|
||||
EXPECT_EQ(stringToVkFormat("R8G8B8_SNORM"), VK_FORMAT_R8G8B8_SNORM);
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_R8G8B8_SNORM"), VK_FORMAT_R8G8B8_SNORM);
|
||||
|
||||
EXPECT_EQ(stringToVkFormat("ASTC_6x6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
|
||||
EXPECT_EQ(stringToVkFormat("ASTC_6X6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
|
||||
EXPECT_EQ(stringToVkFormat("astc_6x6_unorm_block"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6x6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6X6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6X6_UNORM_BLOCK"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
|
||||
EXPECT_EQ(stringToVkFormat("vk_format_astc_6x6_unorm_block"), VK_FORMAT_ASTC_6x6_UNORM_BLOCK);
|
||||
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6x6_UNORM"), VK_FORMAT_UNDEFINED);
|
||||
EXPECT_EQ(stringToVkFormat("VK_FORMAT_ASTC_6x6_UNORM_BLOC"), VK_FORMAT_UNDEFINED);
|
||||
EXPECT_EQ(stringToVkFormat("K_FORMAT_ASTC_6x6_UNORM_BLOCK"), VK_FORMAT_UNDEFINED);
|
||||
EXPECT_EQ(stringToVkFormat("_ASTC_6x6_UNORM_BLOCK"), VK_FORMAT_UNDEFINED);
|
||||
EXPECT_EQ(stringToVkFormat("STC_6x6_UNORM_BLOCK"), VK_FORMAT_UNDEFINED);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,268 @@
|
||||
|
||||
/***************************** Do not edit. *****************************
|
||||
Automatically generated from vulkan_core.h version 287 by mkvkformatfiles.
|
||||
*************************************************************************/
|
||||
|
||||
/*
|
||||
** Copyright 2015-2024 The Khronos Group Inc.
|
||||
**
|
||||
** SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
VK_FORMAT_R4G4_UNORM_PACK8,
|
||||
VK_FORMAT_R4G4B4A4_UNORM_PACK16,
|
||||
VK_FORMAT_B4G4R4A4_UNORM_PACK16,
|
||||
VK_FORMAT_R5G6B5_UNORM_PACK16,
|
||||
VK_FORMAT_B5G6R5_UNORM_PACK16,
|
||||
VK_FORMAT_R5G5B5A1_UNORM_PACK16,
|
||||
VK_FORMAT_B5G5R5A1_UNORM_PACK16,
|
||||
VK_FORMAT_A1R5G5B5_UNORM_PACK16,
|
||||
VK_FORMAT_R8_UNORM,
|
||||
VK_FORMAT_R8_SNORM,
|
||||
VK_FORMAT_R8_USCALED,
|
||||
VK_FORMAT_R8_SSCALED,
|
||||
VK_FORMAT_R8_UINT,
|
||||
VK_FORMAT_R8_SINT,
|
||||
VK_FORMAT_R8_SRGB,
|
||||
VK_FORMAT_R8G8_UNORM,
|
||||
VK_FORMAT_R8G8_SNORM,
|
||||
VK_FORMAT_R8G8_USCALED,
|
||||
VK_FORMAT_R8G8_SSCALED,
|
||||
VK_FORMAT_R8G8_UINT,
|
||||
VK_FORMAT_R8G8_SINT,
|
||||
VK_FORMAT_R8G8_SRGB,
|
||||
VK_FORMAT_R8G8B8_UNORM,
|
||||
VK_FORMAT_R8G8B8_SNORM,
|
||||
VK_FORMAT_R8G8B8_USCALED,
|
||||
VK_FORMAT_R8G8B8_SSCALED,
|
||||
VK_FORMAT_R8G8B8_UINT,
|
||||
VK_FORMAT_R8G8B8_SINT,
|
||||
VK_FORMAT_R8G8B8_SRGB,
|
||||
VK_FORMAT_B8G8R8_UNORM,
|
||||
VK_FORMAT_B8G8R8_SNORM,
|
||||
VK_FORMAT_B8G8R8_USCALED,
|
||||
VK_FORMAT_B8G8R8_SSCALED,
|
||||
VK_FORMAT_B8G8R8_UINT,
|
||||
VK_FORMAT_B8G8R8_SINT,
|
||||
VK_FORMAT_B8G8R8_SRGB,
|
||||
VK_FORMAT_R8G8B8A8_UNORM,
|
||||
VK_FORMAT_R8G8B8A8_SNORM,
|
||||
VK_FORMAT_R8G8B8A8_USCALED,
|
||||
VK_FORMAT_R8G8B8A8_SSCALED,
|
||||
VK_FORMAT_R8G8B8A8_UINT,
|
||||
VK_FORMAT_R8G8B8A8_SINT,
|
||||
VK_FORMAT_R8G8B8A8_SRGB,
|
||||
VK_FORMAT_B8G8R8A8_UNORM,
|
||||
VK_FORMAT_B8G8R8A8_SNORM,
|
||||
VK_FORMAT_B8G8R8A8_USCALED,
|
||||
VK_FORMAT_B8G8R8A8_SSCALED,
|
||||
VK_FORMAT_B8G8R8A8_UINT,
|
||||
VK_FORMAT_B8G8R8A8_SINT,
|
||||
VK_FORMAT_B8G8R8A8_SRGB,
|
||||
VK_FORMAT_A8B8G8R8_UNORM_PACK32,
|
||||
VK_FORMAT_A8B8G8R8_SNORM_PACK32,
|
||||
VK_FORMAT_A8B8G8R8_USCALED_PACK32,
|
||||
VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
|
||||
VK_FORMAT_A8B8G8R8_UINT_PACK32,
|
||||
VK_FORMAT_A8B8G8R8_SINT_PACK32,
|
||||
VK_FORMAT_A8B8G8R8_SRGB_PACK32,
|
||||
VK_FORMAT_A2R10G10B10_UNORM_PACK32,
|
||||
VK_FORMAT_A2R10G10B10_SNORM_PACK32,
|
||||
VK_FORMAT_A2R10G10B10_USCALED_PACK32,
|
||||
VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
|
||||
VK_FORMAT_A2R10G10B10_UINT_PACK32,
|
||||
VK_FORMAT_A2R10G10B10_SINT_PACK32,
|
||||
VK_FORMAT_A2B10G10R10_UNORM_PACK32,
|
||||
VK_FORMAT_A2B10G10R10_SNORM_PACK32,
|
||||
VK_FORMAT_A2B10G10R10_USCALED_PACK32,
|
||||
VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
|
||||
VK_FORMAT_A2B10G10R10_UINT_PACK32,
|
||||
VK_FORMAT_A2B10G10R10_SINT_PACK32,
|
||||
VK_FORMAT_R16_UNORM,
|
||||
VK_FORMAT_R16_SNORM,
|
||||
VK_FORMAT_R16_USCALED,
|
||||
VK_FORMAT_R16_SSCALED,
|
||||
VK_FORMAT_R16_UINT,
|
||||
VK_FORMAT_R16_SINT,
|
||||
VK_FORMAT_R16_SFLOAT,
|
||||
VK_FORMAT_R16G16_UNORM,
|
||||
VK_FORMAT_R16G16_SNORM,
|
||||
VK_FORMAT_R16G16_USCALED,
|
||||
VK_FORMAT_R16G16_SSCALED,
|
||||
VK_FORMAT_R16G16_UINT,
|
||||
VK_FORMAT_R16G16_SINT,
|
||||
VK_FORMAT_R16G16_SFLOAT,
|
||||
VK_FORMAT_R16G16B16_UNORM,
|
||||
VK_FORMAT_R16G16B16_SNORM,
|
||||
VK_FORMAT_R16G16B16_USCALED,
|
||||
VK_FORMAT_R16G16B16_SSCALED,
|
||||
VK_FORMAT_R16G16B16_UINT,
|
||||
VK_FORMAT_R16G16B16_SINT,
|
||||
VK_FORMAT_R16G16B16_SFLOAT,
|
||||
VK_FORMAT_R16G16B16A16_UNORM,
|
||||
VK_FORMAT_R16G16B16A16_SNORM,
|
||||
VK_FORMAT_R16G16B16A16_USCALED,
|
||||
VK_FORMAT_R16G16B16A16_SSCALED,
|
||||
VK_FORMAT_R16G16B16A16_UINT,
|
||||
VK_FORMAT_R16G16B16A16_SINT,
|
||||
VK_FORMAT_R16G16B16A16_SFLOAT,
|
||||
VK_FORMAT_R32_UINT,
|
||||
VK_FORMAT_R32_SINT,
|
||||
VK_FORMAT_R32_SFLOAT,
|
||||
VK_FORMAT_R32G32_UINT,
|
||||
VK_FORMAT_R32G32_SINT,
|
||||
VK_FORMAT_R32G32_SFLOAT,
|
||||
VK_FORMAT_R32G32B32_UINT,
|
||||
VK_FORMAT_R32G32B32_SINT,
|
||||
VK_FORMAT_R32G32B32_SFLOAT,
|
||||
VK_FORMAT_R32G32B32A32_UINT,
|
||||
VK_FORMAT_R32G32B32A32_SINT,
|
||||
VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||
VK_FORMAT_R64_UINT,
|
||||
VK_FORMAT_R64_SINT,
|
||||
VK_FORMAT_R64_SFLOAT,
|
||||
VK_FORMAT_R64G64_UINT,
|
||||
VK_FORMAT_R64G64_SINT,
|
||||
VK_FORMAT_R64G64_SFLOAT,
|
||||
VK_FORMAT_R64G64B64_UINT,
|
||||
VK_FORMAT_R64G64B64_SINT,
|
||||
VK_FORMAT_R64G64B64_SFLOAT,
|
||||
VK_FORMAT_R64G64B64A64_UINT,
|
||||
VK_FORMAT_R64G64B64A64_SINT,
|
||||
VK_FORMAT_R64G64B64A64_SFLOAT,
|
||||
VK_FORMAT_B10G11R11_UFLOAT_PACK32,
|
||||
VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
|
||||
VK_FORMAT_D16_UNORM,
|
||||
VK_FORMAT_X8_D24_UNORM_PACK32,
|
||||
VK_FORMAT_D32_SFLOAT,
|
||||
VK_FORMAT_S8_UINT,
|
||||
VK_FORMAT_D16_UNORM_S8_UINT,
|
||||
VK_FORMAT_D24_UNORM_S8_UINT,
|
||||
VK_FORMAT_D32_SFLOAT_S8_UINT,
|
||||
VK_FORMAT_BC1_RGB_UNORM_BLOCK,
|
||||
VK_FORMAT_BC1_RGB_SRGB_BLOCK,
|
||||
VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
|
||||
VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
|
||||
VK_FORMAT_BC2_UNORM_BLOCK,
|
||||
VK_FORMAT_BC2_SRGB_BLOCK,
|
||||
VK_FORMAT_BC3_UNORM_BLOCK,
|
||||
VK_FORMAT_BC3_SRGB_BLOCK,
|
||||
VK_FORMAT_BC4_UNORM_BLOCK,
|
||||
VK_FORMAT_BC4_SNORM_BLOCK,
|
||||
VK_FORMAT_BC5_UNORM_BLOCK,
|
||||
VK_FORMAT_BC5_SNORM_BLOCK,
|
||||
VK_FORMAT_BC6H_UFLOAT_BLOCK,
|
||||
VK_FORMAT_BC6H_SFLOAT_BLOCK,
|
||||
VK_FORMAT_BC7_UNORM_BLOCK,
|
||||
VK_FORMAT_BC7_SRGB_BLOCK,
|
||||
VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
|
||||
VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
|
||||
VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
|
||||
VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
|
||||
VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
|
||||
VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
|
||||
VK_FORMAT_EAC_R11_UNORM_BLOCK,
|
||||
VK_FORMAT_EAC_R11_SNORM_BLOCK,
|
||||
VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
|
||||
VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
|
||||
VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
|
||||
VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
|
||||
VK_FORMAT_G8B8G8R8_422_UNORM,
|
||||
VK_FORMAT_B8G8R8G8_422_UNORM,
|
||||
VK_FORMAT_R10X6_UNORM_PACK16,
|
||||
VK_FORMAT_R10X6G10X6_UNORM_2PACK16,
|
||||
VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16,
|
||||
VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16,
|
||||
VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16,
|
||||
VK_FORMAT_R12X4_UNORM_PACK16,
|
||||
VK_FORMAT_R12X4G12X4_UNORM_2PACK16,
|
||||
VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16,
|
||||
VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16,
|
||||
VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16,
|
||||
VK_FORMAT_G16B16G16R16_422_UNORM,
|
||||
VK_FORMAT_B16G16R16G16_422_UNORM,
|
||||
VK_FORMAT_A4R4G4B4_UNORM_PACK16,
|
||||
VK_FORMAT_A4B4G4R4_UNORM_PACK16,
|
||||
VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_5x4_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_5x5_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_6x5_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_6x6_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_8x5_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_8x6_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_8x8_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_10x5_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_10x6_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_10x8_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_10x10_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_12x10_SFLOAT_BLOCK,
|
||||
VK_FORMAT_ASTC_12x12_SFLOAT_BLOCK,
|
||||
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG,
|
||||
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG,
|
||||
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG,
|
||||
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG,
|
||||
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG,
|
||||
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG,
|
||||
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG,
|
||||
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG,
|
||||
VK_FORMAT_ASTC_3x3x3_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_3x3x3_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_3x3x3_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x3x3_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x3x3_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x3x3_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x4x3_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x4x3_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x4x3_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x4x4_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x4x4_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_4x4x4_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x4x4_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x4x4_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x4x4_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x5x4_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x5x4_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x5x4_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x5x5_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x5x5_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_5x5x5_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x5x5_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x5x5_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x5x5_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x6x5_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x6x5_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x6x5_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x6x6_UNORM_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x6x6_SRGB_BLOCK_EXT,
|
||||
VK_FORMAT_ASTC_6x6x6_SFLOAT_BLOCK_EXT,
|
||||
VK_FORMAT_R16G16_SFIXED5_NV,
|
||||
VK_FORMAT_A1B5G5R5_UNORM_PACK16_KHR,
|
||||
VK_FORMAT_A8_UNORM_KHR,
|
||||
|
||||
|
||||
@@ -0,0 +1,437 @@
|
||||
/* -*- tab-width: 4; -*- */
|
||||
/* vi: set sw=2 ts=4 expandtab: */
|
||||
|
||||
/*
|
||||
* Copyright 2018-2020 Mark Callow.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @file
|
||||
* @~English
|
||||
*
|
||||
* @brief Helper class for writer tests.
|
||||
*
|
||||
* @author Mark Callow, github.com/MarkCallow
|
||||
*/
|
||||
|
||||
#include "gl_format.h"
|
||||
#include "vkformat_enum.h"
|
||||
#include "vk_format.h"
|
||||
#include "ktx.h"
|
||||
extern "C" {
|
||||
#include "ktxint.h"
|
||||
#include "texture2.h"
|
||||
}
|
||||
#include "unused.h"
|
||||
|
||||
struct wthImageInfo {
|
||||
GLsizei size; // Size of the image data in bytes.
|
||||
GLubyte* data; // Pointer to the image data.
|
||||
};
|
||||
|
||||
class wthTexInfo : public ktxTextureCreateInfo {
|
||||
public:
|
||||
ktx_uint32_t glTypeSize;
|
||||
ktx_uint32_t glType;
|
||||
ktx_uint32_t glFormat;
|
||||
ktx_uint32_t glBaseInternalformat;
|
||||
ktx_uint32_t headerPixelHeight;
|
||||
ktx_uint32_t headerPixelDepth;
|
||||
ktx_uint32_t headerNumLayers;
|
||||
};
|
||||
|
||||
extern "C" KTX_error_code appendLibId(ktxHashList* head,
|
||||
ktxHashListEntry* writerEntry);
|
||||
|
||||
/**
|
||||
* @internal @~English
|
||||
* @brief Template class for creating writer test helpers.
|
||||
*
|
||||
* @tparam component_type the primitive type of a color component.
|
||||
* @tparam numComponents the number of components in a color.
|
||||
* @tparam internalformat the OpenGL internal format enum for the color.
|
||||
*/
|
||||
template<typename component_type,
|
||||
ktx_uint32_t numComponents, GLenum internalformat>
|
||||
class WriterTestHelper {
|
||||
public:
|
||||
enum createFlagBits {
|
||||
eNone = 0x00,
|
||||
eMipmapped = 0x01,
|
||||
eGenerateMipmaps = 0x02,
|
||||
eArray = 0x04
|
||||
};
|
||||
typedef ktx_uint32_t createFlags;
|
||||
|
||||
WriterTestHelper() : writer_ktx2("WriteTestHelper 1.0 __default__") {
|
||||
|
||||
}
|
||||
|
||||
~WriterTestHelper() {
|
||||
ktxHashList_Destruct(&kvHash);
|
||||
ktxHashList_Destruct(&kvHash_ktx2);
|
||||
}
|
||||
|
||||
void resize(createFlags flags,
|
||||
ktx_uint32_t layers, ktx_uint32_t faces,
|
||||
ktx_uint32_t dimensions,
|
||||
ktx_uint32_t w, ktx_uint32_t h, ktx_uint32_t d,
|
||||
std::vector<component_type>* requestedColor = nullptr)
|
||||
{
|
||||
assert(faces == 1 || d == 1);
|
||||
assert(requestedColor == nullptr || requestedColor->size() >= numComponents);
|
||||
|
||||
this->width = w;
|
||||
this->height = h;
|
||||
this->depth = d;
|
||||
numLevels = flags & eMipmapped? levelsFromSize(w, h, d): 1;
|
||||
this->numLayers = layers;
|
||||
this->numFaces=faces;
|
||||
isArray = flags & eArray ? true : false;
|
||||
texinfo.resize(numLevels, layers, faces, dimensions,
|
||||
isArray, w, h, d);
|
||||
|
||||
// Create the image set.
|
||||
imageDataSize = 0;
|
||||
images.resize(numLevels);
|
||||
imageList.resize(numLevels * numLayers * numFaces * depth);
|
||||
std::vector<component_type> color;
|
||||
color.resize(numComponents);
|
||||
if (requestedColor != nullptr) {
|
||||
for (ktx_uint32_t i = 0; i < numComponents; i++) {
|
||||
color[i] = (*requestedColor)[i];
|
||||
}
|
||||
}
|
||||
for (ktx_uint32_t level = 0, count = 0; level < numLevels; level++) {
|
||||
ktx_uint32_t levelWidth = MAX(1, width >> level);
|
||||
ktx_uint32_t levelHeight = MAX(1, height >> level);
|
||||
ktx_uint32_t levelDepth = MAX(1, depth >> level);
|
||||
images[level].resize(numLayers);
|
||||
for (ktx_uint32_t layer = 0; layer < numLayers; layer++) {
|
||||
ktx_uint32_t numImages = numFaces == 6 ? numFaces : levelDepth;
|
||||
images[level][layer].resize(numImages);
|
||||
for (ktx_uint32_t faceSlice = 0; faceSlice < numImages; faceSlice++) {
|
||||
ktx_uint32_t componentCount, pixelCount;
|
||||
pixelCount = levelWidth * levelHeight;
|
||||
componentCount = pixelCount * numComponents;
|
||||
images[level][layer][faceSlice].resize(componentCount);
|
||||
// Using std::vector avoids warnings in the following
|
||||
// switch due to access past the end of the array, if we
|
||||
// were using an array and numComponents < 4.
|
||||
if (requestedColor == nullptr) {
|
||||
switch (numComponents) {
|
||||
case 4:
|
||||
color[3] = (component_type)0.5;
|
||||
FALLTHROUGH;
|
||||
case 3:
|
||||
color[2] = (component_type)faceSlice;
|
||||
FALLTHROUGH;
|
||||
case 2:
|
||||
color[1] = (component_type)layer;
|
||||
FALLTHROUGH;
|
||||
case 1:
|
||||
color[0] = (component_type)level;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (ktx_uint32_t i = 0; i < pixelCount; i++) {
|
||||
for (ktx_uint32_t j = 0; j < numComponents; j++) {
|
||||
ktx_uint32_t ci = i * numComponents + j;
|
||||
images[level][layer][faceSlice][ci] = color[j];
|
||||
}
|
||||
}
|
||||
imageList[count].size
|
||||
= pixelCount * numComponents * sizeof(component_type);
|
||||
imageDataSize += imageList[count].size;
|
||||
imageList[count++].data
|
||||
= (GLubyte*)images[level][layer][faceSlice].data();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (dimensions) {
|
||||
case 1:
|
||||
assert(strlen(KTX_ORIENTATION1_FMT) < sizeof(orientation));
|
||||
snprintf(orientation, sizeof(orientation), KTX_ORIENTATION1_FMT,
|
||||
'r');
|
||||
break;
|
||||
case 2:
|
||||
assert(strlen(KTX_ORIENTATION2_FMT) < sizeof(orientation));
|
||||
snprintf(orientation, sizeof(orientation), KTX_ORIENTATION2_FMT,
|
||||
'r', 'd');
|
||||
break;
|
||||
case 3:
|
||||
assert(strlen(KTX_ORIENTATION3_FMT) < sizeof(orientation));
|
||||
snprintf(orientation, sizeof(orientation), KTX_ORIENTATION3_FMT,
|
||||
'r', 'd', 'i');
|
||||
break;
|
||||
}
|
||||
assert(4 <= sizeof(orientation_ktx2));
|
||||
orientation_ktx2[0] = 'r';
|
||||
orientation_ktx2[1] = 'd';
|
||||
orientation_ktx2[2] = 'i';
|
||||
orientation_ktx2[3] = 0;
|
||||
orientation_ktx2[dimensions] = 0; // Ensure terminating NULL.
|
||||
|
||||
ktxHashList_Construct(&kvHash);
|
||||
ktxHashList_AddKVPair(&kvHash, KTX_ORIENTATION_KEY,
|
||||
(unsigned int)strlen(orientation) + 1,
|
||||
orientation);
|
||||
ktxHashList_Serialize(&kvHash, &kvDataLen, &kvData);
|
||||
|
||||
|
||||
ktxHashList_Construct(&kvHash_ktx2);
|
||||
ktxHashList_AddKVPair(&kvHash_ktx2, KTX_WRITER_KEY,
|
||||
(ktx_uint32_t)writer_ktx2.size(),
|
||||
writer_ktx2.data());
|
||||
|
||||
// Get the library to add its Id to the writer key so it will be
|
||||
// included in the serialized data.
|
||||
ktxHashListEntry* pWriter;
|
||||
ktxHashList_FindEntry(&kvHash_ktx2, KTX_WRITER_KEY,
|
||||
&pWriter);
|
||||
appendLibId(&kvHash_ktx2, pWriter);
|
||||
|
||||
ktxHashList_Serialize(&kvHash_ktx2, &kvDataLenWriter_ktx2, &kvDataWriter_ktx2);
|
||||
ktxHashList_AddKVPair(&kvHash_ktx2, KTX_ORIENTATION_KEY,
|
||||
dimensions + 1,
|
||||
orientation_ktx2);
|
||||
ktxHashList_Sort(&kvHash_ktx2);
|
||||
ktxHashList_Serialize(&kvHash_ktx2, &kvDataLenAll_ktx2, &kvDataAll_ktx2);
|
||||
}
|
||||
|
||||
// Compare the raw images, which are tightly packed, with potentially
|
||||
// row padded images from KTX texture.
|
||||
bool compareRawImages(ktx_uint8_t* pData) {
|
||||
for (ktx_uint32_t level = 0; level < numLevels; level++) {
|
||||
ktx_uint32_t faceLodSize = *(ktx_uint32_t*)pData;
|
||||
ktx_uint32_t levelWidth = MAX(1, width >> level);
|
||||
ktx_uint32_t levelHeight = MAX(1, height >> level);
|
||||
ktx_uint32_t levelDepth = MAX(1, depth >> level);
|
||||
ktx_uint32_t numImages;
|
||||
ktx_uint32_t rowPadding;
|
||||
ktx_size_t paddedImageBytes;
|
||||
ktx_size_t paddedRowBytes, rowBytes;
|
||||
ktx_size_t expectedFaceLodSize;
|
||||
|
||||
rowBytes = levelWidth
|
||||
* sizeof(component_type)
|
||||
* numComponents;
|
||||
rowPadding = 3 - ((rowBytes + KTX_GL_UNPACK_ALIGNMENT-1) % KTX_GL_UNPACK_ALIGNMENT);
|
||||
paddedRowBytes = rowBytes + rowPadding;
|
||||
paddedImageBytes = paddedRowBytes * levelHeight;
|
||||
if (numFaces == 6 && !isArray) {
|
||||
// Non-array cubemap.
|
||||
numImages = numFaces;
|
||||
expectedFaceLodSize = paddedImageBytes;
|
||||
} else {
|
||||
numImages = numFaces == 6 ? numFaces : levelDepth;
|
||||
expectedFaceLodSize = paddedImageBytes * numImages * numLayers;
|
||||
}
|
||||
if (faceLodSize != expectedFaceLodSize)
|
||||
return false;
|
||||
pData += sizeof(ktx_uint32_t);
|
||||
for (ktx_uint32_t layer = 0; layer < numLayers; layer++) {
|
||||
for (ktx_uint32_t faceSlice = 0; faceSlice < numImages; faceSlice++) {
|
||||
if (rowPadding == 0) {
|
||||
if (memcmp(images[level][layer][faceSlice].data(),
|
||||
pData,
|
||||
images[level][layer][faceSlice].size() * sizeof(component_type)))
|
||||
return false;
|
||||
pData += paddedImageBytes;
|
||||
} else {
|
||||
ktx_uint8_t* pImage = (ktx_uint8_t*)images[level][layer][faceSlice].data();
|
||||
for (ktx_uint32_t row = 0; row < levelHeight; row++) {
|
||||
if (memcmp(pImage, pData, rowBytes))
|
||||
return false;
|
||||
pImage += rowBytes;
|
||||
pData += paddedRowBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Compare the raw images, which are tightly packed, with the images from
|
||||
// a KTX 2 texture, which are also tightly packed but have reversed order
|
||||
// for mip levels.
|
||||
bool compareRawImages(ktxLevelIndexEntry levelIndex[], ktx_uint8_t* baseAddr) {
|
||||
for (ktx_uint32_t level = 0; level < numLevels; level++) {
|
||||
ktx_uint64_t levelSize = levelIndex[level].uncompressedByteLength;
|
||||
ktx_uint32_t levelDepth = MAX(1, depth >> level);
|
||||
ktx_uint32_t numImages;
|
||||
ktx_size_t imageBytes;
|
||||
ktx_size_t expectedLevelSize;
|
||||
|
||||
imageBytes = images[level][0][0].size() * sizeof(component_type);
|
||||
numImages = numFaces == 6 ? numFaces : levelDepth;
|
||||
expectedLevelSize = imageBytes * numImages * numLayers;
|
||||
|
||||
if (levelSize != expectedLevelSize)
|
||||
return false;
|
||||
|
||||
ktx_uint8_t* pData = baseAddr + levelIndex[level].byteOffset;
|
||||
for (ktx_uint32_t layer = 0; layer < numLayers; layer++) {
|
||||
for (ktx_uint32_t faceSlice = 0; faceSlice < numImages; faceSlice++) {
|
||||
#if 0 //DUMP_IMAGE
|
||||
fprintf(stdout, "Reading level %d, layer %d, faceSlice %d at offset %#" PRIx64 "\n",
|
||||
level, layer, faceSlice, levelIndex[level].offset);
|
||||
for (ktx_uint32_t i = 0; i < imageBytes; i++)
|
||||
fprintf(stdout, "%#x, ", *(pData + i));
|
||||
fprintf(stdout, "\n");
|
||||
#endif
|
||||
|
||||
if (memcmp(images[level][layer][faceSlice].data(), pData,
|
||||
imageBytes))
|
||||
return false;
|
||||
pData += imageBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
KTX_error_code
|
||||
copyImagesToTexture(ktxTexture* texture) {
|
||||
KTX_error_code result = KTX_SUCCESS;
|
||||
|
||||
for (ktx_uint32_t level = 0; level < images.size(); level++) {
|
||||
for (ktx_uint32_t layer = 0; layer < images[level].size(); layer++) {
|
||||
for (ktx_uint32_t faceSlice = 0; faceSlice < images[level][layer].size(); faceSlice++) {
|
||||
ktx_size_t imageBytes = images[level][layer][faceSlice].size() * sizeof(component_type);
|
||||
ktx_uint8_t* imageDataPtr = (ktx_uint8_t*)(images[level][layer][faceSlice].data());
|
||||
result = ktxTexture_SetImageFromMemory(texture,
|
||||
level, layer,
|
||||
faceSlice,
|
||||
imageDataPtr,
|
||||
imageBytes);
|
||||
if (result != KTX_SUCCESS)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static ktx_uint32_t
|
||||
levelsFromSize(ktx_uint32_t width, ktx_uint32_t height, ktx_uint32_t depth) {
|
||||
ktx_uint32_t mipLevels;
|
||||
ktx_uint32_t max_dim = MAX(MAX(width, height), depth);
|
||||
for (mipLevels = 1; max_dim != 1; mipLevels++, max_dim >>= 1) { }
|
||||
return mipLevels;
|
||||
}
|
||||
|
||||
ktx_uint32_t numLevels;
|
||||
ktx_uint32_t numLayers;
|
||||
ktx_uint32_t numFaces;
|
||||
ktx_uint32_t width;
|
||||
ktx_uint32_t height;
|
||||
ktx_uint32_t depth;
|
||||
bool isArray;
|
||||
|
||||
ktx_uint8_t* kvData;
|
||||
ktx_uint32_t kvDataLen;
|
||||
char orientation[15];
|
||||
|
||||
ktx_uint8_t* kvDataWriter_ktx2;
|
||||
ktx_uint32_t kvDataLenWriter_ktx2;
|
||||
ktx_uint8_t* kvDataAll_ktx2;
|
||||
ktx_uint32_t kvDataLenAll_ktx2;
|
||||
ktxHashList kvHash;
|
||||
ktxHashList kvHash_ktx2;
|
||||
char orientation_ktx2[4];
|
||||
std::string writer_ktx2;
|
||||
std::string comparisonWriter_ktx2;
|
||||
|
||||
ktx_size_t imageDataSize;
|
||||
std::vector< std::vector < std::vector < std::vector<component_type> > > > images;
|
||||
std::vector<wthImageInfo> imageList;
|
||||
|
||||
class texinfo : public wthTexInfo {
|
||||
public:
|
||||
texinfo() {
|
||||
glType = glGetTypeFromInternalFormat(internalformat);
|
||||
glTypeSize = glGetTypeSizeFromType(glType);
|
||||
glFormat = glGetFormatFromInternalFormat(internalformat);
|
||||
glInternalformat = internalformat;
|
||||
glBaseInternalformat = glFormat;
|
||||
}
|
||||
|
||||
void resize(GLuint levels, GLuint layers, GLuint faces,
|
||||
GLuint dimensions, bool array,
|
||||
GLsizei width, GLsizei height, GLsizei depth) {
|
||||
this->numLayers = layers;
|
||||
this->numFaces = faces;
|
||||
this->numLevels = levels;
|
||||
this->numDimensions = dimensions;
|
||||
this->generateMipmaps = false;
|
||||
this->isArray = array;
|
||||
baseWidth = width;
|
||||
baseHeight = height;
|
||||
baseDepth = depth;
|
||||
headerNumLayers = isArray ? numLayers: 0;
|
||||
headerPixelHeight = numDimensions >= 2 ? height : 0;
|
||||
headerPixelDepth = numDimensions == 3 ? depth : 0;
|
||||
}
|
||||
|
||||
bool compare(KTX_header* header) {
|
||||
if (header->glType == glType
|
||||
&& header->glTypeSize == glTypeSize
|
||||
&& header->glFormat == glFormat
|
||||
&& header->glInternalformat == glInternalformat
|
||||
&& header->glBaseInternalformat == glBaseInternalformat
|
||||
&& header->pixelWidth == baseWidth
|
||||
&& header->pixelHeight == headerPixelHeight
|
||||
&& header->pixelDepth == headerPixelDepth
|
||||
&& header->numberOfArrayElements == headerNumLayers
|
||||
&& header->numberOfFaces == numFaces
|
||||
&& header->numberOfMipLevels == numLevels)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool compare(KTX_header2* header) {
|
||||
VkFormat format =
|
||||
vkGetFormatFromOpenGLInternalFormat(glInternalformat);
|
||||
|
||||
// Should find better way to test this. Code we're testing uses the
|
||||
// same switch to convert format.
|
||||
if (header->vkFormat == (ktx_uint32_t)format
|
||||
&& header->pixelWidth == baseWidth
|
||||
&& header->pixelHeight == headerPixelHeight
|
||||
&& header->pixelDepth == headerPixelDepth
|
||||
&& header->layerCount == headerNumLayers
|
||||
&& header->faceCount == numFaces
|
||||
&& header->levelCount == numLevels
|
||||
&& header->supercompressionScheme >= KTX_SS_BEGIN_RANGE
|
||||
&& header->supercompressionScheme <= KTX_SS_END_RANGE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool compare(ktxTexture2* texture) {
|
||||
VkFormat format =
|
||||
vkGetFormatFromOpenGLInternalFormat(glInternalformat);
|
||||
|
||||
if (texture->vkFormat == (ktx_uint32_t)format
|
||||
&& texture->baseWidth == baseWidth
|
||||
&& texture->baseHeight == baseHeight
|
||||
&& texture->baseDepth == baseDepth
|
||||
&& texture->numLayers == numLayers
|
||||
&& texture->numFaces == numFaces
|
||||
&& texture->numLevels == numLevels
|
||||
&& texture->supercompressionScheme >= KTX_SS_BEGIN_RANGE
|
||||
&& texture->supercompressionScheme <= KTX_SS_END_RANGE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
} texinfo;
|
||||
};
|
||||
Reference in New Issue
Block a user