Initial work on porting minimap to new RTT

This commit is contained in:
Marianne Gagnon 2014-06-17 19:26:12 -04:00
parent b9c45b7e0f
commit cd9c2653b6
15 changed files with 153 additions and 70 deletions

View File

@ -199,7 +199,7 @@ public:
FrameBuffer(const std::vector <GLuint> &RTTs, GLuint DS, size_t w, size_t h, bool layered = false);
~FrameBuffer();
void Bind();
std::vector<GLuint> &getRTT() { return RenderTargets; }
const std::vector<GLuint> &getRTT() const { return RenderTargets; }
GLuint &getDepthTexture() { assert(DepthTexture); return DepthTexture; }
size_t getWidth() const { return width; }
size_t getHeight() const { return height; }

View File

@ -2052,7 +2052,10 @@ bool IrrDriver::supportsSplatting()
#endif
// ----------------------------------------------------------------------------
/** Begins a rendering to a texture.
/**
* THIS IS THE OLD OPENGL 1 RTT PROVIDER, USE THE SHADER-BASED
* RTT FOR NEW DEVELOPMENT
* Begins a rendering to a texture.
* \param dimension The size of the texture.
* \param name Name of the texture.
* \param persistent_texture Whether the created RTT texture should persist in

View File

@ -714,8 +714,11 @@ public:
unsigned UpdateLightsInfo(scene::ICameraSceneNode * const camnode, float dt);
void computeCameraMatrix(scene::ICameraSceneNode * const camnode, size_t width, size_t height);
// --------------------- RTT --------------------
// --------------------- OLD RTT --------------------
/**
* THIS IS THE OLD OPENGL 1 RTT PROVIDER, USE THE SHADER-BASED
* RTT FOR NEW DEVELOPMENT
*
* Class that provides RTT (currently, only when no other 3D rendering
* in the main scene is required)
* Provides an optional 'setupRTTScene' method to make it quick and easy

View File

@ -698,7 +698,7 @@ void PostProcessing::applyMLAA()
// ----------------------------------------------------------------------------
/** Render the post-processed scene */
FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode)
FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode, bool isRace)
{
IVideoDriver * const drv = irr_driver->getVideoDriver();
@ -716,7 +716,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode)
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
if (UserConfigParams::m_dof)
if (isRace && UserConfigParams::m_dof)
{
PROFILER_PUSH_CPU_MARKER("- DoF", 0xFF, 0x00, 0x00);
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_DOF));
@ -732,7 +732,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode)
if (World::getWorld() != NULL)
hasgodrays = World::getWorld()->getTrack()->hasGodRays();
if (UserConfigParams::m_light_shaft && m_sunpixels > 30 && hasgodrays)
if (isRace && UserConfigParams::m_light_shaft && m_sunpixels > 30 && hasgodrays)
{
glEnable(GL_DEPTH_TEST);
// Grab the sky
@ -798,7 +798,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode)
{
PROFILER_PUSH_CPU_MARKER("- Bloom", 0xFF, 0x00, 0x00);
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_BLOOM));
if (UserConfigParams::m_bloom)
if (isRace && UserConfigParams::m_bloom)
{
glClear(GL_STENCIL_BUFFER_BIT);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
@ -850,7 +850,7 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode)
{
PROFILER_PUSH_CPU_MARKER("- Motion blur", 0xFF, 0x00, 0x00);
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_MOTIONBLUR));
if (UserConfigParams::m_motionblur && m_any_boost && World::getWorld() != NULL) // motion blur
if (isRace && UserConfigParams::m_motionblur && m_any_boost && World::getWorld() != NULL) // motion blur
{
renderMotionBlur(0, *in_fbo, *out_fbo);
std::swap(in_fbo, out_fbo);

View File

@ -96,7 +96,7 @@ public:
void renderGlow(unsigned tex);
/** Render the post-processed scene */
FrameBuffer *render(scene::ICameraSceneNode * const camnode);
FrameBuffer *render(scene::ICameraSceneNode * const camnode, bool isRace);
/** Use motion blur for a short time */
void giveBoost(unsigned int cam_index);

View File

@ -185,7 +185,7 @@ void IrrDriver::renderGLSL(float dt)
// Render the post-processed scene
if (UserConfigParams::m_dynamic_lights)
{
FrameBuffer *fbo = m_post_processing->render(camnode);
FrameBuffer *fbo = m_post_processing->render(camnode, true);
if (irr_driver->getNormals())
irr_driver->getFBO(FBO_NORMAL_AND_DEPTHS).BlitToDefault(viewport.UpperLeftCorner.X, viewport.UpperLeftCorner.Y, viewport.LowerRightCorner.X, viewport.LowerRightCorner.Y);

View File

@ -20,7 +20,9 @@
#include "config/user_config.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/post_processing.hpp"
#include "utils/log.hpp"
#include <ISceneManager.h>
static GLuint generateRTT3D(GLenum target, size_t w, size_t h, size_t d, GLint internalFormat, GLint format, GLint type)
{
@ -290,3 +292,23 @@ RTT::~RTT()
delete m_RSM;
}
}
FrameBuffer* RTT::render(scene::ICameraSceneNode* camera, float dt)
{
irr_driver->setRTT(this);
irr_driver->getSceneManager()->setActiveCamera(camera);
std::vector<IrrDriver::GlowData> glows;
irr_driver->computeCameraMatrix(camera, 512, 512);
unsigned plc = irr_driver->UpdateLightsInfo(camera, dt);
irr_driver->renderScene(camera, plc, glows, dt, false, true);
FrameBuffer* frame_buffer = irr_driver->getPostProcessing()->render(camera, false);
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
irr_driver->setRTT(NULL);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
irr_driver->getSceneManager()->setActiveCamera(NULL);
return frame_buffer;
}

View File

@ -45,6 +45,9 @@ public:
unsigned getDepthStencilTexture() const { return DepthStencilTexture; }
unsigned getRenderTarget(enum TypeRTT target) const { return RenderTargetTextures[target]; }
FrameBuffer& getFBO(enum TypeFBO fbo) { return FrameBuffers[fbo]; }
FrameBuffer* render(scene::ICameraSceneNode* camera, float dt);
private:
unsigned RenderTargetTextures[RTT_COUNT];
PtrVector<FrameBuffer> FrameBuffers;

View File

@ -173,21 +173,9 @@ void ModelViewWidget::update(float delta)
m_rtt_main_node->setRotation(core::vector3df(0.0f, angle, 0.0f));
m_rtt_main_node->setVisible(true);
irr_driver->setRTT(m_rtt_provider);
irr_driver->getSceneManager()->setActiveCamera(m_camera);
m_frame_buffer = m_rtt_provider->render(m_camera, GUIEngine::getLatestDt());
std::vector<IrrDriver::GlowData> glows;
irr_driver->computeCameraMatrix(m_camera, 512, 512);
unsigned plc = irr_driver->UpdateLightsInfo(m_camera, GUIEngine::getLatestDt());
irr_driver->renderScene(m_camera, plc, glows, GUIEngine::getLatestDt(), false, true);
m_frame_buffer = irr_driver->getPostProcessing()->render(m_camera);
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
irr_driver->setRTT(NULL);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
irr_driver->getSceneManager()->setActiveCamera(NULL);
m_rtt_main_node->setVisible(false);
}
@ -284,10 +272,7 @@ void ModelViewWidget::setupRTTScene(PtrVector<scene::IMesh, REF>& mesh,
m_camera->setAspectRatio(1.0f);
m_camera->setPosition(core::vector3df(0.0, 20.0f, 70.0f));
if (irr_driver->isGLSL())
m_camera->setUpVector(core::vector3df(0.0, 1.0, 0.0));
else
m_camera->setUpVector(core::vector3df(0.0, 1.0, 0.0));
m_camera->setUpVector(core::vector3df(0.0, 1.0, 0.0));
m_camera->setTarget(core::vector3df(0, 10, 0.0f));
m_camera->setFOV(DEGREE_TO_RAD*50.0f);
m_camera->updateAbsolutePosition();

View File

@ -342,19 +342,27 @@ void RaceGUI::drawGlobalMiniMap()
// arenas currently don't have a map.
if(world->getTrack()->isArena() || world->getTrack()->isSoccer()) return;
const video::ITexture *mini_map = world->getTrack()->getMiniMap();
const video::ITexture *old_rtt_mini_map = world->getTrack()->getOldRttMiniMap();
const FrameBuffer* new_rtt_mini_map = world->getTrack()->getNewRttMiniMap();
int upper_y = UserConfigParams::m_height - m_map_bottom - m_map_height;
int lower_y = UserConfigParams::m_height - m_map_bottom;
if (mini_map != NULL)
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> dest(m_map_left, upper_y,
m_map_left + m_map_width, lower_y);
core::rect<s32> source(core::position2di(0, 0),
mini_map->getOriginalSize());
draw2DImage(mini_map, dest, source,
NULL, NULL, true);
old_rtt_mini_map->getOriginalSize());
draw2DImage(old_rtt_mini_map, dest, source,
NULL, NULL, true);
}
else if (new_rtt_mini_map != NULL)
{
core::rect<s32> source(0, 0, new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight());
draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], 512, 512,
dest, source, NULL, true);
}
for(unsigned int i=0; i<world->getNumKarts(); i++)

View File

@ -321,17 +321,25 @@ void RaceGUIOverworld::drawGlobalMiniMap()
}
const video::ITexture *mini_map = world->getTrack()->getMiniMap();
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;
if (mini_map != NULL)
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> dest(m_map_left, upper_y,
m_map_left + m_map_width, lower_y);
core::rect<s32> source(core::position2di(0, 0), mini_map->getOriginalSize());
draw2DImage(mini_map, dest, source, 0, 0, true);
core::rect<s32> source(core::position2di(0, 0), old_rtt_mini_map->getOriginalSize());
draw2DImage(old_rtt_mini_map, dest, source, 0, 0, true);
}
else if (new_rtt_mini_map != NULL)
{
core::rect<s32> source(0, 0, new_rtt_mini_map->getWidth(), new_rtt_mini_map->getHeight());
draw2DImageFromRTT(new_rtt_mini_map->getRTT()[0], 512, 512,
dest, source, NULL, true);
}
Vec3 kart_xyz;

View File

@ -970,20 +970,35 @@ int QuadGraph::findOutOfRoadSector(const Vec3& xyz,
//-----------------------------------------------------------------------------
/** Takes a snapshot of the driveline quads so they can be used as minimap.
*/
video::ITexture *QuadGraph::makeMiniMap(const core::dimension2du &origdimension,
const std::string &name,
const video::SColor &fill_color)
void QuadGraph::makeMiniMap(const core::dimension2du &origdimension,
const std::string &name,
const video::SColor &fill_color,
video::ITexture** oldRttMinimap,
FrameBuffer** newRttMinimap)
{
*oldRttMinimap = NULL;
*newRttMinimap = NULL;
const core::dimension2du dimension = origdimension * 2;
IrrDriver::RTTProvider rttProvider(dimension, name, true);
RTT* newRttProvider = NULL;
IrrDriver::RTTProvider* oldRttProvider = NULL;
if (irr_driver->isGLSL())
{
newRttProvider = new RTT(512, 512);
}
else
{
oldRttProvider = new IrrDriver::RTTProvider(dimension, name, true);
}
video::SColor red(128, 255, 0, 0);
createMesh(/*show_invisible part of the track*/ false,
/*enable_transparency*/ false,
/*track_color*/ &fill_color,
/*lap line color*/ &red );
m_node = irr_driver->getSceneManager()->addMeshSceneNode(m_mesh); // add Debug Mesh
m_node = irr_driver->addMesh(m_mesh);
#ifdef DEBUG
m_node->setName("minimap-mesh");
#endif
@ -1035,28 +1050,47 @@ video::ITexture *QuadGraph::makeMiniMap(const core::dimension2du &origdimension,
range,
-1, bb_max.getY()-bb_min.getY()+1);
camera->setProjectionMatrix(projection, true);
irr_driver->suppressSkyBox();
irr_driver->clearLights();
// Adjust Y position by +1 for max, -1 for min - this helps in case that
// the maximum Y coordinate is negative (otherwise the minimap is mirrored)
// and avoids problems for tracks which have a flat (max Y = min Y) minimap.
camera->setPosition(core::vector3df(center.getX(), bb_max.getY()+1, center.getZ()));
camera->setUpVector(core::vector3df(0, 0, 1));
camera->setTarget(core::vector3df(center.getX(),bb_min.getY()-1,center.getZ()));
camera->setAspectRatio(1.0f);
camera->updateAbsolutePosition();
video::ITexture *texture = rttProvider.renderToTexture();
video::ITexture* texture = NULL;
FrameBuffer* frame_buffer = NULL;
if (irr_driver->isGLSL())
{
frame_buffer = newRttProvider->render(camera, GUIEngine::getLatestDt());
// TODO: leak
//delete newRttProvider;
}
else
{
texture = oldRttProvider->renderToTexture();
delete oldRttProvider;
}
cleanupDebugMesh();
irr_driver->removeCameraSceneNode(camera);
m_min_coord = bb_min;
if (texture == NULL)
if (texture == NULL && frame_buffer == NULL)
{
Log::error("Quad Graph", "[makeMiniMap] WARNING: RTT does not appear to work,"
"mini-map will not be available.");
return NULL;
}
return texture;
*oldRttMinimap = texture;
*newRttMinimap = frame_buffer;
} // makeMiniMap
//-----------------------------------------------------------------------------

View File

@ -37,6 +37,7 @@ namespace irr
using namespace irr;
class CheckLine;
class FrameBuffer;
/**
* \brief This class stores a graph of quads. It uses a 'simplified singleton'
@ -118,10 +119,11 @@ public:
float forwards_distance=1.5f,
float sidewards_distance=1.5f,
float upwards_distance=0.0f) const;
video::ITexture *makeMiniMap(const core::dimension2du &where,
const std::string &name,
const video::SColor &fill_color
=video::SColor(127, 255, 255, 255) );
void makeMiniMap(const core::dimension2du &where,
const std::string &name,
const video::SColor &fill_color,
video::ITexture** oldRttMinimap,
FrameBuffer** newRttMinimap);
void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const;
void updateDistancesForAllSuccessors(unsigned int indx,
float delta,

View File

@ -115,7 +115,8 @@ Track::Track(const std::string &filename)
m_is_soccer = false;
m_is_cutscene = false;
m_camera_far = 1000.0f;
m_mini_map = NULL;
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);
@ -273,13 +274,13 @@ void Track::cleanup()
// Clear reminder of the link between textures and file names.
irr_driver->clearTexturesFileName();
for(unsigned int i=0; i<m_animated_textures.size(); i++)
for (unsigned int i = 0; i < m_animated_textures.size(); i++)
{
delete m_animated_textures[i];
}
m_animated_textures.clear();
for(unsigned int i=0; i<m_all_nodes.size(); i++)
for (unsigned int i = 0; i < m_all_nodes.size(); i++)
{
irr_driver->removeNode(m_all_nodes[i]);
}
@ -310,37 +311,42 @@ void Track::cleanup()
// than once are in m_all_cached_mesh more than once (which is easier
// than storing the mesh only once, but then having to test for each
// mesh if it is already contained in the list or not).
for(unsigned int i=0; i<m_all_cached_meshes.size(); i++)
for (unsigned int i = 0; i < m_all_cached_meshes.size(); i++)
{
irr_driver->dropAllTextures(m_all_cached_meshes[i]);
// If a mesh is not in Irrlicht's texture cache, its refcount is
// 1 (since its scene node was removed, so the only other reference
// is in m_all_cached_meshes). In this case we only drop it once
// and don't try to remove it from the cache.
if(m_all_cached_meshes[i]->getReferenceCount()==1)
if (m_all_cached_meshes[i]->getReferenceCount() == 1)
{
m_all_cached_meshes[i]->drop();
continue;
}
m_all_cached_meshes[i]->drop();
if(m_all_cached_meshes[i]->getReferenceCount()==1)
if (m_all_cached_meshes[i]->getReferenceCount() == 1)
irr_driver->removeMeshFromCache(m_all_cached_meshes[i]);
}
m_all_cached_meshes.clear();
// Now free meshes that are not associated to any scene node.
for (unsigned int i=0; i<m_detached_cached_meshes.size(); i++)
for (unsigned int i = 0; i < m_detached_cached_meshes.size(); i++)
{
irr_driver->dropAllTextures(m_detached_cached_meshes[i]);
irr_driver->removeMeshFromCache(m_detached_cached_meshes[i]);
}
m_detached_cached_meshes.clear();
if(m_mini_map)
if (m_old_rtt_mini_map)
{
assert(m_mini_map->getReferenceCount()==1);
irr_driver->removeTexture(m_mini_map);
m_mini_map = NULL;
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)
{
delete m_new_rtt_mini_map;
m_new_rtt_mini_map = NULL;
}
for(unsigned int i=0; i<m_sky_textures.size(); i++)
@ -637,11 +643,18 @@ void Track::loadQuadGraph(unsigned int mode_id, const bool reverse)
m_mini_map_size = World::getWorld()->getRaceGUI()->getMiniMapSize();
core::dimension2du size = m_mini_map_size
.getOptimalSize(!nonpower,!nonsquare);
m_mini_map = QuadGraph::get()->makeMiniMap(size, "minimap::"+m_ident);
if (m_mini_map)
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_mini_map->getSize().Width);
m_minimap_y_scale = float(m_mini_map_size.Height) / float(m_mini_map->getSize().Height);
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());
}
else
{

View File

@ -371,7 +371,8 @@ private:
video::SColor m_fog_color;
/** The texture for the mini map, which is displayed in the race gui. */
video::ITexture *m_mini_map;
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;
@ -448,7 +449,8 @@ public:
std::vector< std::vector<float> > buildHeightMap();
// ------------------------------------------------------------------------
/** Returns the texture with the mini map for this track. */
const video::ITexture* getMiniMap () const { return m_mini_map; }
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; }
// ------------------------------------------------------------------------