nv-sgl 0.6.0__cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- include/tevclient.h +393 -0
- nv_sgl-0.6.0.dist-info/LICENSE +29 -0
- nv_sgl-0.6.0.dist-info/METADATA +21 -0
- nv_sgl-0.6.0.dist-info/RECORD +133 -0
- nv_sgl-0.6.0.dist-info/WHEEL +6 -0
- nv_sgl-0.6.0.dist-info/top_level.txt +1 -0
- sgl/__init__.py +15 -0
- sgl/__init__.pyi +6738 -0
- sgl/include/sgl/app/app.h +113 -0
- sgl/include/sgl/core/bitmap.h +302 -0
- sgl/include/sgl/core/crypto.h +89 -0
- sgl/include/sgl/core/data_type.h +46 -0
- sgl/include/sgl/core/dds_file.h +103 -0
- sgl/include/sgl/core/enum.h +201 -0
- sgl/include/sgl/core/error.h +161 -0
- sgl/include/sgl/core/file_stream.h +77 -0
- sgl/include/sgl/core/file_system_watcher.h +141 -0
- sgl/include/sgl/core/format.h +36 -0
- sgl/include/sgl/core/fwd.h +90 -0
- sgl/include/sgl/core/hash.h +45 -0
- sgl/include/sgl/core/input.h +522 -0
- sgl/include/sgl/core/logger.h +214 -0
- sgl/include/sgl/core/macros.h +184 -0
- sgl/include/sgl/core/maths.h +45 -0
- sgl/include/sgl/core/memory_mapped_file.h +112 -0
- sgl/include/sgl/core/memory_mapped_file_stream.h +32 -0
- sgl/include/sgl/core/memory_stream.h +74 -0
- sgl/include/sgl/core/object.h +683 -0
- sgl/include/sgl/core/platform.h +239 -0
- sgl/include/sgl/core/plugin.h +331 -0
- sgl/include/sgl/core/resolver.h +39 -0
- sgl/include/sgl/core/short_vector.h +141 -0
- sgl/include/sgl/core/static_vector.h +111 -0
- sgl/include/sgl/core/stream.h +54 -0
- sgl/include/sgl/core/string.h +276 -0
- sgl/include/sgl/core/struct.h +360 -0
- sgl/include/sgl/core/thread.h +28 -0
- sgl/include/sgl/core/timer.h +52 -0
- sgl/include/sgl/core/traits.h +15 -0
- sgl/include/sgl/core/type_utils.h +19 -0
- sgl/include/sgl/core/window.h +177 -0
- sgl/include/sgl/device/agility_sdk.h +24 -0
- sgl/include/sgl/device/blit.h +88 -0
- sgl/include/sgl/device/buffer_cursor.h +162 -0
- sgl/include/sgl/device/command.h +539 -0
- sgl/include/sgl/device/cuda_api.h +766 -0
- sgl/include/sgl/device/cuda_interop.h +39 -0
- sgl/include/sgl/device/cuda_utils.h +107 -0
- sgl/include/sgl/device/cursor_utils.h +129 -0
- sgl/include/sgl/device/device.h +668 -0
- sgl/include/sgl/device/device_resource.h +37 -0
- sgl/include/sgl/device/fence.h +91 -0
- sgl/include/sgl/device/formats.h +330 -0
- sgl/include/sgl/device/framebuffer.h +85 -0
- sgl/include/sgl/device/fwd.h +164 -0
- sgl/include/sgl/device/helpers.h +20 -0
- sgl/include/sgl/device/hot_reload.h +75 -0
- sgl/include/sgl/device/input_layout.h +74 -0
- sgl/include/sgl/device/kernel.h +69 -0
- sgl/include/sgl/device/memory_heap.h +155 -0
- sgl/include/sgl/device/native_formats.h +342 -0
- sgl/include/sgl/device/native_handle.h +73 -0
- sgl/include/sgl/device/native_handle_traits.h +65 -0
- sgl/include/sgl/device/pipeline.h +138 -0
- sgl/include/sgl/device/print.h +45 -0
- sgl/include/sgl/device/python/cursor_utils.h +853 -0
- sgl/include/sgl/device/query.h +52 -0
- sgl/include/sgl/device/raytracing.h +84 -0
- sgl/include/sgl/device/reflection.h +1254 -0
- sgl/include/sgl/device/resource.h +705 -0
- sgl/include/sgl/device/sampler.h +57 -0
- sgl/include/sgl/device/shader.h +516 -0
- sgl/include/sgl/device/shader_cursor.h +85 -0
- sgl/include/sgl/device/shader_object.h +94 -0
- sgl/include/sgl/device/shader_offset.h +67 -0
- sgl/include/sgl/device/shared_handle.h +12 -0
- sgl/include/sgl/device/slang_utils.h +54 -0
- sgl/include/sgl/device/swapchain.h +74 -0
- sgl/include/sgl/device/types.h +782 -0
- sgl/include/sgl/math/colorspace.h +56 -0
- sgl/include/sgl/math/constants.h +7 -0
- sgl/include/sgl/math/float16.h +146 -0
- sgl/include/sgl/math/matrix.h +6 -0
- sgl/include/sgl/math/matrix_math.h +746 -0
- sgl/include/sgl/math/matrix_types.h +207 -0
- sgl/include/sgl/math/python/primitivetype.h +33 -0
- sgl/include/sgl/math/quaternion.h +6 -0
- sgl/include/sgl/math/quaternion_math.h +484 -0
- sgl/include/sgl/math/quaternion_types.h +83 -0
- sgl/include/sgl/math/ray.h +47 -0
- sgl/include/sgl/math/scalar_math.h +249 -0
- sgl/include/sgl/math/scalar_types.h +107 -0
- sgl/include/sgl/math/vector.h +6 -0
- sgl/include/sgl/math/vector_math.h +1796 -0
- sgl/include/sgl/math/vector_types.h +336 -0
- sgl/include/sgl/python/nanobind.h +489 -0
- sgl/include/sgl/python/py_doc.h +11600 -0
- sgl/include/sgl/python/sgl_ext_pch.h +8 -0
- sgl/include/sgl/sgl.h +21 -0
- sgl/include/sgl/sgl_pch.h +6 -0
- sgl/include/sgl/stl/bit.h +377 -0
- sgl/include/sgl/tests/testing.h +54 -0
- sgl/include/sgl/ui/fwd.h +34 -0
- sgl/include/sgl/ui/imgui_config.h +43 -0
- sgl/include/sgl/ui/ui.h +71 -0
- sgl/include/sgl/ui/widgets.h +918 -0
- sgl/include/sgl/utils/python/slangpy.h +366 -0
- sgl/include/sgl/utils/renderdoc.h +50 -0
- sgl/include/sgl/utils/slangpy.h +153 -0
- sgl/include/sgl/utils/tev.h +93 -0
- sgl/include/sgl/utils/texture_loader.h +106 -0
- sgl/libgfx.so +0 -0
- sgl/libsgl.so +0 -0
- sgl/libslang-glslang.so +0 -0
- sgl/libslang.so +0 -0
- sgl/libtevclient.a +0 -0
- sgl/math/__init__.pyi +5083 -0
- sgl/platform/__init__.pyi +102 -0
- sgl/renderdoc/__init__.pyi +51 -0
- sgl/sgl_ext.cpython-313-x86_64-linux-gnu.so +0 -0
- sgl/shaders/sgl/device/blit.slang +93 -0
- sgl/shaders/sgl/device/nvapi.slang +5 -0
- sgl/shaders/sgl/device/nvapi.slangh +7 -0
- sgl/shaders/sgl/device/print.slang +445 -0
- sgl/shaders/sgl/math/constants.slang +4 -0
- sgl/shaders/sgl/math/ray.slang +29 -0
- sgl/shaders/sgl/ui/imgui.slang +49 -0
- sgl/slangpy/__init__.pyi +268 -0
- sgl/tev/__init__.pyi +108 -0
- sgl/thread/__init__.pyi +4 -0
- sgl/ui/__init__.pyi +1118 -0
- share/cmake/tevclient/tevclient-config-release.cmake +19 -0
- share/cmake/tevclient/tevclient-config.cmake +103 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/object.h"
|
6
|
+
#include "sgl/core/window.h"
|
7
|
+
|
8
|
+
#include "sgl/device/fwd.h"
|
9
|
+
#include "sgl/device/device.h"
|
10
|
+
#include "sgl/device/swapchain.h"
|
11
|
+
#include "sgl/ui/fwd.h"
|
12
|
+
|
13
|
+
#include <vector>
|
14
|
+
|
15
|
+
namespace sgl {
|
16
|
+
|
17
|
+
class AppWindow;
|
18
|
+
|
19
|
+
struct AppDesc {
|
20
|
+
/// Device to use for rendering.
|
21
|
+
/// If not provided, a default device will be created.
|
22
|
+
ref<Device> device;
|
23
|
+
};
|
24
|
+
|
25
|
+
class SGL_API App : Object {
|
26
|
+
SGL_OBJECT(App)
|
27
|
+
public:
|
28
|
+
App(AppDesc desc);
|
29
|
+
virtual ~App();
|
30
|
+
|
31
|
+
Device* device() const { return m_device; }
|
32
|
+
|
33
|
+
void run();
|
34
|
+
void run_frame();
|
35
|
+
|
36
|
+
void terminate();
|
37
|
+
|
38
|
+
void _add_window(AppWindow* window);
|
39
|
+
void _remove_window(AppWindow* window);
|
40
|
+
|
41
|
+
private:
|
42
|
+
ref<Device> m_device;
|
43
|
+
|
44
|
+
std::vector<AppWindow*> m_windows;
|
45
|
+
|
46
|
+
bool m_terminate{false};
|
47
|
+
};
|
48
|
+
|
49
|
+
struct AppWindowDesc {
|
50
|
+
App* app{nullptr};
|
51
|
+
/// Width of the window in pixels.
|
52
|
+
uint32_t width{1920};
|
53
|
+
/// Height of the window in pixels.
|
54
|
+
uint32_t height{1280};
|
55
|
+
/// Title of the window.
|
56
|
+
std::string title{"sgl"};
|
57
|
+
/// Window mode.
|
58
|
+
WindowMode mode{WindowMode::normal};
|
59
|
+
/// Whether the window is resizable.
|
60
|
+
bool resizable{true};
|
61
|
+
/// Format of the swapchain images.
|
62
|
+
Format swapchain_format{Format::bgra8_unorm_srgb};
|
63
|
+
/// Enable/disable vertical synchronization.
|
64
|
+
bool enable_vsync{false};
|
65
|
+
};
|
66
|
+
|
67
|
+
class SGL_API AppWindow : Object {
|
68
|
+
SGL_OBJECT(AppWindow)
|
69
|
+
public:
|
70
|
+
AppWindow(AppWindowDesc desc);
|
71
|
+
virtual ~AppWindow();
|
72
|
+
|
73
|
+
App* app() const { return m_app; }
|
74
|
+
Device* device() const { return m_device; }
|
75
|
+
|
76
|
+
ui::Screen* screen() const;
|
77
|
+
|
78
|
+
struct RenderContext {
|
79
|
+
Texture* swapchain_image;
|
80
|
+
Framebuffer* framebuffer;
|
81
|
+
CommandBuffer* command_buffer;
|
82
|
+
};
|
83
|
+
|
84
|
+
virtual void render(RenderContext render_context) { SGL_UNUSED(render_context); }
|
85
|
+
virtual void render_ui() { }
|
86
|
+
|
87
|
+
virtual void on_resize(uint32_t width, uint32_t height) { SGL_UNUSED(width, height); }
|
88
|
+
virtual void on_keyboard_event(const KeyboardEvent& event);
|
89
|
+
virtual void on_mouse_event(const MouseEvent& event) { SGL_UNUSED(event); }
|
90
|
+
virtual void on_gamepad_event(const GamepadEvent& event) { SGL_UNUSED(event); }
|
91
|
+
virtual void on_drop_files(std::span<const char*> files) { SGL_UNUSED(files); }
|
92
|
+
|
93
|
+
void _run_frame();
|
94
|
+
bool _should_close();
|
95
|
+
|
96
|
+
private:
|
97
|
+
void create_framebuffers();
|
98
|
+
|
99
|
+
void handle_resize(uint32_t width, uint32_t height);
|
100
|
+
void handle_keyboard_event(const KeyboardEvent& event);
|
101
|
+
void handle_mouse_event(const MouseEvent& event);
|
102
|
+
void handle_gamepad_event(const GamepadEvent& event);
|
103
|
+
void handle_drop_files(std::span<const char*> files);
|
104
|
+
|
105
|
+
App* m_app;
|
106
|
+
Device* m_device;
|
107
|
+
ref<Window> m_window;
|
108
|
+
ref<Swapchain> m_swapchain;
|
109
|
+
std::vector<ref<Framebuffer>> m_framebuffers;
|
110
|
+
ref<ui::Context> m_ui_context;
|
111
|
+
};
|
112
|
+
|
113
|
+
} // namespace sgl
|
@@ -0,0 +1,302 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
/*
|
4
|
+
This is a modified version of the bitmap.h file from Mitsuba 3.0 found at
|
5
|
+
https://github.com/mitsuba-renderer/mitsuba3/blob/master/include/mitsuba/core/bitmap.h
|
6
|
+
|
7
|
+
Original license below:
|
8
|
+
|
9
|
+
Copyright (c) 2017 Wenzel Jakob <wenzel.jakob@epfl.ch>, All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
15
|
+
list of conditions and the following disclaimer.
|
16
|
+
|
17
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
18
|
+
this list of conditions and the following disclaimer in the documentation
|
19
|
+
and/or other materials provided with the distribution.
|
20
|
+
|
21
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
22
|
+
may be used to endorse or promote products derived from this software
|
23
|
+
without specific prior written permission.
|
24
|
+
|
25
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
26
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
27
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
28
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
29
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
30
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
31
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
32
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
33
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
34
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
|
36
|
+
You are under no obligation whatsoever to provide any bug fixes, patches, or
|
37
|
+
upgrades to the features, functionality or performance of the source code
|
38
|
+
("Enhancements") to anyone; however, if you choose to make your Enhancements
|
39
|
+
available either publicly, or directly to the author of this software, without
|
40
|
+
imposing a separate written license agreement for such Enhancements, then you
|
41
|
+
hereby grant the following license: a non-exclusive, royalty-free perpetual
|
42
|
+
license to install, use, modify, prepare derivative works, incorporate into
|
43
|
+
other computer software, distribute, and sublicense such enhancements or
|
44
|
+
derivative works thereof, in binary and source code form.
|
45
|
+
*/
|
46
|
+
|
47
|
+
#pragma once
|
48
|
+
|
49
|
+
#include "sgl/core/macros.h"
|
50
|
+
#include "sgl/core/object.h"
|
51
|
+
#include "sgl/core/enum.h"
|
52
|
+
#include "sgl/core/stream.h"
|
53
|
+
#include "sgl/core/struct.h"
|
54
|
+
|
55
|
+
#include <filesystem>
|
56
|
+
#include <future>
|
57
|
+
#include <memory>
|
58
|
+
#include <span>
|
59
|
+
#include <string>
|
60
|
+
#include <vector>
|
61
|
+
|
62
|
+
namespace sgl {
|
63
|
+
|
64
|
+
class SGL_API Bitmap : public Object {
|
65
|
+
SGL_OBJECT(Bitmap)
|
66
|
+
public:
|
67
|
+
enum class FileFormat {
|
68
|
+
unknown,
|
69
|
+
auto_,
|
70
|
+
png,
|
71
|
+
jpg,
|
72
|
+
bmp,
|
73
|
+
tga,
|
74
|
+
hdr,
|
75
|
+
exr,
|
76
|
+
};
|
77
|
+
|
78
|
+
SGL_ENUM_INFO(
|
79
|
+
FileFormat,
|
80
|
+
{
|
81
|
+
{FileFormat::unknown, "unknown"},
|
82
|
+
{FileFormat::auto_, "auto"},
|
83
|
+
{FileFormat::png, "png"},
|
84
|
+
{FileFormat::jpg, "jpg"},
|
85
|
+
{FileFormat::bmp, "bmp"},
|
86
|
+
{FileFormat::tga, "tga"},
|
87
|
+
{FileFormat::hdr, "hdr"},
|
88
|
+
{FileFormat::exr, "exr"},
|
89
|
+
}
|
90
|
+
);
|
91
|
+
|
92
|
+
enum class PixelFormat {
|
93
|
+
/// Luminance only.
|
94
|
+
y,
|
95
|
+
/// Luminance + alpha.
|
96
|
+
ya,
|
97
|
+
/// Red.
|
98
|
+
r,
|
99
|
+
/// Red + green.
|
100
|
+
rg,
|
101
|
+
/// RGB.
|
102
|
+
rgb,
|
103
|
+
/// RGB + alpha.
|
104
|
+
rgba,
|
105
|
+
/// Arbitrary multi-channel.
|
106
|
+
multi_channel,
|
107
|
+
};
|
108
|
+
|
109
|
+
static constexpr uint32_t PIXEL_FORMAT_COUNT = uint32_t(PixelFormat::multi_channel) + 1;
|
110
|
+
|
111
|
+
SGL_ENUM_INFO(
|
112
|
+
PixelFormat,
|
113
|
+
{
|
114
|
+
{PixelFormat::y, "y"},
|
115
|
+
{PixelFormat::ya, "ya"},
|
116
|
+
{PixelFormat::r, "r"},
|
117
|
+
{PixelFormat::rg, "rg"},
|
118
|
+
{PixelFormat::rgb, "rgb"},
|
119
|
+
{PixelFormat::rgba, "rgba"},
|
120
|
+
{PixelFormat::multi_channel, "multi_channel"},
|
121
|
+
}
|
122
|
+
);
|
123
|
+
|
124
|
+
using ComponentType = Struct::Type;
|
125
|
+
|
126
|
+
Bitmap(
|
127
|
+
PixelFormat pixel_format,
|
128
|
+
ComponentType component_type,
|
129
|
+
uint32_t width,
|
130
|
+
uint32_t height,
|
131
|
+
uint32_t channel_count = 0,
|
132
|
+
const std::vector<std::string>& channel_names = {},
|
133
|
+
void* data = nullptr
|
134
|
+
);
|
135
|
+
|
136
|
+
Bitmap(Stream* stream, FileFormat format = FileFormat::auto_);
|
137
|
+
|
138
|
+
Bitmap(const std::filesystem::path& path, FileFormat format = FileFormat::auto_);
|
139
|
+
|
140
|
+
/// Copy constructor.
|
141
|
+
Bitmap(const Bitmap& other);
|
142
|
+
|
143
|
+
/// Move constructor.
|
144
|
+
Bitmap(Bitmap&& other);
|
145
|
+
|
146
|
+
/// Destructor.
|
147
|
+
~Bitmap();
|
148
|
+
|
149
|
+
/// Load a list of bitmaps from multiple paths. Uses multi-threading to load bitmaps in parallel.
|
150
|
+
static std::vector<ref<Bitmap>>
|
151
|
+
read_multiple(std::span<std::filesystem::path> paths, FileFormat format = FileFormat::auto_);
|
152
|
+
|
153
|
+
void write(Stream* stream, FileFormat format = FileFormat::auto_, int quality = -1) const;
|
154
|
+
void write(const std::filesystem::path& path, FileFormat format = FileFormat::auto_, int quality = -1) const;
|
155
|
+
|
156
|
+
void write_async(const std::filesystem::path& path, FileFormat format = FileFormat::auto_, int quality = -1) const;
|
157
|
+
|
158
|
+
/// The pixel format.
|
159
|
+
PixelFormat pixel_format() const { return m_pixel_format; }
|
160
|
+
|
161
|
+
/// The component type.
|
162
|
+
ComponentType component_type() const { return m_component_type; }
|
163
|
+
|
164
|
+
/// Struct describing the pixel layout.
|
165
|
+
const Struct* pixel_struct() const { return m_pixel_struct; }
|
166
|
+
|
167
|
+
/// The width of the bitmap in pixels.
|
168
|
+
uint32_t width() const { return m_width; }
|
169
|
+
|
170
|
+
/// The height of the bitmap in pixels.
|
171
|
+
uint32_t height() const { return m_height; }
|
172
|
+
|
173
|
+
/// The total number of pixels in the bitmap.
|
174
|
+
size_t pixel_count() const { return static_cast<size_t>(m_width) * m_height; }
|
175
|
+
|
176
|
+
/// The number of channels in the bitmap.
|
177
|
+
uint32_t channel_count() const { return static_cast<uint32_t>(m_pixel_struct->field_count()); }
|
178
|
+
|
179
|
+
/// The names of the channels in the bitmap.
|
180
|
+
std::vector<std::string> channel_names() const;
|
181
|
+
|
182
|
+
/// True if the bitmap is in sRGB gamma space.
|
183
|
+
bool srgb_gamma() const { return m_srgb_gamma; }
|
184
|
+
|
185
|
+
/// Set the sRGB gamma flag.
|
186
|
+
/// Note that this does not convert the pixel values, it only sets the flag and adjusts the pixel struct.
|
187
|
+
void set_srgb_gamma(bool srgb_gamma);
|
188
|
+
|
189
|
+
/// Returns true if the bitmap has an alpha channel.
|
190
|
+
bool has_alpha() const { return m_pixel_format == PixelFormat::ya || m_pixel_format == PixelFormat::rgba; }
|
191
|
+
|
192
|
+
/// The number of bytes per pixel.
|
193
|
+
size_t bytes_per_pixel() const { return m_pixel_struct->size(); }
|
194
|
+
|
195
|
+
/// The total size of the bitmap in bytes.
|
196
|
+
size_t buffer_size() const { return pixel_count() * bytes_per_pixel(); }
|
197
|
+
|
198
|
+
/// The raw image data.
|
199
|
+
void* data() { return m_data.get(); }
|
200
|
+
const void* data() const { return m_data.get(); }
|
201
|
+
|
202
|
+
/// The raw image data as uint8_t.
|
203
|
+
uint8_t* uint8_data() { return m_data.get(); }
|
204
|
+
const uint8_t* uint8_data() const { return m_data.get(); }
|
205
|
+
|
206
|
+
template<typename T>
|
207
|
+
T* data_as()
|
208
|
+
{
|
209
|
+
return reinterpret_cast<T*>(m_data.get());
|
210
|
+
}
|
211
|
+
template<typename T>
|
212
|
+
const T* data_as() const
|
213
|
+
{
|
214
|
+
return reinterpret_cast<const T*>(m_data.get());
|
215
|
+
}
|
216
|
+
|
217
|
+
/// True if bitmap is empty.
|
218
|
+
bool empty() const { return m_width == 0 || m_height == 0; }
|
219
|
+
|
220
|
+
/// Clears the bitmap to zeros.
|
221
|
+
void clear();
|
222
|
+
|
223
|
+
/// Vertically flip the bitmap.
|
224
|
+
void vflip();
|
225
|
+
|
226
|
+
/**
|
227
|
+
* \brief Split bitmap into multiple bitmaps, each containing the channels with the same prefix.
|
228
|
+
*
|
229
|
+
* For example, if the bitmap has channels `albedo.R`, `albedo.G`, `albedo.B`, `normal.R`, `normal.G`, `normal.B`,
|
230
|
+
* this function will return two bitmaps, one containing the channels `albedo.R`, `albedo.G`, `albedo.B` and the
|
231
|
+
* other containing the channels `normal.R`, `normal.G`, `normal.B`.
|
232
|
+
*
|
233
|
+
* Common pixel formats (e.g. `y`, `rgb`, `rgba`) are automatically detected and used for the split bitmaps.
|
234
|
+
*
|
235
|
+
* Any channels that do not have a prefix will be returned in the bitmap with the empty prefix.
|
236
|
+
*
|
237
|
+
* \return Returns a list of (prefix, bitmap) pairs.
|
238
|
+
*/
|
239
|
+
std::vector<std::pair<std::string, ref<Bitmap>>> split() const;
|
240
|
+
|
241
|
+
ref<Bitmap> convert(PixelFormat pixel_format, ComponentType component_type, bool srgb_gamma) const;
|
242
|
+
|
243
|
+
void convert(Bitmap* target) const;
|
244
|
+
|
245
|
+
/// Equality operator.
|
246
|
+
bool operator==(const Bitmap& other) const;
|
247
|
+
|
248
|
+
/// Inequality operator.
|
249
|
+
bool operator!=(const Bitmap& other) const { return !operator==(other); }
|
250
|
+
|
251
|
+
std::string to_string() const override;
|
252
|
+
|
253
|
+
static FileFormat detect_file_format(Stream* stream);
|
254
|
+
|
255
|
+
static void static_init();
|
256
|
+
static void static_shutdown();
|
257
|
+
|
258
|
+
private:
|
259
|
+
void rebuild_pixel_struct(uint32_t channel_count = 0, const std::vector<std::string>& channel_names = {});
|
260
|
+
|
261
|
+
void read(Stream* stream, FileFormat format);
|
262
|
+
|
263
|
+
void check_required_format(
|
264
|
+
std::string_view file_format,
|
265
|
+
std::vector<Bitmap::PixelFormat> allowed_pixel_formats,
|
266
|
+
std::vector<Bitmap::ComponentType> allowed_component_types
|
267
|
+
) const;
|
268
|
+
|
269
|
+
void read_stb(Stream* stream, const char* format, bool is_srgb, bool is_hdr);
|
270
|
+
|
271
|
+
void read_png(Stream* stream);
|
272
|
+
void write_png(Stream* stream, int compression) const;
|
273
|
+
|
274
|
+
void read_jpg(Stream* stream);
|
275
|
+
void write_jpg(Stream* stream, int quality) const;
|
276
|
+
|
277
|
+
void read_bmp(Stream* stream);
|
278
|
+
void write_bmp(Stream* stream) const;
|
279
|
+
|
280
|
+
void read_tga(Stream* stream);
|
281
|
+
void write_tga(Stream* stream) const;
|
282
|
+
|
283
|
+
void read_hdr(Stream* stream);
|
284
|
+
void write_hdr(Stream* stream) const;
|
285
|
+
|
286
|
+
void read_exr(Stream* stream);
|
287
|
+
void write_exr(Stream* stream, int quality) const;
|
288
|
+
|
289
|
+
PixelFormat m_pixel_format;
|
290
|
+
ComponentType m_component_type;
|
291
|
+
ref<Struct> m_pixel_struct;
|
292
|
+
uint32_t m_width;
|
293
|
+
uint32_t m_height;
|
294
|
+
bool m_srgb_gamma;
|
295
|
+
std::unique_ptr<uint8_t[]> m_data;
|
296
|
+
bool m_owns_data;
|
297
|
+
};
|
298
|
+
|
299
|
+
SGL_ENUM_REGISTER(Bitmap::FileFormat);
|
300
|
+
SGL_ENUM_REGISTER(Bitmap::PixelFormat);
|
301
|
+
|
302
|
+
} // namespace sgl
|
@@ -0,0 +1,89 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
|
7
|
+
#include <array>
|
8
|
+
#include <string>
|
9
|
+
#include <string_view>
|
10
|
+
#include <cstdint>
|
11
|
+
#include <cstdlib>
|
12
|
+
|
13
|
+
namespace sgl {
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Helper to compute SHA-1 hash.
|
17
|
+
*/
|
18
|
+
class SGL_API SHA1 {
|
19
|
+
public:
|
20
|
+
/// Message digest.
|
21
|
+
using Digest = std::array<uint8_t, 20>;
|
22
|
+
|
23
|
+
SHA1();
|
24
|
+
|
25
|
+
SHA1(const void* data, size_t len)
|
26
|
+
: SHA1()
|
27
|
+
{
|
28
|
+
update(data, len);
|
29
|
+
}
|
30
|
+
|
31
|
+
SHA1(std::string_view str)
|
32
|
+
: SHA1()
|
33
|
+
{
|
34
|
+
update(str);
|
35
|
+
}
|
36
|
+
|
37
|
+
SHA1(const SHA1&) = default;
|
38
|
+
SHA1(SHA1&&) = delete;
|
39
|
+
|
40
|
+
SHA1& operator=(const SHA1&) = default;
|
41
|
+
SHA1& operator=(SHA1&&) = delete;
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Update hash by adding one byte.
|
45
|
+
* \param byte Byte to hash.
|
46
|
+
*/
|
47
|
+
SHA1& update(uint8_t byte);
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Update hash by adding the given data.
|
51
|
+
* \param data Data to hash.
|
52
|
+
* \param len Length of data in bytes.
|
53
|
+
*/
|
54
|
+
SHA1& update(const void* data, size_t len);
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Update hash by adding the given string.
|
58
|
+
* \param str String to hash.
|
59
|
+
*/
|
60
|
+
SHA1& update(std::string_view str) { return update(str.data(), str.size()); }
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Update hash by adding the given basic value.
|
64
|
+
* \param value to hash.
|
65
|
+
*/
|
66
|
+
template<typename T>
|
67
|
+
SHA1& update(const T& value)
|
68
|
+
requires std::is_fundamental_v<T> || std::is_enum_v<T>
|
69
|
+
{
|
70
|
+
return update(&value, sizeof(value));
|
71
|
+
}
|
72
|
+
|
73
|
+
/// Return the message digest.
|
74
|
+
Digest digest() const;
|
75
|
+
|
76
|
+
/// Return the message digest as a hex string.
|
77
|
+
std::string hex_digest() const;
|
78
|
+
|
79
|
+
private:
|
80
|
+
void add_byte(uint8_t x);
|
81
|
+
void process_block(const uint8_t* ptr);
|
82
|
+
Digest finalize();
|
83
|
+
|
84
|
+
uint32_t m_index;
|
85
|
+
uint64_t m_bits;
|
86
|
+
uint32_t m_state[5];
|
87
|
+
uint8_t m_buf[64];
|
88
|
+
};
|
89
|
+
}; // namespace sgl
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
#include "sgl/core/enum.h"
|
7
|
+
|
8
|
+
namespace sgl {
|
9
|
+
|
10
|
+
enum class DataType {
|
11
|
+
void_,
|
12
|
+
bool_,
|
13
|
+
int8,
|
14
|
+
int16,
|
15
|
+
int32,
|
16
|
+
int64,
|
17
|
+
uint8,
|
18
|
+
uint16,
|
19
|
+
uint32,
|
20
|
+
uint64,
|
21
|
+
float16,
|
22
|
+
float32,
|
23
|
+
float64,
|
24
|
+
};
|
25
|
+
|
26
|
+
SGL_ENUM_INFO(
|
27
|
+
DataType,
|
28
|
+
{
|
29
|
+
{DataType::void_, "void"},
|
30
|
+
{DataType::bool_, "bool"},
|
31
|
+
{DataType::int8, "int8"},
|
32
|
+
{DataType::int16, "int16"},
|
33
|
+
{DataType::int32, "int32"},
|
34
|
+
{DataType::int64, "int64"},
|
35
|
+
{DataType::uint8, "uint8"},
|
36
|
+
{DataType::uint16, "uint16"},
|
37
|
+
{DataType::uint32, "uint32"},
|
38
|
+
{DataType::uint64, "uint64"},
|
39
|
+
{DataType::float16, "float16"},
|
40
|
+
{DataType::float32, "float32"},
|
41
|
+
{DataType::float64, "float64"},
|
42
|
+
}
|
43
|
+
);
|
44
|
+
SGL_ENUM_REGISTER(DataType);
|
45
|
+
|
46
|
+
} // namespace sgl
|
@@ -0,0 +1,103 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/object.h"
|
6
|
+
#include "sgl/core/enum.h"
|
7
|
+
#include "sgl/core/stream.h"
|
8
|
+
|
9
|
+
#include <filesystem>
|
10
|
+
|
11
|
+
namespace sgl {
|
12
|
+
|
13
|
+
/**
|
14
|
+
* \brief Helper class for loading DDS files.
|
15
|
+
*/
|
16
|
+
class SGL_API DDSFile : public Object {
|
17
|
+
SGL_OBJECT(DDSFile)
|
18
|
+
public:
|
19
|
+
SGL_NON_COPYABLE_AND_MOVABLE(DDSFile);
|
20
|
+
|
21
|
+
explicit DDSFile(Stream* stream);
|
22
|
+
explicit DDSFile(const std::filesystem::path& path);
|
23
|
+
~DDSFile();
|
24
|
+
|
25
|
+
enum class TextureType {
|
26
|
+
texture_1d,
|
27
|
+
texture_2d,
|
28
|
+
texture_3d,
|
29
|
+
texture_cube,
|
30
|
+
};
|
31
|
+
|
32
|
+
SGL_ENUM_INFO(
|
33
|
+
TextureType,
|
34
|
+
{
|
35
|
+
{TextureType::texture_1d, "texture_1d"},
|
36
|
+
{TextureType::texture_2d, "texture_2d"},
|
37
|
+
{TextureType::texture_3d, "texture_3d"},
|
38
|
+
{TextureType::texture_cube, "texture_cube"},
|
39
|
+
}
|
40
|
+
);
|
41
|
+
|
42
|
+
const uint8_t* data() const { return m_data; }
|
43
|
+
size_t size() const { return m_size; }
|
44
|
+
|
45
|
+
const uint8_t* resource_data() const { return m_data + m_header_size; }
|
46
|
+
size_t resource_size() const { return m_size - m_header_size; }
|
47
|
+
|
48
|
+
uint32_t dxgi_format() const { return m_dxgi_format; }
|
49
|
+
TextureType type() const { return m_type; }
|
50
|
+
|
51
|
+
uint32_t width() const { return m_width; }
|
52
|
+
uint32_t height() const { return m_height; }
|
53
|
+
uint32_t depth() const { return m_depth; }
|
54
|
+
uint32_t mip_count() const { return m_mip_count; }
|
55
|
+
uint32_t array_size() const { return m_array_size; }
|
56
|
+
|
57
|
+
uint32_t row_pitch() const { return m_row_pitch; }
|
58
|
+
uint32_t slice_pitch() const { return m_slice_pitch; }
|
59
|
+
uint32_t bits_per_pixel_or_block() const { return m_bits_per_pixel_or_block; }
|
60
|
+
uint32_t block_width() const { return m_block_width; }
|
61
|
+
uint32_t block_height() const { return m_block_height; }
|
62
|
+
bool compressed() const { return m_compressed; }
|
63
|
+
bool srgb() const { return m_srgb; }
|
64
|
+
|
65
|
+
/**
|
66
|
+
* \brief Get a pointer to the start of the data for the specified mip and slice.
|
67
|
+
*
|
68
|
+
* \param mip Mip level.
|
69
|
+
* \param slice Slice index (array index, face index or volume slice index).
|
70
|
+
* \return Pointer to the start of the data.
|
71
|
+
*/
|
72
|
+
const uint8_t* get_subresource_data(uint32_t mip, uint32_t slice);
|
73
|
+
|
74
|
+
virtual std::string to_string() const override;
|
75
|
+
|
76
|
+
static bool detect_dds_file(Stream* stream);
|
77
|
+
|
78
|
+
private:
|
79
|
+
bool decode_header(const uint8_t* data, size_t size);
|
80
|
+
|
81
|
+
uint8_t* m_data{nullptr};
|
82
|
+
size_t m_size{0};
|
83
|
+
|
84
|
+
uint32_t m_dxgi_format;
|
85
|
+
TextureType m_type;
|
86
|
+
uint32_t m_width;
|
87
|
+
uint32_t m_height;
|
88
|
+
uint32_t m_depth;
|
89
|
+
uint32_t m_mip_count;
|
90
|
+
uint32_t m_array_size;
|
91
|
+
uint32_t m_row_pitch;
|
92
|
+
uint32_t m_slice_pitch;
|
93
|
+
uint32_t m_bits_per_pixel_or_block;
|
94
|
+
uint32_t m_block_width;
|
95
|
+
uint32_t m_block_height;
|
96
|
+
bool m_compressed;
|
97
|
+
bool m_srgb;
|
98
|
+
size_t m_header_size;
|
99
|
+
};
|
100
|
+
|
101
|
+
SGL_ENUM_REGISTER(DDSFile::TextureType);
|
102
|
+
|
103
|
+
} // namespace sgl
|