Loading...
Searching...
No Matches
CubemapLoader.hpp
1#pragma once
2
3#include <halp/controls.hpp>
4#include <halp/meta.hpp>
5#include <halp/texture.hpp>
6
7#include <Gfx/Graph/RenderList.hpp>
8
9#include <QtGui/private/qrhi_p.h>
10
11#include <QImage>
12
13namespace Threedim
14{
15
16enum class CubemapLayout
17{
18 Equirectangular,
19 HorizontalCross,
20 VerticalCross,
21 HorizontalStrip,
22 VerticalStrip,
23};
24
26{
27public:
28 halp_meta(name, "Cubemap Loader")
29 halp_meta(category, "Visuals/3D")
30 halp_meta(c_name, "cubemap_loader")
31 halp_meta(
32 manual_url,
33 "https://ossia.io/score-docs/processes/cubemap-loader.html")
34 halp_meta(uuid, "b8d4f9e2-6c3a-4b0f-9e4d-2a7f0c5b3d6e")
35
36 struct ins
37 {
38 struct : halp::lineedit<"Image", "">
39 {
40 void update(CubemapLoader& self) { self.m_imageChanged = true; }
41 } image;
42
43 struct : halp::enum_t<CubemapLayout, "Layout">
44 {
45 void update(CubemapLoader& self) { self.m_imageChanged = true; }
46 } layout;
47
48 struct : halp::spinbox_i32<"Resolution", halp::range{16, 8192, 512}>
49 {
50 void update(CubemapLoader& self) { self.m_imageChanged = true; }
51 } resolution;
52 } inputs;
53
54 struct
55 {
56 halp::gpu_texture_output<"Cubemap"> cubemap;
57 } outputs;
58
59 // GPU resources
60 QRhiTexture* m_cubemapTex{};
61 QRhiTexture* m_equirectTex{};
62 QRhiSampler* m_equirectSampler{};
63
64 // Per-face render targets for equirectangular conversion
65 struct FaceRT
66 {
67 QRhiTextureRenderTarget* renderTarget{};
68 QRhiRenderPassDescriptor* renderPass{};
69 };
70 FaceRT m_faceRTs[6]{};
71 QRhiGraphicsPipeline* m_equirectPipeline{};
72 QRhiShaderResourceBindings* m_equirectSrb{};
73 QRhiBuffer* m_equirectUbo{};
74 QRhiBuffer* m_quadVbuf{};
75
76 int m_faceSize{0};
77 bool m_imageChanged{true};
78 QImage m_loadedImage;
79
80 void operator()() { }
81
82 void init(score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res);
83 void update(
84 score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res,
86 void release(score::gfx::RenderList& r);
87 void runInitialPasses(
88 score::gfx::RenderList& renderer, QRhiCommandBuffer& commands,
89 QRhiResourceUpdateBatch*& res, score::gfx::Edge& edge);
90
91private:
92 void loadImage();
93 void createCubemapTexture(QRhi& rhi, int faceSize);
94 void releaseCubemapTexture();
95 void releaseEquirectResources();
96
97 void uploadCrossOrStrip(QRhiResourceUpdateBatch* res);
98 void renderEquirectangular(
99 score::gfx::RenderList& renderer, QRhiCommandBuffer& commands,
100 QRhiResourceUpdateBatch*& res);
101
102 void setupEquirectPipeline(score::gfx::RenderList& renderer);
103
104 // Extract face from cross/strip layout
105 QImage extractFace(int faceIndex) const;
106};
107
108}
Definition CubemapLoader.hpp:26
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
Definition CubemapLoader.hpp:66
Definition CubemapLoader.hpp:37
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:75