Loading...
Searching...
No Matches
ArrayToBuffer.hpp
1#pragma once
2
3#include <ossia/detail/pod_vector.hpp>
4
5#include <boost/container/vector.hpp>
6
7#include <halp/controls.hpp>
8#include <halp/geometry.hpp>
9#include <halp/meta.hpp>
10#include <halp/texture.hpp>
11
12#include <algorithm>
13
14namespace Threedim
15{
17{
18 using uninitialized_bytes = boost::container::vector<unsigned char>;
19 unsigned char* bytes;
20 int width;
21 int height;
22 enum : uint8_t
23 {
24 RGBA8,
25 BGRA8,
26 R8,
27 RG8,
28 R16,
29 RG16,
30 RED_OR_ALPHA8,
31
32 RGBA16F,
33 RGBA32F,
34 R16F,
35 R32F,
36
37 R8UI,
38 R32UI,
39 RG32UI,
40 RGBA32UI,
41 } format
42 = RGBA8;
43 bool changed;
44
45 int bytes_per_pixel() const noexcept
46 {
47 switch(format)
48 {
49 case RGBA8:
50 case BGRA8:
51 return 4 * 1;
52 case R8:
53 return 1 * 1;
54 case RG8:
55 return 2 * 1;
56 case R16:
57 return 1 * 2;
58 case RG16:
59 return 2 * 2;
60 case RED_OR_ALPHA8:
61 return 1 * 1;
62 case RGBA16F:
63 return 4 * 2;
64 case RGBA32F:
65 return 4 * 4;
66 case R16F:
67 return 1 * 2;
68 case R32F:
69 return 1 * 4;
70 case R8UI:
71 return 1 * 1;
72 case R32UI:
73 return 1 * 4;
74 case RG32UI:
75 return 2 * 4;
76 case RGBA32UI:
77 return 4 * 4;
78 default:
79 return 1;
80 }
81 }
82 auto bytesize() const noexcept { return bytes_per_pixel() * width * height; }
83 /* FIXME the allocation should not be managed by the plug-in */
84 auto allocate(int width, int height)
85 {
86 using namespace boost::container;
87 return uninitialized_bytes(bytesize(), default_init);
88 }
89
90 void update(unsigned char* data, int w, int h) noexcept
91 {
92 bytes = data;
93 width = w;
94 height = h;
95 changed = true;
96 }
97};
99{
100public:
101 halp_meta(name, "Array to texture")
102 halp_meta(category, "Visuals/Textures")
103 halp_meta(c_name, "array_to_texture")
104 halp_meta(manual_url, "https://ossia.io/score-docs/processes/array-to-texture.html")
105 halp_meta(uuid, "bb5dc513-3430-4671-8c74-2bba78e53709")
106
107 struct ins
108 {
109 struct : halp::val_port<"Input", std::vector<float>>
110 {
111 void update(ArrayToTexture& self)
112 {
113 auto sz = self.inputs.size.value;
114 self.outputs.main.create(sz.x, sz.y);
115 std::size_t to_copy = self.outputs.main.texture.bytesize() / 4;
116 to_copy = std::min(to_copy, value.size());
117 std::copy_n(value.data(), to_copy, (float*)self.outputs.main.texture.bytes);
118 self.outputs.main.upload();
119 }
120 } in;
121 halp::xy_spinboxes_i32<"Size"> size;
122 } inputs;
123
124 struct
125 {
126 halp::texture_output<"Output", custom_texture> main;
127 } outputs;
128};
129
130}
Definition ArrayToBuffer.hpp:99
Definition ArrayToBuffer.hpp:108
Definition ArrayToBuffer.hpp:17