diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index dfc1743f0..3ad349ba7 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -193,7 +193,7 @@ namespace MWRender mWater.reset(new Water(mRootNode, sceneRoot, mResourceSystem, mViewer->getIncrementalCompileOperation(), fallback, resourcePath)); mTerrain.reset(new Terrain::TerrainGrid(sceneRoot, mResourceSystem, mViewer->getIncrementalCompileOperation(), - new TerrainStorage(mResourceSystem->getVFS(), false), Mask_Terrain, mUnrefQueue.get())); + new TerrainStorage(mResourceSystem->getVFS(), false), Mask_Terrain, &mResourceSystem->getSceneManager()->getShaderManager(), mUnrefQueue.get())); mCamera.reset(new Camera(mViewer->getCamera())); diff --git a/components/terrain/buffercache.hpp b/components/terrain/buffercache.hpp index d1a57f811..172b9d672 100644 --- a/components/terrain/buffercache.hpp +++ b/components/terrain/buffercache.hpp @@ -3,6 +3,7 @@ #include #include +#include #include diff --git a/components/terrain/material.cpp b/components/terrain/material.cpp index c1aef1f9d..54634d5d4 100644 --- a/components/terrain/material.cpp +++ b/components/terrain/material.cpp @@ -143,7 +143,7 @@ namespace Terrain } } - Effect::Effect(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager& shaderManager, const std::vector &layers, const std::vector > &blendmaps, + Effect::Effect(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager* shaderManager, const std::vector &layers, const std::vector > &blendmaps, int blendmapScale, float layerTileSize) : mShaderManager(shaderManager) , mUseShaders(useShaders) @@ -161,8 +161,8 @@ namespace Terrain { try { - if (mUseShaders) - addTechnique(new ShaderTechnique(mShaderManager, mForcePerPixelLighting, mClampLighting, mLayers, mBlendmaps, mBlendmapScale, mLayerTileSize)); + if (mUseShaders && mShaderManager) + addTechnique(new ShaderTechnique(*mShaderManager, mForcePerPixelLighting, mClampLighting, mLayers, mBlendmaps, mBlendmapScale, mLayerTileSize)); else addTechnique(new FixedFunctionTechnique(mLayers, mBlendmaps, mBlendmapScale, mLayerTileSize)); } diff --git a/components/terrain/material.hpp b/components/terrain/material.hpp index 65349a5e7..e353e5b3a 100644 --- a/components/terrain/material.hpp +++ b/components/terrain/material.hpp @@ -50,7 +50,7 @@ namespace Terrain class Effect : public osgFX::Effect { public: - Effect(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager& shaderManager, + Effect(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager* shaderManager, const std::vector& layers, const std::vector >& blendmaps, int blendmapScale, float layerTileSize); @@ -70,7 +70,7 @@ namespace Terrain } private: - Shader::ShaderManager& mShaderManager; + Shader::ShaderManager* mShaderManager; bool mUseShaders; bool mForcePerPixelLighting; bool mClampLighting; diff --git a/components/terrain/terraingrid.cpp b/components/terrain/terraingrid.cpp index cbafe1677..e008d5e52 100644 --- a/components/terrain/terraingrid.cpp +++ b/components/terrain/terraingrid.cpp @@ -51,11 +51,12 @@ namespace namespace Terrain { -TerrainGrid::TerrainGrid(osg::Group* parent, Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico, Storage* storage, int nodeMask, SceneUtil::UnrefQueue* unrefQueue) +TerrainGrid::TerrainGrid(osg::Group* parent, Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico, Storage* storage, int nodeMask, Shader::ShaderManager* shaderManager, SceneUtil::UnrefQueue* unrefQueue) : Terrain::World(parent, resourceSystem, ico, storage, nodeMask) , mNumSplits(4) , mCache((storage->getCellVertices()-1)/static_cast(mNumSplits) + 1) , mUnrefQueue(unrefQueue) + , mShaderManager(shaderManager) { osg::ref_ptr material (new osg::Material); material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); @@ -211,8 +212,8 @@ osg::ref_ptr TerrainGrid::buildTerrain (osg::Group* parent, float chu geometry->setTexCoordArray(i, mCache.getUVBuffer()); float blendmapScale = ESM::Land::LAND_TEXTURE_SIZE*chunkSize; - osg::ref_ptr effect (new Terrain::Effect(useShaders, mResourceSystem->getSceneManager()->getForcePerPixelLighting(), mResourceSystem->getSceneManager()->getClampLighting(), - mResourceSystem->getSceneManager()->getShaderManager(), layers, blendmapTextures, blendmapScale, blendmapScale)); + osg::ref_ptr effect (new Terrain::Effect(mShaderManager ? useShaders : false, mResourceSystem->getSceneManager()->getForcePerPixelLighting(), mResourceSystem->getSceneManager()->getClampLighting(), + mShaderManager, layers, blendmapTextures, blendmapScale, blendmapScale)); effect->addCullCallback(new SceneUtil::LightListCallback); diff --git a/components/terrain/terraingrid.hpp b/components/terrain/terraingrid.hpp index d2276a0af..defcce8b3 100644 --- a/components/terrain/terraingrid.hpp +++ b/components/terrain/terraingrid.hpp @@ -4,13 +4,22 @@ #include #include "world.hpp" -#include "material.hpp" namespace SceneUtil { class UnrefQueue; } +namespace Shader +{ + class ShaderManager; +} + +namespace osg +{ + class Texture2D; +} + namespace Terrain { @@ -18,7 +27,7 @@ namespace Terrain class TerrainGrid : public Terrain::World { public: - TerrainGrid(osg::Group* parent, Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico, Storage* storage, int nodeMask, SceneUtil::UnrefQueue* unrefQueue = NULL); + TerrainGrid(osg::Group* parent, Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico, Storage* storage, int nodeMask, Shader::ShaderManager* shaderManager = NULL, SceneUtil::UnrefQueue* unrefQueue = NULL); ~TerrainGrid(); /// Load a terrain cell and store it in cache for later use. @@ -59,6 +68,8 @@ namespace Terrain BufferCache mCache; osg::ref_ptr mUnrefQueue; + + Shader::ShaderManager* mShaderManager; }; }