From 87b493aaa2ef080ba28e83d145cdfb0e17217a2c Mon Sep 17 00:00:00 2001 From: Elderme Date: Fri, 7 Aug 2015 15:11:32 +0200 Subject: [PATCH] Cleaned code --- src/graphics/irr_driver.cpp | 38 +---------------------------- src/graphics/render.cpp | 5 ++-- src/graphics/render_lighting.cpp | 4 +-- src/graphics/skybox.cpp | 24 +++++++++--------- src/graphics/sphericalHarmonics.hpp | 2 ++ src/tracks/track.cpp | 14 +++++------ 6 files changed, 23 insertions(+), 64 deletions(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index da55d2d63..74bfb6298 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1367,32 +1367,12 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector &tex const std::vector &spherical_harmonics_textures) { assert(texture.size() == 6); - /*SkyboxTextures = texture; - SphericalHarmonicsTextures = sphericalHarmonics; - SkyboxCubeMap = 0; - SkyboxSpecularProbe = 0;*/ - - //m_skybox_ready = false; - //TODO - //prepareSkybox(); - //m_skybox_ready = true; + m_skybox = new Skybox(texture); if(spherical_harmonics_textures.size() == 6) { m_spherical_harmonics->setTextures(spherical_harmonics_textures); } - /*if(spherical_harmonics_textures.size() == 6) - { - if(m_spherical_harmonics != NULL) - { - delete m_spherical_harmonics; - } - m_spherical_harmonics = new SphericalHarmonics(spherical_harmonics_textures); - } - else - { - //m_spherical_harmonic = new SphericalHarmonic(m_scene_manager->getAmbientLight().toSColor()); - }*/ return m_scene_manager->addSkyBoxSceneNode(texture[0], texture[1], texture[2], texture[3], @@ -1401,21 +1381,8 @@ scene::ISceneNode *IrrDriver::addSkyBox(const std::vector &tex void IrrDriver::suppressSkyBox() { - //TODO! - /*SkyboxTextures.clear(); - SphericalHarmonicsTextures.clear(); - m_skybox_ready = false; - if ((SkyboxCubeMap) && (!ProfileWorld::isNoGraphics())) - { - glDeleteTextures(1, &SkyboxCubeMap); - glDeleteTextures(1, &SkyboxSpecularProbe); - } - SkyboxCubeMap = 0; - SkyboxSpecularProbe = 0;*/ delete m_skybox; m_skybox = NULL; - //delete m_spherical_harmonics; - //m_spherical_harmonics = NULL; } // ---------------------------------------------------------------------------- @@ -1796,9 +1763,6 @@ void IrrDriver::setAmbientLight(const video::SColorf &light) { m_scene_manager->setAmbientLight(light); m_spherical_harmonics->setAmbientLight(light.toSColor()); - //TODO! - - } // setAmbientLight video::SColorf IrrDriver::getAmbientLight() const diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index ed46e5464..336455836 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -186,9 +186,8 @@ void IrrDriver::renderGLSL(float dt) const core::recti &viewport = camera->getViewport(); - //if (World::getWorld() && World::getWorld()->getTrack()->hasShadows() && !SphericalHarmonicsTextures.empty()) - //irr_driver->getSceneManager()->setAmbientLight(SColor(0, 0, 0, 0)); - //TODO! + if (World::getWorld() && World::getWorld()->getTrack()->hasShadows() && m_spherical_harmonics->has6Textures()) + irr_driver->getSceneManager()->setAmbientLight(SColor(0, 0, 0, 0)); if (!CVS->isDefferedEnabled()) glEnable(GL_FRAMEBUFFER_SRGB); diff --git a/src/graphics/render_lighting.cpp b/src/graphics/render_lighting.cpp index 61f5e905b..98330825e 100644 --- a/src/graphics/render_lighting.cpp +++ b/src/graphics/render_lighting.cpp @@ -497,9 +497,7 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow) else { m_post_processing->renderEnvMap(0); - } - - //TODO: move in skybox (or IBL?) class + } } // Render sunlight if and only if track supports shadow diff --git a/src/graphics/skybox.cpp b/src/graphics/skybox.cpp index 3a500e68a..797467b4c 100644 --- a/src/graphics/skybox.cpp +++ b/src/graphics/skybox.cpp @@ -74,8 +74,6 @@ public: }; // SpecularIBLGenerator - - namespace { // ---------------------------------------------------------------------------- void swapPixels(char *old_img, char *new_img, unsigned stride, unsigned old_i, @@ -141,16 +139,7 @@ namespace { } //namespace // ---------------------------------------------------------------------------- -/** Generate an opengl cubemap texture from 6 2d textures. -Out of legacy the sequence of textures maps to : -- 1st texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Y -- 2nd texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_Y -- 3rd texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_X -- 4th texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_X -- 5th texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_Z -- 6th texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Z -* \param textures sequence of 6 textures. -*/ +/** Generate an opengl cubemap texture from 6 2d textures */ void Skybox::generateCubeMapFromTextures() { assert(m_skybox_textures.size() == 6); @@ -218,7 +207,6 @@ void Skybox::generateCubeMapFromTextures() // ---------------------------------------------------------------------------- void Skybox::generateSpecularCubemap() { - glGenTextures(1, &m_specular_probe); glBindTexture(GL_TEXTURE_CUBE_MAP, m_specular_probe); size_t cubemap_size = 256; @@ -315,6 +303,16 @@ void Skybox::generateSpecularCubemap() // ---------------------------------------------------------------------------- +/** Generate a skybox from 6 2d textures. +Out of legacy the sequence of textures maps to: +- 1st texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Y +- 2nd texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_Y +- 3rd texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_X +- 4th texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_X +- 5th texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_Z +- 6th texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Z +* \param skybox_textures sequence of 6 textures. +*/ Skybox::Skybox(const std::vector &skybox_textures) { m_skybox_textures = skybox_textures; diff --git a/src/graphics/sphericalHarmonics.hpp b/src/graphics/sphericalHarmonics.hpp index 2b2e714cd..7097491ff 100644 --- a/src/graphics/sphericalHarmonics.hpp +++ b/src/graphics/sphericalHarmonics.hpp @@ -63,6 +63,8 @@ public: inline const float* getGreenSHCoeff() const {return m_green_SH_coeff; } inline const float* getRedSHCoeff () const {return m_red_SH_coeff; } + inline bool has6Textures() const {return m_spherical_harmonics_textures.size()==6;} + void printCoeff(); void unprojectSH (size_t width, size_t height, diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index fb6f68c57..642486861 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1824,12 +1824,6 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) } m_track_object_manager->enableFog(m_use_fog); - // ---- Set ambient color - // We need to define ambient color before adding Skybox because we will use - // ambient light if the track do not have spherical harmonics textures. - m_ambient_color = m_default_ambient_color; - irr_driver->getSceneManager()->setAmbientLight(m_ambient_color); - // Sky dome and boxes support // -------------------------- irr_driver->suppressSkyBox(); @@ -1860,8 +1854,6 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) m_all_nodes.push_back(irr_driver->addSkyBox(m_sky_textures, m_spherical_harmonics_textures)); //else // m_all_nodes.push_back(irr_driver->addSkyBox(m_sky_textures, m_sky_textures)); - if (m_spherical_harmonics_textures.size() != 6) - irr_driver->getSphericalHarmonics()->setAmbientLight(m_ambient_color); } else if(m_sky_type==SKY_COLOR) { @@ -1877,6 +1869,12 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id) file_manager->popTextureSearchPath(); file_manager->popModelSearchPath (); + // ---- Set ambient color + m_ambient_color = m_default_ambient_color; + irr_driver->getSceneManager()->setAmbientLight(m_ambient_color); + if (m_spherical_harmonics_textures.size() != 6) + irr_driver->getSphericalHarmonics()->setAmbientLight(m_ambient_color); + // ---- Create sun (non-ambient directional light) if (m_sun_position.getLengthSQ() < 0.03f) {