From a257acfd4b5f4168439734656320e49d9fa407ea Mon Sep 17 00:00:00 2001 From: Elderme Date: Mon, 4 Jan 2016 21:36:00 +0100 Subject: [PATCH] Fixed memory leak and improved interfaces for rendering to texture --- src/graphics/abstract_renderer.hpp | 13 ++-- src/graphics/fixed_pipeline_renderer.cpp | 12 ++++ src/graphics/fixed_pipeline_renderer.hpp | 10 ++- src/graphics/irr_driver.cpp | 36 ++--------- src/graphics/irr_driver.hpp | 23 ++----- src/graphics/render_target.cpp | 68 +++++++++++++++++++-- src/graphics/render_target.hpp | 36 ++++++++--- src/graphics/rtts.cpp | 2 +- src/graphics/shader_based_renderer.cpp | 49 +++------------ src/graphics/shader_based_renderer.hpp | 17 +++--- src/guiengine/skin.cpp | 5 +- src/guiengine/widgets/model_view_widget.cpp | 35 ++++------- src/guiengine/widgets/model_view_widget.hpp | 7 +-- src/states_screens/race_gui.cpp | 19 +----- src/states_screens/race_gui_overworld.cpp | 18 +----- src/tracks/quad_graph.cpp | 62 +++++++------------ src/tracks/quad_graph.hpp | 13 ++-- src/tracks/track.cpp | 39 ++++-------- src/tracks/track.hpp | 6 -- 19 files changed, 203 insertions(+), 267 deletions(-) diff --git a/src/graphics/abstract_renderer.hpp b/src/graphics/abstract_renderer.hpp index 9df0afadc..ed58f6ded 100644 --- a/src/graphics/abstract_renderer.hpp +++ b/src/graphics/abstract_renderer.hpp @@ -22,6 +22,7 @@ #include "graphics/rtts.hpp" #include "graphics/sphericalHarmonics.hpp" #include +#include #include #include @@ -98,14 +99,10 @@ public: return m_current_screen_size; } - /*virtual GLuint renderToTexture(size_t width, - size_t height, - irr::scene::ICameraSceneNode* camera, - float dt, - const std::string &rtt_name) { return 0;}*/ - virtual void renderToTexture(RenderTarget *render_target, - irr::scene::ICameraSceneNode* camera, - float dt) {} + + virtual std::unique_ptr createRenderTarget(const irr::core::dimension2du &dimension, + const std::string &name) = 0; + }; #endif //HEADER_ABSTRACT_RENDERER_HPP diff --git a/src/graphics/fixed_pipeline_renderer.cpp b/src/graphics/fixed_pipeline_renderer.cpp index 317766dc0..9798b30b0 100644 --- a/src/graphics/fixed_pipeline_renderer.cpp +++ b/src/graphics/fixed_pipeline_renderer.cpp @@ -19,6 +19,7 @@ #include "config/user_config.hpp" #include "graphics/camera.hpp" #include "graphics/irr_driver.hpp" +#include "graphics/render_target.hpp" #include "modes/world.hpp" #include "physics/physics.hpp" #include "utils/profiler.hpp" @@ -105,3 +106,14 @@ void FixedPipelineRenderer::render(float dt) irr_driver->getVideoDriver()->endScene(); } + +std::unique_ptr FixedPipelineRenderer::createRenderTarget(const irr::core::dimension2du &dimension, + const std::string &name) +{ + /*GL1RenderTarget *render_target = new GL1RenderTarget(dimension, name); + if (m_render_targets.find("name") != m_render_targets.end()) + delete m_render_targets[name]; + m_render_targets[name] = render_target; + return render_target;*/ +} + diff --git a/src/graphics/fixed_pipeline_renderer.hpp b/src/graphics/fixed_pipeline_renderer.hpp index b93998280..d7a9b2de2 100644 --- a/src/graphics/fixed_pipeline_renderer.hpp +++ b/src/graphics/fixed_pipeline_renderer.hpp @@ -19,9 +19,13 @@ #define HEADER_FIXED_PIPELINE_RENDERER_HPP #include "graphics/abstract_renderer.hpp" +#include + +class RenderTarget; +class GL1RenderTarget; class FixedPipelineRenderer: public AbstractRenderer -{ +{ public: void onLoadWorld() ; @@ -32,6 +36,10 @@ public: float dt, bool hasShadows, bool forceRTT){} void updateLightsInfo(irr::scene::ICameraSceneNode * const camnode, float dt){} + + std::unique_ptr createRenderTarget(const irr::core::dimension2du &dimension, + const std::string &name); + }; #endif //HEADER_FIXED_PIPELINE_RENDERER_HPP diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 55ccf740c..aebc5abcf 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -201,41 +201,13 @@ GPUTimer &IrrDriver::getGPUTimer(unsigned i) } -RenderTarget* IrrDriver::addRenderTarget(const irr::core::dimension2du &dimension, - const std::string &name) + +std::unique_ptr IrrDriver::createRenderTarget(const irr::core::dimension2du &dimension, + const std::string &name) { - RenderTarget* render_target; - if(CVS->isGLSL()) - render_target = new GL3RenderTarget(dimension); - else - render_target = new GL1RenderTarget(dimension, name); - - m_render_targets[name] = render_target; - return render_target; + return m_renderer->createRenderTarget(dimension, name); } -void IrrDriver::removeRenderTarget(const std::string &name) -{ - m_render_targets.erase(name); -} - -/*GLuint IrrDriver::renderToTexture(size_t width, - size_t height, - irr::scene::ICameraSceneNode* camera, - float dt, - const std::string &rtt_name) -{ - return m_renderer->renderToTexture(width, height, camera, dt, rtt_name); -}*/ - -void IrrDriver::renderToTexture(RenderTarget *render_target, - irr::scene::ICameraSceneNode* camera, - float dt) -{ - m_renderer->renderToTexture(render_target, camera, dt); -} - - // ---------------------------------------------------------------------------- diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index a26ced29b..69a8b9199 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -27,9 +27,6 @@ * management, etc...) */ -#include -#include - #include #include #include @@ -46,7 +43,9 @@ #include "utils/no_copy.hpp" #include "utils/ptr_vector.hpp" #include "utils/vec3.hpp" - +#include +#include +#include namespace irr @@ -207,8 +206,6 @@ private: float m_ssao_k; float m_ssao_sigma; - std::map m_render_targets; - #ifdef DEBUG /** Used to visualise skeletons. */ std::vector m_debug_meshes; @@ -319,18 +316,8 @@ public: void unsetTextureErrorMessage(); class GPUTimer &getGPUTimer(unsigned); - RenderTarget* addRenderTarget(const irr::core::dimension2du &dimension, - const std::string &name); - void removeRenderTarget(const std::string &name); - - /*GLuint renderToTexture(size_t width, - size_t height, - irr::scene::ICameraSceneNode* camera, - float dt, - const std::string &rtt_name);*/ - void renderToTexture(RenderTarget *render_target, - irr::scene::ICameraSceneNode* camera, - float dt); + std::unique_ptr createRenderTarget(const irr::core::dimension2du &dimension, + const std::string &name); // ------------------------------------------------------------------------ /** Convenience function that loads a texture with default parameters diff --git a/src/graphics/render_target.cpp b/src/graphics/render_target.cpp index 42a7a1518..b4de73800 100644 --- a/src/graphics/render_target.cpp +++ b/src/graphics/render_target.cpp @@ -15,8 +15,11 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "graphics/central_settings.hpp" +#include "graphics/2dutils.hpp" #include "graphics/render_target.hpp" +#include "graphics/central_settings.hpp" +#include "graphics/shader_based_renderer.hpp" + //----------------------------------------------------------------------------- GL1RenderTarget::GL1RenderTarget(const irr::core::dimension2du &dimension, @@ -25,21 +28,47 @@ GL1RenderTarget::GL1RenderTarget(const irr::core::dimension2du &dimension, } -//----------------------------------------------------------------------------- -GLuint GL1RenderTarget::getTextureId() const +GL1RenderTarget::~GL1RenderTarget() { - + /*assert(m_old_rtt_mini_map->getReferenceCount() == 1); + irr_driver->removeTexture(m_old_rtt_mini_map); + m_old_rtt_mini_map = NULL;*/ } //----------------------------------------------------------------------------- irr::core::dimension2du GL1RenderTarget::getTextureSize() const +{ + return m_render_target_texture->getSize(); +} + +//----------------------------------------------------------------------------- +void GL1RenderTarget::renderToTexture(irr::scene::ICameraSceneNode* camera, float dt) { } //----------------------------------------------------------------------------- -GL3RenderTarget::GL3RenderTarget(const irr::core::dimension2du &dimension) +void GL1RenderTarget::draw2DImage(const irr::core::rect& dest_rect, + const irr::core::rect* clip_rect, + const irr::video::SColor &colors, + bool use_alpha_channel_of_texture) const { + irr::core::rect source_rect(irr::core::position2di(0, 0), + m_render_target_texture->getSize()); + + irr_driver->getVideoDriver()->draw2DImage(m_render_target_texture, + dest_rect, source_rect, + clip_rect, &colors, + use_alpha_channel_of_texture); +} + +//----------------------------------------------------------------------------- +GL3RenderTarget::GL3RenderTarget(const irr::core::dimension2du &dimension, + const std::string &name, + ShaderBasedRenderer *renderer) +{ + m_renderer = renderer; + glGenTextures(1, &m_texture_id); glBindTexture(GL_TEXTURE_2D, m_texture_id); if (CVS->isARBTextureStorageUsable()) @@ -64,4 +93,31 @@ irr::core::dimension2du GL3RenderTarget::getTextureSize() const { return irr::core::dimension2du(m_frame_buffer->getWidth(), m_frame_buffer->getHeight()); -} \ No newline at end of file +} + +//----------------------------------------------------------------------------- +FrameBuffer* GL3RenderTarget::getFrameBuffer() +{ + return m_frame_buffer; +} + +//----------------------------------------------------------------------------- +void GL3RenderTarget::renderToTexture(irr::scene::ICameraSceneNode* camera, float dt) +{ + m_renderer->renderToTexture(this, camera, dt); +} + +//----------------------------------------------------------------------------- +void GL3RenderTarget::draw2DImage(const irr::core::rect& dest_rect, + const irr::core::rect* clip_rect, + const irr::video::SColor &colors, + bool use_alpha_channel_of_texture) const +{ + irr::core::rect source_rect(0, 0, m_frame_buffer->getWidth(), + m_frame_buffer->getHeight()); + + draw2DImageFromRTT(m_texture_id, + m_frame_buffer->getWidth(), m_frame_buffer->getHeight(), + dest_rect, source_rect, + clip_rect, colors, use_alpha_channel_of_texture); +} diff --git a/src/graphics/render_target.hpp b/src/graphics/render_target.hpp index 6e0cf3c46..fa1e6feb3 100644 --- a/src/graphics/render_target.hpp +++ b/src/graphics/render_target.hpp @@ -22,11 +22,20 @@ #include #include +class ShaderBasedRenderer; + class RenderTarget { public: - virtual GLuint getTextureId() const = 0; - virtual irr::core::dimension2du getTextureSize() const = 0; + virtual ~RenderTarget() {} + + virtual irr::core::dimension2du getTextureSize() const = 0; + + virtual void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt) = 0; + virtual void draw2DImage(const irr::core::rect& dest_rect, + const irr::core::rect* clip_rect, + const irr::video::SColor &colors, + bool use_alpha_channel_of_texture) const = 0; }; class GL1RenderTarget: public RenderTarget @@ -38,27 +47,40 @@ private: public: GL1RenderTarget(const irr::core::dimension2du &dimension, const std::string &name); + ~GL1RenderTarget(); + - GLuint getTextureId() const; - irr::core::dimension2du getTextureSize() const; + irr::core::dimension2du getTextureSize() const; + void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt); + void draw2DImage(const irr::core::rect& dest_rect, + const irr::core::rect* clip_rect, + const irr::video::SColor &colors, + bool use_alpha_channel_of_texture) const; }; class GL3RenderTarget: public RenderTarget { private: + ShaderBasedRenderer *m_renderer; FrameBuffer *m_frame_buffer; GLuint m_texture_id; public: - GL3RenderTarget(const irr::core::dimension2du &dimension); + GL3RenderTarget(const irr::core::dimension2du &dimension, + const std::string &name, + ShaderBasedRenderer *renderer); ~GL3RenderTarget(); - GLuint getTextureId() const { return m_texture_id; } irr::core::dimension2du getTextureSize() const; - FrameBuffer* getFrameBuffer() { return m_frame_buffer; } + FrameBuffer* getFrameBuffer(); + void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt); + void draw2DImage(const irr::core::rect& dest_rect, + const irr::core::rect* clip_rect, + const irr::video::SColor &colors, + bool use_alpha_channel_of_texture) const; }; diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index d30465f30..3ed8d19c8 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -264,7 +264,7 @@ RTT::RTT(size_t width, size_t height) getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).bind(); glClearColor(.5, .5, .5, .5); glClear(GL_COLOR_BUFFER_BIT); - glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); } RTT::~RTT() diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index ea0b857e1..9768d4333 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -599,6 +599,7 @@ ShaderBasedRenderer::~ShaderBasedRenderer() delete m_geometry_passes; delete m_spherical_harmonics; delete m_skybox; + delete m_rtts; } @@ -607,6 +608,7 @@ void ShaderBasedRenderer::onLoadWorld() const core::recti &viewport = Camera::getCamera(0)->getViewport(); size_t width = viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X; size_t height = viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y; + delete m_rtts; m_rtts = new RTT(width, height); } @@ -803,44 +805,14 @@ void ShaderBasedRenderer::render(float dt) } -/*GLuint ShaderBasedRenderer::renderToTexture(size_t width, - size_t height, - irr::scene::ICameraSceneNode* camera, - float dt, - const std::string &rtt_name) +std::unique_ptr ShaderBasedRenderer::createRenderTarget(const irr::core::dimension2du &dimension, + const std::string &name) { - if(m_rtts == NULL) - m_rtts = new RTT(width, height); - else - { - if((m_rtts->getWidth() != width) || (m_rtts->getHeight() != height)) - { - delete m_rtts; - m_rtts = new RTT(width, height); - } - } - - irr_driver->getSceneManager()->setActiveCamera(camera); + return std::unique_ptr(new GL3RenderTarget(dimension, name, this)); + //return std::make_unique(dimension, name, this); +} - computeMatrixesAndCameras(camera, width, height); - updateLightsInfo(camera, dt); - uploadLightingData(); - renderScene(camera, dt, false, true); - FrameBuffer* frame_buffer = irr_driver->getPostProcessing()->render(camera, false); - GLuint render_target = frame_buffer->getRTT()[0]; - - // reset - glViewport(0, 0, - irr_driver->getActualScreenSize().Width, - irr_driver->getActualScreenSize().Height); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - irr_driver->getSceneManager()->setActiveCamera(NULL); - - return render_target; -}*/ - -void ShaderBasedRenderer::renderToTexture(RenderTarget *render_target, +void ShaderBasedRenderer::renderToTexture(GL3RenderTarget *render_target, irr::scene::ICameraSceneNode* camera, float dt) { @@ -866,9 +838,7 @@ void ShaderBasedRenderer::renderToTexture(RenderTarget *render_target, updateLightsInfo(camera, dt); uploadLightingData(); renderScene(camera, dt, false, true); - FrameBuffer* frame_buffer = irr_driver->getPostProcessing()->render(camera, false, dynamic_cast(render_target)); - //TODO - + irr_driver->getPostProcessing()->render(camera, false, render_target); // reset glViewport(0, 0, @@ -879,3 +849,4 @@ void ShaderBasedRenderer::renderToTexture(RenderTarget *render_target, irr_driver->getSceneManager()->setActiveCamera(NULL); } + diff --git a/src/graphics/shader_based_renderer.hpp b/src/graphics/shader_based_renderer.hpp index beb22dfd4..e6ec32b7c 100644 --- a/src/graphics/shader_based_renderer.hpp +++ b/src/graphics/shader_based_renderer.hpp @@ -25,7 +25,11 @@ #include "graphics/lighting_passes.hpp" #include "graphics/shadow_matrices.hpp" #include "graphics/skybox.hpp" +#include +#include +class RenderTarget; +class GL3RenderTarget; class ShaderBasedRenderer: public AbstractRenderer { @@ -104,16 +108,13 @@ public: void clearGlowingNodes() override; void render(float dt); + + std::unique_ptr createRenderTarget(const irr::core::dimension2du &dimension, + const std::string &name); - /*GLuint renderToTexture(size_t width, - size_t height, - irr::scene::ICameraSceneNode* camera, - float dt, - const std::string &rtt_name) override;*/ - - void renderToTexture(RenderTarget *render_target, + void renderToTexture(GL3RenderTarget *render_target, irr::scene::ICameraSceneNode* camera, - float dt) override; + float dt); }; #endif //HEADER_SHADER_BASED_RENDERER_HPP diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index 16a29f6d3..6ffdd8dc3 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -1958,12 +1958,13 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect, else if (type == WTYPE_MODEL_VIEW) { ModelViewWidget* mvw = dynamic_cast(widget); - FrameBuffer* fb = mvw->getFrameBuffer(); + mvw->drawRTTScene(rect); + /*FrameBuffer* fb = mvw->getFrameBuffer(); if (fb != NULL && fb->getRTT().size() > 0) { draw2DImageFromRTT(fb->getRTT()[0], 512, 512, rect, core::rect(0, 0, 512, 512), NULL, SColor(255, 255, 255, 255), true); - } + }*/ } else if (type == WTYPE_ICON_BUTTON || type == WTYPE_MODEL_VIEW) { diff --git a/src/guiengine/widgets/model_view_widget.cpp b/src/guiengine/widgets/model_view_widget.cpp index a07c6149c..954604195 100644 --- a/src/guiengine/widgets/model_view_widget.cpp +++ b/src/guiengine/widgets/model_view_widget.cpp @@ -22,7 +22,6 @@ #include "graphics/irr_driver.hpp" #include "graphics/post_processing.hpp" #include "graphics/render_target.hpp" -#include "graphics/rtts.hpp" #include #include @@ -40,12 +39,10 @@ using namespace irr::gui; ModelViewWidget::ModelViewWidget() : IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, false) { - m_frame_buffer = NULL; m_rtt_main_node = NULL; m_camera = NULL; m_light = NULL; m_type = WTYPE_MODEL_VIEW; - m_rtt_provider = NULL; m_render_target = NULL; m_rotation_mode = ROTATE_OFF; @@ -58,10 +55,6 @@ IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false, ModelViewWidget::~ModelViewWidget() { GUIEngine::needsUpdate.remove(this); - - delete m_rtt_provider; - m_rtt_provider = NULL; - //TODO: remove render target } // ----------------------------------------------------------------------------- void ModelViewWidget::add() @@ -164,22 +157,14 @@ void ModelViewWidget::update(float delta) if (!CVS->isGLSL()) return; - - /*if (m_rtt_provider == NULL) - { - std::string name = "model view "; - name += m_properties[PROP_ID].c_str(); - - m_rtt_provider = new RTT(512, 512); - }*/ + if (m_render_target == NULL) { std::string name = "model view "; name += m_properties[PROP_ID].c_str(); - m_render_target = irr_driver->addRenderTarget(irr::core::dimension2du(512,512), name); + m_render_target = irr_driver->createRenderTarget(irr::core::dimension2du(512,512), name); } - if (m_rtt_main_node == NULL) { setupRTTScene(m_models, m_model_location, m_model_scale, m_model_frames); @@ -189,9 +174,7 @@ void ModelViewWidget::update(float delta) m_rtt_main_node->setVisible(true); - //m_frame_buffer = m_rtt_provider->render(m_camera, GUIEngine::getLatestDt()); - irr_driver->renderToTexture(m_render_target, m_camera, GUIEngine::getLatestDt()); - m_frame_buffer = dynamic_cast(m_render_target)->getFrameBuffer(); + m_render_target->renderToTexture(m_camera, GUIEngine::getLatestDt()); m_rtt_main_node->setVisible(false); } @@ -319,13 +302,17 @@ bool ModelViewWidget::isRotating() void ModelViewWidget::elementRemoved() { - delete m_rtt_provider; - m_rtt_provider = NULL; + m_render_target = NULL; IconButtonWidget::elementRemoved(); } void ModelViewWidget::clearRttProvider() { - delete m_rtt_provider; - m_rtt_provider = NULL; + m_render_target = NULL;; } + +void ModelViewWidget::drawRTTScene(const irr::core::rect& dest_rect) const +{ + m_render_target->draw2DImage(dest_rect, NULL, video::SColor(255, 255, 255, 255), true); +} + diff --git a/src/guiengine/widgets/model_view_widget.hpp b/src/guiengine/widgets/model_view_widget.hpp index f0d577763..21d63dcab 100644 --- a/src/guiengine/widgets/model_view_widget.hpp +++ b/src/guiengine/widgets/model_view_widget.hpp @@ -50,8 +50,7 @@ namespace GUIEngine AlignedArray m_model_scale; std::vector m_model_frames; - RTT* m_rtt_provider; - RenderTarget *m_render_target; + std::unique_ptr m_render_target; float angle; @@ -63,8 +62,6 @@ namespace GUIEngine scene::ISceneNode *m_light; - FrameBuffer *m_frame_buffer; - public: LEAK_CHECK() @@ -102,7 +99,7 @@ namespace GUIEngine AlignedArray& mesh_scale, const std::vector& model_frames); - FrameBuffer* getFrameBuffer() { return m_frame_buffer; } + void drawRTTScene(const irr::core::rect& dest_rect) const; }; } diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 476d97d92..d183c3c9d 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -345,30 +345,13 @@ void RaceGUI::drawGlobalMiniMap() // arenas currently don't have a map. if(world->getTrack()->isArena() || world->getTrack()->isSoccer()) return; - const video::ITexture *old_rtt_mini_map = world->getTrack()->getOldRttMiniMap(); - const FrameBuffer* new_rtt_mini_map = world->getTrack()->getNewRttMiniMap(); - int upper_y = irr_driver->getActualScreenSize().Height - m_map_bottom - m_map_height; int lower_y = irr_driver->getActualScreenSize().Height - m_map_bottom; core::rect dest(m_map_left, upper_y, m_map_left + m_map_width, lower_y); - if (old_rtt_mini_map != NULL) - { - core::rect source(core::position2di(0, 0), - old_rtt_mini_map->getSize()); - draw2DImage(old_rtt_mini_map, dest, source, - NULL, NULL, true); - } - else if (new_rtt_mini_map != NULL) - { - core::rect source(0, 0, (int)new_rtt_mini_map->getWidth(), - (int)new_rtt_mini_map->getHeight()); - draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], - new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight(), - dest, source, NULL, video::SColor(127, 255, 255, 255), true); - } + QuadGraph::get()->drawMiniMap(dest); for(unsigned int i=0; igetNumKarts(); i++) { diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index db5728899..5a2c30307 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -318,29 +318,13 @@ void RaceGUIOverworld::drawGlobalMiniMap() m_map_left -= (int)left_most; } - - const video::ITexture *old_rtt_mini_map = world->getTrack()->getOldRttMiniMap(); - const FrameBuffer* new_rtt_mini_map = world->getTrack()->getNewRttMiniMap(); - int upper_y = m_map_bottom - m_map_height; int lower_y = m_map_bottom; core::rect dest(m_map_left, upper_y, m_map_left + m_map_width, lower_y); - if (old_rtt_mini_map != NULL) - { - core::rect source(core::position2di(0, 0), old_rtt_mini_map->getSize()); - draw2DImage(old_rtt_mini_map, dest, source, 0, 0, true); - } - else if (new_rtt_mini_map != NULL) - { - core::rect source(0, 0, (int)new_rtt_mini_map->getWidth(), - (int)new_rtt_mini_map->getHeight()); - draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], - new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight(), - dest, source, NULL, video::SColor(127, 255, 255, 255), true); - } + QuadGraph::get()->drawMiniMap(dest); Vec3 kart_xyz; diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index c77c247d6..483711cb1 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -29,7 +29,6 @@ #include "graphics/screen_quad.hpp" #include "graphics/shaders.hpp" #include "graphics/render_target.hpp" -#include "graphics/rtts.hpp" #include "io/file_manager.hpp" #include "io/xml_node.hpp" #include "modes/world.hpp" @@ -982,27 +981,13 @@ int QuadGraph::findOutOfRoadSector(const Vec3& xyz, */ void QuadGraph::makeMiniMap(const core::dimension2du &dimension, const std::string &name, - const video::SColor &fill_color, - video::ITexture** oldRttMinimap, - FrameBuffer** newRttMinimap) + const video::SColor &fill_color) { const SColor oldClearColor = World::getWorld()->getClearColor(); World::getWorld()->setClearbackBufferColor(SColor(0, 255, 255, 255)); World::getWorld()->forceFogDisabled(true); - *oldRttMinimap = NULL; - *newRttMinimap = NULL; - //RTT* newRttProvider = NULL; - IrrDriver::RTTProvider* oldRttProvider = NULL; - if (CVS->isGLSL()) - { - //m_new_rtt = newRttProvider = new RTT(dimension.Width, dimension.Height); - m_render_target = irr_driver->addRenderTarget(dimension, name); - } - else - { - oldRttProvider = new IrrDriver::RTTProvider(dimension, name, true); - } + m_render_target = irr_driver->createRenderTarget(dimension, name); irr_driver->getSceneManager()->setAmbientLight(video::SColor(255, 255, 255, 255)); @@ -1079,34 +1064,12 @@ void QuadGraph::makeMiniMap(const core::dimension2du &dimension, //camera->setAspectRatio(1.0f); camera->updateAbsolutePosition(); - video::ITexture* texture = NULL; - FrameBuffer* frame_buffer = NULL; - - if (CVS->isGLSL()) - { - //frame_buffer = newRttProvider->render(camera, GUIEngine::getLatestDt()); - irr_driver->renderToTexture(m_render_target, camera, GUIEngine::getLatestDt()); - frame_buffer = dynamic_cast(m_render_target)->getFrameBuffer(); - } - else - { - texture = oldRttProvider->renderToTexture(); - delete oldRttProvider; - } + m_render_target->renderToTexture(camera, GUIEngine::getLatestDt()); cleanupDebugMesh(); irr_driver->removeCameraSceneNode(camera); m_min_coord = bb_min; - - - if (texture == NULL && frame_buffer == NULL) - { - Log::error("Quad Graph", "[makeMiniMap] WARNING: RTT does not appear to work," - "mini-map will not be available."); - } - - *oldRttMinimap = texture; - *newRttMinimap = frame_buffer; + World::getWorld()->setClearbackBufferColor(oldClearColor); World::getWorld()->forceFogDisabled(false); @@ -1118,6 +1081,23 @@ void QuadGraph::makeMiniMap(const core::dimension2du &dimension, irr_driver->clearBackgroundNodes(); } // makeMiniMap +//----------------------------------------------------------------------------- +core::dimension2du QuadGraph::getMiniMapTextureSize() const +{ + if(m_render_target) + return m_render_target->getTextureSize(); + else + return core::dimension2du(0,0); +} + +//----------------------------------------------------------------------------- +void QuadGraph::drawMiniMap(const core::rect& dest_rect) const +{ + m_render_target->draw2DImage(dest_rect, NULL, + video::SColor(127, 255, 255, 255), + true); +} + //----------------------------------------------------------------------------- /** Returns the 2d coordinates of a point when drawn on the mini map * texture. diff --git a/src/tracks/quad_graph.hpp b/src/tracks/quad_graph.hpp index 9d9c486dd..9bc108b21 100644 --- a/src/tracks/quad_graph.hpp +++ b/src/tracks/quad_graph.hpp @@ -19,6 +19,7 @@ #ifndef HEADER_QUAD_GRAPH_HPP #define HEADER_QUAD_GRAPH_HPP +#include #include #include #include @@ -29,6 +30,8 @@ #include "utils/no_copy.hpp" #include +#include + namespace irr { namespace scene { class ISceneNode; class IMesh; class IMeshBuffer; } @@ -38,8 +41,6 @@ using namespace irr; class CheckLine; class RenderTarget; -class RTT; -class FrameBuffer; /** * \brief This class stores a graph of quads. It uses a 'simplified singleton' @@ -58,7 +59,7 @@ private: static QuadGraph *m_quad_graph; //RTT* m_new_rtt; - RenderTarget *m_render_target; + std::unique_ptr m_render_target; /** The actual graph data structure. */ std::vector m_all_nodes; @@ -126,9 +127,9 @@ public: float upwards_distance=0.0f) const; void makeMiniMap(const core::dimension2du &where, const std::string &name, - const video::SColor &fill_color, - video::ITexture** oldRttMinimap, - FrameBuffer** newRttMinimap); + const video::SColor &fill_color); + core::dimension2du getMiniMapTextureSize() const; + void drawMiniMap(const irr::core::rect& dest_rect) const; void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const; void updateDistancesForAllSuccessors(unsigned int indx, float delta, diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index a6dc6db65..c35792265 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -118,8 +118,6 @@ Track::Track(const std::string &filename) m_is_soccer = false; m_is_cutscene = false; m_camera_far = 1000.0f; - m_old_rtt_mini_map = NULL; - m_new_rtt_mini_map = NULL; m_bloom = true; m_bloom_threshold = 0.75f; m_color_inlevel = core::vector3df(0.0,1.0, 255.0); @@ -361,17 +359,6 @@ void Track::cleanup() } m_detached_cached_meshes.clear(); - if (m_old_rtt_mini_map) - { - assert(m_old_rtt_mini_map->getReferenceCount() == 1); - irr_driver->removeTexture(m_old_rtt_mini_map); - m_old_rtt_mini_map = NULL; - } - if (m_new_rtt_mini_map) - { - m_new_rtt_mini_map = NULL; // already deleted by QuadGraph::~QuadGraph - } - for(unsigned int i=0; idrop(); @@ -687,23 +674,19 @@ void Track::loadQuadGraph(unsigned int mode_id, const bool reverse) core::dimension2du size = m_mini_map_size .getOptimalSize(!nonpower,!nonsquare); - QuadGraph::get()->makeMiniMap(size, "minimap::" + m_ident, video::SColor(127, 255, 255, 255), - &m_old_rtt_mini_map, &m_new_rtt_mini_map); - if (m_old_rtt_mini_map) - { - m_minimap_x_scale = float(m_mini_map_size.Width) / float(m_old_rtt_mini_map->getSize().Width); - m_minimap_y_scale = float(m_mini_map_size.Height) / float(m_old_rtt_mini_map->getSize().Height); - } - else if (m_new_rtt_mini_map) - { - m_minimap_x_scale = float(m_mini_map_size.Width) / float(m_new_rtt_mini_map->getWidth()); - m_minimap_y_scale = float(m_mini_map_size.Height) / float(m_new_rtt_mini_map->getHeight()); - } + QuadGraph::get()->makeMiniMap(size, "minimap::" + m_ident, video::SColor(127, 255, 255, 255)); + + core::dimension2du mini_map_texture_size = QuadGraph::get()->getMiniMapTextureSize(); + + if(mini_map_texture_size.Width) + m_minimap_x_scale = float(m_mini_map_size.Width) / float(mini_map_texture_size.Width); else - { m_minimap_x_scale = 0; - m_minimap_y_scale = 0; - } + + if(mini_map_texture_size.Height) + m_minimap_y_scale = float(m_mini_map_size.Height) / float(mini_map_texture_size.Height); + else + m_minimap_y_scale = 0; } } // loadQuadGraph diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 9f35487d0..74c746477 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -337,8 +337,6 @@ private: video::SColor m_fog_color; /** The texture for the mini map, which is displayed in the race gui. */ - video::ITexture *m_old_rtt_mini_map; - FrameBuffer *m_new_rtt_mini_map; core::dimension2du m_mini_map_size; float m_minimap_x_scale; float m_minimap_y_scale; @@ -421,10 +419,6 @@ public: std::vector< std::vector > buildHeightMap(); // ------------------------------------------------------------------------ - /** Returns the texture with the mini map for this track. */ - const video::ITexture* getOldRttMiniMap() const { return m_old_rtt_mini_map; } - const FrameBuffer* getNewRttMiniMap() const { return m_new_rtt_mini_map; } - // ------------------------------------------------------------------------ const core::dimension2du& getMiniMapSize() const { return m_mini_map_size; } // ------------------------------------------------------------------------ /** Returns true if this track has an arena mode. */