19#ifndef OSD_SHADERGRAPH_H
20#define OSD_SHADERGRAPH_H
22#include <Editor/EditorWindow.h>
26#include <unordered_set>
30#include <glw/common.h>
32#include <open-cpp-utils/startup.h>
33#include <open-cpp-utils/directed_tree.h>
34#include <open-cpp-utils/any.h>
35#include <open-cpp-utils/object_pool.h>
37#include <imnode-graph/imnode_graph.h>
39#include "FileSystem/FileManager.h"
40#include <Renderer/Assets/Texture.h>
43namespace ocu = open_cpp_utils;
45#define RegisterNode(Name, Type) \
46 inline Node* Create##Type(ShaderGraph& graph, ImVec2 pos) { return new Type(graph, pos); } \
47 STARTUP(_Register##Type) { ShaderGraph::Register(Name, Create##Type); }
49namespace OpenShaderDesigner
65 using FlagT =
unsigned int;
69 , PinFlags_NoCollapse = 1 << 0
70 , PinFlags_AlwaysCollapse = 1 << 1
71 , PinFlags_NoPadding = 1 << 2
72 , PinFlags_Ambiguous = 1 << 3
75 enum InterpolationType_ : glw::enum_t
77 InterpolationType_Flat = 0
78 , InterpolationType_Screen
79 , InterpolationType_Smooth
84 inline const static ImColor Colors[PinType_COUNT] = {
85 ImColor(0x7A, 0x9F, 0x82)
86 , ImColor(0x64, 0x94, 0xAA)
87 , ImColor(0xA6, 0x3D, 0x40)
88 , ImColor(0xE9, 0xB8, 0x72)
89 , ImColor(0xFF, 0xFF, 0xFF)
92 inline static constexpr const char* TypeNames[PinType_COUNT] = {
100 inline const static std::string TypeKeywords[PinType_COUNT] = {
108 inline const static int TypeWidths[PinType_COUNT] = {
116 using Ambiguous = ocu::any<glm::int32, glm::uint32, glm::float32, glm::vec3>;
124 Pin(
const std::string& name, PinType type, FlagT flags = PinFlags_None)
130 std::string GetVarName()
const {
return std::format(
"{}_{}", Name, Ptr.Node); }
136 , NodeFlags_Const = 0x0000'0001
137 , NodeFlags_DynamicInputs = 0x0000'0002
138 , NodeFlags_DynamicOutputs = 0x0000'0004
145 ImVec2 Position = { 0, 0 };
150 ImColor Color, HoveredColor, ActiveColor;
156 std::vector<Pin> Inputs, Outputs;
166 virtual ~Node() =
default;
168 void DrawPin(
int id,
Pin& pin, ImPinDirection direction);
169 void Draw(ImGuiID
id);
171 inline virtual bool CheckConnection(
Pin*,
Pin*) {
return true; }
172 virtual void ValidateConnections() { }
175 virtual void Inspect() = 0;
176 virtual std::string GetCode()
const = 0;
179 using NodeList = ocu::object_list<Node*>;
180 using NodeId = NodeList::uuid_type;
186 glw::enum_t Interpolation;
207 NodeId AddNode(
Node* node) {
return Nodes.insert(node); }
208 void RemoveNode(NodeId node) {
if(Nodes[node]->Info.Flags & NodeFlags_Const)
return; Nodes.erase(node); }
216 inline static const std::string VersionString =
"#version 430 core";
223 void PushState() { History_.push(State_); }
224 void PopState() { State_ = History_.top(); History_.pop();}
227 const GraphState& GetState()
const {
return State_; }
230 const ShaderGraph& GetGraph()
const {
return State_.Parent; }
232 virtual void Compile() = 0;
233 virtual void View(HDRTexture::HandleType* Target) = 0;
241 std::stack<GraphState> History_;
251 struct ContextMenuItem
254 ConstructorPtr Constructor;
257 using ContextMenuHierarchy = ocu::directed_tree<ContextMenuItem>;
258 using ContextID = ContextMenuHierarchy::node;
260 static ContextMenuHierarchy& ContextMenu() {
static ContextMenuHierarchy Menu {{
"",
nullptr }};
return Menu; }
271 void DrawContextMenu();
275 void Paste(ImVec2 pos);
278 Node* FindNode(ImPinPtr ptr);
279 Node* FindNode(ImGuiID
id);
280 Pin& FindPin(ImPinPtr ptr);
282 std::string GetValue(ImPinPtr ptr);
284 void OpenShader(
ShaderAsset* asset) { Shader_ = asset; }
286 static void Register(
const std::filesystem::path& path, ConstructorPtr constructor);
292 ImVec2 ContextMenuPosition_;
293 ocu::optional<NodeId> Selected_;
EditorWindow class for wrapping ImGui window functionality.
Definition EditorWindow.h:32
Definition FileManager.h:77
Definition ShaderGraph.h:302
void DrawWindow() override
DrawWindow function for when the EditorWindow is being drawn.
Definition ShaderGraph.cpp:514
Definition ShaderGraph.h:214
Definition ShaderGraph.h:246
void OnOpen() override
OnOpen callback for when the EditorWindow is opened.
Definition ShaderGraph.cpp:222
void DrawMenu() override
DrawMenu function for when the EditorWindow Menu is being drawn.
Definition ShaderGraph.cpp:229
void DrawWindow() override
DrawWindow function for when the EditorWindow is being drawn.
Definition ShaderGraph.cpp:242
Definition ShaderGraph.h:183
Definition ShaderGraph.h:198
Definition ShaderGraph.h:142
Definition ShaderGraph.h:191
Definition ShaderGraph.h:83