From 290ac3489b6074d185fbd8ac7c0a79aedb7fa8c1 Mon Sep 17 00:00:00 2001 From: Elderme Date: Mon, 4 Jan 2016 22:19:19 +0100 Subject: [PATCH] Added render to texture support for legacy OpenGL (but rendering with legacy GL is currently bugged) --- src/graphics/fixed_pipeline_renderer.cpp | 6 +--- src/graphics/irr_driver.cpp | 1 + src/graphics/render_target.cpp | 40 +++++++++++++++++++-- src/graphics/render_target.hpp | 6 +++- src/guiengine/widgets/model_view_widget.cpp | 3 -- src/tracks/quad_graph.cpp | 3 -- 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/graphics/fixed_pipeline_renderer.cpp b/src/graphics/fixed_pipeline_renderer.cpp index 9798b30b0..d73862d59 100644 --- a/src/graphics/fixed_pipeline_renderer.cpp +++ b/src/graphics/fixed_pipeline_renderer.cpp @@ -110,10 +110,6 @@ void FixedPipelineRenderer::render(float dt) 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;*/ + return std::unique_ptr(new GL1RenderTarget(dimension, name)); } diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index aebc5abcf..df13d9bd6 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -160,6 +160,7 @@ IrrDriver::~IrrDriver() Shaders::destroy(); } delete m_wind; + delete m_renderer; } // ~IrrDriver // ---------------------------------------------------------------------------- diff --git a/src/graphics/render_target.cpp b/src/graphics/render_target.cpp index b4de73800..4e6fc8c82 100644 --- a/src/graphics/render_target.cpp +++ b/src/graphics/render_target.cpp @@ -25,7 +25,16 @@ GL1RenderTarget::GL1RenderTarget(const irr::core::dimension2du &dimension, const std::string &name) { - + m_render_target_texture = + irr_driver->getVideoDriver()->addRenderTargetTexture(dimension, + name.c_str(), + video::ECF_A8R8G8B8); + if (m_render_target_texture != NULL) + { + irr_driver->getVideoDriver()->setRenderTarget(m_render_target_texture); + } + + m_rtt_main_node = NULL; } GL1RenderTarget::~GL1RenderTarget() @@ -44,7 +53,34 @@ irr::core::dimension2du GL1RenderTarget::getTextureSize() const //----------------------------------------------------------------------------- void GL1RenderTarget::renderToTexture(irr::scene::ICameraSceneNode* camera, float dt) { - + // m_render_target_texture will be NULL if RTT doesn't work on this computer + if (m_render_target_texture == NULL) + { + Log::error("GL1RenderTarget", "Cannot render to texture."); + return; + } + + irr_driver->getVideoDriver()->setRenderTarget(m_render_target_texture); + + irr::video::SOverrideMaterial &overridemat = irr_driver->getVideoDriver()->getOverrideMaterial(); + overridemat.EnablePasses = scene::ESNRP_SOLID; + overridemat.EnableFlags = video::EMF_MATERIAL_TYPE; + overridemat.Material.MaterialType = video::EMT_SOLID; + + if (m_rtt_main_node == NULL) + { + irr_driver->getSceneManager()->drawAll(); + } + else + { + m_rtt_main_node->setVisible(true); + irr_driver->getSceneManager()->drawAll(); + m_rtt_main_node->setVisible(false); + } + + overridemat.EnablePasses = 0; + + irr_driver->getVideoDriver()->setRenderTarget(0, false, false); } //----------------------------------------------------------------------------- diff --git a/src/graphics/render_target.hpp b/src/graphics/render_target.hpp index fa1e6feb3..5a00453f6 100644 --- a/src/graphics/render_target.hpp +++ b/src/graphics/render_target.hpp @@ -41,8 +41,12 @@ public: class GL1RenderTarget: public RenderTarget { private: - irr::video::ITexture *m_render_target_texture; + /** A pointer to texture on which a scene is rendered. Only used + * in between beginRenderToTexture() and endRenderToTexture calls. */ + irr::video::ITexture *m_render_target_texture; + /** Main node of the RTT scene */ + irr::scene::ISceneNode *m_rtt_main_node; public: GL1RenderTarget(const irr::core::dimension2du &dimension, diff --git a/src/guiengine/widgets/model_view_widget.cpp b/src/guiengine/widgets/model_view_widget.cpp index 954604195..743b8ae41 100644 --- a/src/guiengine/widgets/model_view_widget.cpp +++ b/src/guiengine/widgets/model_view_widget.cpp @@ -154,9 +154,6 @@ void ModelViewWidget::update(float delta) // stop rotating when target reached if (fabsf(angle - m_rotation_target) < 2.0f) m_rotation_mode = ROTATE_OFF; } - - if (!CVS->isGLSL()) - return; if (m_render_target == NULL) { diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index 483711cb1..029c8a388 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -73,9 +73,6 @@ QuadGraph::~QuadGraph() } if(UserConfigParams::m_track_debug) cleanupDebugMesh(); - //if (m_render_target != NULL) - // delete m_render_target; - //irr_driver->removeRenderTarget(name); //TODO } // ~QuadGraph // -----------------------------------------------------------------------------