1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/apps/openmw/mwrender/water.hpp

179 lines
4.9 KiB
C++
Raw Normal View History

2012-01-14 23:34:14 +00:00
#ifndef GAME_MWRENDER_WATER_H
#define GAME_MWRENDER_WATER_H
#include <OgrePlane.h>
#include <OgreRenderQueue.h>
#include <OgreRenderQueueListener.h>
#include <OgreRenderTargetListener.h>
#include <OgreMaterial.h>
#include <OgreTexture.h>
#include <OgreVector2.h>
2012-01-22 01:05:08 +00:00
#include <components/esm/loadcell.hpp>
2012-05-29 04:45:44 +00:00
#include <components/settings/settings.hpp>
2012-01-14 23:34:14 +00:00
2013-02-27 08:20:42 +00:00
#include <extern/shiny/Main/MaterialInstance.hpp>
2012-04-03 13:13:47 +00:00
#include "renderconst.hpp"
2013-02-27 08:20:42 +00:00
#include "../mwworld/ptr.hpp"
2012-07-20 12:45:42 +00:00
namespace Ogre
{
class Camera;
class SceneManager;
class SceneNode;
class Entity;
class Vector3;
class Rectangle2D;
struct RenderTargetEvent;
2012-10-09 15:10:25 +00:00
}
2012-05-29 04:45:44 +00:00
2012-01-14 23:34:14 +00:00
namespace MWRender {
2012-04-03 19:16:43 +00:00
class SkyManager;
class RenderingManager;
2013-02-01 22:43:23 +00:00
class RippleSimulation;
class Refraction;
2012-04-03 19:16:43 +00:00
class Reflection
{
public:
Reflection(Ogre::SceneManager* sceneManager)
2013-05-02 18:43:21 +00:00
: mSceneMgr(sceneManager)
, mIsUnderwater(false)
2013-07-31 16:46:32 +00:00
, mCamera(NULL)
, mParentCamera(NULL)
2013-05-02 18:43:21 +00:00
{}
virtual ~Reflection() {}
2013-02-03 18:01:59 +00:00
virtual void setHeight (float height) {}
virtual void setParentCamera (Ogre::Camera* parent) { mParentCamera = parent; }
void setUnderwater(bool underwater) { mIsUnderwater = underwater; }
virtual void setActive (bool active) {}
virtual void setViewportBackground(Ogre::ColourValue colour) {}
virtual void update() {}
virtual void setVisibilityMask (int flags) {}
protected:
Ogre::Camera* mCamera;
Ogre::Camera* mParentCamera;
Ogre::TexturePtr mTexture;
Ogre::SceneManager* mSceneMgr;
bool mIsUnderwater;
};
class CubeReflection : public Reflection
{
public:
CubeReflection(Ogre::SceneManager* sceneManager);
virtual ~CubeReflection();
virtual void update();
protected:
Ogre::RenderTarget* mRenderTargets[6];
};
class PlaneReflection : public Reflection, public Ogre::RenderQueueListener, public Ogre::RenderTargetListener
{
public:
PlaneReflection(Ogre::SceneManager* sceneManager, SkyManager* sky);
virtual ~PlaneReflection();
2013-02-03 18:01:59 +00:00
virtual void setHeight (float height);
virtual void setActive (bool active);
virtual void setVisibilityMask (int flags);
void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
void renderQueueStarted (Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &skipThisInvocation);
void renderQueueEnded (Ogre::uint8 queueGroupId, const Ogre::String &invocation, bool &repeatThisInvocation);
virtual void setViewportBackground(Ogre::ColourValue colour);
protected:
Ogre::RenderTarget* mRenderTarget;
SkyManager* mSky;
Ogre::Plane mWaterPlane;
Ogre::Plane mErrorPlane;
2013-02-12 19:56:00 +00:00
Ogre::Plane mErrorPlaneUnderwater;
bool mRenderActive;
};
/// Water rendering
class Water : public sh::MaterialInstanceListener
{
static const int CELL_SIZE = 8192;
Ogre::Camera *mCamera;
Ogre::SceneManager *mSceneMgr;
2012-01-14 23:34:14 +00:00
Ogre::Plane mWaterPlane;
2012-07-19 20:23:07 +00:00
Ogre::SceneNode *mWaterNode;
Ogre::Entity *mWater;
2012-01-14 23:34:14 +00:00
bool mIsUnderwater;
2012-04-03 13:13:47 +00:00
bool mActive;
2012-04-12 14:46:56 +00:00
bool mToggled;
int mTop;
2012-01-14 23:34:14 +00:00
float mWaterTimer;
2013-02-01 22:43:23 +00:00
Ogre::Vector3 getSceneNodeCoordinates(int gridX, int gridY);
2012-01-14 23:34:14 +00:00
protected:
2012-05-29 04:45:44 +00:00
void applyRTT();
void applyVisibilityMask();
2012-04-12 14:46:56 +00:00
void updateVisible();
RenderingManager* mRendering;
2012-04-03 19:16:43 +00:00
SkyManager* mSky;
2012-04-06 13:51:57 +00:00
Ogre::MaterialPtr mMaterial;
bool mUnderwaterEffect;
2012-04-03 13:13:47 +00:00
int mVisibilityFlags;
Reflection* mReflection;
Refraction* mRefraction;
RippleSimulation* mSimulation;
Ogre::Vector2 mPlayer;
public:
2013-02-27 08:20:42 +00:00
Water (Ogre::Camera *camera, RenderingManager* rend);
~Water();
2012-01-14 23:34:14 +00:00
2012-04-03 13:13:47 +00:00
void setActive(bool active);
void toggle();
2013-02-01 22:43:23 +00:00
void update(float dt, Ogre::Vector3 player);
void frameStarted(float dt);
2012-01-14 23:34:14 +00:00
2013-02-27 08:20:42 +00:00
/// adds an emitter, position will be tracked automatically using its scene node
void addEmitter (const MWWorld::Ptr& ptr, float scale = 1.f, float force = 1.f);
void removeEmitter (const MWWorld::Ptr& ptr);
void updateEmitterPtr (const MWWorld::Ptr& old, const MWWorld::Ptr& ptr);
2012-04-05 13:30:55 +00:00
void setViewportBackground(const Ogre::ColourValue& bg);
2012-05-29 04:45:44 +00:00
void processChangedSettings(const Settings::CategorySettingVector& settings);
/// Updates underwater state accordingly
void updateUnderwater(bool underwater);
void changeCell(const ESM::Cell* cell);
void setHeight(const float height);
2012-01-14 23:34:14 +00:00
2012-07-20 12:45:42 +00:00
virtual void requestedConfiguration (sh::MaterialInstance* m, const std::string& configuration);
virtual void createdConfiguration (sh::MaterialInstance* m, const std::string& configuration);
};
2012-01-14 23:34:14 +00:00
}
#endif