2011-10-20 19:02:19 +00:00
# include "renderingmanager.hpp"
2012-07-03 10:30:50 +00:00
# include <cassert>
2011-10-20 22:15:30 +00:00
2012-07-03 13:32:38 +00:00
# include <OgreRoot.h>
# include <OgreRenderWindow.h>
# include <OgreSceneManager.h>
# include <OgreViewport.h>
# include <OgreCamera.h>
# include <OgreTextureManager.h>
# include <OgreCompositorManager.h>
# include <OgreCompositorChain.h>
# include <OgreCompositionTargetPass.h>
# include <OgreCompositionPass.h>
# include <OgreHardwarePixelBuffer.h>
2011-10-20 22:15:30 +00:00
# include <components/esm/loadstat.hpp>
2012-04-02 13:51:48 +00:00
# include <components/settings/settings.hpp>
2011-10-20 22:15:30 +00:00
2012-07-03 10:30:50 +00:00
# include "../mwbase/world.hpp" // these includes can be removed once the static-hack is gone
# include "../mwbase/environment.hpp"
# include "../mwworld/ptr.hpp"
# include "../mwworld/player.hpp"
# include "../mwgui/window_manager.hpp" // FIXME
# include "../mwinput/inputmanager.hpp" // FIXME
2012-04-11 16:53:13 +00:00
# include "shadows.hpp"
# include "shaderhelper.hpp"
# include "localmap.hpp"
# include "water.hpp"
2012-04-29 01:33:10 +00:00
# include "compositors.hpp"
2011-11-01 03:59:16 +00:00
2011-10-20 22:15:30 +00:00
using namespace MWRender ;
using namespace Ogre ;
2011-10-20 19:02:19 +00:00
namespace MWRender {
2012-04-23 13:27:03 +00:00
RenderingManager : : RenderingManager ( OEngine : : Render : : OgreRenderer & _rend , const boost : : filesystem : : path & resDir , OEngine : : Physic : : PhysicEngine * engine )
: mRendering ( _rend ) , mObjects ( mRendering ) , mActors ( mRendering ) , mAmbientMode ( 0 ) , mSunEnabled ( 0 )
2011-10-20 19:02:19 +00:00
{
2012-04-02 16:01:49 +00:00
mRendering . createScene ( " PlayerCam " , Settings : : Manager : : getFloat ( " field of view " , " General " ) , 5 ) ;
2012-05-27 19:39:18 +00:00
mRendering . setWindowEventListener ( this ) ;
2011-10-20 22:15:30 +00:00
2012-04-29 01:33:10 +00:00
mCompositors = new Compositors ( mRendering . getViewport ( ) ) ;
2012-04-05 13:30:55 +00:00
mWater = 0 ;
2012-03-02 22:31:17 +00:00
//The fog type must be set before any terrain objects are created as if the
//fog type is set to FOG_NONE then the initially created terrain won't have any fog
configureFog ( 1 , ColourValue ( 1 , 1 , 1 ) ) ;
2011-10-20 22:15:30 +00:00
// Set default mipmap level (NB some APIs ignore this)
2012-04-02 16:01:49 +00:00
TextureManager : : getSingleton ( ) . setDefaultNumMipmaps ( Settings : : Manager : : getInt ( " num mipmaps " , " General " ) ) ;
// Set default texture filtering options
TextureFilterOptions tfo ;
std : : string filter = Settings : : Manager : : getString ( " texture filtering " , " General " ) ;
if ( filter = = " anisotropic " ) tfo = TFO_ANISOTROPIC ;
else if ( filter = = " trilinear " ) tfo = TFO_TRILINEAR ;
2012-04-08 22:10:42 +00:00
else if ( filter = = " bilinear " ) tfo = TFO_BILINEAR ;
else if ( filter = = " none " ) tfo = TFO_NONE ;
2012-04-02 16:01:49 +00:00
MaterialManager : : getSingleton ( ) . setDefaultTextureFiltering ( tfo ) ;
2012-04-08 22:10:42 +00:00
MaterialManager : : getSingleton ( ) . setDefaultAnisotropy ( ( filter = = " anisotropic " ) ? Settings : : Manager : : getInt ( " anisotropy " , " General " ) : 1 ) ;
2011-10-20 22:15:30 +00:00
// Load resources
ResourceGroupManager : : getSingleton ( ) . initialiseAllResourceGroups ( ) ;
2012-04-17 23:10:00 +00:00
// Due to the huge world size of MW, we'll want camera-relative rendering.
// This prevents precision artifacts when moving very far from the origin.
mRendering . getScene ( ) - > setCameraRelativeRendering ( true ) ;
2012-04-05 17:27:54 +00:00
// disable unsupported effects
2012-04-05 11:09:59 +00:00
const RenderSystemCapabilities * caps = Root : : getSingleton ( ) . getRenderSystem ( ) - > getCapabilities ( ) ;
2012-05-29 04:45:44 +00:00
if ( ! waterShaderSupported ( ) )
2012-04-05 17:27:54 +00:00
Settings : : Manager : : setBool ( " shader " , " Water " , false ) ;
2012-04-16 18:39:41 +00:00
if ( ! ( caps - > isShaderProfileSupported ( " fp40 " ) | | caps - > isShaderProfileSupported ( " ps_4_0 " ) )
| | ! Settings : : Manager : : getBool ( " shaders " , " Objects " ) )
2012-04-13 11:28:31 +00:00
Settings : : Manager : : setBool ( " enabled " , " Shadows " , false ) ;
2012-04-05 11:09:59 +00:00
2012-05-29 04:45:44 +00:00
applyCompositors ( ) ;
2012-04-04 23:21:36 +00:00
2011-10-20 22:15:30 +00:00
// Turn the entire scene (represented by the 'root' node) -90
// degrees around the x axis. This makes Z go upwards, and Y go into
// the screen (when x is to the right.) This is the orientation that
// Morrowind uses, and it automagically makes everything work as it
// should.
2011-11-22 07:39:28 +00:00
SceneNode * rt = mRendering . getScene ( ) - > getRootSceneNode ( ) ;
mMwRoot = rt - > createChildSceneNode ( ) ;
mMwRoot - > pitch ( Degree ( - 90 ) ) ;
mObjects . setMwRoot ( mMwRoot ) ;
2011-11-25 04:13:34 +00:00
mActors . setMwRoot ( mMwRoot ) ;
2011-10-20 22:15:30 +00:00
2011-11-22 07:39:28 +00:00
Ogre : : SceneNode * playerNode = mMwRoot - > createChildSceneNode ( " player " ) ;
2011-10-20 22:15:30 +00:00
playerNode - > pitch ( Degree ( 90 ) ) ;
Ogre : : SceneNode * cameraYawNode = playerNode - > createChildSceneNode ( ) ;
Ogre : : SceneNode * cameraPitchNode = cameraYawNode - > createChildSceneNode ( ) ;
2011-11-22 07:39:28 +00:00
cameraPitchNode - > attachObject ( mRendering . getCamera ( ) ) ;
2012-03-08 06:46:34 +00:00
2012-04-11 16:53:13 +00:00
mShadows = new Shadows ( & mRendering ) ;
mShaderHelper = new ShaderHelper ( this ) ;
2012-04-23 13:27:03 +00:00
mTerrainManager = new TerrainManager ( mRendering . getScene ( ) , this ) ;
2012-04-11 16:53:13 +00:00
2012-04-23 13:27:03 +00:00
mSkyManager = new SkyManager ( mMwRoot , mRendering . getCamera ( ) ) ;
2011-10-20 22:15:30 +00:00
2012-03-24 16:59:26 +00:00
mOcclusionQuery = new OcclusionQuery ( & mRendering , mSkyManager - > getSunNode ( ) ) ;
2012-01-22 20:02:38 +00:00
2011-11-22 07:39:28 +00:00
mPlayer = new MWRender : : Player ( mRendering . getCamera ( ) , playerNode ) ;
2012-02-07 23:32:22 +00:00
mSun = 0 ;
2012-03-10 14:28:18 +00:00
2012-04-23 13:27:03 +00:00
mDebugging = new Debugging ( mMwRoot , engine ) ;
mLocalMap = new MWRender : : LocalMap ( & mRendering , this ) ;
2012-05-22 23:32:36 +00:00
setMenuTransparency ( Settings : : Manager : : getFloat ( " menu transparency " , " GUI " ) ) ;
2011-10-20 19:02:19 +00:00
}
RenderingManager : : ~ RenderingManager ( )
{
2012-06-09 17:15:11 +00:00
mRendering . removeWindowEventListener ( this ) ;
2011-11-21 11:52:28 +00:00
delete mPlayer ;
2011-10-20 19:02:19 +00:00
delete mSkyManager ;
2012-03-08 06:46:34 +00:00
delete mDebugging ;
2012-06-06 19:08:20 +00:00
delete mShaderHelper ;
delete mShadows ;
2012-01-21 16:59:08 +00:00
delete mTerrainManager ;
2012-03-10 14:28:18 +00:00
delete mLocalMap ;
2012-03-24 12:06:01 +00:00
delete mOcclusionQuery ;
2012-04-29 01:33:10 +00:00
delete mCompositors ;
2012-06-06 19:08:20 +00:00
delete mWater ;
2011-10-20 19:02:19 +00:00
}
2012-02-22 18:17:37 +00:00
MWRender : : SkyManager * RenderingManager : : getSkyManager ( )
{
return mSkyManager ;
2011-11-01 03:59:16 +00:00
}
2011-11-24 06:48:54 +00:00
2011-11-01 03:59:16 +00:00
MWRender : : Objects & RenderingManager : : getObjects ( ) {
2011-11-22 07:39:28 +00:00
return mObjects ;
2011-11-01 03:59:16 +00:00
}
2011-11-24 06:48:54 +00:00
MWRender : : Actors & RenderingManager : : getActors ( ) {
return mActors ;
2011-11-01 03:59:16 +00:00
}
2011-11-24 06:48:54 +00:00
2011-11-01 17:46:57 +00:00
MWRender : : Player & RenderingManager : : getPlayer ( ) {
return ( * mPlayer ) ;
2011-11-01 03:59:16 +00:00
}
2012-02-18 17:25:28 +00:00
OEngine : : Render : : Fader * RenderingManager : : getFader ( )
{
return mRendering . getFader ( ) ;
}
2012-03-29 16:33:08 +00:00
void RenderingManager : : removeCell ( MWWorld : : Ptr : : CellStore * store )
{
mObjects . removeCell ( store ) ;
2011-11-25 04:13:34 +00:00
mActors . removeCell ( store ) ;
2012-03-08 06:46:34 +00:00
mDebugging - > cellRemoved ( store ) ;
2012-01-22 16:20:12 +00:00
if ( store - > cell - > isExterior ( ) )
mTerrainManager - > cellRemoved ( store ) ;
2012-01-22 01:05:08 +00:00
}
2012-03-29 16:33:08 +00:00
void RenderingManager : : removeWater ( )
{
2012-01-20 04:29:07 +00:00
if ( mWater ) {
2012-04-03 13:13:47 +00:00
mWater - > setActive ( false ) ;
2012-01-20 04:29:07 +00:00
}
2011-10-20 19:02:19 +00:00
}
2011-11-21 11:52:28 +00:00
2012-03-29 16:33:08 +00:00
void RenderingManager : : toggleWater ( )
{
if ( mWater )
mWater - > toggle ( ) ;
}
2011-11-21 11:52:28 +00:00
void RenderingManager : : cellAdded ( MWWorld : : Ptr : : CellStore * store )
{
2011-11-22 07:39:28 +00:00
mObjects . buildStaticGeometry ( * store ) ;
2012-03-08 06:46:34 +00:00
mDebugging - > cellAdded ( store ) ;
2012-01-22 16:20:12 +00:00
if ( store - > cell - > isExterior ( ) )
mTerrainManager - > cellAdded ( store ) ;
2012-04-03 14:53:33 +00:00
waterAdded ( store ) ;
2011-11-21 11:52:28 +00:00
}
2011-11-11 05:20:53 +00:00
void RenderingManager : : addObject ( const MWWorld : : Ptr & ptr ) {
2011-11-16 21:22:13 +00:00
const MWWorld : : Class & class_ =
MWWorld : : Class : : get ( ptr ) ;
class_ . insertObjectRendering ( ptr , * this ) ;
2011-10-20 19:02:19 +00:00
}
2011-11-21 11:52:28 +00:00
void RenderingManager : : removeObject ( const MWWorld : : Ptr & ptr )
{
2011-11-22 07:39:28 +00:00
if ( ! mObjects . deleteObject ( ptr ) )
2011-11-21 11:52:28 +00:00
{
/// \todo delete non-object MW-references
}
2011-11-25 04:13:34 +00:00
if ( ! mActors . deleteObject ( ptr ) )
2011-11-21 11:52:28 +00:00
{
/// \todo delete non-object MW-references
}
}
2011-10-20 19:02:19 +00:00
2011-11-21 11:52:28 +00:00
void RenderingManager : : moveObject ( const MWWorld : : Ptr & ptr , const Ogre : : Vector3 & position )
{
/// \todo move this to the rendering-subsystems
2011-11-22 07:39:28 +00:00
mRendering . getScene ( ) - > getSceneNode ( ptr . getRefData ( ) . getHandle ( ) ) - >
2011-11-21 11:52:28 +00:00
setPosition ( position ) ;
2011-10-20 19:02:19 +00:00
}
2011-11-21 11:52:28 +00:00
2011-10-20 19:02:19 +00:00
void RenderingManager : : scaleObject ( const MWWorld : : Ptr & ptr , const Ogre : : Vector3 & scale ) {
}
void RenderingManager : : rotateObject ( const MWWorld : : Ptr & ptr , const : : Ogre : : Quaternion & orientation ) {
}
void RenderingManager : : moveObjectToCell ( const MWWorld : : Ptr & ptr , const Ogre : : Vector3 & position , MWWorld : : Ptr : : CellStore * store ) {
}
void RenderingManager : : update ( float duration ) {
2012-01-23 13:33:06 +00:00
mActors . update ( duration ) ;
2012-04-19 18:59:57 +00:00
mObjects . update ( duration ) ;
2012-03-24 16:59:26 +00:00
2012-03-25 22:31:03 +00:00
mOcclusionQuery - > update ( duration ) ;
2012-03-24 16:59:26 +00:00
2012-02-19 22:09:14 +00:00
mSkyManager - > update ( duration ) ;
2012-03-24 16:59:26 +00:00
mSkyManager - > setGlare ( mOcclusionQuery - > getSunVisibility ( ) ) ;
2012-02-19 22:22:29 +00:00
mRendering . update ( duration ) ;
2012-03-14 13:51:58 +00:00
2012-03-30 14:34:36 +00:00
mLocalMap - > updatePlayer ( mRendering . getCamera ( ) - > getRealPosition ( ) , mRendering . getCamera ( ) - > getRealOrientation ( ) ) ;
2012-03-29 03:03:34 +00:00
checkUnderwater ( ) ;
2012-04-18 23:08:26 +00:00
mWater - > update ( ) ;
2012-01-20 04:29:07 +00:00
}
2012-01-22 20:02:38 +00:00
void RenderingManager : : waterAdded ( MWWorld : : Ptr : : CellStore * store ) {
2012-05-17 17:54:09 +00:00
if ( store - > cell - > data . flags & store - > cell - > HasWater
| | ( ( ! ( store - > cell - > data . flags & ESM : : Cell : : Interior ) )
& & ! MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . lands . search ( store - > cell - > data . gridX , store - > cell - > data . gridY ) ) ) // always use water, if the cell does not have land.
{
2012-01-22 01:05:08 +00:00
if ( mWater = = 0 )
2012-04-29 01:33:10 +00:00
mWater = new MWRender : : Water ( mRendering . getCamera ( ) , this , store - > cell ) ;
2012-01-22 21:38:10 +00:00
else
mWater - > changeCell ( store - > cell ) ;
2012-04-03 13:13:47 +00:00
mWater - > setActive ( true ) ;
2012-01-22 01:05:08 +00:00
}
2012-01-22 21:38:10 +00:00
else
removeWater ( ) ;
2011-10-20 19:02:19 +00:00
}
2012-03-29 13:49:24 +00:00
void RenderingManager : : setWaterHeight ( const float height )
{
if ( mWater )
mWater - > setHeight ( height ) ;
}
2011-10-20 19:02:19 +00:00
void RenderingManager : : skyEnable ( )
{
2012-01-25 06:21:30 +00:00
if ( mSkyManager )
2011-10-20 19:02:19 +00:00
mSkyManager - > enable ( ) ;
2012-04-01 13:07:41 +00:00
mOcclusionQuery - > setSunNode ( mSkyManager - > getSunNode ( ) ) ;
2011-10-20 19:02:19 +00:00
}
void RenderingManager : : skyDisable ( )
{
2012-01-25 06:21:30 +00:00
if ( mSkyManager )
mSkyManager - > disable ( ) ;
2011-10-20 19:02:19 +00:00
}
void RenderingManager : : skySetHour ( double hour )
{
2012-01-25 06:21:30 +00:00
if ( mSkyManager )
mSkyManager - > setHour ( hour ) ;
2011-10-20 19:02:19 +00:00
}
void RenderingManager : : skySetDate ( int day , int month )
{
2012-01-25 06:21:30 +00:00
if ( mSkyManager )
mSkyManager - > setDate ( day , month ) ;
2011-10-20 19:02:19 +00:00
}
int RenderingManager : : skyGetMasserPhase ( ) const
{
2012-03-08 06:46:34 +00:00
2011-10-20 19:02:19 +00:00
return mSkyManager - > getMasserPhase ( ) ;
}
int RenderingManager : : skyGetSecundaPhase ( ) const
{
return mSkyManager - > getSecundaPhase ( ) ;
}
2012-01-25 06:21:30 +00:00
void RenderingManager : : skySetMoonColour ( bool red ) {
if ( mSkyManager )
mSkyManager - > setMoonColour ( red ) ;
2011-10-20 19:02:19 +00:00
}
2012-02-18 15:06:03 +00:00
bool RenderingManager : : toggleRenderMode ( int mode )
{
2012-07-03 10:30:50 +00:00
if ( mode = = MWBase : : World : : Render_CollisionDebug | | mode = = MWBase : : World : : Render_Pathgrid )
2012-03-08 06:46:34 +00:00
return mDebugging - > toggleRenderMode ( mode ) ;
2012-07-03 10:30:50 +00:00
else if ( mode = = MWBase : : World : : Render_Wireframe )
2012-02-18 15:06:03 +00:00
{
if ( mRendering . getCamera ( ) - > getPolygonMode ( ) = = PM_SOLID )
{
2012-04-29 01:33:10 +00:00
mCompositors - > setEnabled ( false ) ;
2012-04-04 23:21:36 +00:00
2012-02-18 15:06:03 +00:00
mRendering . getCamera ( ) - > setPolygonMode ( PM_WIREFRAME ) ;
return true ;
}
else
{
2012-04-29 01:33:10 +00:00
mCompositors - > setEnabled ( true ) ;
2012-04-04 23:21:36 +00:00
2012-02-18 15:06:03 +00:00
mRendering . getCamera ( ) - > setPolygonMode ( PM_SOLID ) ;
return false ;
}
}
2012-04-29 01:33:10 +00:00
else //if (mode == MWWorld::World::Render_Compositors)
{
return mCompositors - > toggle ( ) ;
}
2011-10-30 04:25:29 +00:00
}
2011-10-20 19:02:19 +00:00
2012-06-29 14:48:50 +00:00
void RenderingManager : : configureFog ( MWWorld : : Ptr : : CellStore & mCell )
2011-11-04 03:47:15 +00:00
{
2012-04-05 09:52:06 +00:00
Ogre : : ColourValue color ;
color . setAsABGR ( mCell . cell - > ambi . fog ) ;
2011-11-04 03:47:15 +00:00
2012-04-05 09:52:06 +00:00
configureFog ( mCell . cell - > ambi . fogDensity , color ) ;
2012-02-26 12:13:29 +00:00
}
2011-11-04 03:47:15 +00:00
2012-02-26 12:13:29 +00:00
void RenderingManager : : configureFog ( const float density , const Ogre : : ColourValue & colour )
2012-03-08 06:46:34 +00:00
{
2012-04-05 09:52:06 +00:00
float max = Settings : : Manager : : getFloat ( " max viewing distance " , " Viewing distance " ) ;
2012-03-13 21:14:35 +00:00
2012-04-05 09:52:06 +00:00
float low = max / ( density ) * Settings : : Manager : : getFloat ( " fog start factor " , " Viewing distance " ) ;
float high = max / ( density ) * Settings : : Manager : : getFloat ( " fog end factor " , " Viewing distance " ) ;
2012-03-13 21:14:35 +00:00
2012-04-05 09:52:06 +00:00
mRendering . getScene ( ) - > setFog ( FOG_LINEAR , colour , 0 , low , high ) ;
2012-03-08 06:46:34 +00:00
2012-04-05 09:52:06 +00:00
mRendering . getCamera ( ) - > setFarClipDistance ( max / density ) ;
mRendering . getViewport ( ) - > setBackgroundColour ( colour ) ;
CompositorInstance * inst = CompositorManager : : getSingleton ( ) . getCompositorChain ( mRendering . getViewport ( ) ) - > getCompositor ( " gbuffer " ) ;
if ( inst ! = 0 )
inst - > getCompositor ( ) - > getTechnique ( 0 ) - > getTargetPass ( 0 ) - > getPass ( 0 ) - > setClearColour ( colour ) ;
2012-04-05 13:30:55 +00:00
if ( mWater )
mWater - > setViewportBackground ( colour ) ;
2011-11-04 03:47:15 +00:00
}
2012-02-26 12:13:29 +00:00
2011-11-04 03:47:15 +00:00
void RenderingManager : : setAmbientMode ( )
{
switch ( mAmbientMode )
{
case 0 :
2012-02-28 21:04:44 +00:00
setAmbientColour ( mAmbientColor ) ;
2011-11-04 03:47:15 +00:00
break ;
case 1 :
2012-02-28 21:04:44 +00:00
setAmbientColour ( 0.7f * mAmbientColor + 0.3f * ColourValue ( 1 , 1 , 1 ) ) ;
2011-11-04 03:47:15 +00:00
break ;
case 2 :
2012-02-28 21:04:44 +00:00
setAmbientColour ( ColourValue ( 1 , 1 , 1 ) ) ;
2011-11-04 03:47:15 +00:00
break ;
}
}
2012-06-29 14:48:50 +00:00
void RenderingManager : : configureAmbient ( MWWorld : : Ptr : : CellStore & mCell )
2011-11-04 03:47:15 +00:00
{
2012-04-05 09:52:06 +00:00
mAmbientColor . setAsABGR ( mCell . cell - > ambi . ambient ) ;
setAmbientMode ( ) ;
2011-11-04 03:47:15 +00:00
2012-04-05 09:52:06 +00:00
// Create a "sun" that shines light downwards. It doesn't look
// completely right, but leave it for now.
if ( ! mSun )
{
mSun = mRendering . getScene ( ) - > createLight ( ) ;
}
Ogre : : ColourValue colour ;
colour . setAsABGR ( mCell . cell - > ambi . sunlight ) ;
mSun - > setDiffuseColour ( colour ) ;
mSun - > setType ( Ogre : : Light : : LT_DIRECTIONAL ) ;
mSun - > setDirection ( 0 , - 1 , 0 ) ;
2011-11-04 03:47:15 +00:00
}
// Switch through lighting modes.
void RenderingManager : : toggleLight ( )
{
2012-04-05 09:52:06 +00:00
if ( mAmbientMode = = 2 )
mAmbientMode = 0 ;
else
+ + mAmbientMode ;
2011-11-04 03:47:15 +00:00
2012-04-05 09:52:06 +00:00
switch ( mAmbientMode )
{
case 0 : std : : cout < < " Setting lights to normal \n " ; break ;
case 1 : std : : cout < < " Turning the lights up \n " ; break ;
case 2 : std : : cout < < " Turning the lights to full \n " ; break ;
}
2011-11-04 03:47:15 +00:00
2012-04-05 09:52:06 +00:00
setAmbientMode ( ) ;
2011-11-04 03:47:15 +00:00
}
2012-04-05 09:52:06 +00:00
void RenderingManager : : checkUnderwater ( )
{
if ( mWater )
{
2012-03-29 03:03:34 +00:00
mWater - > checkUnderwater ( mRendering . getCamera ( ) - > getRealPosition ( ) . y ) ;
2012-01-20 04:29:07 +00:00
}
2012-01-19 03:42:07 +00:00
}
2011-11-04 03:47:15 +00:00
2011-11-21 13:08:44 +00:00
void RenderingManager : : playAnimationGroup ( const MWWorld : : Ptr & ptr , const std : : string & groupName ,
int mode , int number )
{
2011-12-27 00:23:46 +00:00
mActors . playAnimationGroup ( ptr , groupName , mode , number ) ;
2011-11-21 13:08:44 +00:00
}
2011-11-17 22:10:27 +00:00
2011-11-21 13:08:44 +00:00
void RenderingManager : : skipAnimation ( const MWWorld : : Ptr & ptr )
{
2011-12-29 02:52:05 +00:00
mActors . skipAnimation ( ptr ) ;
2011-11-21 13:08:44 +00:00
}
2011-11-17 22:10:27 +00:00
2012-02-23 19:33:34 +00:00
void RenderingManager : : setSunColour ( const Ogre : : ColourValue & colour )
{
2012-04-11 16:53:13 +00:00
if ( ! mSunEnabled ) return ;
2012-02-23 19:33:34 +00:00
mSun - > setDiffuseColour ( colour ) ;
2012-04-06 12:07:52 +00:00
mSun - > setSpecularColour ( colour ) ;
2012-02-28 21:04:44 +00:00
mTerrainManager - > setDiffuse ( colour ) ;
2012-02-23 19:33:34 +00:00
}
2012-02-23 20:12:06 +00:00
void RenderingManager : : setAmbientColour ( const Ogre : : ColourValue & colour )
{
mRendering . getScene ( ) - > setAmbientLight ( colour ) ;
2012-02-28 21:04:44 +00:00
mTerrainManager - > setAmbient ( colour ) ;
2011-10-20 19:02:19 +00:00
}
2012-02-23 20:12:06 +00:00
2012-02-23 19:33:34 +00:00
void RenderingManager : : sunEnable ( )
{
2012-04-11 16:53:13 +00:00
// Don't disable the light, as the shaders assume the first light to be directional.
//if (mSun) mSun->setVisible(true);
mSunEnabled = true ;
2012-02-23 19:33:34 +00:00
}
2012-02-23 20:12:06 +00:00
2012-02-23 19:33:34 +00:00
void RenderingManager : : sunDisable ( )
{
2012-04-11 16:53:13 +00:00
// Don't disable the light, as the shaders assume the first light to be directional.
//if (mSun) mSun->setVisible(false);
mSunEnabled = false ;
if ( mSun )
{
mSun - > setDiffuseColour ( ColourValue ( 0 , 0 , 0 ) ) ;
mSun - > setSpecularColour ( ColourValue ( 0 , 0 , 0 ) ) ;
}
2011-10-20 19:02:19 +00:00
}
2012-02-23 19:33:34 +00:00
void RenderingManager : : setSunDirection ( const Ogre : : Vector3 & direction )
{
2012-03-08 06:46:34 +00:00
// direction * -1 (because 'direction' is camera to sun vector and not sun to camera),
2012-02-28 19:28:46 +00:00
// then convert from MW to ogre coordinates (swap y,z and make y negative)
if ( mSun ) mSun - > setDirection ( Vector3 ( - direction . x , - direction . z , direction . y ) ) ;
2012-03-08 06:46:34 +00:00
2012-02-24 17:30:16 +00:00
mSkyManager - > setSunDirection ( direction ) ;
2012-02-23 19:33:34 +00:00
}
2012-02-24 15:12:43 +00:00
void RenderingManager : : setGlare ( bool glare )
{
mSkyManager - > setGlare ( glare ) ;
}
2012-03-10 14:28:18 +00:00
void RenderingManager : : requestMap ( MWWorld : : Ptr : : CellStore * cell )
{
if ( ! ( cell - > cell - > data . flags & ESM : : Cell : : Interior ) )
mLocalMap - > requestMap ( cell ) ;
else
mLocalMap - > requestMap ( cell , mObjects . getDimensions ( cell ) ) ;
}
2012-03-14 19:44:06 +00:00
void RenderingManager : : preCellChange ( MWWorld : : Ptr : : CellStore * cell )
{
mLocalMap - > saveFogOfWar ( cell ) ;
}
2012-04-02 17:37:24 +00:00
void RenderingManager : : disableLights ( )
{
mObjects . disableLights ( ) ;
2012-04-14 13:58:58 +00:00
sunDisable ( ) ;
2012-04-02 17:37:24 +00:00
}
void RenderingManager : : enableLights ( )
{
mObjects . enableLights ( ) ;
2012-04-14 13:58:58 +00:00
sunEnable ( ) ;
2012-04-02 17:37:24 +00:00
}
2012-04-05 17:27:54 +00:00
const bool RenderingManager : : useMRT ( )
{
return Settings : : Manager : : getBool ( " shader " , " Water " ) ;
}
2012-04-11 16:53:13 +00:00
Shadows * RenderingManager : : getShadows ( )
{
return mShadows ;
}
2012-04-19 18:59:57 +00:00
void RenderingManager : : switchToInterior ( )
{
2012-04-19 21:25:58 +00:00
mRendering . getScene ( ) - > setCameraRelativeRendering ( false ) ;
2012-04-19 18:59:57 +00:00
}
void RenderingManager : : switchToExterior ( )
{
2012-04-19 21:25:58 +00:00
mRendering . getScene ( ) - > setCameraRelativeRendering ( true ) ;
2012-04-19 18:59:57 +00:00
}
2012-05-14 19:37:43 +00:00
Ogre : : Vector4 RenderingManager : : boundingBoxToScreen ( Ogre : : AxisAlignedBox bounds )
{
Ogre : : Matrix4 mat = mRendering . getCamera ( ) - > getViewMatrix ( ) ;
const Ogre : : Vector3 * corners = bounds . getAllCorners ( ) ;
float min_x = 1.0f , max_x = 0.0f , min_y = 1.0f , max_y = 0.0f ;
2012-05-21 09:24:36 +00:00
// expand the screen-space bounding-box so that it completely encloses
2012-05-14 19:37:43 +00:00
// the object's AABB
for ( int i = 0 ; i < 8 ; i + + )
{
Ogre : : Vector3 corner = corners [ i ] ;
2012-05-21 09:24:36 +00:00
// multiply the AABB corner vertex by the view matrix to
2012-05-14 19:37:43 +00:00
// get a camera-space vertex
corner = mat * corner ;
// make 2D relative/normalized coords from the view-space vertex
// by dividing out the Z (depth) factor -- this is an approximation
float x = corner . x / corner . z + 0.5 ;
float y = corner . y / corner . z + 0.5 ;
2012-05-21 09:24:36 +00:00
if ( x < min_x )
2012-05-14 19:37:43 +00:00
min_x = x ;
2012-05-21 09:24:36 +00:00
if ( x > max_x )
2012-05-14 19:37:43 +00:00
max_x = x ;
2012-05-21 09:24:36 +00:00
if ( y < min_y )
2012-05-14 19:37:43 +00:00
min_y = y ;
2012-05-21 09:24:36 +00:00
if ( y > max_y )
2012-05-14 19:37:43 +00:00
max_y = y ;
}
return Vector4 ( min_x , min_y , max_x , max_y ) ;
}
2012-04-29 01:33:10 +00:00
Compositors * RenderingManager : : getCompositors ( )
{
return mCompositors ;
}
2012-05-22 23:32:36 +00:00
void RenderingManager : : processChangedSettings ( const Settings : : CategorySettingVector & settings )
{
2012-05-27 19:39:18 +00:00
bool changeRes = false ;
2012-05-22 23:32:36 +00:00
for ( Settings : : CategorySettingVector : : const_iterator it = settings . begin ( ) ;
it ! = settings . end ( ) ; + + it )
{
if ( it - > second = = " menu transparency " & & it - > first = = " GUI " )
{
setMenuTransparency ( Settings : : Manager : : getFloat ( " menu transparency " , " GUI " ) ) ;
}
2012-05-27 19:39:18 +00:00
else if ( it - > second = = " max viewing distance " & & it - > first = = " Viewing distance " )
{
if ( ! MWBase : : Environment : : get ( ) . getWorld ( ) - > isCellExterior ( ) & & ! MWBase : : Environment : : get ( ) . getWorld ( ) - > isCellQuasiExterior ( ) )
configureFog ( * MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayer ( ) . getPlayer ( ) . getCell ( ) ) ;
}
else if ( it - > first = = " Video " & & (
it - > second = = " resolution x "
| | it - > second = = " resolution y "
| | it - > second = = " fullscreen " ) )
changeRes = true ;
2012-05-29 02:54:54 +00:00
else if ( it - > second = = " field of view " & & it - > first = = " General " )
mRendering . setFov ( Settings : : Manager : : getFloat ( " field of view " , " General " ) ) ;
else if ( ( it - > second = = " texture filtering " & & it - > first = = " General " )
| | ( it - > second = = " anisotropy " & & it - > first = = " General " ) )
{
TextureFilterOptions tfo ;
std : : string filter = Settings : : Manager : : getString ( " texture filtering " , " General " ) ;
if ( filter = = " anisotropic " ) tfo = TFO_ANISOTROPIC ;
else if ( filter = = " trilinear " ) tfo = TFO_TRILINEAR ;
else if ( filter = = " bilinear " ) tfo = TFO_BILINEAR ;
else if ( filter = = " none " ) tfo = TFO_NONE ;
MaterialManager : : getSingleton ( ) . setDefaultTextureFiltering ( tfo ) ;
MaterialManager : : getSingleton ( ) . setDefaultAnisotropy ( ( filter = = " anisotropic " ) ? Settings : : Manager : : getInt ( " anisotropy " , " General " ) : 1 ) ;
}
2012-05-29 04:45:44 +00:00
else if ( it - > second = = " shader " & & it - > first = = " Water " )
{
applyCompositors ( ) ;
mShaderHelper - > applyShaders ( ) ;
}
2012-05-27 19:39:18 +00:00
}
if ( changeRes )
{
2012-05-28 07:19:25 +00:00
unsigned int x = Settings : : Manager : : getInt ( " resolution x " , " Video " ) ;
unsigned int y = Settings : : Manager : : getInt ( " resolution y " , " Video " ) ;
if ( x ! = mRendering . getWindow ( ) - > getWidth ( ) | | y ! = mRendering . getWindow ( ) - > getHeight ( ) )
{
mRendering . getWindow ( ) - > resize ( x , y ) ;
}
2012-05-27 19:39:18 +00:00
mRendering . getWindow ( ) - > setFullscreen ( Settings : : Manager : : getBool ( " fullscreen " , " Video " ) , x , y ) ;
2012-05-22 23:32:36 +00:00
}
2012-05-29 04:45:44 +00:00
if ( mWater )
mWater - > processChangedSettings ( settings ) ;
2012-05-22 23:32:36 +00:00
}
void RenderingManager : : setMenuTransparency ( float val )
{
Ogre : : TexturePtr tex = Ogre : : TextureManager : : getSingleton ( ) . getByName ( " transparent.png " ) ;
std : : vector < Ogre : : uint32 > buffer ;
buffer . resize ( 1 ) ;
buffer [ 0 ] = ( int ( 255 * val ) < < 24 ) ;
memcpy ( tex - > getBuffer ( ) - > lock ( Ogre : : HardwareBuffer : : HBL_DISCARD ) , & buffer [ 0 ] , 1 * 4 ) ;
tex - > getBuffer ( ) - > unlock ( ) ;
}
2012-05-27 19:39:18 +00:00
void RenderingManager : : windowResized ( Ogre : : RenderWindow * rw )
{
2012-05-28 07:19:25 +00:00
Settings : : Manager : : setInt ( " resolution x " , " Video " , rw - > getWidth ( ) ) ;
Settings : : Manager : : setInt ( " resolution y " , " Video " , rw - > getHeight ( ) ) ;
mRendering . adjustViewport ( ) ;
2012-05-27 19:39:18 +00:00
mCompositors - > recreate ( ) ;
mWater - > assignTextures ( ) ;
2012-05-28 07:19:25 +00:00
const Settings : : CategorySettingVector & changed = Settings : : Manager : : apply ( ) ;
MWBase : : Environment : : get ( ) . getInputManager ( ) - > processChangedSettings ( changed ) ; //FIXME
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > processChangedSettings ( changed ) ; // FIXME
2012-05-27 19:39:18 +00:00
}
void RenderingManager : : windowClosed ( Ogre : : RenderWindow * rw )
{
}
2012-05-29 04:45:44 +00:00
bool RenderingManager : : waterShaderSupported ( )
{
const RenderSystemCapabilities * caps = Root : : getSingleton ( ) . getRenderSystem ( ) - > getCapabilities ( ) ;
if ( caps - > getNumMultiRenderTargets ( ) < 2 | | ! Settings : : Manager : : getBool ( " shaders " , " Objects " ) )
return false ;
return true ;
}
void RenderingManager : : applyCompositors ( )
{
mCompositors - > removeAll ( ) ;
if ( useMRT ( ) )
{
mCompositors - > addCompositor ( " gbuffer " , 0 ) ;
mCompositors - > setCompositorEnabled ( " gbuffer " , true ) ;
mCompositors - > addCompositor ( " Underwater " , 1 ) ;
mCompositors - > addCompositor ( " gbufferFinalizer " , 2 ) ;
mCompositors - > setCompositorEnabled ( " gbufferFinalizer " , true ) ;
}
else
{
mCompositors - > addCompositor ( " UnderwaterNoMRT " , 0 ) ;
}
if ( mWater )
mWater - > assignTextures ( ) ;
}
2012-06-22 10:56:04 +00:00
void RenderingManager : : getTriangleBatchCount ( unsigned int & triangles , unsigned int & batches )
{
if ( mCompositors - > anyCompositorEnabled ( ) )
{
mCompositors - > countTrianglesBatches ( triangles , batches ) ;
}
else
{
triangles = mRendering . getWindow ( ) - > getTriangleCount ( ) ;
batches = mRendering . getWindow ( ) - > getBatchCount ( ) ;
}
}
2012-02-23 19:33:34 +00:00
} // namespace