Loading...
Searching...
No Matches
ArrayToTexture.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
14#if (!defined(__linux__) && !defined(_MSC_VER))
15#define SCORE_LIBC_HAS_FLOAT16 1
16#elif (defined(__linux__) && defined(__GLIBC__))
17#if __GLIBC_PREREQ(2, 40)
18#define SCORE_LIBC_HAS_FLOAT16 1
19#endif
20#endif
21
22// when you enter the least obvious syntax competition and your opponent is clang builtins
23#if defined(__is_identifier) && !defined(_MSC_VER)
24#if (!__is_identifier(_Float16))
25#define SCORE_COMPILER_HAS_FLOAT16 1
26#endif
27#endif
28
29namespace Threedim
30{
32{
33public:
34 halp_meta(name, "Array to texture")
35 halp_meta(category, "Visuals/Textures")
36 halp_meta(c_name, "array_to_texture")
37 halp_meta(manual_url, "https://ossia.io/score-docs/processes/array-to-texture.html")
38 halp_meta(uuid, "bb5dc513-3430-4671-8c74-2bba78e53709")
39
40 struct ins
41 {
42 struct : halp::val_port<"Input", std::vector<float>>
43 {
44 void update(ArrayToTexture& self) { self.recreate(); }
45 } in;
46 struct : halp::xy_spinboxes_i32<"Size">
47 {
48 void update(ArrayToTexture& self) { self.recreate(); }
49 } size;
50 struct : halp::enum_t<halp::custom_texture::texture_format, "Format">
51 {
52 void update(ArrayToTexture& self) { self.recreate(); }
53 } format;
54 } inputs;
55
56 struct
57 {
58 halp::texture_output<"Output", halp::custom_texture> main;
59 } outputs;
60
61 void recreate()
62 {
63 const auto format = inputs.format;
64 const auto sz = inputs.size.value;
65 outputs.main.texture.request_format = format;
66 outputs.main.create(sz.x, sz.y);
67 std::size_t to_copy = sz.x * sz.y * outputs.main.texture.components(format);
68 const auto& value = inputs.in.value;
69 to_copy = std::min(to_copy, value.size());
70
71 auto* out = outputs.main.texture.bytes;
72 using enum halp::custom_texture::texture_format;
73 switch(format)
74 {
75 case RGBA8:
76 case BGRA8:
77 case R8:
78 case RG8:
79 case RED_OR_ALPHA8:
80 case R8UI:
81 std::copy_n(value.data(), to_copy, (uint8_t*)out);
82 break;
83
84 case R16:
85 case RG16:
86 std::copy_n(value.data(), to_copy, (uint16_t*)out);
87 break;
88
89 case R32UI:
90 case RG32UI:
91 case RGBA32UI:
92 std::copy_n(value.data(), to_copy, (uint32_t*)out);
93 break;
94
95 case R32F:
96 case RGBA32F:
97 std::copy_n(value.data(), to_copy, (float*)out);
98 break;
99
100 case R16F:
101 case RGBA16F:
102
103#if (SCORE_LIBC_HAS_FLOAT16 && SCORE_COMPILER_HAS_FLOAT16)
104 std::copy_n(value.data(), to_copy, (_Float16*)out);
105#endif
106 break;
107
108 default:
109 break;
110 }
111 outputs.main.upload();
112 }
113};
114
115}
Definition ArrayToTexture.hpp:32
Definition ArrayToTexture.hpp:41