Try to make RTT creation as close to master as possible
This commit is contained in:
parent
7998c326fc
commit
07ebb760ac
@ -1421,19 +1421,10 @@ void PostProcessing::renderLightning(core::vector3df intensity)
|
|||||||
/** Render the post-processed scene */
|
/** Render the post-processed scene */
|
||||||
FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
|
FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
|
||||||
bool isRace,
|
bool isRace,
|
||||||
RTT *rtts,
|
RTT *rtts)
|
||||||
GL3RenderTarget *specified_render_target)
|
|
||||||
{
|
{
|
||||||
FrameBuffer *in_fbo = &rtts->getFBO(FBO_COLORS);
|
FrameBuffer *in_fbo = &rtts->getFBO(FBO_COLORS);
|
||||||
FrameBuffer *out_fbo;
|
FrameBuffer *out_fbo = &rtts->getFBO(FBO_TMP1_WITH_DS);
|
||||||
|
|
||||||
// Workaround a bug with srgb fbo on sandy bridge windows
|
|
||||||
if ((GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_WORKING))
|
|
||||||
&&(specified_render_target != NULL))
|
|
||||||
out_fbo = specified_render_target->getFrameBuffer();
|
|
||||||
else
|
|
||||||
out_fbo = &rtts->getFBO(FBO_TMP1_WITH_DS);
|
|
||||||
|
|
||||||
// Each effect uses these as named, and sets them up for the next effect.
|
// Each effect uses these as named, and sets them up for the next effect.
|
||||||
// This allows chaining effects where some may be disabled.
|
// This allows chaining effects where some may be disabled.
|
||||||
|
|
||||||
@ -1587,16 +1578,11 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
|
|||||||
return in_fbo;
|
return in_fbo;
|
||||||
|
|
||||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||||
if(specified_render_target == NULL)
|
out_fbo = &rtts->getFBO(FBO_MLAA_COLORS);
|
||||||
out_fbo = &rtts->getFBO(FBO_MLAA_COLORS);
|
|
||||||
else
|
|
||||||
out_fbo = specified_render_target->getFrameBuffer();
|
|
||||||
|
|
||||||
out_fbo->bind();
|
out_fbo->bind();
|
||||||
renderPassThrough(in_fbo->getRTT()[0],
|
renderPassThrough(in_fbo->getRTT()[0],
|
||||||
out_fbo->getWidth(),
|
out_fbo->getWidth(),
|
||||||
out_fbo->getHeight());
|
out_fbo->getHeight());
|
||||||
|
|
||||||
|
|
||||||
if (UserConfigParams::m_mlaa) // MLAA. Must be the last pp filter.
|
if (UserConfigParams::m_mlaa) // MLAA. Must be the last pp filter.
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "graphics/camera.hpp"
|
#include "graphics/camera.hpp"
|
||||||
#include "graphics/glwrap.hpp"
|
#include "graphics/glwrap.hpp"
|
||||||
|
|
||||||
class GL3RenderTarget;
|
|
||||||
class RTT;
|
class RTT;
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -124,7 +123,7 @@ public:
|
|||||||
|
|
||||||
/** Render the post-processed scene */
|
/** Render the post-processed scene */
|
||||||
FrameBuffer *render(scene::ICameraSceneNode * const camnode, bool isRace,
|
FrameBuffer *render(scene::ICameraSceneNode * const camnode, bool isRace,
|
||||||
RTT *rtts, GL3RenderTarget *specified_render_target = NULL);
|
RTT *rtts);
|
||||||
}; // class PostProcessing
|
}; // class PostProcessing
|
||||||
|
|
||||||
#endif // HEADER_POST_PROCESSING_HPP
|
#endif // HEADER_POST_PROCESSING_HPP
|
||||||
|
@ -15,10 +15,12 @@
|
|||||||
// along with this program; if not, write to the Free Software
|
// along with this program; if not, write to the Free Software
|
||||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "graphics/2dutils.hpp"
|
|
||||||
#include "graphics/render_target.hpp"
|
#include "graphics/render_target.hpp"
|
||||||
|
|
||||||
|
#include "graphics/2dutils.hpp"
|
||||||
#include "graphics/central_settings.hpp"
|
#include "graphics/central_settings.hpp"
|
||||||
#include "graphics/graphics_restrictions.hpp"
|
#include "graphics/graphics_restrictions.hpp"
|
||||||
|
#include "graphics/rtts.hpp"
|
||||||
#include "graphics/shader_based_renderer.hpp"
|
#include "graphics/shader_based_renderer.hpp"
|
||||||
|
|
||||||
|
|
||||||
@ -100,53 +102,35 @@ void GL1RenderTarget::draw2DImage(const irr::core::rect<s32>& dest_rect,
|
|||||||
GL3RenderTarget::GL3RenderTarget(const irr::core::dimension2du &dimension,
|
GL3RenderTarget::GL3RenderTarget(const irr::core::dimension2du &dimension,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
ShaderBasedRenderer *renderer)
|
ShaderBasedRenderer *renderer)
|
||||||
|
: m_renderer(renderer), m_name(name)
|
||||||
{
|
{
|
||||||
m_renderer = renderer;
|
m_rtts = m_renderer->createRTT(dimension.Width, dimension.Height);
|
||||||
|
m_frame_buffer = NULL;
|
||||||
glGenTextures(1, &m_texture_id);
|
} // GL3RenderTarget
|
||||||
glBindTexture(GL_TEXTURE_2D, m_texture_id);
|
|
||||||
|
|
||||||
// Workaround a bug with srgb fbo on sandy bridge windows
|
|
||||||
if (GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_WORKING))
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, dimension.Width, dimension.Height, 0, GL_BGRA, GL_FLOAT, 0);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (CVS->isARBTextureStorageUsable())
|
|
||||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, dimension.Width, dimension.Height);
|
|
||||||
else
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, dimension.Width, dimension.Height, 0, GL_BGR, GL_UNSIGNED_BYTE, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<GLuint> somevector;
|
|
||||||
somevector.push_back(m_texture_id);
|
|
||||||
m_frame_buffer = new FrameBuffer(somevector, dimension.Width, dimension.Height);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
GL3RenderTarget::~GL3RenderTarget()
|
GL3RenderTarget::~GL3RenderTarget()
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &m_texture_id);
|
delete m_rtts;
|
||||||
delete m_frame_buffer;
|
} // ~GL3RenderTarget
|
||||||
}
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void GL3RenderTarget::renderToTexture(irr::scene::ICameraSceneNode* camera,
|
||||||
|
float dt)
|
||||||
|
{
|
||||||
|
m_frame_buffer = NULL;
|
||||||
|
m_renderer->setRTT(m_rtts);
|
||||||
|
m_renderer->renderToTexture(this, camera, dt);
|
||||||
|
|
||||||
|
} // renderToTexture
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
irr::core::dimension2du GL3RenderTarget::getTextureSize() const
|
irr::core::dimension2du GL3RenderTarget::getTextureSize() const
|
||||||
{
|
{
|
||||||
return irr::core::dimension2du(m_frame_buffer->getWidth(),
|
return irr::core::dimension2du(m_frame_buffer->getWidth(),
|
||||||
m_frame_buffer->getHeight());
|
m_frame_buffer->getHeight());
|
||||||
}
|
} // getTextureSize
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
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,
|
void GL3RenderTarget::draw2DImage(const irr::core::rect<s32>& dest_rect,
|
||||||
@ -154,12 +138,14 @@ void GL3RenderTarget::draw2DImage(const irr::core::rect<s32>& dest_rect,
|
|||||||
const irr::video::SColor &colors,
|
const irr::video::SColor &colors,
|
||||||
bool use_alpha_channel_of_texture) const
|
bool use_alpha_channel_of_texture) const
|
||||||
{
|
{
|
||||||
|
assert(m_frame_buffer != NULL);
|
||||||
irr::core::rect<s32> source_rect(0, 0, m_frame_buffer->getWidth(),
|
irr::core::rect<s32> source_rect(0, 0, m_frame_buffer->getWidth(),
|
||||||
m_frame_buffer->getHeight());
|
m_frame_buffer->getHeight());
|
||||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
glEnable(GL_FRAMEBUFFER_SRGB);
|
||||||
draw2DImageFromRTT(m_texture_id,
|
draw2DImageFromRTT(m_frame_buffer->getRTT()[0],
|
||||||
m_frame_buffer->getWidth(), m_frame_buffer->getHeight(),
|
m_frame_buffer->getWidth(), m_frame_buffer->getHeight(),
|
||||||
dest_rect, source_rect,
|
dest_rect, source_rect,
|
||||||
clip_rect, colors, use_alpha_channel_of_texture);
|
clip_rect, colors, use_alpha_channel_of_texture);
|
||||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||||
}
|
|
||||||
|
} // draw2DImage
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class ShaderBasedRenderer;
|
class ShaderBasedRenderer;
|
||||||
|
class RTT;
|
||||||
|
|
||||||
class RenderTarget
|
class RenderTarget
|
||||||
{
|
{
|
||||||
@ -67,25 +68,24 @@ public:
|
|||||||
class GL3RenderTarget: public RenderTarget
|
class GL3RenderTarget: public RenderTarget
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
ShaderBasedRenderer *m_renderer;
|
ShaderBasedRenderer* m_renderer;
|
||||||
FrameBuffer *m_frame_buffer;
|
std::string m_name;
|
||||||
GLuint m_texture_id;
|
RTT* m_rtts;
|
||||||
|
FrameBuffer* m_frame_buffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GL3RenderTarget(const irr::core::dimension2du &dimension,
|
GL3RenderTarget(const irr::core::dimension2du &dimension,
|
||||||
const std::string &name,
|
const std::string &name,
|
||||||
ShaderBasedRenderer *renderer);
|
ShaderBasedRenderer *renderer);
|
||||||
~GL3RenderTarget();
|
~GL3RenderTarget();
|
||||||
|
|
||||||
irr::core::dimension2du getTextureSize() const;
|
|
||||||
FrameBuffer* getFrameBuffer();
|
|
||||||
|
|
||||||
void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt);
|
|
||||||
void draw2DImage(const irr::core::rect<s32>& dest_rect,
|
void draw2DImage(const irr::core::rect<s32>& dest_rect,
|
||||||
const irr::core::rect<s32>* clip_rect,
|
const irr::core::rect<s32>* clip_rect,
|
||||||
const irr::video::SColor &colors,
|
const irr::video::SColor &colors,
|
||||||
bool use_alpha_channel_of_texture) const;
|
bool use_alpha_channel_of_texture) const;
|
||||||
|
irr::core::dimension2du getTextureSize() const;
|
||||||
|
void renderToTexture(irr::scene::ICameraSceneNode* camera, float dt);
|
||||||
|
void setFrameBuffer(FrameBuffer* fb) { m_frame_buffer = fb; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,36 +45,18 @@
|
|||||||
extern std::vector<float> BoundingBoxes; //TODO: replace global variable by something cleaner
|
extern std::vector<float> BoundingBoxes; //TODO: replace global variable by something cleaner
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void ShaderBasedRenderer::setRTTDimensions(size_t width, size_t height)
|
RTT* ShaderBasedRenderer::createRTT(size_t width, size_t height)
|
||||||
{
|
{
|
||||||
if(m_rtts == NULL)
|
RTT* rtts = new RTT(width, height);
|
||||||
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);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//same dimensions; we don't need to create a new RTT
|
|
||||||
//just clear FBO_COMBINED_DIFFUSE_SPECULAR
|
|
||||||
m_rtts->getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).bind();
|
|
||||||
glClearColor(.5, .5, .5, .5);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<GLuint> prefilled_textures =
|
std::vector<GLuint> prefilled_textures =
|
||||||
createVector<GLuint>(m_rtts->getRenderTarget(RTT_DIFFUSE),
|
createVector<GLuint>(rtts->getRenderTarget(RTT_DIFFUSE),
|
||||||
m_rtts->getRenderTarget(RTT_SPECULAR),
|
rtts->getRenderTarget(RTT_SPECULAR),
|
||||||
m_rtts->getRenderTarget(RTT_HALF1_R),
|
rtts->getRenderTarget(RTT_HALF1_R),
|
||||||
m_rtts->getDepthStencilTexture());
|
rtts->getDepthStencilTexture());
|
||||||
m_geometry_passes->setFirstPassRenderTargets(prefilled_textures);
|
m_geometry_passes->setFirstPassRenderTargets(prefilled_textures);
|
||||||
} //setRTTDimensions
|
return rtts;
|
||||||
|
|
||||||
|
} //createRTT
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
void ShaderBasedRenderer::compressPowerUpTextures()
|
void ShaderBasedRenderer::compressPowerUpTextures()
|
||||||
@ -419,7 +401,7 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
m_geometry_passes->renderSolidSecondPass(m_draw_calls);
|
m_geometry_passes->renderSolidSecondPass(m_draw_calls);
|
||||||
@ -711,8 +693,9 @@ void ShaderBasedRenderer::onLoadWorld()
|
|||||||
const core::recti &viewport = Camera::getCamera(0)->getViewport();
|
const core::recti &viewport = Camera::getCamera(0)->getViewport();
|
||||||
size_t width = viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X;
|
size_t width = viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X;
|
||||||
size_t height = viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y;
|
size_t height = viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y;
|
||||||
setRTTDimensions(width, height);
|
RTT* rtts = createRTT(width, height);
|
||||||
|
setRTT(rtts);
|
||||||
|
|
||||||
compressPowerUpTextures();
|
compressPowerUpTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -960,29 +943,26 @@ void ShaderBasedRenderer::renderToTexture(GL3RenderTarget *render_target,
|
|||||||
{
|
{
|
||||||
resetObjectCount();
|
resetObjectCount();
|
||||||
resetPolyCount();
|
resetPolyCount();
|
||||||
|
assert(m_rtts != NULL);
|
||||||
irr::core::dimension2du texture_size = render_target->getTextureSize();
|
|
||||||
|
|
||||||
size_t width = texture_size.Width ;
|
|
||||||
size_t height = texture_size.Height;
|
|
||||||
|
|
||||||
setRTTDimensions(width, height);
|
|
||||||
|
|
||||||
irr_driver->getSceneManager()->setActiveCamera(camera);
|
irr_driver->getSceneManager()->setActiveCamera(camera);
|
||||||
|
|
||||||
computeMatrixesAndCameras(camera, width, height);
|
computeMatrixesAndCameras(camera, m_rtts->getWidth(), m_rtts->getHeight());
|
||||||
updateLightsInfo(camera, dt);
|
updateLightsInfo(camera, dt);
|
||||||
if(CVS->isARBUniformBufferObjectUsable())
|
if (CVS->isARBUniformBufferObjectUsable())
|
||||||
uploadLightingData();
|
uploadLightingData();
|
||||||
|
|
||||||
renderScene(camera, dt, false, true);
|
renderScene(camera, dt, false, true);
|
||||||
m_post_processing->render(camera, false, m_rtts, render_target);
|
render_target->setFrameBuffer(m_post_processing
|
||||||
|
->render(camera, false, m_rtts));
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
glViewport(0, 0,
|
glViewport(0, 0,
|
||||||
irr_driver->getActualScreenSize().Width,
|
irr_driver->getActualScreenSize().Width,
|
||||||
irr_driver->getActualScreenSize().Height);
|
irr_driver->getActualScreenSize().Height);
|
||||||
|
m_rtts = NULL;
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
irr_driver->getSceneManager()->setActiveCamera(NULL);
|
irr_driver->getSceneManager()->setActiveCamera(NULL);
|
||||||
|
|
||||||
} //renderToTexture
|
} //renderToTexture
|
||||||
|
@ -50,9 +50,7 @@ private:
|
|||||||
* Glowing items can appear ordisappear each frame */
|
* Glowing items can appear ordisappear each frame */
|
||||||
std::vector<GlowData> m_glowing;
|
std::vector<GlowData> m_glowing;
|
||||||
size_t m_nb_static_glowing;
|
size_t m_nb_static_glowing;
|
||||||
|
|
||||||
void setRTTDimensions(size_t width, size_t height);
|
|
||||||
|
|
||||||
void compressPowerUpTextures();
|
void compressPowerUpTextures();
|
||||||
void setOverrideMaterial();
|
void setOverrideMaterial();
|
||||||
|
|
||||||
@ -123,7 +121,15 @@ public:
|
|||||||
void renderToTexture(GL3RenderTarget *render_target,
|
void renderToTexture(GL3RenderTarget *render_target,
|
||||||
irr::scene::ICameraSceneNode* camera,
|
irr::scene::ICameraSceneNode* camera,
|
||||||
float dt);
|
float dt);
|
||||||
|
|
||||||
|
RTT* createRTT(size_t width, size_t height);
|
||||||
|
|
||||||
|
void setRTT(RTT* rtts)
|
||||||
|
{
|
||||||
|
assert(m_rtts == NULL);
|
||||||
|
m_rtts = rtts;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //HEADER_SHADER_BASED_RENDERER_HPP
|
#endif //HEADER_SHADER_BASED_RENDERER_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user