]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/object.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / render / object.h
index 48e3045930559fd354af6d868a935100a2fab09d..dc92326730c4f25a8abf8ec7d479a0d7966ca7f4 100644 (file)
@@ -2,31 +2,31 @@
 #define MSP_GL_OBJECT_H_
 
 #include <vector>
-#include "bindable.h"
 #include "renderable.h"
-#include "renderpass.h"
+#include "rendermethod.h"
 #include "resourceobserver.h"
 
 namespace Msp {
 namespace GL {
 
-class Material;
 class Mesh;
 class ObjectInstance;
 class Technique;
-class Texture;
 
 /**
-Combines a Mesh with a Technique to give it an appearance.  The Technique will
-define which render passes the Object supports.
+Combines a Mesh with a Technique for a complete model.
 
-In many cases, it's desirable to include multiple copies of an Object in a
-Scene, with different model matrices.  ObjectInstances can be used to alter the
-rendering of an object on a per-instance basis.
+An object does not have a model matrix and will be rendered at origin if used
+by itself.  The ObjectInstance class provides a way to position objects in a
+scene and customize them in other ways.
 
-Objects can have multiple levels of detail.  The most detailed level has index
-0, with increasing indices having less detail.  When rendering an instance, the
-instance's get_level_of_detail method is called to determine which LoD to use.
+Objects can have multiple levels of detail, with different resources.  The most
+detailed level has index 0, with increasing indices having less detail.  When
+rendering an instance, the instance's get_level_of_detail method is called to
+determine which LoD to use.
+
+An Object can be rendered with any tag its Technique supports.  Unknown tags
+are silently ignored.
 */
 class Object: public Renderable, private ResourceObserver
 {
@@ -40,7 +40,7 @@ private:
                LevelOfDetail &lod;
 
        public:
-               LodLoader(Object &, unsigned, Collection *);
+               LodLoader(Object &, unsigned, Collection &);
 
        private:
                void mesh(const std::string &);
@@ -53,10 +53,8 @@ public:
        class Loader: public LodLoader
        {
        public:
-               Loader(Object &);
                Loader(Object &, Collection &);
        private:
-               void init();
                virtual void finish();
 
                void bounding_sphere_hint(float, float, float, float);
@@ -66,30 +64,34 @@ public:
 private:
        struct LevelOfDetail
        {
-               RefPtr<const Mesh> mesh;
-               RefPtr<const Technique> technique;
+               const Mesh *mesh;
+               const Technique *technique;
        };
 
        std::vector<LevelOfDetail> lods;
        Geometry::BoundingSphere<float, 3> bounding_sphere;
-       bool lod0_watched;
+       bool lod0_watched = false;
 
-       static Matrix identity_matrix;
+       static const Matrix identity_matrix;
 
 public:
        Object();
        Object(const Mesh *, const Technique *);
+       Object(const Object &);
+       Object(Object &&);
        ~Object();
 
 private:
        LevelOfDetail &get_lod(unsigned, const char *);
+       void watch_lod0();
 
 public:
        /** Sets the mesh for the highest level of detail (index 0). */
        void set_mesh(const Mesh *m) { set_mesh(0, m); }
 
-       /** Sets the mesh for a given level of detail.  Previous LoDs must have been
-       defined. */
+       /** Sets the mesh for a specific level of detail.  LoDs must be defined in
+       order, without gaps.  If this call creates a new LoD, technique is copied
+       from the previous one. */
        void set_mesh(unsigned, const Mesh *);
 
 private:
@@ -100,8 +102,9 @@ public:
        /** Sets the technique for the highest level of detail (index 0). */
        void set_technique(const Technique *t) { set_technique(0, t); }
 
-       /** Sets the technique for a given level of detail.  Previous LoDs must have
-       been defined. */
+       /** Sets the technique for a specific level of detail.  LoDs must be defined
+       in order, without gaps.  If this call creates a new LoD, mesh is copied from
+       the previous one. */
        void set_technique(unsigned, const Technique *);
 
        const Technique *get_technique(unsigned = 0) const;
@@ -110,18 +113,18 @@ public:
        virtual const Matrix *get_matrix() const { return &identity_matrix; }
        virtual const Geometry::BoundingSphere<float, 3> *get_bounding_sphere() const { return &bounding_sphere; }
 
-       virtual void render(Renderer &, const Tag & = Tag()) const;
+       virtual void render(Renderer &, Tag = Tag()) const;
 
        /** Renders an instance of the object.  The instance's hook functions are
        called before and after drawing the mesh. */
-       virtual void render(Renderer &, const ObjectInstance &, const Tag & = Tag()) const;
+       virtual void render(Renderer &, const ObjectInstance &, Tag = Tag()) const;
 
 protected:
-       virtual void setup_render(Renderer &, const Tag &) const { }
-       virtual void finish_render(Renderer &, const Tag &) const { }
+       virtual void setup_render(Renderer &, Tag) const { }
+       virtual void finish_render(Renderer &, Tag) const { }
 
 private:
-       const RenderPass *get_pass(const Tag &, unsigned) const;
+       const RenderMethod *get_method(Tag, unsigned) const;
 
        virtual void resource_loaded(Resource &);
        virtual void resource_removed(Resource &);