Fix terrain error in OpenCS

move
scrawl 9 years ago
parent 7071d286e8
commit 6a0ac824bd

@ -193,7 +193,7 @@ namespace MWRender
mWater.reset(new Water(mRootNode, sceneRoot, mResourceSystem, mViewer->getIncrementalCompileOperation(), fallback, resourcePath)); mWater.reset(new Water(mRootNode, sceneRoot, mResourceSystem, mViewer->getIncrementalCompileOperation(), fallback, resourcePath));
mTerrain.reset(new Terrain::TerrainGrid(sceneRoot, mResourceSystem, mViewer->getIncrementalCompileOperation(), 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())); mCamera.reset(new Camera(mViewer->getCamera()));

@ -3,6 +3,7 @@
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <osg/Array> #include <osg/Array>
#include <osg/PrimitiveSet>
#include <map> #include <map>

@ -143,7 +143,7 @@ namespace Terrain
} }
} }
Effect::Effect(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager& shaderManager, const std::vector<TextureLayer> &layers, const std::vector<osg::ref_ptr<osg::Texture2D> > &blendmaps, Effect::Effect(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager* shaderManager, const std::vector<TextureLayer> &layers, const std::vector<osg::ref_ptr<osg::Texture2D> > &blendmaps,
int blendmapScale, float layerTileSize) int blendmapScale, float layerTileSize)
: mShaderManager(shaderManager) : mShaderManager(shaderManager)
, mUseShaders(useShaders) , mUseShaders(useShaders)
@ -161,8 +161,8 @@ namespace Terrain
{ {
try try
{ {
if (mUseShaders) if (mUseShaders && mShaderManager)
addTechnique(new ShaderTechnique(mShaderManager, mForcePerPixelLighting, mClampLighting, mLayers, mBlendmaps, mBlendmapScale, mLayerTileSize)); addTechnique(new ShaderTechnique(*mShaderManager, mForcePerPixelLighting, mClampLighting, mLayers, mBlendmaps, mBlendmapScale, mLayerTileSize));
else else
addTechnique(new FixedFunctionTechnique(mLayers, mBlendmaps, mBlendmapScale, mLayerTileSize)); addTechnique(new FixedFunctionTechnique(mLayers, mBlendmaps, mBlendmapScale, mLayerTileSize));
} }

@ -50,7 +50,7 @@ namespace Terrain
class Effect : public osgFX::Effect class Effect : public osgFX::Effect
{ {
public: public:
Effect(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager& shaderManager, Effect(bool useShaders, bool forcePerPixelLighting, bool clampLighting, Shader::ShaderManager* shaderManager,
const std::vector<TextureLayer>& layers, const std::vector<TextureLayer>& layers,
const std::vector<osg::ref_ptr<osg::Texture2D> >& blendmaps, int blendmapScale, float layerTileSize); const std::vector<osg::ref_ptr<osg::Texture2D> >& blendmaps, int blendmapScale, float layerTileSize);
@ -70,7 +70,7 @@ namespace Terrain
} }
private: private:
Shader::ShaderManager& mShaderManager; Shader::ShaderManager* mShaderManager;
bool mUseShaders; bool mUseShaders;
bool mForcePerPixelLighting; bool mForcePerPixelLighting;
bool mClampLighting; bool mClampLighting;

@ -51,11 +51,12 @@ namespace
namespace Terrain 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) : Terrain::World(parent, resourceSystem, ico, storage, nodeMask)
, mNumSplits(4) , mNumSplits(4)
, mCache((storage->getCellVertices()-1)/static_cast<float>(mNumSplits) + 1) , mCache((storage->getCellVertices()-1)/static_cast<float>(mNumSplits) + 1)
, mUnrefQueue(unrefQueue) , mUnrefQueue(unrefQueue)
, mShaderManager(shaderManager)
{ {
osg::ref_ptr<osg::Material> material (new osg::Material); osg::ref_ptr<osg::Material> material (new osg::Material);
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
@ -211,8 +212,8 @@ osg::ref_ptr<osg::Node> TerrainGrid::buildTerrain (osg::Group* parent, float chu
geometry->setTexCoordArray(i, mCache.getUVBuffer()); geometry->setTexCoordArray(i, mCache.getUVBuffer());
float blendmapScale = ESM::Land::LAND_TEXTURE_SIZE*chunkSize; float blendmapScale = ESM::Land::LAND_TEXTURE_SIZE*chunkSize;
osg::ref_ptr<osgFX::Effect> effect (new Terrain::Effect(useShaders, mResourceSystem->getSceneManager()->getForcePerPixelLighting(), mResourceSystem->getSceneManager()->getClampLighting(), osg::ref_ptr<osgFX::Effect> effect (new Terrain::Effect(mShaderManager ? useShaders : false, mResourceSystem->getSceneManager()->getForcePerPixelLighting(), mResourceSystem->getSceneManager()->getClampLighting(),
mResourceSystem->getSceneManager()->getShaderManager(), layers, blendmapTextures, blendmapScale, blendmapScale)); mShaderManager, layers, blendmapTextures, blendmapScale, blendmapScale));
effect->addCullCallback(new SceneUtil::LightListCallback); effect->addCullCallback(new SceneUtil::LightListCallback);

@ -4,13 +4,22 @@
#include <osg/Vec2f> #include <osg/Vec2f>
#include "world.hpp" #include "world.hpp"
#include "material.hpp"
namespace SceneUtil namespace SceneUtil
{ {
class UnrefQueue; class UnrefQueue;
} }
namespace Shader
{
class ShaderManager;
}
namespace osg
{
class Texture2D;
}
namespace Terrain namespace Terrain
{ {
@ -18,7 +27,7 @@ namespace Terrain
class TerrainGrid : public Terrain::World class TerrainGrid : public Terrain::World
{ {
public: 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(); ~TerrainGrid();
/// Load a terrain cell and store it in cache for later use. /// Load a terrain cell and store it in cache for later use.
@ -59,6 +68,8 @@ namespace Terrain
BufferCache mCache; BufferCache mCache;
osg::ref_ptr<SceneUtil::UnrefQueue> mUnrefQueue; osg::ref_ptr<SceneUtil::UnrefQueue> mUnrefQueue;
Shader::ShaderManager* mShaderManager;
}; };
} }

Loading…
Cancel
Save