Added render to texture support for legacy OpenGL (but rendering with legacy GL is currently bugged)

This commit is contained in:
Elderme 2016-01-04 22:19:19 +01:00
parent a257acfd4b
commit 290ac3489b
6 changed files with 45 additions and 14 deletions

View File

@ -110,10 +110,6 @@ void FixedPipelineRenderer::render(float dt)
std::unique_ptr<RenderTarget> 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<RenderTarget>(new GL1RenderTarget(dimension, name));
}

View File

@ -160,6 +160,7 @@ IrrDriver::~IrrDriver()
Shaders::destroy();
}
delete m_wind;
delete m_renderer;
} // ~IrrDriver
// ----------------------------------------------------------------------------

View File

@ -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);
}
//-----------------------------------------------------------------------------

View File

@ -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,

View File

@ -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)
{

View File

@ -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
// -----------------------------------------------------------------------------