#ifndef MSP_GL_FRAMEBUFFER_H_
#define MSP_GL_FRAMEBUFFER_H_
+#include <GL/gl.h>
#include "types.h"
namespace Msp {
return i->second;
}
-void Object::render(const ObjectInstance *inst) const
+void Object::render() const
{
- render(*normal_pass, inst);
+ render(*normal_pass, 0);
}
-void Object::render(const string &pn, const ObjectInstance *inst) const
+void Object::render(const ObjectInstance &inst) const
{
- render(get_pass(pn), inst);
+ render(*normal_pass, &inst);
+}
+
+void Object::render(const string &pn) const
+{
+ render(get_pass(pn), 0);
+}
+
+void Object::render(const string &pn, const ObjectInstance &inst) const
+{
+ render(get_pass(pn), &inst);
}
void Object::render(const list<const ObjectInstance *> &insts) const
#include <vector>
#include <msp/datafile/collection.h>
#include "objectpass.h"
+#include "renderable.h"
namespace Msp {
namespace GL {
See also class ObjectInstance.
*/
-class Object
+class Object: public Renderable
{
private:
std::vector<Mesh *> meshes;
Object();
~Object();
- bool has_pass(const std::string &) const;
+ virtual bool has_pass(const std::string &) const;
const ObjectPass &get_pass(const std::string &) const;
/**
Renders the object. If an ObjectInstance is provided, its hook functions
are called.
*/
- void render(const ObjectInstance * =0) const;
- void render(const std::string &, const ObjectInstance *) const;
+ virtual void render() const;
+ virtual void render(const ObjectInstance &) const;
+ virtual void render(const std::string &) const;
+ virtual void render(const std::string &, const ObjectInstance &) const;
/**
Renders multiple instances of the object in one go. This may be a
#include "objectinstance.h"
#include "programdata.h"
+using namespace std;
+
namespace Msp {
namespace GL {
object(obj)
{ }
+bool ObjectInstance::has_pass(const string &pn) const
+{
+ return object.has_pass(pn);
+}
+
void ObjectInstance::render() const
{
- object.render(this);
+ object.render(*this);
}
-void ObjectInstance::render(const std::string &pn) const
+void ObjectInstance::render(const string &pn) const
{
- object.render(pn, this);
+ object.render(pn, *this);
}
} // namespace GL
#define MSP_GL_OBJETCINSTANCE_H_
#include <string>
+#include "renderable.h"
namespace Msp {
namespace GL {
class from this and overload the hook functions to specify location and other
instance-specific parameters for the rendered objects.
*/
-class ObjectInstance
+class ObjectInstance: public Renderable
{
protected:
const Object &object;
const Object &get_object() const { return object; }
- void render() const;
- void render(const std::string &) const;
+ virtual bool has_pass(const std::string &) const;
+
+ virtual void render() const;
+ virtual void render(const std::string &) const;
/**
Hook function, called from Object just before rendering the mesh.
--- /dev/null
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef MSP_GL_RENDERABLE_H_
+#define MSP_GL_RENDERABLE_H_
+
+#include <string>
+
+namespace Msp {
+namespace GL {
+
+class Renderable
+{
+public:
+ virtual bool has_pass(const std::string &pn) const =0;
+
+ virtual void render() const =0;
+ virtual void render(const std::string &pn) const =0;
+};
+
+} // namespace Msp
+} // namespace GL
+
+#endif
--- /dev/null
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "scene.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+void Scene::add(const Renderable &r)
+{
+ renderables.insert(&r);
+}
+
+void Scene::remove(const Renderable &r)
+{
+ renderables.erase(&r);
+}
+
+void Scene::render() const
+{
+ for(set<const Renderable *>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
+ (*i)->render();
+}
+
+void Scene::render(const string &pn) const
+{
+ for(set<const Renderable *>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
+ if((*i)->has_pass(pn))
+ (*i)->render(pn);
+}
+
+} // namespace GL
+} // namespace Msp
--- /dev/null
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef MSP_GL_SCENE_H_
+#define MSP_GL_SCENE_H_
+
+#include <set>
+#include "renderable.h"
+
+namespace Msp {
+namespace GL {
+
+class Scene: public Renderable
+{
+private:
+ std::set<const Renderable *> renderables;
+
+public:
+ void add(const Renderable &);
+ void remove(const Renderable &);
+
+ virtual bool has_pass(const std::string &) const { return true; }
+ virtual void render() const;
+ virtual void render(const std::string &) const;
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif