OROCHI
 
Loading...
Searching...
No Matches
GxGuiFormShaderGraph.h
Go to the documentation of this file.
1//===========================================================================
9//===========================================================================
10#pragma once
11
12#if GX_DEVELOP
13
14GX_CORE_NAMESPACE_BEGIN()
15
16//===========================================================================
18//===========================================================================
19class GxGuiFormShaderGraph : public GxGuiForm
20{
21 //-----------------------------------------------------------
23 //-----------------------------------------------------------
25public:
26 class GxGraphNode;
27 class GxGraphNodeConst;
28 class GxGraphNodeSampler;
29 class GxGraphNodeOutput;
30 class GxGraphNodeMaterialInput;
31 class GxGraphNodeMaterialOutput;
32 class GxGraphNodeCustom;
33 class GxGraphNodeSwitch;
34 class GxGraphConnect;
35
36 //===========================================================================
38 //===========================================================================
39 class GxGraph : public GxClassBase
40 {
41 //-----------------------------------------------------------
43 //-----------------------------------------------------------
45 public:
46 GX_RTTI_CLASS(GxGraph, GxClassBase)
47 // ClassBase継承クラス用禁止宣言
49 private:
51 enum OUTPUT_TYPE
52 {
53 PARAMETER = (1 << 0),
54 SAMPLER = (1 << 1),
55 ALL = 0xFFFFFFFF,
56 };
57
59 //-----------------------------------------------------------
61 //-----------------------------------------------------------
63 public:
65 GxGraph(void) : _pNodeOutput(nullptr), _pNodeMaterialInput(nullptr) { initializeDynamicElements(); }
67 ~GxGraph(void) override;
69 void initializeDynamicElements(void);
71 void terminateDynamicElements(void);
72
74 //-----------------------------------------------------------
76 //-----------------------------------------------------------
78
80 void outputProgram(GX_CSTR outputPath, GX_CSTR resourcePath, b32 isGlsl);
82 GxString getReference(GX_CSTR outputPath, GX_CSTR resourcePath, GxArray& references, b32 isGlsl, OUTPUT_TYPE outputType) const;
84 b32 findReference(GX_CSTR name, const GxArray& references) const;
85
87 //-----------------------------------------------------------
89 //-----------------------------------------------------------
91
93 void getNodes(GxArrayClassBase& nodes, const GxRtti& rtti);
94
96 //-----------------------------------------------------------
98 //-----------------------------------------------------------
100
101 GxArrayClassBase _dynamicElements;
102 GxArrayClassBase _nodes;
103 GxArrayClassBase _inputNodes;
104 GxGraphNode* _pNodeOutput;
105 GxGraphNode* _pNodeMaterialInput;
106
108 };
109
110 GX_RTTI_CLASS(GxGuiFormShaderGraph, GxGuiForm)
111 // ClassBaseReference継承クラス用禁止宣言
112 GX_PROHIBIT_CLASS_BASE_REFERENCE(GxGuiFormShaderGraph)
113
114private:
115 static const f32 ZOOM_MIN;
116 static const f32 ZOOM_MAX;
117
119 //-----------------------------------------------------------
121 //-----------------------------------------------------------
123public:
125 GxGuiFormShaderGraph(b32 isFunction);
127 static void initializeStaticElements(void);
129 static void terminateStaticElements(void);
130private:
132 GxGuiFormShaderGraph(void) {}
133
135 //-----------------------------------------------------------
137 //-----------------------------------------------------------
139protected:
141 void update(void) override;
143 void onDraw(void) override;
145 void onMouseWheel(const GxPoint2& position, s32 rotate) override;
147 void onMouseDown(const GxPoint2& position, u32 button) override;
149 void onMouseUp(const GxPoint2& position, u32 button) override;
151 void onDoubleClick(const GxPoint2& position, u32 button) override;
153 GxGraphNode* addNode(GxShaderGraphElement* pShaderElement);
155 void removeNode(GxGraphNode* pNode);
157 GxGraphNode* getNode(const GxPoint2& position);
158private:
160 void removeSelectNode(void);
162 void removeSelectConnectAll(void);
164 void createMenu(const GxPropertyTable& propertyTable, b32 useSearchBar);
166 static void replaceStaticElements(GxGraph& graph);
167
169 //-----------------------------------------------------------
171 //-----------------------------------------------------------
173
174public:
176 void setGraph(GxGraph& graph, GxRenderMaterial::PASS pass = GxRenderMaterial::PASS::MODEL);
178 GxGraphNode* getSelectNode(void);
179private:
181 void getSelectNodes(GxArrayClassBase& nodes);
183 GX_FORCE_INLINE static f32 getZoom(void) { return _zoom; }
184
186 //-----------------------------------------------------------
188 //-----------------------------------------------------------
190private:
191 static GxPoint2 _offset;
192 static f32 _zoom;
193 static GxArrayClassBase _staticElements;
194 GxGraph* _pGraph;
195 GxGraphNode* _pDragNode;
196 GxGraphConnect* _pDragConnect;
197 GxPoint2 _dragPoint;
198 GxPoint2 _dragOffset;
199 GxPoint2 _rightClickPoint;
200 b32 _isFunction;
201
203};
204
205//===========================================================================
207//===========================================================================
208class GxGuiFormShaderGraph::GxGraphNode : public GxClassBaseReference
209{
210 //-----------------------------------------------------------
212 //-----------------------------------------------------------
214public:
215 GX_RTTI_CLASS(GxGraphNode, GxClassBaseReference)
216 // ClassBase継承クラス用禁止宣言
218
219 static constexpr u32 MIN_WIDTH = 120;
220 static constexpr u32 CHAR_WIDTH = 10;
221 static constexpr u32 NAME_HEIGHT = 16;
222 static const u32 NAME_FONT_OFFSET;
223 static constexpr u32 PARAM_RADIUS = 4;
224 static constexpr u32 PARAM_HEIGHT = 16;
225 static constexpr u32 PARAM_HEIGHT_HALF = PARAM_HEIGHT / 2;
226 static const u32 PARAM_FONT_OFFSET;
227 static const GxColor& SELECT_COLOR;
228 static const GX_CSTR OUTPUT_TEXTS[];
229 static const GxColor* OUTPUT_COLORS[];
230 static const GX_CSTR OUTPUT_COLOR_TEXTS[];
231
233 //-----------------------------------------------------------
235 //-----------------------------------------------------------
237public:
239 GxGraphNode(GxShaderGraphElement& shaderElement);
241 void cleanup(void) override;
243 virtual void initialize(void);
244protected:
246 GxGraphNode(void) : _pShaderElement(nullptr), _isSelect(false){ _delayReleaseCount = 1; }
247
249 //-----------------------------------------------------------
251 //-----------------------------------------------------------
253public:
255 virtual void render(const GxPoint2& offset);
257 void renderConnect(const GxPoint2& offset);
259 virtual void addInputConnect(GxGraphConnect& connect);
261 virtual void removeInputConnect(u32 index);
263 void addOutputConnect(GxGraphConnect& connect);
265 void removeOutputConnect(GxGraphConnect* pConnect);
267 void removeConnectAll(void);
269 GxString getProgram(const GxGraph& graph, b32 isGlsl, u32 outputIndex = 0);
271 GX_FORCE_INLINE virtual void addMenuItems(GxPropertyTable& /*propertyTable*/) {}
272private:
274 GxString getProgram(const GxGraph& graph, b32 isGlsl, GxString* pArguments, u32 outputIndex);
275
277 //-----------------------------------------------------------
279 //-----------------------------------------------------------
281public:
283 constexpr GX_CSTR getVirtualName(void) const { return _virtualName.getString(); }
285 constexpr GxShaderGraphElement* getShaderElement(void) const { return _pShaderElement; }
287 void setShaderElement(GxShaderGraphElement& shaderElement, b32 withRelease = true);
289 GX_FORCE_INLINE const GxPoint2& getPosition(void) const { return _position; }
291 GX_FORCE_INLINE void setPosition(const GxPoint2& position) { _position = position; }
293 GX_FORCE_INLINE const GxSize& getSize(void) const { return _size; }
295 GX_FORCE_INLINE void setSize(const GxSize& size) { _size = size; }
297 GX_FORCE_INLINE b32 isIncluding(const GxPoint2& position) const { return GxRect(_position, _size).isIncluding(position); }
299 b32 getConnectIndex(const GxPoint2& position, s32& outputIndex, s32& inputIndex) const;
301 GxGraphConnect* getConnect(const GxPoint2& position) const;
303 GxGraphConnect* getInputConnect(u32 index) const;
305 GxGraphConnect* getOutputConnect(u32 index) const;
307 constexpr u32 getInputConnectCount(void) const { return _inputConnects.getCount(); }
309 constexpr u32 getOutputConnectCount(void) const { return _outputConnects.getCount(); }
311 GxPoint2 getInputConnectPosition(u32 index) const;
313 GxPoint2 getOutputConnectPosition(u32 index) const;
315 GxShaderGraphElement::TYPE getInputType(u32 index) const;
317 b32 isConnectNode(GxGraphNode* pNode) const;
319 static b32 isConnectable(const GxGraphNode* pOutputNode, u32 outputIndex, const GxGraphNode* pInputNode, u32 inputIndex);
321 GX_FORCE_INLINE b32 isSelect(void) const { return _isSelect; }
323 GX_FORCE_INLINE void setSelect(b32 enable) { _isSelect = enable; }
324
326 //-----------------------------------------------------------
328 //-----------------------------------------------------------
330protected:
331 GxString _virtualName;
332 GxShaderGraphElement* _pShaderElement;
333 GxArrayClassBase _inputConnects;
334 GxArrayClassBase _defaultValues;
335 GxArrayClassBase _outputConnects;
336 GxPoint2 _position;
337 GxSize _size;
338 b32 _isSelect;
339
341};
342
343//===========================================================================
345//===========================================================================
346class GxGuiFormShaderGraph::GxGraphNodeConst : public GxGraphNode
347{
348 //-----------------------------------------------------------
350 //-----------------------------------------------------------
352public:
353 GX_RTTI_CLASS(GxGraphNodeConst, GxGraphNode)
354 // ClassBase継承クラス用禁止宣言
355 GX_PROHIBIT_CLASS_BASE_REFERENCE(GxGraphNodeConst)
356
357
358 //-----------------------------------------------------------
360 //-----------------------------------------------------------
362public:
364 GxGraphNodeConst(GxShaderGraphElement& shaderElement) : Super(shaderElement) { _value._type = shaderElement.getOutputType(); }
365private:
367 GxGraphNodeConst(void){}
368
370 //-----------------------------------------------------------
372 //-----------------------------------------------------------
374public:
376 constexpr GX_CSTR getLabel(void) const { return _label.getString(); }
378 constexpr GX_CSTR getLabel(u32 index) const { return _labels[index].getString(); }
380 GX_FORCE_INLINE const GxShaderGraphElement::GxConstValue& getValue(void) const { return _value; }
381
383 //-----------------------------------------------------------
385 //-----------------------------------------------------------
387private:
388 GxString _label;
389 GxString _labels[4];
390 GxShaderGraphElement::GxConstValue _value;
391
393};
394
395//===========================================================================
397//===========================================================================
398class GxGuiFormShaderGraph::GxGraphNodeSampler : public GxGraphNode
399{
400 //-----------------------------------------------------------
402 //-----------------------------------------------------------
404public:
405 GX_RTTI_CLASS(GxGraphNodeSampler, GxGraphNode)
406 // ClassBase継承クラス用禁止宣言
407 GX_PROHIBIT_CLASS_BASE_REFERENCE(GxGraphNodeSampler)
408private:
409 static constexpr u32 TEXTURE_SIZE = 60;
410
412 //-----------------------------------------------------------
414 //-----------------------------------------------------------
416public:
418 GxGraphNodeSampler(GxShaderGraphElement& shaderElement) : Super(shaderElement), _pResTexture(nullptr) {}
420 void initialize(void) override;
422 void cleanup(void) override;
423private:
425 GxGraphNodeSampler(void) : _pResTexture(nullptr){}
426
428 //-----------------------------------------------------------
430 //-----------------------------------------------------------
432public:
434 void render(const GxPoint2& offset) override;
435
437 //-----------------------------------------------------------
439 //-----------------------------------------------------------
441public:
443 constexpr GX_CSTR getLabel(void) const { return _label.getString(); }
445 GX_FORCE_INLINE void getPropertyTextureResource(void* const pValue) { *static_cast<GxResTexture**>(pValue) = _pResTexture; }
447 GX_FORCE_INLINE void setPropertyTextureResource(const void* const pValue) { setTextureResource(*static_cast<GxResTexture**>(const_cast<void*>(pValue))); }
449 void setTextureResource(GxResTexture* pResTexture);
450
452 //-----------------------------------------------------------
454 //-----------------------------------------------------------
456private:
457 GxString _label;
458 GxResTexture* _pResTexture;
459
461};
462
463//===========================================================================
465//===========================================================================
466class GxGuiFormShaderGraph::GxGraphNodeOutput : public GxGraphNode
467{
468 //-----------------------------------------------------------
470 //-----------------------------------------------------------
472public:
473 GX_RTTI_CLASS(GxGraphNodeOutput, GxGraphNode)
474 // ClassBase継承クラス用禁止宣言
475 GX_PROHIBIT_CLASS_BASE_REFERENCE(GxGraphNodeOutput)
476
477
478 //-----------------------------------------------------------
480 //-----------------------------------------------------------
482public:
484 GxGraphNodeOutput(GxShaderGraphElement& shaderElement);
486 void cleanup(void) override;
488 void initialize(void) override;
489protected:
491 GxGraphNodeOutput(void) : _ppFunctionLabels(nullptr), _functionLabelCount(0), _outputType(GxShaderGraphElement::TYPE::UNKNOWN){}
492
494 //-----------------------------------------------------------
496 //-----------------------------------------------------------
498public:
500 void addInputConnect(GxGraphConnect& connect) override;
502 void removeInputConnect(u32 index) override;
504 void addMenuItems(GxPropertyTable& propList) override;
505private:
507 void addFunction(void);
509 void removeFunction(void);
510
512 //-----------------------------------------------------------
514 //-----------------------------------------------------------
516public:
518 constexpr GX_CSTR getLabel(void) const { return _label.getString(); }
520 GX_FORCE_INLINE GX_CSTR getFunctionLabel(u32 index) const { return static_cast<GxString*>(_ppFunctionLabels[index])->getString(); }
522 void setOutputType(GxShaderGraphElement::TYPE type);
524 constexpr u32 getFunctionLabelCount(void) const { return _functionLabelCount; }
526 void setFunctionLabelCount(u32 count);
527private:
529 GX_FORCE_INLINE void getPropertyFunctionLabel(void* pValue, u32 index) const { *static_cast<GxString**>(pValue) = (index >= _functionLabelCount) ? nullptr : _ppFunctionLabels[index]; }
531 void setPropertyFunctionLabel(const void* pValue, u32 index);
532
534 //-----------------------------------------------------------
536 //-----------------------------------------------------------
538protected:
539 GxString _label;
540 GxString** _ppFunctionLabels;
541 u32 _functionLabelCount;
542 GxShaderGraphElement::TYPE _outputType;
543
545};
546
547//===========================================================================
549//===========================================================================
550class GxGuiFormShaderGraph::GxGraphNodeMaterialInput : public GxGraphNode
551{
552 //-----------------------------------------------------------
554 //-----------------------------------------------------------
556public:
557 GX_RTTI_CLASS(GxGraphNodeMaterialInput, GxGraphNode)
558 // ClassBase継承クラス用禁止宣言
559 GX_PROHIBIT_CLASS_BASE_REFERENCE(GxGraphNodeMaterialInput)
560
561 static const GX_CSTR OUTPUT_MATERIAL_INPUT_TEXTS[];
562
564 //-----------------------------------------------------------
566 //-----------------------------------------------------------
568public:
570 GxGraphNodeMaterialInput(GxShaderGraphElement& shaderElement);
572 void cleanup(void) override;
573protected:
575 GxGraphNodeMaterialInput(void) {}
576
578};
579
580//===========================================================================
582//===========================================================================
583class GxGuiFormShaderGraph::GxGraphNodeMaterialOutput : public GxGraphNode
584{
585 //-----------------------------------------------------------
587 //-----------------------------------------------------------
589public:
590 GX_RTTI_CLASS(GxGraphNodeMaterialOutput, GxGraphNode)
591 // ClassBase継承クラス用禁止宣言
592 GX_PROHIBIT_CLASS_BASE_REFERENCE(GxGraphNodeMaterialOutput)
593
594
595 //-----------------------------------------------------------
597 //-----------------------------------------------------------
599public:
601 GxGraphNodeMaterialOutput(GxShaderGraphElement& shaderElement);
603 void cleanup(void) override;
604protected:
606 GxGraphNodeMaterialOutput(void) {}
607
609};
610
611//===========================================================================
613//===========================================================================
614class GxGuiFormShaderGraph::GxGraphNodeCustom : public GxGraphNode
615{
616 //-----------------------------------------------------------
618 //-----------------------------------------------------------
620public:
621 GX_RTTI_CLASS(GxGraphNodeCustom, GxGraphNode)
622 // ClassBase継承クラス用禁止宣言
623 GX_PROHIBIT_CLASS_BASE_REFERENCE(GxGraphNodeCustom)
624
625
626 //-----------------------------------------------------------
628 //-----------------------------------------------------------
630public:
632 GxGraphNodeCustom(GxShaderGraphElement& shaderElement, GX_CSTR guid);
634 void cleanup(void) override;
636 void initialize(void) override;
637protected:
639 GxGraphNodeCustom(void) {}
640
642 //-----------------------------------------------------------
644 //-----------------------------------------------------------
646public:
648 constexpr GX_CSTR getMaterialFunctionGuid(void) const { return _materialFunctionGuid.getString(); }
650 constexpr void setOutputType(GxShaderGraphElement::TYPE type) { _outputType = type; }
651
653 //-----------------------------------------------------------
655 //-----------------------------------------------------------
657protected:
658 GxString _materialFunctionGuid;
659 GxShaderGraphElement::TYPE _outputType;
660
662};
663
664//===========================================================================
666//===========================================================================
667class GxGuiFormShaderGraph::GxGraphConnect : public GxClassBase
668{
669 //-----------------------------------------------------------
671 //-----------------------------------------------------------
673public:
674 GX_RTTI_CLASS(GxGraphConnect, GxClassBase)
675 // ClassBase継承クラス用禁止宣言
676 GX_PROHIBIT_CLASS_BASE(GxGraphConnect)
677
678 static constexpr u32 LINE_WIDTH = 2;
679 static constexpr u32 CURVE_THRESHOLD = 5;
680
682 //-----------------------------------------------------------
684 //-----------------------------------------------------------
686public:
688 GxGraphConnect(GxGraphNode* pOutputNode, u32 outputIndex, GxGraphNode* pInputNode, u32 inputIndex)
689 : _pOutputNode(pOutputNode), _pInputNode(pInputNode), _outputIndex(outputIndex), _inputIndex(inputIndex){}
691 ~GxGraphConnect(void) override;
692private:
694 GxGraphConnect(void) : _pOutputNode(nullptr), _pInputNode(nullptr), _outputIndex(U32_MAX), _inputIndex(U32_MAX){}
695
697 //-----------------------------------------------------------
699 //-----------------------------------------------------------
701public:
703 constexpr GxGraphNode* getOutputNode(void) const { return _pOutputNode; }
705 constexpr void setOutputNode(GxGraphNode* pNode) { _pOutputNode = pNode; }
707 constexpr GxGraphNode* getInputNode(void) const { return _pInputNode; }
709 constexpr void setInputNode(GxGraphNode* pNode) { _pInputNode = pNode; }
711 constexpr u32 getOutputIndex(void) const { return _outputIndex; }
713 constexpr void setOutputIndex(u32 index) { _outputIndex = index; }
715 constexpr u32 getInputIndex(void) const { return _inputIndex; }
717 constexpr void setInputIndex(u32 index) { _inputIndex = index; }
718
720 //-----------------------------------------------------------
722 //-----------------------------------------------------------
724private:
725 GxGraphNode* _pOutputNode;
726 GxGraphNode* _pInputNode;
727 u32 _outputIndex;
728 u32 _inputIndex;
729
731};
732
733GX_CORE_NAMESPACE_END()
734
735#endif // GX_DEVELOP
#define GX_PROHIBIT_CLASS_BASE_REFERENCE(__CLASS__)
GxClassBaseReference継承の禁止宣言(new以外の生成禁止 + コピー禁止)
Definition GxBase.h:244
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
OUTPUT_TYPE
出力形式
Definition GxDefine.h:244
@ UNKNOWN
未定義
配列クラス
Definition GxArrayClassBase.h:18
配列クラス
Definition GxArray.h:18
オブジェクト基底クラス
Definition GxBase.h:88
参照オブジェクト基底クラス
Definition GxBase.h:122
virtual void cleanup(void)
delete直前に呼び出される関数
Definition GxBase.cpp:248
プロパティテーブルクラス
Definition GxProperty.h:1641
PASS
描画パス定義
Definition GxRenderMaterial.h:39
@ MODEL
3Dモデル用
テクスチャリソース
Definition GxResTexture.h:23
実行時型情報クラス
Definition GxRtti.h:154
Definition GxColor.h:21
座標
Definition GxStruct.h:867
矩形
Definition GxStruct.h:951
GX_INLINE b32 isIncluding(const GxRect &rect) const
内包判定
Definition GxStruct.inl:1801
サイズ
Definition GxStruct.h:730
文字列型クラス
Definition GxString.h:18
32bitブーリアン
Definition GxDefine.h:173