From 9cf9c2876e9bcd9ea40d3090deb896df6988e9b4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 2 May 2015 22:45:27 +0200 Subject: [PATCH] Pathgrid rendering --- apps/openmw/CMakeLists.txt | 4 +- apps/openmw/mwbase/world.hpp | 12 +- apps/openmw/mwmechanics/pathfinding.hpp | 5 + apps/openmw/mwrender/creatureanimation.cpp | 3 - apps/openmw/mwrender/debugging.cpp | 245 +++++++++------------ apps/openmw/mwrender/debugging.hpp | 50 ++--- apps/openmw/mwrender/npcanimation.cpp | 1 - apps/openmw/mwrender/objects.cpp | 1 - apps/openmw/mwrender/renderconst.hpp | 76 ------- apps/openmw/mwrender/renderingmanager.cpp | 30 +++ apps/openmw/mwrender/renderingmanager.hpp | 6 + apps/openmw/mwrender/rendermode.hpp | 17 ++ apps/openmw/mwrender/sky.cpp | 1 - apps/openmw/mwrender/vismask.hpp | 1 + apps/openmw/mwscript/miscextensions.cpp | 8 +- apps/openmw/mwworld/scene.cpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 4 +- apps/openmw/mwworld/worldimp.hpp | 2 +- 18 files changed, 197 insertions(+), 271 deletions(-) delete mode 100644 apps/openmw/mwrender/renderconst.hpp create mode 100644 apps/openmw/mwrender/rendermode.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index f049f03870..ed55301260 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -21,8 +21,8 @@ source_group(game FILES ${GAME} ${GAME_HEADER}) add_openmw_dir (mwrender actors objects renderingmanager animation sky npcanimation vismask - creatureanimation effectmanager util renderinginterface -# debugging camera activatoranimation + creatureanimation effectmanager util renderinginterface debugging rendermode +# camera activatoranimation # localmap occlusionquery water shadows # characterpreview globalmap ripplesimulation refraction # terrainstorage renderconst weaponanimation diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 1f27756d10..4ccbfc784c 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -9,6 +9,8 @@ #include "../mwworld/ptr.hpp" +#include "../mwrender/rendermode.hpp" + namespace Ogre { class Vector2; @@ -83,14 +85,6 @@ namespace MWBase public: - enum RenderMode - { - Render_CollisionDebug, - Render_Wireframe, - Render_Pathgrid, - Render_BoundingBoxes - }; - struct DoorMarker { std::string name; @@ -320,7 +314,7 @@ namespace MWBase /// collisions and gravity. /// \return Resulting mode - virtual bool toggleRenderMode (RenderMode mode) = 0; + virtual bool toggleRenderMode (MWRender::RenderMode mode) = 0; ///< Toggle a render mode. ///< \return Resulting mode diff --git a/apps/openmw/mwmechanics/pathfinding.hpp b/apps/openmw/mwmechanics/pathfinding.hpp index f48de6624c..0f4d42775c 100644 --- a/apps/openmw/mwmechanics/pathfinding.hpp +++ b/apps/openmw/mwmechanics/pathfinding.hpp @@ -88,6 +88,11 @@ namespace MWMechanics return ESM::Pathgrid::Point(static_cast(p.pos[0]), static_cast(p.pos[1]), static_cast(p.pos[2])); } + static osg::Vec3f MakeOsgVec3(const ESM::Pathgrid::Point& p) + { + return osg::Vec3f(static_cast(p.mX), static_cast(p.mY), static_cast(p.mZ)); + } + /// utility function to convert a Pathgrid::Point to a Ogre::Vector3 static Ogre::Vector3 MakeOgreVector3(const ESM::Pathgrid::Point& p) { diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index d2abf14135..25d9e9e471 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -12,12 +12,9 @@ #include "../mwworld/class.hpp" -#include "renderconst.hpp" - namespace MWRender { - CreatureAnimation::CreatureAnimation(const MWWorld::Ptr &ptr, const std::string& model, Resource::ResourceSystem* resourceSystem) : Animation(ptr, osg::ref_ptr(ptr.getRefData().getBaseNode()), resourceSystem) diff --git a/apps/openmw/mwrender/debugging.cpp b/apps/openmw/mwrender/debugging.cpp index 79eeff2d04..97ead9d7d3 100644 --- a/apps/openmw/mwrender/debugging.cpp +++ b/apps/openmw/mwrender/debugging.cpp @@ -2,13 +2,10 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include @@ -23,145 +20,118 @@ #include "../mwworld/esmstore.hpp" #include "../mwmechanics/pathfinding.hpp" -#include "renderconst.hpp" - -using namespace Ogre; +#include "vismask.hpp" namespace MWRender { -static const std::string PATHGRID_POINT_MATERIAL = "pathgridPointMaterial"; -static const std::string PATHGRID_LINE_MATERIAL = "pathgridLineMaterial"; -static const std::string DEBUGGING_GROUP = "debugging"; static const int POINT_MESH_BASE = 35; -void Debugging::createGridMaterials() +osg::ref_ptr Debugging::createPathgridLines(const ESM::Pathgrid *pathgrid) { - if (mGridMatsCreated) return; + osg::ref_ptr geom = new osg::Geometry; - if (MaterialManager::getSingleton().getByName(PATHGRID_LINE_MATERIAL, DEBUGGING_GROUP).isNull()) - { - MaterialPtr lineMatPtr = MaterialManager::getSingleton().create(PATHGRID_LINE_MATERIAL, DEBUGGING_GROUP); - lineMatPtr->setReceiveShadows(false); - lineMatPtr->getTechnique(0)->setLightingEnabled(true); - lineMatPtr->getTechnique(0)->getPass(0)->setDiffuse(1,1,0,0); - lineMatPtr->getTechnique(0)->getPass(0)->setAmbient(1,1,0); - lineMatPtr->getTechnique(0)->getPass(0)->setSelfIllumination(1,1,0); - } + osg::ref_ptr vertices = new osg::Vec3Array; - if (MaterialManager::getSingleton().getByName(PATHGRID_POINT_MATERIAL, DEBUGGING_GROUP).isNull()) - { - MaterialPtr pointMatPtr = MaterialManager::getSingleton().create(PATHGRID_POINT_MATERIAL, DEBUGGING_GROUP); - pointMatPtr->setReceiveShadows(false); - pointMatPtr->getTechnique(0)->setLightingEnabled(true); - pointMatPtr->getTechnique(0)->getPass(0)->setDiffuse(1,0,0,0); - pointMatPtr->getTechnique(0)->getPass(0)->setAmbient(1,0,0); - pointMatPtr->getTechnique(0)->getPass(0)->setSelfIllumination(1,0,0); - } - mGridMatsCreated = true; -} - -void Debugging::destroyGridMaterials() -{ - if (mGridMatsCreated) - { - MaterialManager::getSingleton().remove(PATHGRID_POINT_MATERIAL); - MaterialManager::getSingleton().remove(PATHGRID_LINE_MATERIAL); - mGridMatsCreated = false; - } -} - -ManualObject *Debugging::createPathgridLines(const ESM::Pathgrid *pathgrid) -{ - ManualObject *result = mSceneMgr->createManualObject(); - - result->begin(PATHGRID_LINE_MATERIAL, RenderOperation::OT_LINE_LIST); for(ESM::Pathgrid::EdgeList::const_iterator it = pathgrid->mEdges.begin(); it != pathgrid->mEdges.end(); ++it) { const ESM::Pathgrid::Edge &edge = *it; const ESM::Pathgrid::Point &p1 = pathgrid->mPoints[edge.mV0], &p2 = pathgrid->mPoints[edge.mV1]; - Vector3 direction = (MWMechanics::PathFinder::MakeOgreVector3(p2) - MWMechanics::PathFinder::MakeOgreVector3(p1)); - Vector3 lineDisplacement = direction.crossProduct(Vector3::UNIT_Z).normalisedCopy(); + + osg::Vec3f direction = MWMechanics::PathFinder::MakeOsgVec3(p2) - MWMechanics::PathFinder::MakeOsgVec3(p1); + osg::Vec3f lineDisplacement = (direction^osg::Vec3f(0,0,1)); + lineDisplacement.normalize(); + lineDisplacement = lineDisplacement * POINT_MESH_BASE + - Vector3(0, 0, 10); // move lines up a little, so they will be less covered by meshes/landscape - result->position(MWMechanics::PathFinder::MakeOgreVector3(p1) + lineDisplacement); - result->position(MWMechanics::PathFinder::MakeOgreVector3(p2) + lineDisplacement); + osg::Vec3f(0, 0, 10); // move lines up a little, so they will be less covered by meshes/landscape + + vertices->push_back(MWMechanics::PathFinder::MakeOsgVec3(p1) + lineDisplacement); + vertices->push_back(MWMechanics::PathFinder::MakeOsgVec3(p2) + lineDisplacement); } - result->end(); - result->setVisibilityFlags (RV_Debug); + geom->setVertexArray(vertices); - return result; + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); + + osg::ref_ptr colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.f, 1.f, 0.f, 1.f)); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); + + return geom; } -ManualObject *Debugging::createPathgridPoints(const ESM::Pathgrid *pathgrid) +osg::ref_ptr Debugging::createPathgridPoints(const ESM::Pathgrid *pathgrid) { - ManualObject *result = mSceneMgr->createManualObject(); + osg::ref_ptr geom = new osg::Geometry; + const float height = POINT_MESH_BASE * sqrtf(2); - result->begin(PATHGRID_POINT_MATERIAL, RenderOperation::OT_TRIANGLE_STRIP); + osg::ref_ptr vertices = new osg::Vec3Array; + osg::ref_ptr indices = new osg::UShortArray; bool first = true; - uint32 startIndex = 0; + unsigned short startIndex = 0; for(ESM::Pathgrid::PointList::const_iterator it = pathgrid->mPoints.begin(); it != pathgrid->mPoints.end(); ++it, startIndex += 6) { - Vector3 pointPos(MWMechanics::PathFinder::MakeOgreVector3(*it)); + osg::Vec3f pointPos(MWMechanics::PathFinder::MakeOsgVec3(*it)); if (!first) { // degenerate triangle from previous octahedron - result->index(startIndex - 4); // 2nd point of previous octahedron - result->index(startIndex); // start point of current octahedron + indices->push_back(startIndex - 4); // 2nd point of previous octahedron + indices->push_back(startIndex); // start point of current octahedron } - Ogre::Real pointMeshBase = static_cast(POINT_MESH_BASE); + float pointMeshBase = static_cast(POINT_MESH_BASE); - result->position(pointPos + Vector3(0, 0, height)); // 0 - result->position(pointPos + Vector3(-pointMeshBase, -pointMeshBase, 0)); // 1 - result->position(pointPos + Vector3(pointMeshBase, -pointMeshBase, 0)); // 2 - result->position(pointPos + Vector3(pointMeshBase, pointMeshBase, 0)); // 3 - result->position(pointPos + Vector3(-pointMeshBase, pointMeshBase, 0)); // 4 - result->position(pointPos + Vector3(0, 0, -height)); // 5 + vertices->push_back(pointPos + osg::Vec3f(0, 0, height)); // 0 + vertices->push_back(pointPos + osg::Vec3f(-pointMeshBase, -pointMeshBase, 0)); // 1 + vertices->push_back(pointPos + osg::Vec3f(pointMeshBase, -pointMeshBase, 0)); // 2 + vertices->push_back(pointPos + osg::Vec3f(pointMeshBase, pointMeshBase, 0)); // 3 + vertices->push_back(pointPos + osg::Vec3f(-pointMeshBase, pointMeshBase, 0)); // 4 + vertices->push_back(pointPos + osg::Vec3f(0, 0, -height)); // 5 - result->index(startIndex + 0); - result->index(startIndex + 1); - result->index(startIndex + 2); - result->index(startIndex + 5); - result->index(startIndex + 3); - result->index(startIndex + 4); + indices->push_back(startIndex + 0); + indices->push_back(startIndex + 1); + indices->push_back(startIndex + 2); + indices->push_back(startIndex + 5); + indices->push_back(startIndex + 3); + indices->push_back(startIndex + 4); // degenerates - result->index(startIndex + 4); - result->index(startIndex + 5); - result->index(startIndex + 5); + indices->push_back(startIndex + 4); + indices->push_back(startIndex + 5); + indices->push_back(startIndex + 5); // end degenerates - result->index(startIndex + 1); - result->index(startIndex + 4); - result->index(startIndex + 0); - result->index(startIndex + 3); - result->index(startIndex + 2); + indices->push_back(startIndex + 1); + indices->push_back(startIndex + 4); + indices->push_back(startIndex + 0); + indices->push_back(startIndex + 3); + indices->push_back(startIndex + 2); first = false; } - result->end(); + geom->setVertexArray(vertices); - result->setVisibilityFlags (RV_Debug); + geom->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, indices->size(), &(*indices)[0])); - return result; + osg::ref_ptr colors = new osg::Vec4Array; + colors->push_back(osg::Vec4(1.f, 0.f, 0.f, 1.f)); + geom->setColorArray(colors, osg::Array::BIND_OVERALL); + + return geom; } -Debugging::Debugging(SceneNode *root, OEngine::Physic::PhysicEngine *engine) : - mRootNode(root), mEngine(engine), - mSceneMgr(root->getCreator()), - mPathgridEnabled(false), - mInteriorPathgridNode(NULL), mPathGridRoot(NULL), - mGridMatsCreated(false) +Debugging::Debugging(osg::ref_ptr root /*, OEngine::Physic::PhysicEngine *engine*/) + : mRootNode(root) + , mPathgridEnabled(false) + , mInteriorPathgridNode(NULL) + , mPathGridRoot(NULL) { - ResourceGroupManager::getSingleton().createResourceGroup(DEBUGGING_GROUP); } Debugging::~Debugging() @@ -170,34 +140,34 @@ Debugging::~Debugging() { togglePathgrid(); } - - ResourceGroupManager::getSingleton().destroyResourceGroup(DEBUGGING_GROUP); } bool Debugging::toggleRenderMode (int mode){ switch (mode) { - case MWBase::World::Render_CollisionDebug: + //case Render_CollisionDebug: - return mEngine->toggleDebugRendering(); + //return mEngine->toggleDebugRendering(); - case MWBase::World::Render_Pathgrid: + case Render_Pathgrid: togglePathgrid(); return mPathgridEnabled; + default: + return false; } return false; } -void Debugging::cellAdded(MWWorld::CellStore *store) +void Debugging::addCell(const MWWorld::CellStore *store) { mActiveCells.push_back(store); if (mPathgridEnabled) enableCellPathgrid(store); } -void Debugging::cellRemoved(MWWorld::CellStore *store) +void Debugging::removeCell(const MWWorld::CellStore *store) { mActiveCells.erase(std::remove(mActiveCells.begin(), mActiveCells.end(), store), mActiveCells.end()); if (mPathgridEnabled) @@ -209,10 +179,11 @@ void Debugging::togglePathgrid() mPathgridEnabled = !mPathgridEnabled; if (mPathgridEnabled) { - createGridMaterials(); - // add path grid meshes to already loaded cells - mPathGridRoot = mRootNode->createChildSceneNode(); + mPathGridRoot = new osg::Group; + mPathGridRoot->setNodeMask(Mask_Debug); + mRootNode->addChild(mPathGridRoot); + for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); ++it) { enableCellPathgrid(*it); @@ -225,29 +196,44 @@ void Debugging::togglePathgrid() { disableCellPathgrid(*it); } - mPathGridRoot->removeAndDestroyAllChildren(); - mSceneMgr->destroySceneNode(mPathGridRoot); - mPathGridRoot = NULL; - destroyGridMaterials(); + + if (mPathGridRoot) + { + mRootNode->removeChild(mPathGridRoot); + mPathGridRoot = NULL; + } } } -void Debugging::enableCellPathgrid(MWWorld::CellStore *store) +void Debugging::enableCellPathgrid(const MWWorld::CellStore *store) { MWBase::World* world = MWBase::Environment::get().getWorld(); const ESM::Pathgrid *pathgrid = world->getStore().get().search(*store->getCell()); if (!pathgrid) return; - Vector3 cellPathGridPos(0, 0, 0); + osg::Vec3f cellPathGridPos(0, 0, 0); if (store->getCell()->isExterior()) { - cellPathGridPos.x = static_cast(store->getCell()->mData.mX * ESM::Land::REAL_SIZE); - cellPathGridPos.y = static_cast(store->getCell()->mData.mY * ESM::Land::REAL_SIZE); + cellPathGridPos.x() = static_cast(store->getCell()->mData.mX * ESM::Land::REAL_SIZE); + cellPathGridPos.y() = static_cast(store->getCell()->mData.mY * ESM::Land::REAL_SIZE); } - SceneNode *cellPathGrid = mPathGridRoot->createChildSceneNode(cellPathGridPos); - cellPathGrid->attachObject(createPathgridLines(pathgrid)); - cellPathGrid->attachObject(createPathgridPoints(pathgrid)); + + osg::ref_ptr cellPathGrid = new osg::PositionAttitudeTransform; + cellPathGrid->setPosition(cellPathGridPos); + + osg::ref_ptr lineGeode = new osg::Geode; + osg::ref_ptr lines = createPathgridLines(pathgrid); + lineGeode->addDrawable(lines); + + osg::ref_ptr pointGeode = new osg::Geode; + osg::ref_ptr points = createPathgridPoints(pathgrid); + pointGeode->addDrawable(points); + + cellPathGrid->addChild(lineGeode); + cellPathGrid->addChild(pointGeode); + + mPathGridRoot->addChild(cellPathGrid); if (store->getCell()->isExterior()) { @@ -260,7 +246,7 @@ void Debugging::enableCellPathgrid(MWWorld::CellStore *store) } } -void Debugging::disableCellPathgrid(MWWorld::CellStore *store) +void Debugging::disableCellPathgrid(const MWWorld::CellStore *store) { if (store->getCell()->isExterior()) { @@ -268,7 +254,7 @@ void Debugging::disableCellPathgrid(MWWorld::CellStore *store) mExteriorPathgridNodes.find(std::make_pair(store->getCell()->getGridX(), store->getCell()->getGridY())); if (it != mExteriorPathgridNodes.end()) { - destroyCellPathgridNode(it->second); + mPathGridRoot->removeChild(it->second); mExteriorPathgridNodes.erase(it); } } @@ -276,27 +262,10 @@ void Debugging::disableCellPathgrid(MWWorld::CellStore *store) { if (mInteriorPathgridNode) { - destroyCellPathgridNode(mInteriorPathgridNode); + mPathGridRoot->removeChild(mInteriorPathgridNode); mInteriorPathgridNode = NULL; } } } -void Debugging::destroyCellPathgridNode(SceneNode *node) -{ - mPathGridRoot->removeChild(node); - destroyAttachedObjects(node); - mSceneMgr->destroySceneNode(node); -} - -void Debugging::destroyAttachedObjects(SceneNode *node) -{ - SceneNode::ObjectIterator objIt = node->getAttachedObjectIterator(); - while (objIt.hasMoreElements()) - { - MovableObject *mesh = static_cast(objIt.getNext()); - mSceneMgr->destroyMovableObject(mesh); - } -} - } diff --git a/apps/openmw/mwrender/debugging.hpp b/apps/openmw/mwrender/debugging.hpp index e243318013..4ec5bc41d3 100644 --- a/apps/openmw/mwrender/debugging.hpp +++ b/apps/openmw/mwrender/debugging.hpp @@ -7,6 +7,8 @@ #include #include +#include + namespace ESM { struct Pathgrid; @@ -20,16 +22,10 @@ namespace OEngine } } -namespace Ogre +namespace osg { - class Camera; - class Viewport; - class SceneManager; - class SceneNode; - class RaySceneQuery; - class Quaternion; - class Vector3; - class ManualObject; + class Group; + class Geometry; } namespace MWWorld @@ -42,47 +38,37 @@ namespace MWRender { class Debugging { - OEngine::Physic::PhysicEngine* mEngine; - Ogre::SceneManager *mSceneMgr; + //OEngine::Physic::PhysicEngine* mEngine; // Path grid stuff bool mPathgridEnabled; void togglePathgrid(); - typedef std::vector CellList; + typedef std::vector CellList; CellList mActiveCells; - Ogre::SceneNode *mRootNode; + osg::ref_ptr mRootNode; - Ogre::SceneNode *mPathGridRoot; + osg::ref_ptr mPathGridRoot; - typedef std::map, Ogre::SceneNode *> ExteriorPathgridNodes; + typedef std::map, osg::ref_ptr > ExteriorPathgridNodes; ExteriorPathgridNodes mExteriorPathgridNodes; - Ogre::SceneNode *mInteriorPathgridNode; + osg::ref_ptr mInteriorPathgridNode; - void enableCellPathgrid(MWWorld::CellStore *store); - void disableCellPathgrid(MWWorld::CellStore *store); - - // utility - void destroyCellPathgridNode(Ogre::SceneNode *node); - void destroyAttachedObjects(Ogre::SceneNode *node); - - // materials - bool mGridMatsCreated; - void createGridMaterials(); - void destroyGridMaterials(); + void enableCellPathgrid(const MWWorld::CellStore *store); + void disableCellPathgrid(const MWWorld::CellStore *store); // path grid meshes - Ogre::ManualObject *createPathgridLines(const ESM::Pathgrid *pathgrid); - Ogre::ManualObject *createPathgridPoints(const ESM::Pathgrid *pathgrid); + osg::ref_ptr createPathgridLines(const ESM::Pathgrid *pathgrid); + osg::ref_ptr createPathgridPoints(const ESM::Pathgrid *pathgrid); public: - Debugging(Ogre::SceneNode* root, OEngine::Physic::PhysicEngine *engine); + Debugging(osg::ref_ptr root /*, OEngine::Physic::PhysicEngine *engine*/); ~Debugging(); bool toggleRenderMode (int mode); - void cellAdded(MWWorld::CellStore* store); - void cellRemoved(MWWorld::CellStore* store); + void addCell(const MWWorld::CellStore* store); + void removeCell(const MWWorld::CellStore* store); }; diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 80dbf3c7f6..d6aa05fcbc 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -23,7 +23,6 @@ #include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/soundmanager.hpp" -#include "renderconst.hpp" #include "camera.hpp" namespace diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index a06b751cc7..6f4f4ef79d 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -17,7 +17,6 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/class.hpp" -#include "renderconst.hpp" #include "animation.hpp" #include "npcanimation.hpp" #include "creatureanimation.hpp" diff --git a/apps/openmw/mwrender/renderconst.hpp b/apps/openmw/mwrender/renderconst.hpp deleted file mode 100644 index cfd84cb32e..0000000000 --- a/apps/openmw/mwrender/renderconst.hpp +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef GAME_RENDER_CONST_H -#define GAME_RENDER_CONST_H - -#include - -namespace MWRender -{ - -// Render queue groups -enum RenderQueueGroups -{ - // Sky early (atmosphere, clouds, moons) - RQG_SkiesEarly = Ogre::RENDER_QUEUE_SKIES_EARLY, - - RQG_Main = Ogre::RENDER_QUEUE_MAIN, - - RQG_Alpha = Ogre::RENDER_QUEUE_MAIN+1, - - RQG_OcclusionQuery = Ogre::RENDER_QUEUE_6, - - RQG_UnderWater = Ogre::RENDER_QUEUE_4, - - RQG_Water = RQG_Alpha, - RQG_Ripples = RQG_Water+1, - - // Sky late (sun & sun flare) - RQG_SkiesLate = Ogre::RENDER_QUEUE_SKIES_LATE -}; - -// Visibility flags -enum VisibilityFlags -{ - // Terrain - RV_Terrain = (1<<0), - - // Statics (e.g. trees, houses) - RV_Statics = (1<<1), - - // Small statics - RV_StaticsSmall = (1<<2), - - // Water - RV_Water = (1<<3), - - // Actors (npcs, creatures) - RV_Actors = (1<<4), - - // Misc objects (containers, dynamic objects) - RV_Misc = (1<<5), - - // VFX, don't appear on map and don't cast shadows - RV_Effects = (1<<6), - - RV_Sky = (1<<7), - - // not visible in reflection - RV_NoReflection = (1<<8), - - RV_OcclusionQuery = (1<<9), - - RV_Debug = (1<<10), - - // overlays, we only want these on the main render target - RV_Overlay = (1<<11), - - // First person meshes do not cast shadows - RV_FirstPerson = (1<<12), - - RV_Map = RV_Terrain + RV_Statics + RV_StaticsSmall + RV_Misc + RV_Water, - - RV_Refraction = RV_Actors + RV_Misc + RV_Statics + RV_StaticsSmall + RV_Terrain + RV_Effects + RV_Sky + RV_FirstPerson -}; - -} - -#endif diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index d07c98ed7d..5cb7795453 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -21,10 +21,13 @@ #include +#include "../mwbase/world.hpp" + #include "sky.hpp" #include "effectmanager.hpp" #include "npcanimation.hpp" #include "vismask.hpp" +#include "debugging.hpp" namespace MWRender { @@ -88,6 +91,8 @@ namespace MWRender mRootNode->addChild(lightRoot); + mDebugging.reset(new Debugging(mRootNode)); + mObjects.reset(new Objects(mResourceSystem, lightRoot)); mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem)); @@ -182,8 +187,14 @@ namespace MWRender return eye; } + void RenderingManager::addCell(const MWWorld::CellStore *store) + { + mDebugging->addCell(store); + } + void RenderingManager::removeCell(const MWWorld::CellStore *store) { + mDebugging->removeCell(store); mObjects->removeCell(store); } @@ -192,6 +203,25 @@ namespace MWRender mSky->setEnabled(enabled); } + bool RenderingManager::toggleRenderMode(RenderMode mode) + { + if (mode == Render_CollisionDebug || mode == Render_Pathgrid) + return mDebugging->toggleRenderMode(mode); + else if (mode == Render_Wireframe) + { + return false; + } + /* + else //if (mode == Render_BoundingBoxes) + { + bool show = !mRendering.getScene()->getShowBoundingBoxes(); + mRendering.getScene()->showBoundingBoxes(show); + return show; + } + */ + return false; + } + void RenderingManager::configureFog(const ESM::Cell *cell) { osg::Vec4f color = SceneUtil::colourFromRGB(cell->mAmbi.mFog); diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 71c70b9907..334025096d 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -7,6 +7,7 @@ #include "objects.hpp" #include "renderinginterface.hpp" +#include "rendermode.hpp" namespace osg { @@ -37,6 +38,7 @@ namespace MWRender class EffectManager; class SkyManager; class NpcAnimation; + class Debugging; class RenderingManager : public MWRender::RenderingInterface { @@ -57,6 +59,7 @@ namespace MWRender void configureFog(const ESM::Cell* cell); void configureFog(float fogDepth, const osg::Vec4f& colour); + void addCell(const MWWorld::CellStore* store); void removeCell(const MWWorld::CellStore* store); // TODO rename to setRotation/setPosition/setScale, along with the World equivalents @@ -66,6 +69,8 @@ namespace MWRender void setSkyEnabled(bool enabled); + bool toggleRenderMode(RenderMode mode); + SkyManager* getSkyManager(); osg::Vec3f getEyePos(); @@ -94,6 +99,7 @@ namespace MWRender osg::ref_ptr mSunLight; + std::auto_ptr mDebugging; std::auto_ptr mObjects; std::auto_ptr mSky; std::auto_ptr mEffectManager; diff --git a/apps/openmw/mwrender/rendermode.hpp b/apps/openmw/mwrender/rendermode.hpp new file mode 100644 index 0000000000..a74d9bd526 --- /dev/null +++ b/apps/openmw/mwrender/rendermode.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_MWRENDER_RENDERMODE_H +#define OPENMW_MWRENDER_RENDERMODE_H + +namespace MWRender +{ + + enum RenderMode + { + Render_CollisionDebug, + Render_Wireframe, + Render_Pathgrid, + Render_BoundingBoxes + }; + +} + +#endif diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 4fd5b7e631..48de57239c 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -34,7 +34,6 @@ #include "../mwworld/fallback.hpp" -#include "renderconst.hpp" #include "renderingmanager.hpp" namespace diff --git a/apps/openmw/mwrender/vismask.hpp b/apps/openmw/mwrender/vismask.hpp index 48845c78c3..8726955568 100644 --- a/apps/openmw/mwrender/vismask.hpp +++ b/apps/openmw/mwrender/vismask.hpp @@ -11,6 +11,7 @@ namespace MWRender // child of Scene Mask_Effect = 0x2, + Mask_Debug = 0x4, // top level masks Mask_Scene = 0x10, diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 29f586a653..ce74c0c9f3 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -213,7 +213,7 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { bool enabled = - MWBase::Environment::get().getWorld()->toggleRenderMode (MWBase::World::Render_CollisionDebug); + MWBase::Environment::get().getWorld()->toggleRenderMode (MWRender::Render_CollisionDebug); runtime.getContext().report (enabled ? "Collision Mesh Rendering -> On" : "Collision Mesh Rendering -> Off"); @@ -228,7 +228,7 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { bool enabled = - MWBase::Environment::get().getWorld()->toggleRenderMode (MWBase::World::Render_BoundingBoxes); + MWBase::Environment::get().getWorld()->toggleRenderMode (MWRender::Render_BoundingBoxes); runtime.getContext().report (enabled ? "Bounding Box Rendering -> On" : "Bounding Box Rendering -> Off"); @@ -242,7 +242,7 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { bool enabled = - MWBase::Environment::get().getWorld()->toggleRenderMode (MWBase::World::Render_Wireframe); + MWBase::Environment::get().getWorld()->toggleRenderMode (MWRender::Render_Wireframe); runtime.getContext().report (enabled ? "Wireframe Rendering -> On" : "Wireframe Rendering -> Off"); @@ -255,7 +255,7 @@ namespace MWScript virtual void execute (Interpreter::Runtime& runtime) { bool enabled = - MWBase::Environment::get().getWorld()->toggleRenderMode (MWBase::World::Render_Pathgrid); + MWBase::Environment::get().getWorld()->toggleRenderMode (MWRender::Render_Pathgrid); runtime.getContext().report (enabled ? "Path Grid rendering -> On" : "Path Grid Rendering -> Off"); diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index e61e5d84e8..637fde18ca 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -270,8 +270,8 @@ namespace MWWorld /// \todo rescale depending on the state of a new GMST insertCell (*cell, true, loadingListener); + mRendering.addCell(cell); #if 0 - mRendering.cellAdded (cell); bool waterEnabled = cell->getCell()->hasWater(); mRendering.setWaterEnabled(waterEnabled); if (waterEnabled) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 842a24dedb..fda9d53af6 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1501,9 +1501,9 @@ namespace MWWorld return 0;//mPhysics->toggleCollisionMode(); } - bool World::toggleRenderMode (RenderMode mode) + bool World::toggleRenderMode (MWRender::RenderMode mode) { - return 0;//mRendering->toggleRenderMode (mode); + return mRendering->toggleRenderMode (mode); } const ESM::Potion *World::createRecord (const ESM::Potion& record) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 9598d43571..464f2d605a 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -396,7 +396,7 @@ namespace MWWorld /// collisions and gravity. ///< \return Resulting mode - virtual bool toggleRenderMode (RenderMode mode); + virtual bool toggleRenderMode (MWRender::RenderMode mode); ///< Toggle a render mode. ///< \return Resulting mode