Fixed memory leak and improved interfaces for rendering to texture
This commit is contained in:
parent
956ae27eca
commit
a257acfd4b
@ -22,6 +22,7 @@
|
||||
#include "graphics/rtts.hpp"
|
||||
#include "graphics/sphericalHarmonics.hpp"
|
||||
#include <irrlicht.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -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<RenderTarget> createRenderTarget(const irr::core::dimension2du &dimension,
|
||||
const std::string &name) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif //HEADER_ABSTRACT_RENDERER_HPP
|
||||
|
@ -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<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;*/
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,10 @@
|
||||
#define HEADER_FIXED_PIPELINE_RENDERER_HPP
|
||||
|
||||
#include "graphics/abstract_renderer.hpp"
|
||||
#include <map>
|
||||
|
||||
class RenderTarget;
|
||||
class GL1RenderTarget;
|
||||
|
||||
class FixedPipelineRenderer: public AbstractRenderer
|
||||
{
|
||||
@ -32,6 +36,10 @@ public:
|
||||
float dt, bool hasShadows, bool forceRTT){}
|
||||
void updateLightsInfo(irr::scene::ICameraSceneNode * const camnode,
|
||||
float dt){}
|
||||
|
||||
std::unique_ptr<RenderTarget> createRenderTarget(const irr::core::dimension2du &dimension,
|
||||
const std::string &name);
|
||||
|
||||
};
|
||||
|
||||
#endif //HEADER_FIXED_PIPELINE_RENDERER_HPP
|
||||
|
@ -201,41 +201,13 @@ GPUTimer &IrrDriver::getGPUTimer(unsigned i)
|
||||
}
|
||||
|
||||
|
||||
RenderTarget* IrrDriver::addRenderTarget(const irr::core::dimension2du &dimension,
|
||||
|
||||
std::unique_ptr<RenderTarget> 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
@ -27,9 +27,6 @@
|
||||
* management, etc...)
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <IVideoDriver.h>
|
||||
#include <vector2d.h>
|
||||
#include <dimension2d.h>
|
||||
@ -46,7 +43,9 @@
|
||||
#include "utils/no_copy.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "utils/vec3.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace irr
|
||||
@ -207,8 +206,6 @@ private:
|
||||
float m_ssao_k;
|
||||
float m_ssao_sigma;
|
||||
|
||||
std::map<std::string, RenderTarget*> m_render_targets;
|
||||
|
||||
#ifdef DEBUG
|
||||
/** Used to visualise skeletons. */
|
||||
std::vector<irr::scene::IAnimatedMeshSceneNode*> m_debug_meshes;
|
||||
@ -319,18 +316,8 @@ public:
|
||||
void unsetTextureErrorMessage();
|
||||
class GPUTimer &getGPUTimer(unsigned);
|
||||
|
||||
RenderTarget* addRenderTarget(const irr::core::dimension2du &dimension,
|
||||
std::unique_ptr<RenderTarget> createRenderTarget(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);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Convenience function that loads a texture with default parameters
|
||||
|
@ -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<s32>& dest_rect,
|
||||
const irr::core::rect<s32>* clip_rect,
|
||||
const irr::video::SColor &colors,
|
||||
bool use_alpha_channel_of_texture) const
|
||||
{
|
||||
irr::core::rect<s32> 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())
|
||||
@ -65,3 +94,30 @@ irr::core::dimension2du GL3RenderTarget::getTextureSize() const
|
||||
return irr::core::dimension2du(m_frame_buffer->getWidth(),
|
||||
m_frame_buffer->getHeight());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
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<s32>& dest_rect,
|
||||
const irr::core::rect<s32>* clip_rect,
|
||||
const irr::video::SColor &colors,
|
||||
bool use_alpha_channel_of_texture) const
|
||||
{
|
||||
irr::core::rect<s32> 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);
|
||||
}
|
||||
|
@ -22,11 +22,20 @@
|
||||
#include <irrlicht.h>
|
||||
#include <string>
|
||||
|
||||
class ShaderBasedRenderer;
|
||||
|
||||
class RenderTarget
|
||||
{
|
||||
public:
|
||||
virtual GLuint getTextureId() 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<s32>& dest_rect,
|
||||
const irr::core::rect<s32>* 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;
|
||||
|
||||
void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt);
|
||||
void draw2DImage(const irr::core::rect<s32>& dest_rect,
|
||||
const irr::core::rect<s32>* 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<s32>& dest_rect,
|
||||
const irr::core::rect<s32>* clip_rect,
|
||||
const irr::video::SColor &colors,
|
||||
bool use_alpha_channel_of_texture) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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<RenderTarget> 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);
|
||||
}
|
||||
return std::unique_ptr<RenderTarget>(new GL3RenderTarget(dimension, name, this));
|
||||
//return std::make_unique<GL3RenderTarget>(dimension, name, this);
|
||||
}
|
||||
|
||||
irr_driver->getSceneManager()->setActiveCamera(camera);
|
||||
|
||||
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<GL3RenderTarget*>(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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,11 @@
|
||||
#include "graphics/lighting_passes.hpp"
|
||||
#include "graphics/shadow_matrices.hpp"
|
||||
#include "graphics/skybox.hpp"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class RenderTarget;
|
||||
class GL3RenderTarget;
|
||||
|
||||
class ShaderBasedRenderer: public AbstractRenderer
|
||||
{
|
||||
@ -105,15 +109,12 @@ public:
|
||||
|
||||
void render(float dt);
|
||||
|
||||
/*GLuint renderToTexture(size_t width,
|
||||
size_t height,
|
||||
irr::scene::ICameraSceneNode* camera,
|
||||
float dt,
|
||||
const std::string &rtt_name) override;*/
|
||||
std::unique_ptr<RenderTarget> createRenderTarget(const irr::core::dimension2du &dimension,
|
||||
const std::string &name);
|
||||
|
||||
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
|
||||
|
@ -1958,12 +1958,13 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect,
|
||||
else if (type == WTYPE_MODEL_VIEW)
|
||||
{
|
||||
ModelViewWidget* mvw = dynamic_cast<ModelViewWidget*>(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<s32>(0, 0, 512, 512), NULL, SColor(255, 255, 255, 255), true);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else if (type == WTYPE_ICON_BUTTON || type == WTYPE_MODEL_VIEW)
|
||||
{
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/post_processing.hpp"
|
||||
#include "graphics/render_target.hpp"
|
||||
#include "graphics/rtts.hpp"
|
||||
|
||||
#include <IAnimatedMesh.h>
|
||||
#include <IAnimatedMeshSceneNode.h>
|
||||
@ -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()
|
||||
@ -165,21 +158,13 @@ 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<GL3RenderTarget*>(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<s32>& dest_rect) const
|
||||
{
|
||||
m_render_target->draw2DImage(dest_rect, NULL, video::SColor(255, 255, 255, 255), true);
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,7 @@ namespace GUIEngine
|
||||
AlignedArray<Vec3> m_model_scale;
|
||||
std::vector<int> m_model_frames;
|
||||
|
||||
RTT* m_rtt_provider;
|
||||
RenderTarget *m_render_target;
|
||||
std::unique_ptr<RenderTarget> 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<Vec3>& mesh_scale,
|
||||
const std::vector<int>& model_frames);
|
||||
|
||||
FrameBuffer* getFrameBuffer() { return m_frame_buffer; }
|
||||
void drawRTTScene(const irr::core::rect<s32>& dest_rect) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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<s32> dest(m_map_left, upper_y,
|
||||
m_map_left + m_map_width, lower_y);
|
||||
|
||||
if (old_rtt_mini_map != NULL)
|
||||
{
|
||||
core::rect<s32> 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<s32> 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; i<world->getNumKarts(); i++)
|
||||
{
|
||||
|
@ -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<s32> dest(m_map_left, upper_y,
|
||||
m_map_left + m_map_width, lower_y);
|
||||
|
||||
if (old_rtt_mini_map != NULL)
|
||||
{
|
||||
core::rect<s32> 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<s32> 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;
|
||||
|
||||
|
@ -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<GL3RenderTarget*>(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<s32>& 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.
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef HEADER_QUAD_GRAPH_HPP
|
||||
#define HEADER_QUAD_GRAPH_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <set>
|
||||
@ -29,6 +30,8 @@
|
||||
#include "utils/no_copy.hpp"
|
||||
|
||||
#include <dimension2d.h>
|
||||
#include <rect.h>
|
||||
|
||||
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<RenderTarget> m_render_target;
|
||||
|
||||
/** The actual graph data structure. */
|
||||
std::vector<GraphNode*> 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<s32>& dest_rect) const;
|
||||
void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const;
|
||||
void updateDistancesForAllSuccessors(unsigned int indx,
|
||||
float delta,
|
||||
|
@ -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; i<m_sky_textures.size(); i++)
|
||||
{
|
||||
m_sky_textures[i]->drop();
|
||||
@ -687,24 +674,20 @@ 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;
|
||||
|
||||
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
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -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<float> > 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. */
|
||||
|
Loading…
Reference in New Issue
Block a user