From 8785ddf1484f09a86d5dfda309e77ab4cb930294 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 12 Dec 2016 08:05:07 +1100 Subject: [PATCH] Moved force-fog settings into track. --- src/graphics/draw_calls.cpp | 3 ++- src/graphics/geometry_passes.cpp | 4 +++- src/graphics/shader_based_renderer.cpp | 7 +++---- src/graphics/stk_mesh_scene_node.cpp | 3 ++- src/modes/world.cpp | 7 ------- src/modes/world.hpp | 6 ------ src/tracks/graph.cpp | 5 +++-- src/tracks/track.cpp | 5 +++-- src/tracks/track.hpp | 16 +++++++++++++++- 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/graphics/draw_calls.cpp b/src/graphics/draw_calls.cpp index de7411572..36b1cb8c9 100644 --- a/src/graphics/draw_calls.cpp +++ b/src/graphics/draw_calls.cpp @@ -196,7 +196,8 @@ void DrawCalls::handleSTKCommon(scene::ISceneNode *Node, } // Transparent - if (World::getWorld() && World::getWorld()->isFogEnabled()) + const World *world = World::getWorld(); + if (world && world->getTrack()->isFogEnabled()) { const Track * const track = World::getWorld()->getTrack(); diff --git a/src/graphics/geometry_passes.cpp b/src/graphics/geometry_passes.cpp index f9fb65400..a30bbac03 100644 --- a/src/graphics/geometry_passes.cpp +++ b/src/graphics/geometry_passes.cpp @@ -25,6 +25,7 @@ #include "graphics/rtts.hpp" #include "graphics/shaders.hpp" #include "modes/world.hpp" +#include "tracks/track.hpp" #include "utils/tuple.hpp" #include #include @@ -260,7 +261,8 @@ void AbstractGeometryPasses::renderTransparent(const DrawCalls& draw_calls, if (CVS->isARBBaseInstanceUsable()) glBindVertexArray(VAOManager::getInstance()->getVAO(video::EVT_STANDARD)); - if (World::getWorld() && World::getWorld()->isFogEnabled()) + const World *world = World::getWorld(); + if (world && world->getTrack()->isFogEnabled()) { glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); renderTransparenPassisDefferedEnabled() && World::getWorld() != NULL && - World::getWorld()->isFogEnabled()) + const World *world = World::getWorld(); + if (CVS->isDefferedEnabled() && world && world->getTrack()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- Ambient scatter", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_FOG)); @@ -446,8 +446,7 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, } // Render discrete lights scattering - if (CVS->isDefferedEnabled() && World::getWorld() != NULL && - World::getWorld()->isFogEnabled()) + if (CVS->isDefferedEnabled() && world && world->getTrack()->isFogEnabled()) { PROFILER_PUSH_CPU_MARKER("- PointLight Scatter", 0xFF, 0x00, 0x00); ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_FOG)); diff --git a/src/graphics/stk_mesh_scene_node.cpp b/src/graphics/stk_mesh_scene_node.cpp index 92a0a6cc8..028ffe18d 100644 --- a/src/graphics/stk_mesh_scene_node.cpp +++ b/src/graphics/stk_mesh_scene_node.cpp @@ -512,7 +512,8 @@ void STKMeshSceneNode::render() else glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - if (World::getWorld() && World::getWorld()->isFogEnabled()) + const World* world = World::getWorld(); + if (world && world->getTrack()->isFogEnabled()) { Shaders::TransparentFogShader::getInstance()->use(); for (unsigned i = 0; i < GLmeshes.size(); i++) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 6b5f2cf29..e68a9f394 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -133,7 +133,6 @@ World::World() : WorldStatus() m_schedule_tutorial = false; m_is_network_world = false; m_weather = NULL; - m_force_disable_fog = false; m_stop_music_when_dialog_open = true; @@ -1291,12 +1290,6 @@ void World::escapePressed() new RacePausedDialog(0.8f, 0.6f); } // escapePressed -//----------------------------------------------------------------------------- -bool World::isFogEnabled() const -{ - return !m_force_disable_fog && (m_track != NULL && m_track->isFogEnabled()); -} // isFogEnabled - // ---------------------------------------------------------------------------- /** Returns the start transform with the give index. * \param rescue_pos Index of the start position to be returned. diff --git a/src/modes/world.hpp b/src/modes/world.hpp index 313cb8ad2..d10a43113 100644 --- a/src/modes/world.hpp +++ b/src/modes/world.hpp @@ -97,7 +97,6 @@ protected: RandomGenerator m_random; Physics* m_physics; - bool m_force_disable_fog; AbstractKart* m_fastest_kart; /** Number of eliminated karts. */ int m_eliminated_karts; @@ -324,8 +323,6 @@ public: /** Returns a pointer to the Scripting Engine. */ Scripting::ScriptEngine *getScriptEngine() const { return m_script_engine; } - //------------------------------------------------------------------------- - bool isFogEnabled() const; // ------------------------------------------------------------------------ void moveKartTo(AbstractKart* kart, const btTransform &t); // ------------------------------------------------------------------------ @@ -337,9 +334,6 @@ public: /** \return whether this world can generate/have highscores */ bool useHighScores() const { return m_use_highscores; } // ------------------------------------------------------------------------ - /** Override track fog value to force disabled */ - void forceFogDisabled(bool v) { m_force_disable_fog = v; } - // ------------------------------------------------------------------------ /** Override if you want to know when a kart presses fire */ virtual void onFirePressed(Controller* who) {} // ------------------------------------------------------------------------ diff --git a/src/tracks/graph.cpp b/src/tracks/graph.cpp index 2fec46183..d4953e60f 100644 --- a/src/tracks/graph.cpp +++ b/src/tracks/graph.cpp @@ -28,6 +28,7 @@ #include "tracks/arena_node_3d.hpp" #include "tracks/drive_node_2d.hpp" #include "tracks/drive_node_3d.hpp" +#include "tracks/track.hpp" #include "utils/log.hpp" const int Graph::UNKNOWN_SECTOR = -1; @@ -245,7 +246,7 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, const video::SColor oldClearColor = irr_driver->getClearColor(); irr_driver->setClearbackBufferColor(video::SColor(0, 255, 255, 255)); - World::getWorld()->forceFogDisabled(true); + World::getWorld()->getTrack()->forceFogDisabled(true); #ifndef SERVER_ONLY m_render_target = irr_driver->createRenderTarget(dimension, name); #endif @@ -330,7 +331,7 @@ RenderTarget* Graph::makeMiniMap(const core::dimension2du &dimension, irr_driver->removeCameraSceneNode(camera); irr_driver->setClearbackBufferColor(oldClearColor); - World::getWorld()->forceFogDisabled(false); + World::getWorld()->getTrack()->forceFogDisabled(false); irr_driver->getSceneManager()->clear(); VAOManager::kill(); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 76d1f65ab..8956c56a2 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -145,8 +145,9 @@ Track::Track(const std::string &filename) m_render_target = NULL; m_minimap_x_scale = 1.0f; m_minimap_y_scale = 1.0f; - m_startup_run = false; - m_default_number_of_laps= 3; + m_force_disable_fog = false; + m_startup_run = false; + m_default_number_of_laps = 3; m_all_nodes.clear(); m_static_physics_only_nodes.clear(); m_all_cached_meshes.clear(); diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index ddc04e691..21bd667e5 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -313,7 +313,12 @@ private: /** The name used in sorting the track. */ core::stringw m_sort_name; + /** True if the track uses fog. */ bool m_use_fog; + + /** Can be set to force fog off (e.g. for rendering minimap). */ + bool m_force_disable_fog; + /** True if this track supports using smoothed normals. */ bool m_smooth_normals; @@ -546,7 +551,16 @@ public: // ------------------------------------------------------------------------ ParticleKind* getSkyParticles () { return m_sky_particles; } // ------------------------------------------------------------------------ - bool isFogEnabled() const { return m_use_fog; } + /** Override track fog value to force disabled */ + void forceFogDisabled(bool v) { m_force_disable_fog = v; } + //------------------------------------------------------------------------- + /** Returns if fog is currently enabled. It can be disabled per track, or + * temporary be disabled (e.g. for rendering mini map). */ + bool isFogEnabled() const + { + return !m_force_disable_fog && m_use_fog; + } // isFogEnabled + // ------------------------------------------------------------------------ float getFogStart() const { return m_fog_start; } // ------------------------------------------------------------------------