forked from KhronosGroup/Vulkan-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture_compression_comparison.h
More file actions
87 lines (78 loc) · 3.75 KB
/
texture_compression_comparison.h
File metadata and controls
87 lines (78 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Copyright (c) 2021, Holochip
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "ktx.h"
#include "api_vulkan_sample.h"
#include "scene_graph/components/camera.h"
class TextureCompressionComparison : public vkb::VulkanSample
{
public:
TextureCompressionComparison() = default;
~TextureCompressionComparison() override = default;
bool prepare(vkb::Platform &platform) override;
void update(float delta_time) override;
void draw_gui() override;
private:
struct CompressedTexture_t
{
VkBool32 VkPhysicalDeviceFeatures::*feature_ptr{nullptr};
const char * extension_name = "";
VkFormat format = VK_FORMAT_MAX_ENUM;
ktx_transcode_fmt_e ktx_format = KTX_TTF_NOSELECTION;
const char * format_name = "";
const char * short_name = "";
bool always_supported = false;
};
struct TextureBenchmark
{
TextureBenchmark &operator+=(const TextureBenchmark &other)
{
total_bytes += other.total_bytes;
compress_time_ms += other.compress_time_ms;
frame_time_ms += other.frame_time_ms;
return *this;
}
VkDeviceSize total_bytes = 0;
float compress_time_ms = 0.f;
float frame_time_ms = 0.f;
};
struct SampleTexture
{
std::vector<uint8_t> raw_bytes;
std::unique_ptr<vkb::sg::Image> image;
TextureBenchmark benchmark;
};
private:
static const std::vector<CompressedTexture_t> & get_texture_formats();
bool is_texture_format_supported(const CompressedTexture_t &format);
void get_available_texture_formats();
void load_assets();
void create_subpass();
TextureBenchmark update_textures(const CompressedTexture_t &new_format);
std::unique_ptr<vkb::sg::Image> create_image(ktxTexture2 *ktx_texture, const std::string &name);
static std::vector<uint8_t> get_raw_image(const std::string &filename);
std::pair<std::unique_ptr<vkb::sg::Image>, TextureBenchmark> compress(const std::string &filename, CompressedTexture_t texture_format, const std::string &name);
std::vector<std::string> gui_texture_names;
std::vector<CompressedTexture_t> available_texture_formats = {};
std::unordered_map<std::string, SampleTexture> texture_raw_data;
std::vector<std::pair<vkb::sg::Texture *, std::string>> textures;
vkb::sg::Camera * camera{VK_NULL_HANDLE};
TextureBenchmark current_benchmark{};
int current_format = 0, current_gui_format = 0;
bool require_redraw = true;
};
std::unique_ptr<TextureCompressionComparison> create_texture_compression_comparison();