~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/environment/pagedgeometry/include/BatchedGeometry.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------------------
 
2
Copyright (c) 2006 John Judnich
 
3
 
 
4
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
 
5
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
 
6
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
 
7
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
 
8
3. This notice may not be removed or altered from any source distribution.
 
9
-------------------------------------------------------------------------------------*/
 
10
 
 
11
//BatchedGeometry.h
 
12
//A "lightweight" version of Ogre::StaticGeometry, which gives you a little more control
 
13
//over the batch materials, etc.
 
14
//-------------------------------------------------------------------------------------
 
15
 
 
16
#ifndef __BatchedGeometry_H__
 
17
#define __BatchedGeometry_H__
 
18
 
 
19
#include <OgrePrerequisites.h>
 
20
#include <OgreMovableObject.h>
 
21
#include <OgreSceneNode.h>
 
22
#include <OgreMaterialManager.h>
 
23
 
 
24
namespace PagedGeometry {
 
25
 
 
26
class BatchedGeometry: public Ogre::MovableObject
 
27
{
 
28
public:
 
29
        BatchedGeometry(Ogre::SceneManager *mgr, Ogre::SceneNode *rootSceneNode);
 
30
        ~BatchedGeometry();
 
31
 
 
32
        void addEntity(Ogre::Entity *ent, const Ogre::Vector3 &position, const Ogre::Quaternion &orientation = Ogre::Quaternion::IDENTITY, const Ogre::Vector3 &scale = Ogre::Vector3::UNIT_SCALE, const Ogre::ColourValue &color = Ogre::ColourValue::White);
 
33
        void build();
 
34
        void clear();
 
35
 
 
36
        Ogre::Vector3 _convertToLocal(const Ogre::Vector3 &globalVec) const;
 
37
 
 
38
        void _notifyCurrentCamera(Ogre::Camera *cam);
 
39
        void _updateRenderQueue(Ogre::RenderQueue *queue);
 
40
        bool isVisible();
 
41
        const Ogre::AxisAlignedBox &getBoundingBox(void) const { return bounds; }
 
42
        Ogre::Real getBoundingRadius(void) const { return radius; }
 
43
        const Ogre::String &getMovableType(void) const { static Ogre::String t = "BatchedGeometry"; return t; }
 
44
        
 
45
        #if OGRE_VERSION_MAJOR == 1 && OGRE_VERSION_MINOR > 4
 
46
        //Shaggoth compatibility
 
47
        void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables) {}
 
48
        #endif
 
49
 
 
50
        class SubBatch: public Ogre::Renderable
 
51
        {
 
52
        public:
 
53
                SubBatch(BatchedGeometry *parent, Ogre::SubEntity *ent);
 
54
                ~SubBatch();
 
55
 
 
56
                void addSubEntity(Ogre::SubEntity *ent, const Ogre::Vector3 &position, const Ogre::Quaternion &orientation, const Ogre::Vector3 &scale, const Ogre::ColourValue &color = Ogre::ColourValue::White);
 
57
                void build();
 
58
                void clear();
 
59
                
 
60
                void setMaterial(Ogre::MaterialPtr &mat) { material = mat; }
 
61
                void setMaterialName(const Ogre::String &mat) { material = Ogre::MaterialManager::getSingleton().getByName(mat); }
 
62
                inline Ogre::String getMaterialName() const { return material->getName(); }
 
63
 
 
64
                void addSelfToRenderQueue(Ogre::RenderQueue *queue, Ogre::uint8 group);
 
65
                void getRenderOperation(Ogre::RenderOperation& op);
 
66
                Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
 
67
                const Ogre::LightList& getLights(void) const;
 
68
 
 
69
                Ogre::Technique *getTechnique() const { return bestTechnqiue; }
 
70
                const Ogre::MaterialPtr &getMaterial(void) const { return material; }
 
71
                void getWorldTransforms(Ogre::Matrix4* xform) const { *xform = parent->_getParentNodeFullTransform(); }
 
72
                const Ogre::Quaternion& getWorldOrientation(void) const { return parent->sceneNode->_getDerivedOrientation(); }
 
73
                const Ogre::Vector3& getWorldPosition(void) const { return parent->sceneNode->_getDerivedPosition(); }
 
74
                bool castsShadows(void) const { return parent->getCastShadows(); }
 
75
 
 
76
        private:
 
77
                //This function is used to make a single clone of materials used, since the materials
 
78
                //will be modified by the batch system (and it wouldn't be good to modify the original materials
 
79
                //that the user may be using somewhere else).
 
80
                Ogre::Material *getMaterialClone(Ogre::Material *mat);
 
81
 
 
82
                //A structure defining the desired position/orientation/scale of a batched mesh. The
 
83
                //SubMesh is not specified since that can be determined by which MeshQueue this belongs to.
 
84
                struct QueuedMesh
 
85
                {
 
86
                        Ogre::SubMesh *mesh;
 
87
                        Ogre::Vector3 position;
 
88
                        Ogre::Quaternion orientation;
 
89
                        Ogre::Vector3 scale;
 
90
                        Ogre::ColourValue color;
 
91
                };
 
92
 
 
93
                bool built;
 
94
                
 
95
                Ogre::VertexData *vertexData;
 
96
                Ogre::IndexData *indexData;
 
97
 
 
98
                Ogre::SubMesh *meshType;
 
99
                BatchedGeometry *parent;
 
100
                Ogre::MaterialPtr material;
 
101
                Ogre::Technique *bestTechnqiue; //This is recalculated every frame
 
102
 
 
103
                typedef std::vector<QueuedMesh>::iterator MeshQueueIterator;
 
104
                typedef std::vector<QueuedMesh> MeshQueue;
 
105
                MeshQueue meshQueue;    //The list of meshes to be added to this batch
 
106
        };
 
107
 
 
108
private:
 
109
        Ogre::String getFormatString(Ogre::SubEntity *ent);
 
110
 
 
111
        typedef std::map<Ogre::String, SubBatch*> SubBatchMap;  //Stores a list of GeomBatch'es, using a format string (generated with getGeometryFormatString()) as the key value
 
112
        SubBatchMap subBatchMap;
 
113
 
 
114
        Ogre::Vector3 center;
 
115
        Ogre::AxisAlignedBox bounds;
 
116
        bool boundsUndefined;
 
117
        Ogre::Real radius;
 
118
 
 
119
        Ogre::SceneManager *sceneMgr;
 
120
        Ogre::SceneNode *sceneNode, *parentSceneNode;
 
121
 
 
122
        Ogre::Real minDistanceSquared;
 
123
        bool withinFarDistance;
 
124
 
 
125
        bool built;
 
126
 
 
127
public:
 
128
        typedef Ogre::MapIterator<SubBatchMap> SubBatchIterator;
 
129
        SubBatchIterator getSubBatchIterator() const;
 
130
};
 
131
 
 
132
 
 
133
}
 
134
 
 
135
#endif