-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathTextureGeneratorExample.hpp
More file actions
85 lines (77 loc) · 2.41 KB
/
Copy pathTextureGeneratorExample.hpp
File metadata and controls
85 lines (77 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include <avnd/concepts/audio_port.hpp>
#include <avnd/concepts/gfx.hpp>
#include <avnd/concepts/parameter.hpp>
#include <halp/audio.hpp>
#include <halp/controls.hpp>
#include <halp/meta.hpp>
#include <halp/sample_accurate_controls.hpp>
#include <halp/texture.hpp>
namespace examples
{
/**
* The next part is about working with the video system.
*
* Note that this is a very inefficient way of doing generation / processing
* of video data, as this is done on the CPU ; this should
* only ever be used if the algorithm is not implementable as a GPU shader,
* with the ISF format that score supports.
* For instance, if you want to use some OpenCV or Dlib goodness.
*
* Note that the API is a bit more limited, as in this case the nodes
* run in the GPU processing thread, at the screen / output's frame rate, instead
* of running in the audio thread, at audio buffer rate.
*
* In particular, currently, timing information is not accessible, and it is only
* possible to have an output texture.
*/
struct TextureGeneratorExample
{
halp_meta(name, "My example texture generator")
halp_meta(c_name, "oscr_TextureGeneratorExample")
halp_meta(category, "Demo")
halp_meta(author, "<AUTHOR>")
halp_meta(description, "<DESCRIPTION>")
halp_meta(uuid, "01247f4f-6b19-458d-845d-9f7cc2d9d663")
// By know you know the drill: define inputs, outputs...
struct
{
halp::hslider_f32<"Bamboozling", halp::range{0.0001, 0.1, 0.01}> bamboozle;
} inputs;
struct
{
// See TextureFilterExample for helper types which abstract the allocation side of things
struct
{
halp_meta(name, "Out");
// This type is a view on a texture
halp::rgba_texture texture;
} image;
} outputs;
// Some place in RAM to store our pixels
halp::rgba_texture::uninitialized_bytes bytes;
TextureGeneratorExample()
{
// Allocate some initial data
bytes = halp::rgba_texture::allocate(480, 270);
for(unsigned char& c : bytes)
{
c = std::rand() % 10;
}
}
// Note that as soon as we use textures,
// we run at frame rate (e.g. 60hz) instead of audio buffer rate
// (e.g. maybe 1000hz if you have a decent enough soundcard).
void operator()()
{
// Do some magic
int k = 0;
for(unsigned char& c : bytes)
{
c += k++ * inputs.bamboozle.value;
}
// Call this when the texture changed
outputs.image.texture.update(bytes.data(), 480, 270);
}
};
}