85 lines
3.5 KiB
C++
85 lines
3.5 KiB
C++
/* Copyright (c) 2021-2024, 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::VulkanSampleC
|
|
{
|
|
public:
|
|
TextureCompressionComparison() = default;
|
|
~TextureCompressionComparison() override = default;
|
|
bool prepare(const vkb::ApplicationOptions &options) 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 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);
|
|
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::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();
|