Fix attempt for #1836

Reinitialize m_sun_interposer each time we load a track
This commit is contained in:
Vincent Lejeune 2015-01-17 00:26:06 +01:00
parent d2e84c8e86
commit c8bd922314
3 changed files with 37 additions and 23 deletions

View File

@ -517,28 +517,6 @@ void IrrDriver::initDevice()
m_mrt.clear();
m_mrt.reallocate(2);
scene::IMesh * sphere = m_scene_manager->getGeometryCreator()->createSphereMesh(1, 16, 16);
for (unsigned i = 0; i < sphere->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer *mb = sphere->getMeshBuffer(i);
if (!mb)
continue;
mb->getMaterial().setTexture(0, getUnicolorTexture(video::SColor(255, 255, 255, 255)));
mb->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
}
m_sun_interposer = new STKMeshSceneNode(sphere, m_scene_manager->getRootSceneNode(), NULL, -1, "sun_interposer");
m_sun_interposer->grab();
m_sun_interposer->setParent(NULL);
m_sun_interposer->setScale(core::vector3df(20));
m_sun_interposer->getMaterial(0).Lighting = false;
m_sun_interposer->getMaterial(0).ColorMask = video::ECP_NONE;
m_sun_interposer->getMaterial(0).ZWriteEnable = false;
m_sun_interposer->getMaterial(0).MaterialType = m_shaders->getShader(ES_OBJECTPASS);
sphere->drop();
m_suncam = m_scene_manager->addCameraSceneNode(0, vector3df(0), vector3df(0), -1, false);
m_suncam->grab();
m_suncam->setParent(NULL);
@ -610,6 +588,35 @@ void IrrDriver::initDevice()
m_pointer_shown = true;
} // initDevice
void IrrDriver::cleanSunInterposer()
{
delete m_sun_interposer;
}
void IrrDriver::createSunInterposer()
{
scene::IMesh * sphere = m_scene_manager->getGeometryCreator()->createSphereMesh(1, 16, 16);
for (unsigned i = 0; i < sphere->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer *mb = sphere->getMeshBuffer(i);
if (!mb)
continue;
mb->getMaterial().setTexture(0, getUnicolorTexture(video::SColor(255, 255, 255, 255)));
mb->getMaterial().setTexture(1, getUnicolorTexture(video::SColor(0, 0, 0, 0)));
}
m_sun_interposer = new STKMeshSceneNode(sphere, m_scene_manager->getRootSceneNode(), NULL, -1, "sun_interposer");
m_sun_interposer->grab();
m_sun_interposer->setParent(NULL);
m_sun_interposer->setScale(core::vector3df(20));
m_sun_interposer->getMaterial(0).Lighting = false;
m_sun_interposer->getMaterial(0).ColorMask = video::ECP_NONE;
m_sun_interposer->getMaterial(0).ZWriteEnable = false;
m_sun_interposer->getMaterial(0).MaterialType = m_shaders->getShader(ES_OBJECTPASS);
sphere->drop();
}
//-----------------------------------------------------------------------------
void IrrDriver::getOpenGLData(std::string *vendor, std::string *renderer,
std::string *version)

View File

@ -667,6 +667,8 @@ public:
void clearLights();
// ------------------------------------------------------------------------
class STKMeshSceneNode *getSunInterposer() { return m_sun_interposer; }
void cleanSunInterposer();
void createSunInterposer();
// ------------------------------------------------------------------------
void setViewMatrix(core::matrix4 matrix) { m_ViewMatrix = matrix; matrix.getInverse(m_InvViewMatrix); }
const core::matrix4 &getViewMatrix() const { return m_ViewMatrix; }

View File

@ -310,6 +310,9 @@ void Track::cleanup()
delete m_gfx_effect_mesh;
m_gfx_effect_mesh = NULL;
if (CVS->isGLSL())
irr_driver->cleanSunInterposer();
// The m_all_cached_mesh contains each mesh loaded from a file, which
// means that the mesh is stored in irrlichts mesh cache. To clean
@ -1851,12 +1854,14 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
if (m_sun_position.getLengthSQ() < 0.03f)
// Backward compatibility: if no sun is specified, use the
// old hardcoded default angle
m_sun->setRotation( core::vector3df(180, 45, 45) );
m_sun->setRotation(core::vector3df(180, 45, 45));
else
m_sun->setRotation((-m_sun_position).getHorizontalAngle());
sun->getLightData().SpecularColor = m_sun_specular_color;
}
else
irr_driver->createSunInterposer();
createPhysicsModel(main_track_count);