Try to make RTT creation as close to master as possible

This commit is contained in:
Benau 2016-10-31 00:33:06 +08:00
parent 7998c326fc
commit 07ebb760ac
6 changed files with 74 additions and 117 deletions

View File

@ -1421,19 +1421,10 @@ void PostProcessing::renderLightning(core::vector3df intensity)
/** Render the post-processed scene */
FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
bool isRace,
RTT *rtts,
GL3RenderTarget *specified_render_target)
RTT *rtts)
{
FrameBuffer *in_fbo = &rtts->getFBO(FBO_COLORS);
FrameBuffer *out_fbo;
// 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);
FrameBuffer *out_fbo = &rtts->getFBO(FBO_TMP1_WITH_DS);
// Each effect uses these as named, and sets them up for the next effect.
// This allows chaining effects where some may be disabled.
@ -1587,16 +1578,11 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
return in_fbo;
glEnable(GL_FRAMEBUFFER_SRGB);
if(specified_render_target == NULL)
out_fbo = &rtts->getFBO(FBO_MLAA_COLORS);
else
out_fbo = specified_render_target->getFrameBuffer();
out_fbo = &rtts->getFBO(FBO_MLAA_COLORS);
out_fbo->bind();
renderPassThrough(in_fbo->getRTT()[0],
out_fbo->getWidth(),
out_fbo->getHeight());
if (UserConfigParams::m_mlaa) // MLAA. Must be the last pp filter.
{

View File

@ -24,7 +24,6 @@
#include "graphics/camera.hpp"
#include "graphics/glwrap.hpp"
class GL3RenderTarget;
class RTT;
#include <vector>
@ -124,7 +123,7 @@ public:
/** Render the post-processed scene */
FrameBuffer *render(scene::ICameraSceneNode * const camnode, bool isRace,
RTT *rtts, GL3RenderTarget *specified_render_target = NULL);
RTT *rtts);
}; // class PostProcessing
#endif // HEADER_POST_PROCESSING_HPP

View File

@ -15,10 +15,12 @@
// 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/2dutils.hpp"
#include "graphics/render_target.hpp"
#include "graphics/2dutils.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/graphics_restrictions.hpp"
#include "graphics/rtts.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,
const std::string &name,
ShaderBasedRenderer *renderer)
: m_renderer(renderer), m_name(name)
{
m_renderer = renderer;
glGenTextures(1, &m_texture_id);
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);
}
m_rtts = m_renderer->createRTT(dimension.Width, dimension.Height);
m_frame_buffer = NULL;
} // GL3RenderTarget
//-----------------------------------------------------------------------------
GL3RenderTarget::~GL3RenderTarget()
{
glDeleteTextures(1, &m_texture_id);
delete m_frame_buffer;
}
delete m_rtts;
} // ~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
{
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);
}
} // getTextureSize
//-----------------------------------------------------------------------------
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,
bool use_alpha_channel_of_texture) const
{
assert(m_frame_buffer != NULL);
irr::core::rect<s32> source_rect(0, 0, m_frame_buffer->getWidth(),
m_frame_buffer->getHeight());
glEnable(GL_FRAMEBUFFER_SRGB);
draw2DImageFromRTT(m_texture_id,
draw2DImageFromRTT(m_frame_buffer->getRTT()[0],
m_frame_buffer->getWidth(), m_frame_buffer->getHeight(),
dest_rect, source_rect,
clip_rect, colors, use_alpha_channel_of_texture);
glDisable(GL_FRAMEBUFFER_SRGB);
}
} // draw2DImage

View File

@ -23,6 +23,7 @@
#include <string>
class ShaderBasedRenderer;
class RTT;
class RenderTarget
{
@ -67,25 +68,24 @@ public:
class GL3RenderTarget: public RenderTarget
{
private:
ShaderBasedRenderer *m_renderer;
FrameBuffer *m_frame_buffer;
GLuint m_texture_id;
ShaderBasedRenderer* m_renderer;
std::string m_name;
RTT* m_rtts;
FrameBuffer* m_frame_buffer;
public:
GL3RenderTarget(const irr::core::dimension2du &dimension,
const std::string &name,
ShaderBasedRenderer *renderer);
~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,
const irr::core::rect<s32>* clip_rect,
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

View File

@ -45,36 +45,18 @@
extern std::vector<float> BoundingBoxes; //TODO: replace global variable by something cleaner
// ----------------------------------------------------------------------------
void ShaderBasedRenderer::setRTTDimensions(size_t width, size_t height)
{
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);
}
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;
}
}
RTT* ShaderBasedRenderer::createRTT(size_t width, size_t height)
{
RTT* rtts = new RTT(width, height);
std::vector<GLuint> prefilled_textures =
createVector<GLuint>(m_rtts->getRenderTarget(RTT_DIFFUSE),
m_rtts->getRenderTarget(RTT_SPECULAR),
m_rtts->getRenderTarget(RTT_HALF1_R),
m_rtts->getDepthStencilTexture());
m_geometry_passes->setFirstPassRenderTargets(prefilled_textures);
} //setRTTDimensions
createVector<GLuint>(rtts->getRenderTarget(RTT_DIFFUSE),
rtts->getRenderTarget(RTT_SPECULAR),
rtts->getRenderTarget(RTT_HALF1_R),
rtts->getDepthStencilTexture());
m_geometry_passes->setFirstPassRenderTargets(prefilled_textures);
return rtts;
} //createRTT
// ----------------------------------------------------------------------------
void ShaderBasedRenderer::compressPowerUpTextures()
@ -419,7 +401,7 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode,
glClear(GL_COLOR_BUFFER_BIT);
glDepthMask(GL_FALSE);
}
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
m_geometry_passes->renderSolidSecondPass(m_draw_calls);
@ -711,8 +693,9 @@ 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;
setRTTDimensions(width, height);
RTT* rtts = createRTT(width, height);
setRTT(rtts);
compressPowerUpTextures();
}
@ -960,29 +943,26 @@ void ShaderBasedRenderer::renderToTexture(GL3RenderTarget *render_target,
{
resetObjectCount();
resetPolyCount();
irr::core::dimension2du texture_size = render_target->getTextureSize();
size_t width = texture_size.Width ;
size_t height = texture_size.Height;
setRTTDimensions(width, height);
assert(m_rtts != NULL);
irr_driver->getSceneManager()->setActiveCamera(camera);
computeMatrixesAndCameras(camera, width, height);
computeMatrixesAndCameras(camera, m_rtts->getWidth(), m_rtts->getHeight());
updateLightsInfo(camera, dt);
if(CVS->isARBUniformBufferObjectUsable())
if (CVS->isARBUniformBufferObjectUsable())
uploadLightingData();
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
glViewport(0, 0,
irr_driver->getActualScreenSize().Width,
irr_driver->getActualScreenSize().Height);
m_rtts = NULL;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
irr_driver->getSceneManager()->setActiveCamera(NULL);
} //renderToTexture

View File

@ -50,9 +50,7 @@ private:
* Glowing items can appear ordisappear each frame */
std::vector<GlowData> m_glowing;
size_t m_nb_static_glowing;
void setRTTDimensions(size_t width, size_t height);
void compressPowerUpTextures();
void setOverrideMaterial();
@ -123,7 +121,15 @@ public:
void renderToTexture(GL3RenderTarget *render_target,
irr::scene::ICameraSceneNode* camera,
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