shader_graph.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*************************************************************************/
  2. /* shader_graph.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef SHADER_GRAPH_H
  30. #define SHADER_GRAPH_H
  31. #if 0
  32. /**
  33. @author Juan Linietsky <reduzio@gmail.com>
  34. */
  35. #include "servers/visual_server.h"
  36. #include "map.h"
  37. class ShaderCodeGenerator {
  38. public:
  39. virtual void begin()=0;
  40. virtual Error add_node(VS::ShaderNodeType p_type,int p_node_pos,int p_id,const Variant& p_param,const Vector<int>& p_in_connections,const Vector<int>& p_out_connections,const Vector<int>& p_out_connection_outputs)=0;
  41. virtual void end()=0;
  42. virtual ~ShaderCodeGenerator() {}
  43. };
  44. class ShaderGraph {
  45. public:
  46. struct Connection {
  47. int src_id;
  48. int src_slot;
  49. int dst_id;
  50. int dst_slot;
  51. };
  52. private:
  53. struct Node {
  54. int16_t x,y;
  55. VS::ShaderNodeType type;
  56. Variant param;
  57. int id;
  58. mutable int order; // used for sorting
  59. mutable bool out_valid;
  60. mutable bool in_valid;
  61. };
  62. Map<int,Node> node_map;
  63. List<Connection> connections;
  64. public:
  65. Error generate(ShaderCodeGenerator * p_generator) const;
  66. void node_add(VS::ShaderNodeType p_type,int p_id);
  67. void node_remove(int p_id);
  68. void node_change_type(int p_id, VS::ShaderNodeType p_type);
  69. void node_set_param(int p_id, const Variant& p_value);
  70. void node_set_pos(int p_id, int p_x,int p_y);
  71. int node_get_pos_x(int p_id) const;
  72. int node_get_pos_y(int p_id) const;
  73. void get_node_list(List<int> *p_node_list) const;
  74. void get_sorted_node_list(List<int> *p_node_list) const;
  75. VS::ShaderNodeType node_get_type(int p_id) const;
  76. Variant node_get_param(int p_id) const;
  77. Error connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
  78. bool is_connected(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const;
  79. void disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
  80. void clear();
  81. List<Connection> get_connection_list() const;
  82. ShaderGraph();
  83. ~ShaderGraph();
  84. };
  85. #endif
  86. #endif