Graphite  Version 3
An experimental 3D geometry processing program
lua_grob.h
Go to the documentation of this file.
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000-2009 INRIA - Project ALICE
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 - levy@loria.fr
24  *
25  * Project ALICE
26  * LORIA, INRIA Lorraine,
27  * Campus Scientifique, BP 239
28  * 54506 VANDOEUVRE LES NANCY CEDEX
29  * FRANCE
30  *
31  * Note that the GNU General Public License does not permit incorporating
32  * the Software into proprietary programs.
33  *
34  * As an exception to the GPL, Graphite can be linked
35  * with the following (non-GPL) libraries:
36  * Qt, SuperLU, WildMagic and CGAL
37  */
38 
39 
40 #ifndef H_OGF_GRAPHITE_LUAGROB_LUA_GROB_H
41 #define H_OGF_GRAPHITE_LUAGROB_LUA_GROB_H
42 
45 
46 #ifdef GOMGEN
47 typedef int lua_State;
48 #else
49 extern "C" {
50 #include <geogram/third_party/lua/lua.h>
51 }
52 #endif
53 
58 namespace OGF {
59 
63  gom_class LUAGROB_API LuaGrob : public Grob {
64  public:
71 
75  ~LuaGrob() override;
76 
82  bool shader_OK() const {
83  return !lua_error_occured_;
84  }
85 
86  gom_properties:
87 
95  bool get_autorun() const {
96  return autorun_;
97  }
98 
105  void set_autorun(bool x) {
106  autorun_ = x;
107  }
108 
113  void set_source(const std::string& source) {
114  source_ = source;
115  }
116 
121  const std::string& get_source() const {
122  return source_;
123  }
124 
130  void set_shader_source(const std::string& source) {
131  shader_source_ = source;
132  execute_shader_program();
133  }
134 
139  const std::string& get_shader_source() const {
140  return shader_source_;
141  }
142 
143 
144  gom_slots:
145 
151  void execute_program();
152 
158  bool execute_shader_command(const std::string& value);
159 
164 
169  void load_program_source(const std::string& value);
170 
175  void save_program_source(const std::string& value);
176 
181  void load_shader_source(const std::string& value);
182 
187  void save_shader_source(const std::string& value);
188 
189  public:
190 
195  void set_box(const Box3d& box);
196 
200  void clear() override;
201 
205  Grob* duplicate(SceneGraph* sg) override;
206 
210  bool is_serializable() const override;
211 
215  bool serialize_read(InputGraphiteFile& geofile) override;
216 
220  bool serialize_write(OutputGraphiteFile& geofile) override;
221 
225  void update() override;
226 
230  Box3d bbox() const override;
231 
241  SceneGraph* sg, const std::string& name
242  );
243 
251  static LuaGrob* find(SceneGraph* sg, const std::string& name);
252 
253  private:
254  lua_State* lua_shader_state_;
255  bool lua_error_occured_;
256  Box3d box_;
257  bool autorun_;
258  std::string source_;
259  std::string shader_source_;
260  };
261 
270 
281 }
282 #endif
283 
A 3d axis aligned box.
Definition: geometry.h:235
A Composite Graphite Object.
Base class for all 3D Graphite objects.
Definition: grob.h:68
An extension of InputGeoFile for storing a complete Graphite scenegraph in a structured binary file.
Definition: geofile.h:67
A Grob class for luagrob grids.
Definition: lua_grob.h:63
bool serialize_read(InputGraphiteFile &geofile) override
Reads this Grob from a GeoFile.
void execute_shader_program()
Executes the loaded LUA shader program.
const std::string & get_shader_source() const
Gets the source of the LUA shader program.
Definition: lua_grob.h:139
static LuaGrob * find_or_create(SceneGraph *sg, const std::string &name)
Finds or creates a LuaGrob with the specified name.
void set_shader_source(const std::string &source)
Sets the source of the LUA shader program and executes it.
Definition: lua_grob.h:130
bool shader_OK() const
Tests the status of the loaded LUA program.
Definition: lua_grob.h:82
void load_program_source(const std::string &value)
Loads the LUA program from a file.
void set_autorun(bool x)
Sets whether the source should be executed automatically when the object is loaded.
Definition: lua_grob.h:105
void load_shader_source(const std::string &value)
Loads the LUA shader program from a file.
bool serialize_write(OutputGraphiteFile &geofile) override
Writes this Grob into a stream.
void save_shader_source(const std::string &value)
Saves the LUA shader program to a file.
const std::string & get_source() const
Gets the source of the LUA program.
Definition: lua_grob.h:121
LuaGrob(CompositeGrob *parent)
LuaGrob constructor.
void set_box(const Box3d &box)
Sets the bounding box.
bool execute_shader_command(const std::string &value)
Executes a LUA command in the interpreter used for the shader.
void set_source(const std::string &source)
Sets the source of the LUA program.
Definition: lua_grob.h:113
Box3d bbox() const override
Gets the bounding box.
Grob * duplicate(SceneGraph *sg) override
Duplicates this Grob.
~LuaGrob() override
LuaGrob destructor.
void save_program_source(const std::string &value)
Saves the LUA program to a file.
static LuaGrob * find(SceneGraph *sg, const std::string &name)
Finds a LuaGrob by name.
void update() override
void clear() override
Clears this Grob.
bool is_serializable() const override
Tests whether this Grob can be serialized in GeoFile.
A template class for strings that need to have a specific type in the GOM system.
Definition: properties.h:218
An extension of InputGeoFile for storing a complete Graphite scenegraph in a structured binary file.
Definition: geofile.h:129
Represents the list of objects loaded in Graphite.
Definition: scene_graph.h:62
The base class for all 3D objects in the system.
Global Graphite namespace.
Definition: common.h:76
Name< LuaGrob * > LuaGrobName
The name of an existing LuaGrob in the SceneGraph.
Definition: lua_grob.h:269
Name< LuaGrob *, true > NewLuaGrobName
The name of an (existing or not) LuaGrob in the SceneGraph.
Definition: lua_grob.h:280
Definitions common to all include files in the luagrob library.