-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtextures.hpp
101 lines (81 loc) · 2.97 KB
/
textures.hpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Copyright (C) 2019 G'k
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#pragma once
//#include "FilesystemOperations.h"
//#include "PluginsOperations.h"
//#include "Profiles.h"
//#include "pch.h"
#include "libs/DirectXTex/DirectXTex.h"
#include <optional>
#include <wrl/client.h>
class TexturesOptimizer final
{
public:
TexturesOptimizer();
enum TextureType
{
DDS,
};
bool open(const std::string &filePath, const TextureType &type);
bool saveToFile(const std::string &filePath) const;
/*!
* \brief Decompress the current texture. It is required to use several functions.
* \return False if an error happens
*/
bool decompress();
/*!
* \brief Convenience function, that will use appropriately convertWithCompression or convertWithoutCompression
* \param format The format to use
* \return False in case of error
*/
bool convert(uint32_t adapter, const DXGI_FORMAT &format);
/*!
* \brief Compress the file using the provided compression format,
* \param format The format to use
*/
bool convertWithCompression(uint32_t adapter, const DXGI_FORMAT &format);
bool convertWithoutCompression(const DXGI_FORMAT &format);
/*!
* \brief Check if a texture is compressed
* \return True if the file is compressed
*/
bool isCompressed() const;
[[nodiscard]] bool canBeCompressed() const;
/*!
* \brief Perform various optimizations on the current texture
* \return False if an error happens
*/
bool doCPUWork(const std::optional<size_t> &tWidth,
const std::optional<size_t> &tHeight);
bool doGPUWork(uint32_t adapter);
bool resize(size_t targetWidth, size_t targetHeight);
static void fitPowerOfTwo(size_t &resultX, size_t &resultY);
bool isPowerOfTwo() const;
bool generateMipMaps();
bool canHaveMipMaps();
size_t calculateOptimalMipMapsNumber() const;
DirectX::TexMetadata getInfo() const;
static bool compareInfo(const DirectX::TexMetadata &info1, const DirectX::TexMetadata &info2);
struct TexOptOptionsResult
{
bool bNeedsResize;
bool bNeedsCompress;
bool bNeedsMipmaps;
size_t tWidth;
size_t tHeight;
};
TexOptOptionsResult processArguments(const std::optional<size_t> &tWidth,
const std::optional<size_t> &tHeight);
bool modifiedCurrentTexture = false;
bool read(const std::string& filePath, const char *data, size_t length, const TextureType &type);
private:
std::unique_ptr<DirectX::ScratchImage> _image{};
DirectX::TexMetadata _info{};
std::string _name;
TextureType _type;
Microsoft::WRL::ComPtr<ID3D11Device> _pDevice;
bool createDevice(uint32_t adapter, ID3D11Device **pDevice) const;
static bool getDXGIFactory(IDXGIFactory1 **pFactory) ;
};