Loading...
Searching...
No Matches
Texgen.hpp
1#pragma once
2#if __has_include(<score_plugin_gfx.hpp>)
3#define SCORE_JIT_HAS_TEXGEN 1
4#include <Process/Execution/ProcessComponent.hpp>
5#include <Process/GenericProcessFactory.hpp>
6#include <Process/Process.hpp>
7#include <Process/ProcessMetadata.hpp>
8#include <Process/Script/ScriptEditor.hpp>
9#include <Process/Script/ScriptProcess.hpp>
10
11#include <Scenario/Commands/ScriptEditCommand.hpp>
12
13#include <Control/DefaultEffectItem.hpp>
14#include <Effect/EffectFactory.hpp>
15#include <JitCpp/EditScript.hpp>
16
17#include <ossia/dataflow/execution_state.hpp>
18#include <ossia/dataflow/graph_node.hpp>
19#include <ossia/dataflow/node_process.hpp>
20
21#include <verdigris>
22
23namespace Jit
24{
25class TexgenModel;
26}
27PROCESS_METADATA(
28 , Jit::TexgenModel, "b9a20181-2925-4ade-925e-a2fd05fcbf9b", "Jit",
29 "Texture generator", Process::ProcessCategory::Script, "Visuals",
30 "Generate a texture", "ossia score", QStringList{}, {}, {},
31 QUrl("https://ossia.io/score-docs/processes/texgen.html#texture-generator"),
32 Process::ProcessFlags::SupportsAll)
33namespace Jit
34{
35struct Driver;
36using TexgenFunction = void(unsigned char* rgb, int width, int height, int t);
37using TexgenCompiler = Driver;
38using TexgenFactory = std::function<TexgenFunction>;
39class TexgenModel : public Process::ProcessModel
40{
41 friend class JitUI;
42 friend class JitUpdateUI;
43 SCORE_SERIALIZE_FRIENDS
44 PROCESS_METADATA_IMPL(TexgenModel)
45
46 W_OBJECT(TexgenModel)
47public:
48 TexgenModel(
49 TimeVal t, const QString& jitProgram, const Id<Process::ProcessModel>&,
50 QObject* parent);
51 ~TexgenModel() override;
52
53 TexgenModel(DataStream::Deserializer& vis, QObject* parent);
54 TexgenModel(JSONObject::Deserializer& vis, QObject* parent);
55 TexgenModel(DataStream::Deserializer&& vis, QObject* parent);
56 TexgenModel(JSONObject::Deserializer&& vis, QObject* parent);
57
58 bool validate(const QString& txt) const noexcept;
59 const QString& script() const noexcept { return m_text; }
60 [[nodiscard]] Process::ScriptChangeResult setScript(const QString& txt);
61 void scriptChanged(const QString& txt) W_SIGNAL(scriptChanged, txt);
62 void programChanged() W_SIGNAL(programChanged);
63
64 static constexpr bool hasExternalUI() noexcept { return true; }
65
66 QString prettyName() const noexcept override;
67
68 TexgenFactory factory;
69
70 void errorMessage(int line, const QString& e) W_SIGNAL(errorMessage, line, e);
71
72 PROPERTY(QString, script READ script WRITE setScript NOTIFY scriptChanged)
73private:
74 QString effect() const noexcept override;
75 void loadPreset(const Process::Preset& preset) override;
76 Process::Preset savePreset() const noexcept override;
77 void init();
78 [[nodiscard]] Process::ScriptChangeResult reload();
79 QString m_text;
80 std::unique_ptr<TexgenCompiler> m_compiler;
81};
82}
83
84namespace Process
85{
86template <>
87QString
88EffectProcessFactory_T<Jit::TexgenModel>::customConstructionData() const noexcept;
89
90template <>
91Process::Descriptor
92EffectProcessFactory_T<Jit::TexgenModel>::descriptor(QString d) const noexcept;
93template <>
94Process::Descriptor EffectProcessFactory_T<Jit::TexgenModel>::descriptor(
95 const Process::ProcessModel& d) const noexcept;
96}
97class QPlainTextEdit;
98namespace Jit
99{
100
101struct TexgenLanguageSpec
102{
103 static constexpr const char* language = "C++";
104};
105
106using TexgenEffectFactory = Process::EffectProcessFactory_T<TexgenModel>;
107using TexgenLayerFactory = Process::EffectLayerFactory_T<
108 TexgenModel, Process::DefaultEffectItem,
110 TexgenModel, TexgenModel::p_script, TexgenLanguageSpec>>;
111
112class TexgenExecutor final
113 : public Execution::ProcessComponent_T<Jit::TexgenModel, ossia::node_process>
114{
115 COMPONENT_METADATA("ec4bd3af-8d81-4d92-9b53-86a34d8108f8")
116
117public:
118 static constexpr bool is_unique = true;
119
120 TexgenExecutor(Jit::TexgenModel& proc, const Execution::Context& ctx, QObject* parent);
121 ~TexgenExecutor() override;
122};
123using TexgenExecutorFactory = Execution::ProcessComponentFactory_T<TexgenExecutor>;
124}
125
126namespace Jit
127{
128class EditTexgen : public Scenario::EditScript<TexgenModel, TexgenModel::p_script>
129{
130 SCORE_COMMAND_DECL(CommandFactoryName(), EditTexgen, "Edit a texture script")
131public:
132 using Scenario::EditScript<TexgenModel, TexgenModel::p_script>::EditScript;
133};
134
135}
136
137namespace score
138{
139template <>
140struct StaticPropertyCommand<Jit::TexgenModel::p_script> : Jit::EditTexgen
141{
142 using Jit::EditTexgen::EditTexgen;
143};
144}
145
146#endif
Definition DataStreamVisitor.hpp:202
Definition JSONVisitor.hpp:423
Definition DefaultEffectItem.hpp:26
Definition EffectFactory.hpp:67
Definition EffectFactory.hpp:14
The Process class.
Definition score-lib-process/Process/Process.hpp:61
Definition ScriptEditor.hpp:42
Definition ScriptEditCommand.hpp:18
The id_base_t class.
Definition Identifier.hpp:57
Components used for the execution of a score.
Definition ProcessComponent.cpp:12
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
Base toolkit upon which the software is built.
Definition Application.cpp:90
STL namespace.
Definition Process/Execution/ProcessComponent.hpp:89
Definition ScriptProcess.hpp:14
Definition TimeValue.hpp:21