shader_graph.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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-2015 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. #if 0
  30. /**
  31. @author Juan Linietsky <reduzio@gmail.com>
  32. */
  33. #include "servers/visual_server.h"
  34. #include "map.h"
  35. class ShaderCodeGenerator {
  36. public:
  37. virtual void begin()=0;
  38. 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;
  39. virtual void end()=0;
  40. virtual ~ShaderCodeGenerator() {}
  41. };
  42. class ShaderGraph {
  43. public:
  44. struct Connection {
  45. int src_id;
  46. int src_slot;
  47. int dst_id;
  48. int dst_slot;
  49. };
  50. private:
  51. struct Node {
  52. int16_t x,y;
  53. VS::ShaderNodeType type;
  54. Variant param;
  55. int id;
  56. mutable int order; // used for sorting
  57. mutable bool out_valid;
  58. mutable bool in_valid;
  59. };
  60. Map<int,Node> node_map;
  61. List<Connection> connections;
  62. public:
  63. Error generate(ShaderCodeGenerator * p_generator) const;
  64. void node_add(VS::ShaderNodeType p_type,int p_id);
  65. void node_remove(int p_id);
  66. void node_change_type(int p_id, VS::ShaderNodeType p_type);
  67. void node_set_param(int p_id, const Variant& p_value);
  68. void node_set_pos(int p_id, int p_x,int p_y);
  69. int node_get_pos_x(int p_id) const;
  70. int node_get_pos_y(int p_id) const;
  71. void get_node_list(List<int> *p_node_list) const;
  72. void get_sorted_node_list(List<int> *p_node_list) const;
  73. VS::ShaderNodeType node_get_type(int p_id) const;
  74. Variant node_get_param(int p_id) const;
  75. Error connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
  76. bool is_connected(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const;
  77. void disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
  78. void clear();
  79. List<Connection> get_connection_list() const;
  80. ShaderGraph();
  81. ~ShaderGraph();
  82. };
  83. #endif