Use render_target in deferred renderer
This commit is contained in:
parent
0206ebc2cb
commit
cc1cb13487
2 changed files with 8 additions and 16 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
#include <psemek/gfx/mesh.hpp>
|
#include <psemek/gfx/mesh.hpp>
|
||||||
#include <psemek/gfx/texture.hpp>
|
#include <psemek/gfx/texture.hpp>
|
||||||
#include <psemek/gfx/framebuffer.hpp>
|
#include <psemek/gfx/framebuffer.hpp>
|
||||||
|
#include <psemek/gfx/render_target.hpp>
|
||||||
|
|
||||||
#include <psemek/geom/camera.hpp>
|
#include <psemek/geom/camera.hpp>
|
||||||
#include <psemek/geom/box.hpp>
|
#include <psemek/geom/box.hpp>
|
||||||
|
|
@ -75,9 +76,6 @@ namespace psemek::gfx
|
||||||
|
|
||||||
struct options
|
struct options
|
||||||
{
|
{
|
||||||
gfx::framebuffer const * framebuffer;
|
|
||||||
GLenum draw_buffer;
|
|
||||||
geom::box<int, 2> viewport;
|
|
||||||
geom::camera const * camera;
|
geom::camera const * camera;
|
||||||
|
|
||||||
std::optional<color_4f> clear_color;
|
std::optional<color_4f> clear_color;
|
||||||
|
|
@ -91,7 +89,7 @@ namespace psemek::gfx
|
||||||
std::optional<float> min_intensity;
|
std::optional<float> min_intensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
void render(std::vector<object> const & objects, options const & opts);
|
void render(std::vector<object> const & objects, render_target const & target, options const & opts);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
psemek_declare_pimpl
|
psemek_declare_pimpl
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,7 @@ void main()
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deferred_renderer::render(std::vector<object> const & objects, options const & opts)
|
void deferred_renderer::render(std::vector<object> const & objects, render_target const & target, options const & opts)
|
||||||
{
|
{
|
||||||
// Get camera info
|
// Get camera info
|
||||||
|
|
||||||
|
|
@ -437,7 +437,7 @@ void main()
|
||||||
|
|
||||||
// Resize g-buffer if needed
|
// Resize g-buffer if needed
|
||||||
|
|
||||||
auto buffer_size = geom::cast<std::size_t>(opts.viewport.dimensions());
|
auto buffer_size = geom::cast<std::size_t>(target.viewport.dimensions());
|
||||||
if (!impl().g_buffer_size || *impl().g_buffer_size != buffer_size)
|
if (!impl().g_buffer_size || *impl().g_buffer_size != buffer_size)
|
||||||
{
|
{
|
||||||
// TODO: compact normals storage
|
// TODO: compact normals storage
|
||||||
|
|
@ -466,11 +466,10 @@ void main()
|
||||||
|
|
||||||
impl().g_framebuffer.bind();
|
impl().g_framebuffer.bind();
|
||||||
|
|
||||||
gl::Viewport(0, 0, opts.viewport[0].length(), opts.viewport[1].length());
|
gl::Viewport(0, 0, target.viewport[0].length(), target.viewport[1].length());
|
||||||
|
|
||||||
GLenum draw_buffers[4] { gl::COLOR_ATTACHMENT0, gl::COLOR_ATTACHMENT1, gl::COLOR_ATTACHMENT2, gl::COLOR_ATTACHMENT3 };
|
GLenum g_draw_buffers[4] { gl::COLOR_ATTACHMENT0, gl::COLOR_ATTACHMENT1, gl::COLOR_ATTACHMENT2, gl::COLOR_ATTACHMENT3 };
|
||||||
gl::DrawBuffers(4, draw_buffers);
|
gl::DrawBuffers(4, g_draw_buffers);
|
||||||
check_error();
|
|
||||||
float buffer_1_clear[4] { 0.f, 0.f, 0.f, 0.f };
|
float buffer_1_clear[4] { 0.f, 0.f, 0.f, 0.f };
|
||||||
if (opts.clear_color)
|
if (opts.clear_color)
|
||||||
{
|
{
|
||||||
|
|
@ -533,12 +532,7 @@ void main()
|
||||||
|
|
||||||
// Setup destination framebuffer
|
// Setup destination framebuffer
|
||||||
|
|
||||||
assert(opts.framebuffer);
|
target.bind();
|
||||||
opts.framebuffer->bind();
|
|
||||||
|
|
||||||
gl::DrawBuffer(opts.draw_buffer);
|
|
||||||
|
|
||||||
gl::Viewport(opts.viewport[0].min, opts.viewport[1].min, opts.viewport[0].length(), opts.viewport[1].length());
|
|
||||||
|
|
||||||
gl::Disable(gl::DEPTH_TEST);
|
gl::Disable(gl::DEPTH_TEST);
|
||||||
gl::Disable(gl::BLEND);
|
gl::Disable(gl::BLEND);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue