Graphite  Version 3
An experimental 3D geometry processing program
scene_graph_library.h
Go to the documentation of this file.
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 
38 #ifndef H_OGF_SCENE_GRAPH_TYPES_SCENE_GRAPH_LIBRARY_H
39 #define H_OGF_SCENE_GRAPH_TYPES_SCENE_GRAPH_LIBRARY_H
40 
43 
45 
46 #include <map>
47 
53 namespace OGF {
54 
55  class SceneGraph;
56  class SceneGraphShaderManager;
57  class SceneGraphToolsManager;
58 
68  class SCENE_GRAPH_API SceneGraphLibrary : public Environment {
69  public:
70 
75 
79  ~SceneGraphLibrary() override;
80 
86 
92  static void initialize();
93 
99  static void terminate();
100 
101 
107  return scene_graph_;
108  }
109 
114  const SceneGraph* scene_graph() const {
115  return scene_graph_;
116  }
117 
123  return scene_graph_tools_manager_;
124  }
125 
135  const std::string& grob_class_name, bool abstract=false
136  );
137 
148  const std::string& grob_class_name, const std::string& extension
149  );
150 
161  const std::string& grob_class_name, const std::string& extension
162  );
163 
176  const std::string& grob_class_name,
177  const std::string& shader_class_name,
178  const std::string& shader_user_name=""
179  );
180 
191  const std::string& grob_class_name,
192  const std::string& tool_class_name
193  );
194 
195 
206  const std::string& grob_class_name,
207  const std::string& interface_class_name
208  );
209 
220  const std::string& grob_class_name,
221  const std::string& commands_class_name
222  );
223 
234  const std::string& full_screen_effect_class_name,
235  const std::string& user_name=""
236  );
237 
245  std::string file_extension_to_grob(const std::string& extension) const;
246 
262  const std::string& name, std::string& value
263  ) const override;
264 
269  const std::string& name, const std::string& value
270  ) override;
271 
281  const std::string& grob_class_name
282  ) const;
283 
293  const std::string& grob_class_name
294  ) const;
295 
305  const std::string& shader_user_to_classname(
306  const std::string& grob_class_name,
307  const std::string& shader_user_name
308  ) const;
309 
319  const std::string& shader_classname_to_user(
320  const std::string& grob_class_name,
321  const std::string& shader_class_name
322  ) const;
323 
333  const std::string& full_screen_effect_user_name
334  ) const;
335 
344  const std::string& full_screen_effect_classname
345  ) const;
346 
347  protected:
348  friend class SceneGraph;
349  friend class SceneGraphCommandsManager;
350  friend class SceneGraphShaderManager;
351  friend class SceneGraphToolsManager;
352 
353 
359 
365  void set_scene_graph(SceneGraph* scene_graph) {
366  ogf_assert(scene_graph_ == nullptr);
367  scene_graph_ = scene_graph;
368  }
369 
377  SceneGraphShaderManager* scene_graph_shader_manager
378  ) {
379  ogf_assert(scene_graph_shader_manager_ == nullptr);
380  scene_graph_shader_manager_ = scene_graph_shader_manager;
381  }
382 
390  SceneGraphToolsManager* scene_graph_tools_manager
391  ) {
392  ogf_assert(scene_graph_tools_manager_ == nullptr);
393  scene_graph_tools_manager_ = scene_graph_tools_manager;
394  }
395 
396  private:
397  struct GrobInfo {
398  GrobInfo(bool abstract_in=false) : abstract(abstract_in) {
399  }
400  std::vector<std::string> read_file_extensions;
401  std::vector<std::string> write_file_extensions;
402  std::vector<std::string> shaders;
403  std::vector<std::string> shaders_user_names;
404  std::vector<std::string> tools;
405  std::vector<std::string> commands;
406  std::vector<std::string> interfaces;
407  bool abstract;
408  std::string read_file_extensions_string() const;
409  std::string write_file_extensions_string() const;
410  std::string shaders_user_names_string() const;
411  std::string tools_string() const;
412  std::string commands_string() const;
413  std::string interfaces_string() const;
414  bool has_read_extension(const std::string& ext) const;
415  };
416  std::map<std::string, GrobInfo> grob_infos_;
417  std::vector<std::string> full_screen_effects_;
418  std::vector<std::string> full_screen_effects_user_names_;
419  SceneGraph* scene_graph_;
420  SceneGraphShaderManager* scene_graph_shader_manager_;
421  SceneGraphToolsManager* scene_graph_tools_manager_;
422  static SceneGraphLibrary* instance_;
423  };
424 
425 //______________________________________________________________________________
426 
427 
432  template <class T> class ogf_register_grob_type {
433  public:
443  ogf_meta<T>::type()->name()
444  );
445  }
446  };
447 
448 
454  template <class T> class ogf_register_abstract_grob_type {
455  public:
465  ogf_meta<T>::type()->name(), true
466  );
467  }
468  };
469 
474  template <class T> class ogf_register_grob_read_file_extension {
475  public:
485  ogf_meta<T>::type()->name(), extension
486  );
487  }
488  };
489 
494  template <class T> class ogf_register_grob_write_file_extension {
495  public:
505  ogf_meta<T>::type()->name(), extension
506  );
507  }
508  };
509 
515  template <class T1, class T2> class ogf_register_grob_shader {
516  public:
517 
527  ogf_register_grob_shader(const std::string& shader_user_name="") {
529  ogf_meta<T1>::type()->name(),
530  ogf_meta<T2>::type()->name(),
531  shader_user_name
532  );
533  }
534  };
535 
541  template <class T1, class T2> class ogf_register_grob_interface {
542  public:
543 
553  ogf_meta<T1>::type()->name(), ogf_meta<T2>::type()->name()
554  );
555  }
556  };
557 
563  template <class T1, class T2> class ogf_register_grob_commands {
564  public:
565 
575  ogf_meta<T1>::type()->name(), ogf_meta<T2>::type()->name()
576  );
577  }
578  };
579 
585  template <class T1, class T2> class ogf_register_grob_tool {
586  public:
587 
597  ogf_meta<T1>::type()->name(), ogf_meta<T2>::type()->name()
598  );
599  }
600  };
601 
606  template <class T> class ogf_register_full_screen_effect {
607  public:
608 
618  ogf_register_full_screen_effect(const std::string& user_name="") {
620  ogf_meta<T>::type()->name(), user_name
621  );
622  }
623  };
624 
625 }
626 
627 #endif
Application environment.
Definition: environment.h:211
Provides functions to dynamically declare new Grob classes, commands, shaders and tools.
SceneGraphToolsManager * scene_graph_tools_manager()
Gets the SceneGraphToolsManager.
void scene_graph_values_changed_notify_environment()
Notifies all listeners of scene graph environment variables.
static void initialize()
Initializes the SceneGraphLibrary instance.
const std::string & full_screen_effect_classname_to_user(const std::string &full_screen_effect_classname) const
Converts a full screen effect class name to the associated user name.
std::string default_grob_read_extension(const std::string &grob_class_name) const
Gets the default file extension associated with a Grob class for reading.
void register_grob_write_file_extension(const std::string &grob_class_name, const std::string &extension)
Registers a new file extension associated with a Grob type for writing.
void register_grob_shader(const std::string &grob_class_name, const std::string &shader_class_name, const std::string &shader_user_name="")
Registers a new Shader class associated with a Grob class.
static SceneGraphLibrary * instance()
Gets the instance.
std::string file_extension_to_grob(const std::string &extension) const
Finds the object class names associated with a file extension for reading.
bool get_local_value(const std::string &name, std::string &value) const override
Retrieves a variable value locally.
void register_grob_interface(const std::string &grob_class_name, const std::string &interface_class_name)
Registers a new Interface class associated with a Grob class.
void register_grob_type(const std::string &grob_class_name, bool abstract=false)
Registers a new Grob type.
void register_grob_read_file_extension(const std::string &grob_class_name, const std::string &extension)
Registers a new file extension associated with a Grob type for reading.
std::string full_screen_effect_user_to_classname(const std::string &full_screen_effect_user_name) const
Converts a full screen effect user name to the associated internal full screen effect class name.
static void terminate()
Terminates the SceneGraphLibrary instance.
void set_scene_graph_tools_manager(SceneGraphToolsManager *scene_graph_tools_manager)
Sets the SceneGraphToolsManager.
void set_scene_graph(SceneGraph *scene_graph)
Sets the SceneGraph.
std::string default_grob_write_extension(const std::string &grob_class_name) const
Gets the default file extension associated with a Grob class for writing.
SceneGraphLibrary()
SceneGraphLibrary constructor.
void register_grob_tool(const std::string &grob_class_name, const std::string &tool_class_name)
Registers a new Tool class associated with a Grob class.
~SceneGraphLibrary() override
SceneGraphLibrary destructor.
const SceneGraph * scene_graph() const
Gets the SceneGraph.
const std::string & shader_user_to_classname(const std::string &grob_class_name, const std::string &shader_user_name) const
Converts a shader user name to the associated internal class name.
void set_scene_graph_shader_manager(SceneGraphShaderManager *scene_graph_shader_manager)
Sets the SceneGraphShaderManager.
bool set_local_value(const std::string &name, const std::string &value) override
Sets a variable value locally.
const std::string & shader_classname_to_user(const std::string &grob_class_name, const std::string &shader_class_name) const
Converts a shader class name to the associated user shader name.
void register_grob_commands(const std::string &grob_class_name, const std::string &commands_class_name)
Registers a new Commands class associated with a Grob class.
void register_full_screen_effect(const std::string &full_screen_effect_class_name, const std::string &user_name="")
Registers a new full screen effect.
SceneGraph * scene_graph()
Gets the SceneGraph.
Manages the shaders and full screen effects for the entire SceneGraph.
Manages the tools for the entire SceneGraph.
Represents the list of objects loaded in Graphite.
Definition: scene_graph.h:62
Provides easy access to meta information from C++ types.
Definition: meta.h:257
Helper class to register a new abstract Grob class.
ogf_register_abstract_grob_type()
Registers a new Grob class.
Helper class to register a new FullScreenEffect.
ogf_register_full_screen_effect(const std::string &user_name="")
Registers a new FullScreenEffect.
Helper class to register a new Commands associated with a Grob.
ogf_register_grob_commands()
Registers a new Commands associated with a Grob.
Helper class to register a new Commands associated with a Grob.
ogf_register_grob_interface()
Registers a new Interface associated with a Grob.
Helper class to register a new file extension for reading.
ogf_register_grob_read_file_extension(const std::string &extension)
Registers a new file extension for reading.
Helper class to register a new Shader associated with a Grob.
ogf_register_grob_shader(const std::string &shader_user_name="")
Registers a new Shader associated with a Grob.
Helper class to register a new Tool associated with a Grob.
ogf_register_grob_tool()
Registers a new Tool associated with a Grob.
Helper class to register a new Grob class.
ogf_register_grob_type()
Registers a new Grob class.
Helper class to register a new file extension for writing.
ogf_register_grob_write_file_extension(const std::string &extension)
Registers a new file extension for writing.
Provides a mechanism to store global variables, retrieve them by their names and attach observers to ...
The meta-information used by the reflection API.
std::string extension(const std::string &path)
Gets a path extension.
Global Graphite namespace.
Definition: common.h:76
Definitions common to all include files in the scene_graph library.