#pragma once #include "SharedRuns.h" #include "OgreRenderable.h" #include "Ogre.h" using namespace Ogre; enum GlobalTargetType { ILLUM_GLOBAL_TARGET_FIREPARTICLES }; class GlobalUseRenderTarget { public: GlobalUseRenderTarget(){lastUpdated = 0; renderTarget = 0;} unsigned long lastUpdated; RenderTarget* renderTarget; }; /** @brief Class of SharedRuns used in an OGRE environment. */ class OgreSharedRuns : public SharedRuns { public: /** @brief Constructor. */ OgreSharedRuns(){} /** @brief Retrieves the contaied RenderingRuns with their type information @return map of renderables */ std::map& getSharedRuns(){return sharedRuns;} /** @brief Sets the bounding sphere of the node. @param sphere bounding sphere */ void setBoundingSphere(Sphere& sphere){boundingSphere = sphere;} /** @brief Sets the axis-aligned bounding box of the node. @param box bounding box */ void setBoundingBox(AxisAlignedBox& box){boundingBox = box;} /** @brief Returns the bounding sphere of the node. @return a reference to the bounding sphere */ Sphere& getBoundingSphere(){ return boundingSphere;} /** @brief Returns the axis-aligned bounding box of the node. @return a reference to the bounding box */ AxisAlignedBox& getBoundingBox(){ return boundingBox;} /** @brief Returns the bounding sphere of the root parent node. @return a reference to the bounding sphere */ Sphere& getRootBoundingSphere() {return ((OgreSharedRuns*)getRoot())->getBoundingSphere();} /** @brief Retrieves the bounding sphere of the topmost parent node of this SharedRuns node, which have a specified RenderingRun type. @param runType the RenderingRun type @return a reference to the bounding sphere */ Sphere& getRootBoundingSphere(RenderingRunType runType) {return ((OgreSharedRuns*)getRoot(runType))->getBoundingSphere();} /** @brief Returns the axis-aligned bounding box of the root parent node. @return a reference to the bounding box */ AxisAlignedBox& getRootBoundingBox() {return ((OgreSharedRuns*)getRoot())->getBoundingBox();} /** @brief Retrieves the axis-aligned bounding box of the topmost parent node of this SharedRuns node, which have a specified RenderingRun type. @param runType the RenderingRun type @return a reference to the bounding box */ AxisAlignedBox& getRootBoundingBox(RenderingRunType runType) {return ((OgreSharedRuns*)getRoot(runType))->getBoundingBox();} /** @brief Returns the world space center position of the root parent node. @return a reference to the center position */ const Vector3& getRootPosition() {return getRootBoundingSphere().getCenter();} /** @brief Retrieves the world space center position of the topmost parent node of this SharedRuns node, which have a specified RenderingRun type. @param runType the RenderingRun type @return a reference to the center position */ const Vector3& getRootPosition(RenderingRunType runType) {return getRootBoundingSphere(runType).getCenter();} /** @brief Checks if two SharedRuns node can be joined. @param r1 pointer to one of the SharedRuns instance @param r2 pointer to the other SharedRuns instance */ static bool canJoin(SharedRuns* r1, SharedRuns* r2); /** @brief Checks if two SharedRuns have common resources so that they can be joined. @param r1 pointer to one of the SharedRuns instance @param r2 pointer to the other SharedRuns instance */ static bool haveCommonRuns(SharedRuns* r1, SharedRuns* r2, std::vector& commonruns); /** @brief Checks if this node has a resource with the given type. Only this node none of the child nodes are checked. @param the type of the RenderingRun to look for */ bool hasOwnRun(RenderingRunType runType); /** @brief Adds all the Renderables connected to this node to a given RenderQueue. The function is called recoursively for all child nodes. @param pointer to the RenderQueue to add the Renderables to */ void addRenderablesToQueue(RenderQueue* rq, bool checkVisible = true); /** @brief Calls notifyCamera() to all the Renderables connected to this node The function is called recoursively for all child nodes. @param pointer to the Camera instance to call notifyCamera() with */ void notifyCamera(Camera* cam); /** @brief Finds all the topmost nodes which have resources of the given type. This function is called for the root node, and will be called recoursively downwards in the tree for all childs. If a node with with the given resource is found, the node can be added and it's childs don't need to be checked anymore. From a given group of objects (root node) a new set of groups will be created (they will be the members of the given vector). Each new group will be a subtree of the original tree. They will form groups that contain the maximum number of objects that can be joined by the the given resource type. @param runType the type of RenderingRun to look for @param roots reference to the collection to add the new groups to */ void findSharedRootsForType(RenderingRunType runType, std::vector& roots); //inherited RenderingRun* getRun(RenderingRunType runType); //inherited void addRun(RenderingRunType runType, RenderingRun* run); //inherited void updateRun(RenderingRunType runType, unsigned long frameNum); //inherited void addRenderable(OgreRenderable* rend) { if(renderables[rend] != 0) renderables[rend] = rend->isVisible(); } //inherited void updateBounds(); //inherited void validate(); //inherited void destroy(); //inherited void runUpdated(RenderingRunType runType, RenderingRun* run); //inherited void runChanged(RenderingRunType runType, RenderingRun* run); //inherited virtual void addTechniqueGroup(TechniqueGroup* group){childTechniqueGroups.push_back(group);} /** @brief Sets the given material for all connected renderables. The previous materials will be stored so later can be restored. @see restoreMaterial @param name of the material to be set. */ void setMaterial(String materialName); /** @brief Restores the prevoius materials for the connected renderables. @see setMaterial */ void restoreMaterial(); protected: /** @brief child TechniqueGroup instance. If this SharedRuns node is a leaf, it containes a reference to a TechniqueGroup instance. All messages will be transfered to this object, and bounding information will be retrieved from this TechniqueGroup */ std::vector childTechniqueGroups; /** @brief map of contained RenderingRuns */ std::map sharedRuns; /** @brief map of connected renderables with visibility information Used to show or hide the renderables connected to a leaf OgreSharedRuns node. */ std::map renderables; /** @brief map of connected renderables with material name information Used to resture the original materials of the renderables connected to a leaf OgreSharedRuns node. */ std::map renderableMaterials; /** @brief the bounding sphere of all the objects connected to this node. */ Sphere boundingSphere; /** @brief the axis aligned bounding box of all the objects connected to this node. */ AxisAlignedBox boundingBox; //inherited void gatherRuns(); //inherited void fireRunChanges(); //inherited SharedRuns* createInstance(); //inherited void hideRenderables() { std::map::iterator it = renderables.begin(); std::map::iterator itend = renderables.end(); while(it != itend) { (*it).second = (*it).first->isVisible(); (*it).first->setVisible(false); it++; } } //inherited void restoreRenderableVisibility() { std::map::iterator it = renderables.begin(); std::map::iterator itend = renderables.end(); while(it != itend) { (*it).first->setVisible((*it).second); it++; } } //inherited void setRenderablesVisible(bool visible) { std::map::iterator it = renderables.begin(); std::map::iterator itend = renderables.end(); while(it != itend) { (*it).first->setVisible(visible); it++; } } };