2011-10-20 19:02:19 +00:00
# include "renderingmanager.hpp"
2015-04-12 13:34:50 +00:00
# include <stdexcept>
2015-08-21 10:00:08 +00:00
# include <limits>
2011-10-20 22:15:30 +00:00
2015-04-12 13:34:50 +00:00
# include <osg/Light>
# include <osg/LightModel>
2015-04-21 21:27:26 +00:00
# include <osg/Fog>
2015-06-01 15:02:44 +00:00
# include <osg/PolygonMode>
2015-04-12 13:34:50 +00:00
# include <osg/Group>
2015-05-24 01:36:34 +00:00
# include <osg/UserDataContainer>
# include <osg/ComputeBoundsVisitor>
2011-10-20 22:15:30 +00:00
2015-05-24 01:36:34 +00:00
# include <osgUtil/LineSegmentIntersector>
2015-05-03 16:16:54 +00:00
# include <osgUtil/IncrementalCompileOperation>
2015-04-12 13:34:50 +00:00
# include <osgViewer/Viewer>
2013-07-29 00:32:08 +00:00
2015-04-22 17:08:56 +00:00
# include <components/resource/resourcesystem.hpp>
2016-02-05 22:03:53 +00:00
# include <components/resource/imagemanager.hpp>
2015-05-26 18:20:18 +00:00
# include <components/resource/scenemanager.hpp>
2015-04-22 17:08:56 +00:00
2015-04-21 21:27:26 +00:00
# include <components/settings/settings.hpp>
2015-04-12 13:34:50 +00:00
# include <components/sceneutil/util.hpp>
# include <components/sceneutil/lightmanager.hpp>
2015-04-14 15:29:12 +00:00
# include <components/sceneutil/statesetupdater.hpp>
2015-11-20 20:57:04 +00:00
# include <components/sceneutil/positionattitudetransform.hpp>
2016-02-09 00:02:40 +00:00
# include <components/sceneutil/workqueue.hpp>
2016-02-09 14:30:53 +00:00
# include <components/sceneutil/unrefqueue.hpp>
2015-04-14 13:55:56 +00:00
2015-06-02 23:18:36 +00:00
# include <components/terrain/terraingrid.hpp>
2015-04-12 13:34:50 +00:00
# include <components/esm/loadcell.hpp>
2016-01-06 11:46:06 +00:00
# include <components/fallback/fallback.hpp>
2013-08-16 11:01:52 +00:00
2015-11-03 01:17:42 +00:00
# include "../mwworld/cellstore.hpp"
2015-11-01 21:09:02 +00:00
2015-04-14 13:55:56 +00:00
# include "sky.hpp"
2015-04-19 15:55:56 +00:00
# include "effectmanager.hpp"
2015-05-01 16:21:50 +00:00
# include "npcanimation.hpp"
2015-04-30 21:21:25 +00:00
# include "vismask.hpp"
2015-05-04 15:41:30 +00:00
# include "pathgrid.hpp"
2015-05-21 21:54:39 +00:00
# include "camera.hpp"
2015-06-02 14:35:35 +00:00
# include "water.hpp"
2015-06-02 23:18:36 +00:00
# include "terrainstorage.hpp"
2016-01-29 16:00:18 +00:00
# include "util.hpp"
2015-04-14 13:55:56 +00:00
2015-04-12 13:34:50 +00:00
namespace MWRender
2012-03-08 06:46:34 +00:00
{
2012-03-13 21:14:35 +00:00
2015-04-14 15:29:12 +00:00
class StateUpdater : public SceneUtil : : StateSetUpdater
2015-04-14 13:55:56 +00:00
{
public :
2015-04-21 21:27:26 +00:00
StateUpdater ( )
2015-07-01 01:21:39 +00:00
: mFogStart ( 0.f )
, mFogEnd ( 0.f )
2015-06-01 15:02:44 +00:00
, mWireframe ( false )
2015-04-21 21:27:26 +00:00
{
}
2015-04-14 13:55:56 +00:00
virtual void setDefaults ( osg : : StateSet * stateset )
{
osg : : LightModel * lightModel = new osg : : LightModel ;
stateset - > setAttribute ( lightModel , osg : : StateAttribute : : ON ) ;
2015-04-21 21:27:26 +00:00
osg : : Fog * fog = new osg : : Fog ;
2015-05-26 16:22:21 +00:00
fog - > setMode ( osg : : Fog : : LINEAR ) ;
2015-04-21 21:27:26 +00:00
stateset - > setAttributeAndModes ( fog , osg : : StateAttribute : : ON ) ;
2015-06-01 15:02:44 +00:00
if ( mWireframe )
{
osg : : PolygonMode * polygonmode = new osg : : PolygonMode ;
polygonmode - > setMode ( osg : : PolygonMode : : FRONT_AND_BACK , osg : : PolygonMode : : LINE ) ;
stateset - > setAttributeAndModes ( polygonmode , osg : : StateAttribute : : ON ) ;
}
else
stateset - > removeAttribute ( osg : : StateAttribute : : POLYGONMODE ) ;
2015-04-14 13:55:56 +00:00
}
virtual void apply ( osg : : StateSet * stateset , osg : : NodeVisitor * )
{
osg : : LightModel * lightModel = static_cast < osg : : LightModel * > ( stateset - > getAttribute ( osg : : StateAttribute : : LIGHTMODEL ) ) ;
lightModel - > setAmbientIntensity ( mAmbientColor ) ;
2015-04-21 21:27:26 +00:00
osg : : Fog * fog = static_cast < osg : : Fog * > ( stateset - > getAttribute ( osg : : StateAttribute : : FOG ) ) ;
fog - > setColor ( mFogColor ) ;
2015-07-01 01:21:39 +00:00
fog - > setStart ( mFogStart ) ;
2015-04-21 21:27:26 +00:00
fog - > setEnd ( mFogEnd ) ;
2015-04-14 13:55:56 +00:00
}
2015-04-21 21:27:26 +00:00
void setAmbientColor ( const osg : : Vec4f & col )
2015-04-14 13:55:56 +00:00
{
mAmbientColor = col ;
}
2015-04-21 21:27:26 +00:00
void setFogColor ( const osg : : Vec4f & col )
{
mFogColor = col ;
}
2015-07-01 01:21:39 +00:00
void setFogStart ( float start )
{
mFogStart = start ;
}
2015-04-21 21:27:26 +00:00
void setFogEnd ( float end )
{
mFogEnd = end ;
}
2015-06-01 15:02:44 +00:00
void setWireframe ( bool wireframe )
{
if ( mWireframe ! = wireframe )
{
mWireframe = wireframe ;
reset ( ) ;
}
}
bool getWireframe ( ) const
{
return mWireframe ;
}
2015-04-14 13:55:56 +00:00
private :
osg : : Vec4f mAmbientColor ;
2015-04-21 21:27:26 +00:00
osg : : Vec4f mFogColor ;
2015-07-01 01:21:39 +00:00
float mFogStart ;
2015-04-21 21:27:26 +00:00
float mFogEnd ;
2015-06-01 15:02:44 +00:00
bool mWireframe ;
2015-04-14 13:55:56 +00:00
} ;
2016-02-09 00:17:02 +00:00
class PreloadCommonAssetsWorkItem : public SceneUtil : : WorkItem
{
public :
PreloadCommonAssetsWorkItem ( Resource : : ResourceSystem * resourceSystem )
: mResourceSystem ( resourceSystem )
{
}
virtual void doWork ( )
{
for ( std : : vector < std : : string > : : const_iterator it = mModels . begin ( ) ; it ! = mModels . end ( ) ; + + it )
mResourceSystem - > getSceneManager ( ) - > getTemplate ( * it ) ;
for ( std : : vector < std : : string > : : const_iterator it = mTextures . begin ( ) ; it ! = mTextures . end ( ) ; + + it )
mResourceSystem - > getImageManager ( ) - > getImage ( * it ) ;
}
std : : vector < std : : string > mModels ;
std : : vector < std : : string > mTextures ;
private :
Resource : : ResourceSystem * mResourceSystem ;
} ;
2015-10-26 20:36:19 +00:00
RenderingManager : : RenderingManager ( osgViewer : : Viewer * viewer , osg : : ref_ptr < osg : : Group > rootNode , Resource : : ResourceSystem * resourceSystem ,
2016-01-06 11:46:06 +00:00
const Fallback : : Map * fallback , const std : : string & resourcePath )
2015-04-12 13:34:50 +00:00
: mViewer ( viewer )
, mRootNode ( rootNode )
, mResourceSystem ( resourceSystem )
2016-02-09 00:02:40 +00:00
, mWorkQueue ( new SceneUtil : : WorkQueue )
2016-02-09 14:30:53 +00:00
, mUnrefQueue ( new SceneUtil : : UnrefQueue )
2015-07-01 01:21:39 +00:00
, mFogDepth ( 0.f )
2015-11-04 19:34:50 +00:00
, mUnderwaterColor ( fallback - > getFallbackColour ( " Water_UnderwaterColor " ) )
, mUnderwaterWeight ( fallback - > getFallbackFloat ( " Water_UnderwaterColorWeight " ) )
, mUnderwaterFog ( 0.f )
, mUnderwaterIndoorFog ( fallback - > getFallbackFloat ( " Water_UnderwaterIndoorFog " ) )
2015-06-11 21:16:05 +00:00
, mNightEyeFactor ( 0.f )
2015-12-07 15:11:47 +00:00
, mFieldOfViewOverride ( 0.f )
, mFieldOfViewOverridden ( false )
2014-06-22 14:10:52 +00:00
{
2015-11-10 16:00:33 +00:00
resourceSystem - > getSceneManager ( ) - > setParticleSystemMask ( MWRender : : Mask_ParticleSystem ) ;
2016-02-16 17:18:48 +00:00
resourceSystem - > getSceneManager ( ) - > setShaderPath ( resourcePath + " /shaders " ) ;
2016-02-18 16:08:18 +00:00
resourceSystem - > getSceneManager ( ) - > setForceShaders ( Settings : : Manager : : getBool ( " force shaders " , " Shaders " ) ) ;
resourceSystem - > getSceneManager ( ) - > setClampLighting ( Settings : : Manager : : getBool ( " clamp lighting " , " Shaders " ) ) ;
resourceSystem - > getSceneManager ( ) - > setForcePerPixelLighting ( Settings : : Manager : : getBool ( " force per pixel lighting " , " Shaders " ) ) ;
2016-02-20 16:57:19 +00:00
resourceSystem - > getSceneManager ( ) - > setAutoUseNormalMaps ( Settings : : Manager : : getBool ( " auto use object normal maps " , " Shaders " ) ) ;
resourceSystem - > getSceneManager ( ) - > setNormalMapPattern ( Settings : : Manager : : getString ( " normal map pattern " , " Shaders " ) ) ;
2016-02-20 18:02:11 +00:00
resourceSystem - > getSceneManager ( ) - > setAutoUseSpecularMaps ( Settings : : Manager : : getBool ( " auto use object specular maps " , " Shaders " ) ) ;
resourceSystem - > getSceneManager ( ) - > setSpecularMapPattern ( Settings : : Manager : : getString ( " specular map pattern " , " Shaders " ) ) ;
2015-11-10 16:00:33 +00:00
2016-02-08 15:45:56 +00:00
osg : : ref_ptr < SceneUtil : : LightManager > sceneRoot = new SceneUtil : : LightManager ;
sceneRoot - > setLightingMask ( Mask_Lighting ) ;
mSceneRoot = sceneRoot ;
sceneRoot - > setStartLight ( 1 ) ;
2012-07-20 14:44:03 +00:00
2016-02-08 15:45:56 +00:00
mRootNode - > addChild ( sceneRoot ) ;
2011-11-04 03:47:15 +00:00
2015-05-04 15:41:30 +00:00
mPathgrid . reset ( new Pathgrid ( mRootNode ) ) ;
2015-05-02 20:45:27 +00:00
2016-02-08 15:45:56 +00:00
mObjects . reset ( new Objects ( mResourceSystem , sceneRoot , mUnrefQueue . get ( ) ) ) ;
2012-02-26 12:13:29 +00:00
2015-05-14 19:42:04 +00:00
mViewer - > setIncrementalCompileOperation ( new osgUtil : : IncrementalCompileOperation ) ;
2015-05-03 16:16:54 +00:00
2015-05-26 18:20:18 +00:00
mResourceSystem - > getSceneManager ( ) - > setIncrementalCompileOperation ( mViewer - > getIncrementalCompileOperation ( ) ) ;
2015-05-03 16:16:54 +00:00
2016-02-08 15:45:56 +00:00
mEffectManager . reset ( new EffectManager ( sceneRoot , mResourceSystem ) ) ;
2015-06-02 14:35:35 +00:00
2016-02-08 15:45:56 +00:00
mWater . reset ( new Water ( mRootNode , sceneRoot , mResourceSystem , mViewer - > getIncrementalCompileOperation ( ) , fallback , resourcePath ) ) ;
2015-06-02 23:18:36 +00:00
2016-02-08 15:45:56 +00:00
mTerrain . reset ( new Terrain : : TerrainGrid ( sceneRoot , mResourceSystem , mViewer - > getIncrementalCompileOperation ( ) ,
2016-02-20 18:54:47 +00:00
new TerrainStorage ( mResourceSystem - > getVFS ( ) , Settings : : Manager : : getString ( " normal map pattern " , " Shaders " ) , Settings : : Manager : : getBool ( " auto use terrain normal maps " , " Shaders " ) ,
Settings : : Manager : : getString ( " terrain specular map pattern " , " Shaders " ) , Settings : : Manager : : getBool ( " auto use terrain specular maps " , " Shaders " ) ) ,
Mask_Terrain , & mResourceSystem - > getSceneManager ( ) - > getShaderManager ( ) , mUnrefQueue . get ( ) ) ) ;
2015-04-19 15:55:56 +00:00
2015-05-21 21:54:39 +00:00
mCamera . reset ( new Camera ( mViewer - > getCamera ( ) ) ) ;
2015-05-14 19:42:04 +00:00
mViewer - > setLightingMode ( osgViewer : : View : : NO_LIGHT ) ;
2011-11-04 03:47:15 +00:00
2015-04-12 13:34:50 +00:00
osg : : ref_ptr < osg : : LightSource > source = new osg : : LightSource ;
2015-11-10 16:19:51 +00:00
source - > setNodeMask ( Mask_Lighting ) ;
2015-04-12 13:34:50 +00:00
mSunLight = new osg : : Light ;
source - > setLight ( mSunLight ) ;
mSunLight - > setDiffuse ( osg : : Vec4f ( 0 , 0 , 0 , 1 ) ) ;
mSunLight - > setAmbient ( osg : : Vec4f ( 0 , 0 , 0 , 1 ) ) ;
2015-05-26 16:22:21 +00:00
mSunLight - > setSpecular ( osg : : Vec4f ( 0 , 0 , 0 , 0 ) ) ;
2015-04-12 13:34:50 +00:00
mSunLight - > setConstantAttenuation ( 1.f ) ;
2016-02-08 15:45:56 +00:00
sceneRoot - > addChild ( source ) ;
2011-11-04 03:47:15 +00:00
2016-02-08 15:45:56 +00:00
sceneRoot - > getOrCreateStateSet ( ) - > setMode ( GL_CULL_FACE , osg : : StateAttribute : : ON ) ;
sceneRoot - > getOrCreateStateSet ( ) - > setMode ( GL_LIGHTING , osg : : StateAttribute : : ON ) ;
sceneRoot - > getOrCreateStateSet ( ) - > setMode ( GL_NORMALIZE , osg : : StateAttribute : : ON ) ;
2015-04-14 13:55:56 +00:00
2016-02-08 15:45:56 +00:00
sceneRoot - > setNodeMask ( Mask_Scene ) ;
sceneRoot - > setName ( " Scene Root " ) ;
2015-04-30 21:21:25 +00:00
2016-02-08 15:45:56 +00:00
mSky . reset ( new SkyManager ( sceneRoot , resourceSystem - > getSceneManager ( ) ) ) ;
2015-04-30 21:21:25 +00:00
2015-04-14 13:55:56 +00:00
source - > setStateSetModes ( * mRootNode - > getOrCreateStateSet ( ) , osg : : StateAttribute : : ON ) ;
mStateUpdater = new StateUpdater ;
2016-02-08 15:45:56 +00:00
sceneRoot - > addUpdateCallback ( mStateUpdater ) ;
2015-04-21 21:27:26 +00:00
osg : : Camera : : CullingMode cullingMode = osg : : Camera : : DEFAULT_CULLING | osg : : Camera : : FAR_PLANE_CULLING ;
2011-11-04 03:47:15 +00:00
2015-05-24 00:34:20 +00:00
if ( ! Settings : : Manager : : getBool ( " small feature culling " , " Camera " ) )
2015-05-14 16:46:04 +00:00
cullingMode & = ~ ( osg : : CullStack : : SMALL_FEATURE_CULLING ) ;
else
cullingMode | = osg : : CullStack : : SMALL_FEATURE_CULLING ;
2015-04-21 21:27:26 +00:00
2015-05-14 19:42:04 +00:00
mViewer - > getCamera ( ) - > setCullingMode ( cullingMode ) ;
2015-04-14 13:55:56 +00:00
2015-05-14 19:42:04 +00:00
mViewer - > getCamera ( ) - > setComputeNearFarMode ( osg : : Camera : : DO_NOT_COMPUTE_NEAR_FAR ) ;
mViewer - > getCamera ( ) - > setCullingMode ( cullingMode ) ;
2015-04-21 21:27:26 +00:00
2015-10-28 18:39:22 +00:00
mViewer - > getCamera ( ) - > setCullMask ( ~ ( Mask_UpdateVisitor | Mask_SimpleWater ) ) ;
2015-05-20 01:35:52 +00:00
2015-05-24 00:34:20 +00:00
mNearClip = Settings : : Manager : : getFloat ( " near clip " , " Camera " ) ;
mViewDistance = Settings : : Manager : : getFloat ( " viewing distance " , " Camera " ) ;
2015-12-07 15:23:06 +00:00
mFieldOfView = Settings : : Manager : : getFloat ( " field of view " , " Camera " ) ;
2015-12-07 15:29:30 +00:00
mFirstPersonFieldOfView = Settings : : Manager : : getFloat ( " first person field of view " , " Camera " ) ;
2015-05-14 16:46:04 +00:00
updateProjectionMatrix ( ) ;
2015-06-02 14:35:35 +00:00
mStateUpdater - > setFogEnd ( mViewDistance ) ;
2015-10-28 17:59:35 +00:00
mRootNode - > getOrCreateStateSet ( ) - > addUniform ( new osg : : Uniform ( " near " , mNearClip ) ) ;
mRootNode - > getOrCreateStateSet ( ) - > addUniform ( new osg : : Uniform ( " far " , mViewDistance ) ) ;
2015-04-14 13:55:56 +00:00
}
RenderingManager : : ~ RenderingManager ( )
{
2013-02-03 14:46:23 +00:00
}
2012-02-24 15:12:43 +00:00
2015-04-12 13:34:50 +00:00
MWRender : : Objects & RenderingManager : : getObjects ( )
2014-03-05 20:45:43 +00:00
{
2015-04-12 13:34:50 +00:00
return * mObjects . get ( ) ;
2014-03-05 20:45:43 +00:00
}
2014-02-18 15:44:37 +00:00
2015-04-12 13:34:50 +00:00
Resource : : ResourceSystem * RenderingManager : : getResourceSystem ( )
2012-05-14 19:37:43 +00:00
{
2015-04-12 13:34:50 +00:00
return mResourceSystem ;
2012-05-14 19:37:43 +00:00
}
2016-02-09 19:57:30 +00:00
SceneUtil : : WorkQueue * RenderingManager : : getWorkQueue ( )
2016-02-09 00:02:40 +00:00
{
return mWorkQueue . get ( ) ;
}
2016-02-09 19:57:30 +00:00
SceneUtil : : UnrefQueue * RenderingManager : : getUnrefQueue ( )
2016-02-09 18:04:59 +00:00
{
return mUnrefQueue . get ( ) ;
}
2016-02-09 19:57:30 +00:00
Terrain : : World * RenderingManager : : getTerrain ( )
{
return mTerrain . get ( ) ;
}
2016-02-09 00:17:02 +00:00
void RenderingManager : : preloadCommonAssets ( )
{
osg : : ref_ptr < PreloadCommonAssetsWorkItem > workItem ( new PreloadCommonAssetsWorkItem ( mResourceSystem ) ) ;
mSky - > listAssetsToPreload ( workItem - > mModels , workItem - > mTextures ) ;
mWater - > listAssetsToPreload ( workItem - > mTextures ) ;
workItem - > mTextures . push_back ( " textures/_land_default.dds " ) ;
mWorkQueue - > addWorkItem ( workItem ) ;
}
2016-02-06 23:36:31 +00:00
double RenderingManager : : getReferenceTime ( ) const
{
return mViewer - > getFrameStamp ( ) - > getReferenceTime ( ) ;
}
2015-12-04 23:44:04 +00:00
osg : : Group * RenderingManager : : getLightRoot ( )
{
2016-02-08 15:45:56 +00:00
return mSceneRoot . get ( ) ;
2015-12-04 23:44:04 +00:00
}
2015-06-11 21:16:05 +00:00
void RenderingManager : : setNightEyeFactor ( float factor )
{
if ( factor ! = mNightEyeFactor )
{
mNightEyeFactor = factor ;
updateAmbient ( ) ;
}
}
2015-04-14 13:55:56 +00:00
void RenderingManager : : setAmbientColour ( const osg : : Vec4f & colour )
{
2015-06-11 21:16:05 +00:00
mAmbientColor = colour ;
updateAmbient ( ) ;
2015-04-14 13:55:56 +00:00
}
2015-06-16 18:56:48 +00:00
void RenderingManager : : skySetDate ( int day , int month )
{
mSky - > setDate ( day , month ) ;
}
int RenderingManager : : skyGetMasserPhase ( ) const
{
return mSky - > getMasserPhase ( ) ;
}
int RenderingManager : : skyGetSecundaPhase ( ) const
{
return mSky - > getSecundaPhase ( ) ;
}
void RenderingManager : : skySetMoonColour ( bool red )
{
mSky - > setMoonColour ( red ) ;
}
2015-04-12 13:34:50 +00:00
void RenderingManager : : configureAmbient ( const ESM : : Cell * cell )
2012-05-22 23:32:36 +00:00
{
2015-04-14 13:55:56 +00:00
setAmbientColour ( SceneUtil : : colourFromRGB ( cell - > mAmbi . mAmbient ) ) ;
2012-05-29 02:54:54 +00:00
2016-02-20 18:02:11 +00:00
osg : : Vec4f diffuse = SceneUtil : : colourFromRGB ( cell - > mAmbi . mSunlight ) ;
mSunLight - > setDiffuse ( diffuse ) ;
mSunLight - > setSpecular ( diffuse ) ;
2015-04-12 13:34:50 +00:00
mSunLight - > setDirection ( osg : : Vec3f ( 1.f , - 1.f , - 1.f ) ) ;
2012-05-27 19:39:18 +00:00
}
2015-04-14 13:55:56 +00:00
void RenderingManager : : setSunColour ( const osg : : Vec4f & colour )
{
2015-05-26 16:22:21 +00:00
// need to wrap this in a StateUpdater?
2015-04-14 13:55:56 +00:00
mSunLight - > setDiffuse ( colour ) ;
2015-10-26 20:36:19 +00:00
mSunLight - > setSpecular ( colour ) ;
2015-04-14 13:55:56 +00:00
}
void RenderingManager : : setSunDirection ( const osg : : Vec3f & direction )
{
2015-05-20 00:07:18 +00:00
osg : : Vec3 position = direction * - 1 ;
2015-05-26 16:22:21 +00:00
// need to wrap this in a StateUpdater?
2015-05-20 00:07:18 +00:00
mSunLight - > setPosition ( osg : : Vec4 ( position . x ( ) , position . y ( ) , position . z ( ) , 0 ) ) ;
2015-04-14 13:55:56 +00:00
2015-05-20 00:07:18 +00:00
mSky - > setSunDirection ( position ) ;
2015-04-14 13:55:56 +00:00
}
2015-04-12 13:34:50 +00:00
osg : : Vec3f RenderingManager : : getEyePos ( )
2012-05-27 19:39:18 +00:00
{
2015-05-14 19:42:04 +00:00
osg : : Vec3d eye = mViewer - > getCameraManipulator ( ) - > getMatrix ( ) . getTrans ( ) ;
2015-04-12 13:34:50 +00:00
return eye ;
2012-05-22 23:32:36 +00:00
}
2012-05-29 04:45:44 +00:00
2015-05-02 20:45:27 +00:00
void RenderingManager : : addCell ( const MWWorld : : CellStore * store )
{
2015-05-04 15:41:30 +00:00
mPathgrid - > addCell ( store ) ;
2015-06-02 14:35:35 +00:00
mWater - > changeCell ( store ) ;
2015-06-02 23:18:36 +00:00
if ( store - > getCell ( ) - > isExterior ( ) )
mTerrain - > loadCell ( store - > getCell ( ) - > getGridX ( ) , store - > getCell ( ) - > getGridY ( ) ) ;
2015-05-02 20:45:27 +00:00
}
2015-04-12 13:34:50 +00:00
void RenderingManager : : removeCell ( const MWWorld : : CellStore * store )
2013-08-20 07:52:27 +00:00
{
2015-05-04 15:41:30 +00:00
mPathgrid - > removeCell ( store ) ;
2015-04-12 13:34:50 +00:00
mObjects - > removeCell ( store ) ;
2015-06-02 23:18:36 +00:00
if ( store - > getCell ( ) - > isExterior ( ) )
mTerrain - > unloadCell ( store - > getCell ( ) - > getGridX ( ) , store - > getCell ( ) - > getGridY ( ) ) ;
2015-06-16 18:36:48 +00:00
mWater - > removeCell ( store ) ;
2013-08-20 07:52:27 +00:00
}
2012-05-22 23:32:36 +00:00
2015-04-14 13:55:56 +00:00
void RenderingManager : : setSkyEnabled ( bool enabled )
{
mSky - > setEnabled ( enabled ) ;
}
2015-05-02 20:45:27 +00:00
bool RenderingManager : : toggleRenderMode ( RenderMode mode )
{
if ( mode = = Render_CollisionDebug | | mode = = Render_Pathgrid )
2015-05-04 15:41:30 +00:00
return mPathgrid - > toggleRenderMode ( mode ) ;
2015-05-02 20:45:27 +00:00
else if ( mode = = Render_Wireframe )
{
2015-06-01 15:02:44 +00:00
bool wireframe = ! mStateUpdater - > getWireframe ( ) ;
mStateUpdater - > setWireframe ( wireframe ) ;
return wireframe ;
2015-05-02 20:45:27 +00:00
}
2015-06-02 14:35:35 +00:00
else if ( mode = = Render_Water )
{
return mWater - > toggle ( ) ;
}
else if ( mode = = Render_Scene )
{
int mask = mViewer - > getCamera ( ) - > getCullMask ( ) ;
bool enabled = mask & Mask_Scene ;
enabled = ! enabled ;
if ( enabled )
mask | = Mask_Scene ;
else
mask & = ~ Mask_Scene ;
mViewer - > getCamera ( ) - > setCullMask ( mask ) ;
return enabled ;
}
2015-05-02 20:45:27 +00:00
/*
else //if (mode == Render_BoundingBoxes)
{
bool show = ! mRendering . getScene ( ) - > getShowBoundingBoxes ( ) ;
mRendering . getScene ( ) - > showBoundingBoxes ( show ) ;
return show ;
}
*/
return false ;
}
2015-04-21 21:27:26 +00:00
void RenderingManager : : configureFog ( const ESM : : Cell * cell )
{
osg : : Vec4f color = SceneUtil : : colourFromRGB ( cell - > mAmbi . mFog ) ;
2015-11-01 21:09:02 +00:00
configureFog ( cell - > mAmbi . mFogDensity , mUnderwaterIndoorFog , color ) ;
2015-04-21 21:27:26 +00:00
}
2015-11-01 21:09:02 +00:00
void RenderingManager : : configureFog ( float fogDepth , float underwaterFog , const osg : : Vec4f & color )
2015-04-14 13:55:56 +00:00
{
2015-07-01 01:21:39 +00:00
mFogDepth = fogDepth ;
2015-06-02 14:35:35 +00:00
mFogColor = color ;
2015-11-01 21:09:02 +00:00
mUnderwaterFog = underwaterFog ;
2015-04-14 13:55:56 +00:00
}
SkyManager * RenderingManager : : getSkyManager ( )
{
return mSky . get ( ) ;
}
2015-04-18 23:57:52 +00:00
void RenderingManager : : update ( float dt , bool paused )
{
2016-02-09 14:30:53 +00:00
mUnrefQueue - > flush ( mWorkQueue . get ( ) ) ;
2015-06-19 01:32:48 +00:00
if ( ! paused )
2015-06-20 15:08:46 +00:00
{
2015-06-19 01:32:48 +00:00
mEffectManager - > update ( dt ) ;
2015-06-20 15:08:46 +00:00
mSky - > update ( dt ) ;
}
2015-06-19 01:32:48 +00:00
2015-06-16 18:36:48 +00:00
mWater - > update ( dt ) ;
2015-05-21 23:43:16 +00:00
mCamera - > update ( dt , paused ) ;
2015-06-02 14:35:35 +00:00
osg : : Vec3f focal , cameraPos ;
mCamera - > getPosition ( focal , cameraPos ) ;
2015-12-03 14:16:20 +00:00
mCurrentCameraPos = cameraPos ;
2015-06-02 14:35:35 +00:00
if ( mWater - > isUnderwater ( cameraPos ) )
{
2015-11-01 21:09:02 +00:00
setFogColor ( mUnderwaterColor * mUnderwaterWeight + mFogColor * ( 1.f - mUnderwaterWeight ) ) ;
mStateUpdater - > setFogStart ( mViewDistance * ( 1 - mUnderwaterFog ) ) ;
mStateUpdater - > setFogEnd ( mViewDistance ) ;
2015-06-02 14:35:35 +00:00
}
else
{
setFogColor ( mFogColor ) ;
2015-08-18 23:13:14 +00:00
if ( mFogDepth = = 0.f )
{
mStateUpdater - > setFogStart ( 0.f ) ;
2015-08-21 07:34:28 +00:00
mStateUpdater - > setFogEnd ( std : : numeric_limits < float > : : max ( ) ) ;
2015-08-18 23:13:14 +00:00
}
else
{
mStateUpdater - > setFogStart ( mViewDistance * ( 1 - mFogDepth ) ) ;
mStateUpdater - > setFogEnd ( mViewDistance ) ;
}
2015-06-02 14:35:35 +00:00
}
2015-04-19 15:55:56 +00:00
}
2015-05-21 21:54:39 +00:00
void RenderingManager : : updatePlayerPtr ( const MWWorld : : Ptr & ptr )
{
if ( mPlayerAnimation . get ( ) )
mPlayerAnimation - > updatePtr ( ptr ) ;
mCamera - > attachTo ( ptr ) ;
}
2015-06-16 18:36:48 +00:00
void RenderingManager : : removePlayer ( const MWWorld : : Ptr & player )
{
mWater - > removeEmitter ( player ) ;
}
2015-04-23 21:50:46 +00:00
void RenderingManager : : rotateObject ( const MWWorld : : Ptr & ptr , const osg : : Quat & rot )
{
2015-05-21 21:54:39 +00:00
if ( ptr = = mCamera - > getTrackingPtr ( ) & &
! mCamera - > isVanityOrPreviewModeEnabled ( ) )
{
mCamera - > rotateCamera ( - ptr . getRefData ( ) . getPosition ( ) . rot [ 0 ] , - ptr . getRefData ( ) . getPosition ( ) . rot [ 2 ] , false ) ;
}
2015-04-23 21:50:46 +00:00
ptr . getRefData ( ) . getBaseNode ( ) - > setAttitude ( rot ) ;
}
void RenderingManager : : moveObject ( const MWWorld : : Ptr & ptr , const osg : : Vec3f & pos )
{
ptr . getRefData ( ) . getBaseNode ( ) - > setPosition ( pos ) ;
}
void RenderingManager : : scaleObject ( const MWWorld : : Ptr & ptr , const osg : : Vec3f & scale )
{
ptr . getRefData ( ) . getBaseNode ( ) - > setScale ( scale ) ;
2015-11-09 16:30:11 +00:00
if ( ptr = = mCamera - > getTrackingPtr ( ) ) // update height of camera
mCamera - > processViewChange ( ) ;
2015-04-23 21:50:46 +00:00
}
2015-05-21 22:55:43 +00:00
void RenderingManager : : removeObject ( const MWWorld : : Ptr & ptr )
{
mObjects - > removeObject ( ptr ) ;
2015-06-16 18:36:48 +00:00
mWater - > removeEmitter ( ptr ) ;
2015-05-21 22:55:43 +00:00
}
2015-06-02 14:35:35 +00:00
void RenderingManager : : setWaterEnabled ( bool enabled )
{
mWater - > setEnabled ( enabled ) ;
2015-11-03 22:15:43 +00:00
mSky - > setWaterEnabled ( enabled ) ;
2015-06-02 14:35:35 +00:00
}
void RenderingManager : : setWaterHeight ( float height )
{
mWater - > setHeight ( height ) ;
2015-11-03 22:15:43 +00:00
mSky - > setWaterHeight ( height ) ;
2015-06-02 14:35:35 +00:00
}
2015-06-03 14:40:16 +00:00
class NotifyDrawCompletedCallback : public osg : : Camera : : DrawCallback
{
public :
2015-08-02 15:57:50 +00:00
NotifyDrawCompletedCallback ( )
: mDone ( false )
{
}
2015-06-03 14:40:16 +00:00
virtual void operator ( ) ( osg : : RenderInfo & renderInfo ) const
{
2015-08-02 15:57:50 +00:00
mMutex . lock ( ) ;
mDone = true ;
mMutex . unlock ( ) ;
2015-06-03 14:40:16 +00:00
mCondition . signal ( ) ;
}
2015-08-02 15:57:50 +00:00
void waitTillDone ( )
{
mMutex . lock ( ) ;
if ( mDone )
return ;
mCondition . wait ( & mMutex ) ;
mMutex . unlock ( ) ;
}
2015-06-03 14:40:16 +00:00
mutable OpenThreads : : Condition mCondition ;
2015-08-02 15:57:50 +00:00
mutable OpenThreads : : Mutex mMutex ;
mutable bool mDone ;
2015-06-03 14:40:16 +00:00
} ;
void RenderingManager : : screenshot ( osg : : Image * image , int w , int h )
{
osg : : ref_ptr < osg : : Camera > rttCamera ( new osg : : Camera ) ;
rttCamera - > setNodeMask ( Mask_RenderToTexture ) ;
rttCamera - > attach ( osg : : Camera : : COLOR_BUFFER , image ) ;
rttCamera - > setRenderOrder ( osg : : Camera : : PRE_RENDER ) ;
rttCamera - > setReferenceFrame ( osg : : Camera : : ABSOLUTE_RF ) ;
rttCamera - > setRenderTargetImplementation ( osg : : Camera : : FRAME_BUFFER_OBJECT , osg : : Camera : : PIXEL_BUFFER_RTT ) ;
rttCamera - > setProjectionMatrixAsPerspective ( mFieldOfView , w / float ( h ) , mNearClip , mViewDistance ) ;
rttCamera - > setViewMatrix ( mViewer - > getCamera ( ) - > getViewMatrix ( ) ) ;
rttCamera - > setViewport ( 0 , 0 , w , h ) ;
osg : : ref_ptr < osg : : Texture2D > texture ( new osg : : Texture2D ) ;
texture - > setInternalFormat ( GL_RGB ) ;
texture - > setTextureSize ( w , h ) ;
texture - > setResizeNonPowerOfTwoHint ( false ) ;
2015-10-25 17:28:50 +00:00
texture - > setFilter ( osg : : Texture : : MIN_FILTER , osg : : Texture : : LINEAR ) ;
texture - > setFilter ( osg : : Texture : : MAG_FILTER , osg : : Texture : : LINEAR ) ;
2015-06-03 14:40:16 +00:00
rttCamera - > attach ( osg : : Camera : : COLOR_BUFFER , texture ) ;
image - > setDataType ( GL_UNSIGNED_BYTE ) ;
image - > setPixelFormat ( texture - > getInternalFormat ( ) ) ;
2015-11-06 22:13:57 +00:00
rttCamera - > setUpdateCallback ( new NoTraverseCallback ) ;
2016-02-08 15:45:56 +00:00
rttCamera - > addChild ( mSceneRoot ) ;
2015-08-02 16:05:15 +00:00
rttCamera - > setCullMask ( mViewer - > getCamera ( ) - > getCullMask ( ) & ( ~ Mask_GUI ) ) ;
2015-06-03 14:40:16 +00:00
mRootNode - > addChild ( rttCamera ) ;
// The draw needs to complete before we can copy back our image.
osg : : ref_ptr < NotifyDrawCompletedCallback > callback ( new NotifyDrawCompletedCallback ) ;
rttCamera - > setFinalDrawCallback ( callback ) ;
2015-08-02 15:57:50 +00:00
2015-11-06 21:41:32 +00:00
// at the time this function is called we are in the middle of a frame,
// so out of order calls are necessary to get a correct frameNumber for the next frame.
// refer to the advance() and frame() order in Engine::go()
mViewer - > eventTraversal ( ) ;
mViewer - > updateTraversal ( ) ;
mViewer - > renderingTraversals ( ) ;
2015-08-02 15:57:50 +00:00
callback - > waitTillDone ( ) ;
2015-06-03 14:40:16 +00:00
2015-11-06 21:41:32 +00:00
// now that we've "used up" the current frame, get a fresh framenumber for the next frame() following after the screenshot is completed
mViewer - > advance ( mViewer - > getFrameStamp ( ) - > getSimulationTime ( ) ) ;
2015-06-03 14:40:16 +00:00
rttCamera - > removeChildren ( 0 , rttCamera - > getNumChildren ( ) ) ;
rttCamera - > setGraphicsContext ( NULL ) ;
mRootNode - > removeChild ( rttCamera ) ;
}
2015-05-24 01:36:34 +00:00
osg : : Vec4f RenderingManager : : getScreenBounds ( const MWWorld : : Ptr & ptr )
{
if ( ! ptr . getRefData ( ) . getBaseNode ( ) )
return osg : : Vec4f ( ) ;
osg : : ComputeBoundsVisitor computeBoundsVisitor ;
2015-06-30 00:51:32 +00:00
computeBoundsVisitor . setTraversalMask ( ~ ( Mask_ParticleSystem | Mask_Effect ) ) ;
2015-05-24 01:36:34 +00:00
ptr . getRefData ( ) . getBaseNode ( ) - > accept ( computeBoundsVisitor ) ;
osg : : Matrix viewProj = mViewer - > getCamera ( ) - > getViewMatrix ( ) * mViewer - > getCamera ( ) - > getProjectionMatrix ( ) ;
float min_x = 1.0f , max_x = 0.0f , min_y = 1.0f , max_y = 0.0f ;
for ( int i = 0 ; i < 8 ; + + i )
{
osg : : Vec3f corner = computeBoundsVisitor . getBoundingBox ( ) . corner ( i ) ;
corner = corner * viewProj ;
float x = ( corner . x ( ) + 1.f ) * 0.5f ;
float y = ( corner . y ( ) - 1.f ) * ( - 0.5f ) ;
if ( x < min_x )
min_x = x ;
if ( x > max_x )
max_x = x ;
if ( y < min_y )
min_y = y ;
if ( y > max_y )
max_y = y ;
}
return osg : : Vec4f ( min_x , min_y , max_x , max_y ) ;
}
2015-06-05 00:26:16 +00:00
RenderingManager : : RayResult getIntersectionResult ( osgUtil : : LineSegmentIntersector * intersector )
{
RenderingManager : : RayResult result ;
result . mHit = false ;
if ( intersector - > containsIntersections ( ) )
{
result . mHit = true ;
osgUtil : : LineSegmentIntersector : : Intersection intersection = intersector - > getFirstIntersection ( ) ;
result . mHitPointWorld = intersection . getWorldIntersectPoint ( ) ;
result . mHitNormalWorld = intersection . getWorldIntersectNormal ( ) ;
PtrHolder * ptrHolder = NULL ;
for ( osg : : NodePath : : const_iterator it = intersection . nodePath . begin ( ) ; it ! = intersection . nodePath . end ( ) ; + + it )
{
osg : : UserDataContainer * userDataContainer = ( * it ) - > getUserDataContainer ( ) ;
if ( ! userDataContainer )
continue ;
for ( unsigned int i = 0 ; i < userDataContainer - > getNumUserObjects ( ) ; + + i )
{
if ( PtrHolder * p = dynamic_cast < PtrHolder * > ( userDataContainer - > getUserObject ( i ) ) )
ptrHolder = p ;
}
}
if ( ptrHolder )
result . mHitObject = ptrHolder - > mPtr ;
}
return result ;
}
2015-10-31 00:30:02 +00:00
osg : : ref_ptr < osgUtil : : IntersectionVisitor > createIntersectionVisitor ( osgUtil : : Intersector * intersector , bool ignorePlayer , bool ignoreActors )
2015-06-05 00:26:16 +00:00
{
2015-10-31 00:30:02 +00:00
osg : : ref_ptr < osgUtil : : IntersectionVisitor > intersectionVisitor ( new osgUtil : : IntersectionVisitor ( intersector ) ) ;
int mask = intersectionVisitor - > getTraversalMask ( ) ;
mask & = ~ ( Mask_RenderToTexture | Mask_Sky | Mask_Debug | Mask_Effect | Mask_Water | Mask_SimpleWater ) ;
2015-06-05 00:26:16 +00:00
if ( ignorePlayer )
mask & = ~ ( Mask_Player ) ;
if ( ignoreActors )
mask & = ~ ( Mask_Actor | Mask_Player ) ;
2015-10-31 00:30:02 +00:00
intersectionVisitor - > setTraversalMask ( mask ) ;
return intersectionVisitor ;
}
RenderingManager : : RayResult RenderingManager : : castRay ( const osg : : Vec3f & origin , const osg : : Vec3f & dest , bool ignorePlayer , bool ignoreActors )
{
osg : : ref_ptr < osgUtil : : LineSegmentIntersector > intersector ( new osgUtil : : LineSegmentIntersector ( osgUtil : : LineSegmentIntersector : : MODEL ,
origin , dest ) ) ;
intersector - > setIntersectionLimit ( osgUtil : : LineSegmentIntersector : : LIMIT_NEAREST ) ;
2015-06-05 00:26:16 +00:00
2015-10-31 00:30:02 +00:00
mRootNode - > accept ( * createIntersectionVisitor ( intersector , ignorePlayer , ignoreActors ) ) ;
2015-06-05 00:26:16 +00:00
return getIntersectionResult ( intersector ) ;
}
RenderingManager : : RayResult RenderingManager : : castCameraToViewportRay ( const float nX , const float nY , float maxDistance , bool ignorePlayer , bool ignoreActors )
2015-05-24 01:36:34 +00:00
{
osg : : ref_ptr < osgUtil : : LineSegmentIntersector > intersector ( new osgUtil : : LineSegmentIntersector ( osgUtil : : LineSegmentIntersector : : PROJECTION ,
nX * 2.f - 1.f , nY * ( - 2.f ) + 1.f ) ) ;
osg : : Vec3d dist ( 0.f , 0.f , - maxDistance ) ;
dist = dist * mViewer - > getCamera ( ) - > getProjectionMatrix ( ) ;
osg : : Vec3d end = intersector - > getEnd ( ) ;
end . z ( ) = dist . z ( ) ;
intersector - > setEnd ( end ) ;
intersector - > setIntersectionLimit ( osgUtil : : LineSegmentIntersector : : LIMIT_NEAREST ) ;
2015-10-31 00:30:02 +00:00
mViewer - > getCamera ( ) - > accept ( * createIntersectionVisitor ( intersector , ignorePlayer , ignoreActors ) ) ;
2015-05-24 01:36:34 +00:00
2015-06-05 00:26:16 +00:00
return getIntersectionResult ( intersector ) ;
2015-05-24 01:36:34 +00:00
}
2015-05-14 15:34:55 +00:00
void RenderingManager : : updatePtr ( const MWWorld : : Ptr & old , const MWWorld : : Ptr & updated )
{
mObjects - > updatePtr ( old , updated ) ;
}
2015-04-19 15:55:56 +00:00
void RenderingManager : : spawnEffect ( const std : : string & model , const std : : string & texture , const osg : : Vec3f & worldPosition , float scale )
{
mEffectManager - > addEffect ( model , texture , worldPosition , scale ) ;
}
void RenderingManager : : notifyWorldSpaceChanged ( )
{
mEffectManager - > clear ( ) ;
2015-06-16 18:36:48 +00:00
mWater - > clearRipples ( ) ;
2015-04-19 15:55:56 +00:00
}
void RenderingManager : : clear ( )
{
2015-06-16 18:56:48 +00:00
mSky - > setMoonColour ( false ) ;
2015-04-19 15:55:56 +00:00
notifyWorldSpaceChanged ( ) ;
2015-04-18 23:57:52 +00:00
}
2015-04-25 13:19:17 +00:00
MWRender : : Animation * RenderingManager : : getAnimation ( const MWWorld : : Ptr & ptr )
{
2015-05-22 02:36:17 +00:00
if ( mPlayerAnimation . get ( ) & & ptr = = mPlayerAnimation - > getPtr ( ) )
return mPlayerAnimation . get ( ) ;
2015-04-25 13:19:17 +00:00
return mObjects - > getAnimation ( ptr ) ;
}
2015-12-18 16:21:51 +00:00
const MWRender : : Animation * RenderingManager : : getAnimation ( const MWWorld : : ConstPtr & ptr ) const
{
if ( mPlayerAnimation . get ( ) & & ptr = = mPlayerAnimation - > getPtr ( ) )
return mPlayerAnimation . get ( ) ;
return mObjects - > getAnimation ( ptr ) ;
}
2015-05-01 16:21:50 +00:00
void RenderingManager : : setupPlayer ( const MWWorld : : Ptr & player )
{
if ( ! mPlayerNode )
{
2015-11-20 20:57:04 +00:00
mPlayerNode = new SceneUtil : : PositionAttitudeTransform ;
2015-05-24 01:36:34 +00:00
mPlayerNode - > setNodeMask ( Mask_Player ) ;
2016-02-08 15:45:56 +00:00
mSceneRoot - > addChild ( mPlayerNode ) ;
2015-05-01 16:21:50 +00:00
}
2015-05-24 02:00:35 +00:00
mPlayerNode - > setUserDataContainer ( new osg : : DefaultUserDataContainer ) ;
mPlayerNode - > getUserDataContainer ( ) - > addUserObject ( new PtrHolder ( player ) ) ;
2015-05-01 16:21:50 +00:00
2015-05-24 02:00:35 +00:00
player . getRefData ( ) . setBaseNode ( mPlayerNode ) ;
2015-06-16 18:36:48 +00:00
mWater - > addEmitter ( player ) ;
2015-05-01 16:21:50 +00:00
}
void RenderingManager : : renderPlayer ( const MWWorld : : Ptr & player )
{
2015-12-07 15:29:30 +00:00
mPlayerAnimation . reset ( new NpcAnimation ( player , player . getRefData ( ) . getBaseNode ( ) , mResourceSystem , 0 , false , NpcAnimation : : VM_Normal ,
mFirstPersonFieldOfView ) ) ;
2015-05-01 16:21:50 +00:00
2015-05-21 21:54:39 +00:00
mCamera - > setAnimation ( mPlayerAnimation . get ( ) ) ;
mCamera - > attachTo ( player ) ;
2015-05-01 16:21:50 +00:00
}
2015-05-21 21:54:39 +00:00
void RenderingManager : : rebuildPtr ( const MWWorld : : Ptr & ptr )
{
NpcAnimation * anim = NULL ;
if ( ptr = = mPlayerAnimation - > getPtr ( ) )
anim = mPlayerAnimation . get ( ) ;
else
anim = dynamic_cast < NpcAnimation * > ( mObjects - > getAnimation ( ptr ) ) ;
if ( anim )
{
anim - > rebuild ( ) ;
if ( mCamera - > getTrackingPtr ( ) = = ptr )
{
mCamera - > attachTo ( ptr ) ;
mCamera - > setAnimation ( anim ) ;
}
}
}
2015-06-16 18:36:48 +00:00
void RenderingManager : : addWaterRippleEmitter ( const MWWorld : : Ptr & ptr )
{
mWater - > addEmitter ( ptr ) ;
}
void RenderingManager : : removeWaterRippleEmitter ( const MWWorld : : Ptr & ptr )
{
mWater - > removeEmitter ( ptr ) ;
}
2015-12-04 22:28:11 +00:00
void RenderingManager : : emitWaterRipple ( const osg : : Vec3f & pos )
{
mWater - > emitRipple ( pos ) ;
}
2015-05-14 16:46:04 +00:00
void RenderingManager : : updateProjectionMatrix ( )
{
2015-05-26 14:40:44 +00:00
double aspect = mViewer - > getCamera ( ) - > getViewport ( ) - > aspectRatio ( ) ;
2015-12-07 15:11:47 +00:00
float fov = mFieldOfView ;
if ( mFieldOfViewOverridden )
fov = mFieldOfViewOverride ;
mViewer - > getCamera ( ) - > setProjectionMatrixAsPerspective ( fov , aspect , mNearClip , mViewDistance ) ;
2015-05-14 19:42:04 +00:00
}
void RenderingManager : : updateTextureFiltering ( )
{
2016-02-14 22:14:52 +00:00
mViewer - > stopThreading ( ) ;
2016-02-05 22:20:13 +00:00
2016-02-05 17:51:51 +00:00
mResourceSystem - > getSceneManager ( ) - > setFilterSettings (
2015-12-14 01:05:19 +00:00
Settings : : Manager : : getString ( " texture mag filter " , " General " ) ,
Settings : : Manager : : getString ( " texture min filter " , " General " ) ,
2015-12-14 00:51:27 +00:00
Settings : : Manager : : getString ( " texture mipmap " , " General " ) ,
2016-02-14 22:14:52 +00:00
Settings : : Manager : : getInt ( " anisotropy " , " General " )
2015-12-14 00:51:27 +00:00
) ;
2016-02-14 22:14:52 +00:00
mTerrain - > updateTextureFiltering ( ) ;
mViewer - > startThreading ( ) ;
2015-05-14 16:46:04 +00:00
}
2015-06-11 21:16:05 +00:00
void RenderingManager : : updateAmbient ( )
{
osg : : Vec4f color = mAmbientColor ;
if ( mNightEyeFactor > 0.f )
color + = osg : : Vec4f ( 0.7 , 0.7 , 0.7 , 0.0 ) * mNightEyeFactor ;
mStateUpdater - > setAmbientColor ( color ) ;
}
2015-06-02 14:35:35 +00:00
void RenderingManager : : setFogColor ( const osg : : Vec4f & color )
{
mViewer - > getCamera ( ) - > setClearColor ( color ) ;
mStateUpdater - > setFogColor ( color ) ;
}
2015-05-14 16:46:04 +00:00
void RenderingManager : : processChangedSettings ( const Settings : : CategorySettingVector & changed )
{
for ( Settings : : CategorySettingVector : : const_iterator it = changed . begin ( ) ; it ! = changed . end ( ) ; + + it )
{
2015-12-07 15:23:06 +00:00
if ( it - > first = = " Camera " & & it - > second = = " field of view " )
2015-05-14 16:46:04 +00:00
{
2015-12-07 15:23:06 +00:00
mFieldOfView = Settings : : Manager : : getFloat ( " field of view " , " Camera " ) ;
2015-05-14 16:46:04 +00:00
updateProjectionMatrix ( ) ;
}
2015-05-24 00:34:20 +00:00
else if ( it - > first = = " Camera " & & it - > second = = " viewing distance " )
2015-05-14 16:46:04 +00:00
{
2015-05-24 00:34:20 +00:00
mViewDistance = Settings : : Manager : : getFloat ( " viewing distance " , " Camera " ) ;
2015-05-21 23:43:04 +00:00
mStateUpdater - > setFogEnd ( mViewDistance ) ;
2015-05-14 16:46:04 +00:00
updateProjectionMatrix ( ) ;
}
2015-12-14 00:02:09 +00:00
else if ( it - > first = = " General " & & ( it - > second = = " texture filter " | |
it - > second = = " texture mipmap " | |
2015-12-13 19:24:23 +00:00
it - > second = = " anisotropy " ) )
2015-05-14 19:42:04 +00:00
updateTextureFiltering ( ) ;
2015-10-28 20:22:14 +00:00
else if ( it - > first = = " Water " )
mWater - > processChangedSettings ( changed ) ;
2015-05-14 16:46:04 +00:00
}
}
2015-06-01 13:34:46 +00:00
float RenderingManager : : getNearClipDistance ( ) const
{
return mNearClip ;
}
2015-06-02 23:18:36 +00:00
float RenderingManager : : getTerrainHeightAt ( const osg : : Vec3f & pos )
{
return mTerrain - > getHeightAt ( pos ) ;
}
2015-05-21 21:54:39 +00:00
bool RenderingManager : : vanityRotateCamera ( const float * rot )
{
if ( ! mCamera - > isVanityOrPreviewModeEnabled ( ) )
return false ;
mCamera - > rotateCamera ( rot [ 0 ] , rot [ 2 ] , true ) ;
return true ;
}
void RenderingManager : : setCameraDistance ( float dist , bool adjust , bool override )
{
if ( ! mCamera - > isVanityOrPreviewModeEnabled ( ) & & ! mCamera - > isFirstPerson ( ) )
{
if ( mCamera - > isNearest ( ) & & dist > 0.f )
mCamera - > toggleViewMode ( ) ;
else
mCamera - > setCameraDistance ( - dist / 120.f * 10 , adjust , override ) ;
}
else if ( mCamera - > isFirstPerson ( ) & & dist < 0.f )
{
mCamera - > toggleViewMode ( ) ;
mCamera - > setCameraDistance ( 0.f , false , override ) ;
}
}
void RenderingManager : : resetCamera ( )
{
mCamera - > reset ( ) ;
}
float RenderingManager : : getCameraDistance ( ) const
{
return mCamera - > getCameraDistance ( ) ;
}
Camera * RenderingManager : : getCamera ( )
{
return mCamera . get ( ) ;
}
2015-12-03 14:16:20 +00:00
const osg : : Vec3f & RenderingManager : : getCameraPosition ( ) const
{
return mCurrentCameraPos ;
}
2015-05-21 21:54:39 +00:00
void RenderingManager : : togglePOV ( )
{
mCamera - > toggleViewMode ( ) ;
}
void RenderingManager : : togglePreviewMode ( bool enable )
{
mCamera - > togglePreviewMode ( enable ) ;
}
bool RenderingManager : : toggleVanityMode ( bool enable )
{
return mCamera - > toggleVanityMode ( enable ) ;
}
void RenderingManager : : allowVanityMode ( bool allow )
{
mCamera - > allowVanityMode ( allow ) ;
}
void RenderingManager : : togglePlayerLooking ( bool enable )
{
mCamera - > togglePlayerLooking ( enable ) ;
}
void RenderingManager : : changeVanityModeScale ( float factor )
{
if ( mCamera - > isVanityOrPreviewModeEnabled ( ) )
mCamera - > setCameraDistance ( - factor / 120.f * 10 , true , true ) ;
}
2015-12-07 15:11:47 +00:00
void RenderingManager : : overrideFieldOfView ( float val )
{
if ( mFieldOfViewOverridden ! = true | | mFieldOfViewOverride ! = val )
{
mFieldOfViewOverridden = true ;
mFieldOfViewOverride = val ;
updateProjectionMatrix ( ) ;
}
}
void RenderingManager : : resetFieldOfView ( )
{
if ( mFieldOfViewOverridden = = true )
{
mFieldOfViewOverridden = false ;
updateProjectionMatrix ( ) ;
}
}
2012-05-27 19:39:18 +00:00
}