Loading...
Searching...
No Matches
TextureToBuffer.hpp
1#pragma once
2
3#include <ossia/detail/pod_vector.hpp>
4#include <Threedim/GeometryToBufferStrategies.hpp>
5
6#include <boost/container/vector.hpp>
7
8#include <halp/controls.hpp>
9#include <halp/geometry.hpp>
10#include <halp/meta.hpp>
11#include <halp/texture.hpp>
12#include <halp/buffer.hpp>
13#include <halp/texture.hpp>
14
15namespace Threedim
16{
18{
19public:
20 halp_meta(name, "Texture to buffer")
21 halp_meta(category, "Visuals/3D")
22 halp_meta(c_name, "texture_to_buffer")
23 halp_meta(manual_url, "https://ossia.io/score-docs/processes/texture-to-buffer.html")
24 halp_meta(uuid, "fd7d6339-c745-4733-a1c2-6ebd0a25fd92")
25
26 struct ins
27 {
28 halp::texture_input<"Texture", halp::custom_variable_texture> texture;
29 } inputs;
30 struct
31 {
32 halp::gpu_buffer_output<"Buffer"> buffer;
33 } outputs;
34
35 QRhiBuffer* buf{};
36 void init(score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res)
37 {
38 outputs.buffer.buffer.handle = nullptr;
39 outputs.buffer.buffer.byte_size = 0;
40 outputs.buffer.buffer.byte_offset = 0;
41 outputs.buffer.buffer.changed = true;
42
43 if(!inputs.texture.texture.bytes)
44 return;
45 auto bytes = inputs.texture.texture.bytesize();
46
47 if(buf)
48 renderer.releaseBuffer(buf);
49 if(bytes <= 0)
50 return;
51
52 buf = renderer.state.rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer | QRhiBuffer::VertexBuffer, bytes);
53 if(!buf->create())
54 {
55 delete buf;
56 buf = nullptr;
57 return;
58 }
59
60 outputs.buffer.buffer.handle = buf;
61 outputs.buffer.buffer.byte_size = bytes;
62 outputs.buffer.buffer.byte_offset = 0;
63 outputs.buffer.buffer.changed = true;
64 }
65
66 void update(
67 score::gfx::RenderList& renderer, QRhiResourceUpdateBatch& res,
69 {
70 if(!buf || inputs.texture.texture.bytesize() != buf->size())
71 init(renderer, res);
72 }
73
74 void release(score::gfx::RenderList& r)
75 {
76 }
77
78 void runInitialPasses(
79 score::gfx::RenderList& renderer, QRhiCommandBuffer& commands,
80 QRhiResourceUpdateBatch*& res, score::gfx::Edge& edge)
81 {
82 if(!inputs.texture.texture.bytes)
83 return;
84 if(!buf)
85 return;
86 auto sz = buf->size();
87 if(inputs.texture.texture.bytesize() != sz)
88 return;
89
90
91 res->uploadStaticBuffer(
92 buf,
93 QByteArray::fromRawData((const char*)inputs.texture.texture.bytes, sz));
94 }
95};
96
97}
Definition TextureToBuffer.hpp:18
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:94
Definition TextureToBuffer.hpp:27
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:71