1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00

added api

This commit is contained in:
scrawl 2012-03-24 20:41:23 +01:00
parent e212a32350
commit 9d30a139cc
2 changed files with 85 additions and 8 deletions

View file

@ -3,12 +3,16 @@
#include <OgreRenderSystem.h> #include <OgreRenderSystem.h>
#include <OgreRoot.h> #include <OgreRoot.h>
#include <OgreBillboardSet.h> #include <OgreBillboardSet.h>
#include <OgreHardwareOcclusionQuery.h>
#include <OgreEntity.h>
using namespace MWRender; using namespace MWRender;
using namespace Ogre; using namespace Ogre;
OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNode* sunNode) : OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNode* sunNode) :
mSunTotalAreaQuery(0), mSunVisibleAreaQuery(0), mActiveQuery(0), mDoQuery(0), mSunVisibility(0) mSunTotalAreaQuery(0), mSunVisibleAreaQuery(0), mSingleObjectQuery(0), mActiveQuery(0),
mDoQuery(0), mSunVisibility(0), mQuerySingleObjectStarted(false),
mQuerySingleObjectRequested(false)
{ {
mRendering = renderer; mRendering = renderer;
mSunNode = sunNode; mSunNode = sunNode;
@ -18,8 +22,9 @@ OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNod
mSunTotalAreaQuery = renderSystem->createHardwareOcclusionQuery(); mSunTotalAreaQuery = renderSystem->createHardwareOcclusionQuery();
mSunVisibleAreaQuery = renderSystem->createHardwareOcclusionQuery(); mSunVisibleAreaQuery = renderSystem->createHardwareOcclusionQuery();
mSingleObjectQuery = renderSystem->createHardwareOcclusionQuery();
mSupported = (mSunTotalAreaQuery != 0) && (mSunVisibleAreaQuery != 0); mSupported = (mSunTotalAreaQuery != 0) && (mSunVisibleAreaQuery != 0) && (mSingleObjectQuery != 0);
} }
catch (Ogre::Exception e) catch (Ogre::Exception e)
{ {
@ -47,6 +52,8 @@ OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNod
mBBNode = mSunNode->getParentSceneNode()->createChildSceneNode(); mBBNode = mSunNode->getParentSceneNode()->createChildSceneNode();
mObjectNode = mRendering->getScene()->getRootSceneNode()->createChildSceneNode();
mBBQueryTotal = mRendering->getScene()->createBillboardSet(1); mBBQueryTotal = mRendering->getScene()->createBillboardSet(1);
mBBQueryTotal->setDefaultDimensions(150, 150); mBBQueryTotal->setDefaultDimensions(150, 150);
mBBQueryTotal->createBillboard(Vector3::ZERO); mBBQueryTotal->createBillboard(Vector3::ZERO);
@ -61,6 +68,13 @@ OcclusionQuery::OcclusionQuery(OEngine::Render::OgreRenderer* renderer, SceneNod
mBBQueryVisible->setRenderQueueGroup(queue); mBBQueryVisible->setRenderQueueGroup(queue);
mBBNode->attachObject(mBBQueryVisible); mBBNode->attachObject(mBBQueryVisible);
mBBQuerySingleObject = mRendering->getScene()->createBillboardSet(1);
mBBQuerySingleObject->setDefaultDimensions(10, 10);
mBBQuerySingleObject->createBillboard(Vector3::ZERO);
mBBQuerySingleObject->setMaterialName("QueryVisiblePixels");
mBBQuerySingleObject->setRenderQueueGroup(queue);
mObjectNode->attachObject(mBBQuerySingleObject);
mRendering->getScene()->addRenderObjectListener(this); mRendering->getScene()->addRenderObjectListener(this);
mDoQuery = true; mDoQuery = true;
} }
@ -70,6 +84,7 @@ OcclusionQuery::~OcclusionQuery()
RenderSystem* renderSystem = Root::getSingleton().getRenderSystem(); RenderSystem* renderSystem = Root::getSingleton().getRenderSystem();
if (mSunTotalAreaQuery) renderSystem->destroyHardwareOcclusionQuery(mSunTotalAreaQuery); if (mSunTotalAreaQuery) renderSystem->destroyHardwareOcclusionQuery(mSunTotalAreaQuery);
if (mSunVisibleAreaQuery) renderSystem->destroyHardwareOcclusionQuery(mSunVisibleAreaQuery); if (mSunVisibleAreaQuery) renderSystem->destroyHardwareOcclusionQuery(mSunVisibleAreaQuery);
if (mSingleObjectQuery) renderSystem->destroyHardwareOcclusionQuery(mSingleObjectQuery);
} }
bool OcclusionQuery::supported() bool OcclusionQuery::supported()
@ -100,11 +115,15 @@ void OcclusionQuery::notifyRenderSingleObject(Renderable* rend, const Pass* pass
mActiveQuery = mSunTotalAreaQuery; mActiveQuery = mSunTotalAreaQuery;
else if (rend == mBBQueryVisible) else if (rend == mBBQueryVisible)
mActiveQuery = mSunVisibleAreaQuery; mActiveQuery = mSunVisibleAreaQuery;
else if (rend == mBBQuerySingleObject && mQuerySingleObjectRequested)
{
mQuerySingleObjectStarted = true;
mQuerySingleObjectRequested = false;
mActiveQuery = mSingleObjectQuery;
}
if (mActiveQuery != NULL) if (mActiveQuery != NULL)
{
mActiveQuery->beginOcclusionQuery(); mActiveQuery->beginOcclusionQuery();
}
} }
} }
@ -125,7 +144,9 @@ void OcclusionQuery::update()
// (may not happen on the same frame they are requested in) // (may not happen on the same frame they are requested in)
mDoQuery = false; mDoQuery = false;
if (!mSunTotalAreaQuery->isStillOutstanding() && !mSunVisibleAreaQuery->isStillOutstanding()) if (!mSunTotalAreaQuery->isStillOutstanding()
&& !mSunVisibleAreaQuery->isStillOutstanding()
&& !mSingleObjectQuery->isStillOutstanding())
{ {
unsigned int totalPixels; unsigned int totalPixels;
unsigned int visiblePixels; unsigned int visiblePixels;
@ -144,7 +165,49 @@ void OcclusionQuery::update()
if (mSunVisibility > 1) mSunVisibility = 1; if (mSunVisibility > 1) mSunVisibility = 1;
} }
if (mQuerySingleObjectStarted)
{
unsigned int visiblePixels;
mSingleObjectQuery->pullOcclusionQuery(&visiblePixels);
mBBQuerySingleObject->setVisible(false);
mObject->setRenderQueueGroup(mObjectOldRenderQueue);
mQuerySingleObjectStarted = false;
mQuerySingleObjectRequested = false;
}
mDoQuery = true; mDoQuery = true;
} }
} }
void OcclusionQuery::occlusionTest(const Ogre::Vector3& position, Ogre::Entity* entity)
{
assert( !occlusionTestPending()
&& "Occlusion test still pending");
mBBQuerySingleObject->setVisible(true);
// we don't want the object to occlude itself
mObjectOldRenderQueue = entity->getRenderQueueGroup();
if (mObjectOldRenderQueue < RENDER_QUEUE_MAIN+2)
entity->setRenderQueueGroup(RENDER_QUEUE_MAIN+2);
mObjectNode->setPosition(position);
mQuerySingleObjectRequested = true;
}
bool OcclusionQuery::occlusionTestPending()
{
return (mQuerySingleObjectRequested || mQuerySingleObjectStarted);
}
bool OcclusionQuery::getTestResult()
{
assert( !occlusionTestPending()
&& "Occlusion test still pending");
return mTestResult;
}

View file

@ -1,9 +1,15 @@
#ifndef _GAME_OCCLUSION_QUERY_H #ifndef _GAME_OCCLUSION_QUERY_H
#define _GAME_OCCLUSION_QUERY_H #define _GAME_OCCLUSION_QUERY_H
#include <OgreHardwareOcclusionQuery.h>
#include <OgreRenderObjectListener.h> #include <OgreRenderObjectListener.h>
namespace Ogre
{
class HardwareOcclusionQuery;
class Entity;
class SceneNode;
}
#include <openengine/ogre/renderer.hpp> #include <openengine/ogre/renderer.hpp>
namespace MWRender namespace MWRender
@ -49,22 +55,30 @@ namespace MWRender
private: private:
Ogre::HardwareOcclusionQuery* mSunTotalAreaQuery; Ogre::HardwareOcclusionQuery* mSunTotalAreaQuery;
Ogre::HardwareOcclusionQuery* mSunVisibleAreaQuery; Ogre::HardwareOcclusionQuery* mSunVisibleAreaQuery;
Ogre::HardwareOcclusionQuery* mSingleObjectQuery;
Ogre::HardwareOcclusionQuery* mActiveQuery; Ogre::HardwareOcclusionQuery* mActiveQuery;
Ogre::BillboardSet* mBBQueryVisible; Ogre::BillboardSet* mBBQueryVisible;
Ogre::BillboardSet* mBBQueryTotal; Ogre::BillboardSet* mBBQueryTotal;
Ogre::BillboardSet* mBBQuerySingleObject;
Ogre::SceneNode* mSunNode; Ogre::SceneNode* mSunNode;
Ogre::SceneNode* mBBNode; Ogre::SceneNode* mBBNode;
float mSunVisibility; float mSunVisibility;
Ogre::Entity* mObject;
Ogre::SceneNode* mObjectNode;
int mObjectOldRenderQueue;
bool mTestResult; bool mTestResult;
bool mSupported; bool mSupported;
bool mDoQuery; bool mDoQuery;
bool mQuerySingleObjectRequested;
bool mQuerySingleObjectStarted;
OEngine::Render::OgreRenderer* mRendering; OEngine::Render::OgreRenderer* mRendering;
protected: protected: