]> git.tdb.fi Git - libs/gl.git/blobdiff - source/objectinstance.h
Do not clear previous assignments on assignment to array subscript
[libs/gl.git] / source / objectinstance.h
index 602cbc24d80a50989a4faee48db6e0319bda9cdc..906ba2f32785093237c8dbf108e500a655fe3454 100644 (file)
@@ -1,31 +1,22 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #ifndef MSP_GL_OBJETCINSTANCE_H_
 #define MSP_GL_OBJETCINSTANCE_H_
 
 #include <string>
-#include "renderable.h"
+#include "object.h"
+#include "placeable.h"
 
 namespace Msp {
 namespace GL {
 
-class Object;
-class ProgramData;
-
 /**
-Represents a single instance of an Object.  An application can derive another
-class from this and overload the hook functions to specify location and other
-instance-specific parameters for the rendered objects.
+Represents a single instance of an Object.  Thanks to being derived from
+Placeable in can be positioned without additional effort.  Other instance
+parameters can be set by overriding the hook functions.
 
-The finish_render function generally should clean up everything done by
-setup_render, unless the rendering sequence is known to allow otherwise.
+ObjectInstances can benefit from being put in an InstanceScene, which will
+render all instances of the same object consecutively.
 */
-class ObjectInstance: public Renderable
+class ObjectInstance: public PlacedRenderable
 {
 protected:
        const Object &object;
@@ -34,20 +25,23 @@ public:
        ObjectInstance(const Object &);
 
        const Object &get_object() const { return object; }
+       virtual long get_instance_key() const { return reinterpret_cast<long>(&object); }
+
+       virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return object.get_bounding_sphere(); }
 
-       virtual void render(const Tag &tag=Tag()) const;
+       virtual void render(const Tag &tag = Tag()) const;
+       virtual void render(Renderer &, const Tag & = Tag()) const;
 
-       /**
-       Hook function, called from Object just before rendering the mesh.
-       */
-       virtual void setup_render(const Tag &) const { }
+       /** Hook function, called from Object just before rendering the mesh.
+       Renderer state will have been pushed before this is called. */
+       virtual void setup_render(Renderer &, const Tag &) const;
 
-       /**
-       Hook function, called from Object right after rendering the mesh.
-       */
-       virtual void finish_render(const Tag &) const { }
+       /** Hook function, called from Object right after rendering the mesh.  Since
+       Object takes care of pushing Renderer state, this rarely needs to do
+       anything. */
+       virtual void finish_render(Renderer &, const Tag &) const { }
 
-       virtual unsigned get_level_of_detail() const { return 0; }
+       virtual unsigned get_level_of_detail(const Renderer &) const { return 0; }
 };
 
 } // namespace GL