Implement simple overlay effect that fills a texture over a render target
This commit is contained in:
parent
dd520c4cae
commit
4915b171c7
2 changed files with 97 additions and 0 deletions
22
libs/gfx/include/psemek/gfx/effect/overlay.hpp
Normal file
22
libs/gfx/include/psemek/gfx/effect/overlay.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/gfx/texture.hpp>
|
||||
#include <psemek/gfx/render_target.hpp>
|
||||
|
||||
#include <psemek/util/pimpl.hpp>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
||||
struct overlay
|
||||
{
|
||||
overlay();
|
||||
~overlay();
|
||||
|
||||
void invoke(texture_2d const & src, render_target const & dst);
|
||||
|
||||
private:
|
||||
psemek_declare_pimpl
|
||||
};
|
||||
|
||||
}
|
||||
75
libs/gfx/source/effect/overlay.cpp
Normal file
75
libs/gfx/source/effect/overlay.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
#include <psemek/gfx/effect/overlay.hpp>
|
||||
#include <psemek/gfx/program.hpp>
|
||||
#include <psemek/gfx/array.hpp>
|
||||
|
||||
#include <psemek/util/pimpl.hpp>
|
||||
|
||||
namespace psemek::gfx
|
||||
{
|
||||
|
||||
static char const overlay_vs[] =
|
||||
R"(#version 330
|
||||
|
||||
const vec4 vertices[6] = vec4[6](
|
||||
vec4(-1.0, -1.0, 0.0, 1.0),
|
||||
vec4( 1.0, -1.0, 0.0, 1.0),
|
||||
vec4( 1.0, 1.0, 0.0, 1.0),
|
||||
|
||||
vec4(-1.0, -1.0, 0.0, 1.0),
|
||||
vec4( 1.0, 1.0, 0.0, 1.0),
|
||||
vec4(-1.0, 1.0, 0.0, 1.0)
|
||||
);
|
||||
|
||||
out vec2 texcoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vertices[gl_VertexID];
|
||||
texcoord = vertices[gl_VertexID].xy * 0.5 + vec2(0.5);
|
||||
}
|
||||
)";
|
||||
|
||||
static char const overlay_fs[] =
|
||||
R"(#version 330
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
in vec2 texcoord;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
out_color = texture(u_texture, texcoord);
|
||||
}
|
||||
)";
|
||||
|
||||
struct overlay::impl
|
||||
{
|
||||
gfx::program program{overlay_vs, overlay_fs};
|
||||
gfx::array array;
|
||||
};
|
||||
|
||||
overlay::overlay()
|
||||
: pimpl_{std::make_unique<struct impl>()}
|
||||
{
|
||||
impl().program.bind();
|
||||
impl().program["u_texture"] = 0;
|
||||
}
|
||||
|
||||
overlay::~overlay() = default;
|
||||
|
||||
void overlay::invoke(texture_2d const & src, render_target const & dst)
|
||||
{
|
||||
gl::Disable(gl::DEPTH_TEST);
|
||||
gl::Disable(gl::CULL_FACE);
|
||||
|
||||
dst.bind();
|
||||
gl::ActiveTexture(gl::TEXTURE0);
|
||||
src.bind();
|
||||
impl().array.bind();
|
||||
impl().program.bind();
|
||||
gl::DrawArrays(gl::TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue