mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
post-processing test
This commit is contained in:
parent
e7af5830cf
commit
8ed65ca51e
13 changed files with 268 additions and 113 deletions
42
src/graphics/PostProcessing.cpp
Normal file
42
src/graphics/PostProcessing.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "PostProcessing.h"
|
||||
#include "Mesh.h"
|
||||
#include "Shader.h"
|
||||
#include "Texture.h"
|
||||
#include "Framebuffer.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
PostProcessing::PostProcessing() {
|
||||
// Fullscreen quad mesh bulding
|
||||
float vertices[] {
|
||||
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
|
||||
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f
|
||||
};
|
||||
vattr attrs[] {{2}, {0}};
|
||||
quadMesh = std::make_unique<Mesh>(vertices, 6, attrs);
|
||||
}
|
||||
|
||||
PostProcessing::~PostProcessing() {
|
||||
}
|
||||
|
||||
void PostProcessing::use(GfxContext& context) {
|
||||
const auto& vp = context.getViewport();
|
||||
if (fbo) {
|
||||
fbo->resize(vp.getWidth(), vp.getHeight());
|
||||
} else {
|
||||
fbo = std::make_unique<Framebuffer>(vp.getWidth(), vp.getHeight());
|
||||
}
|
||||
context.setFramebuffer(fbo.get());
|
||||
}
|
||||
|
||||
void PostProcessing::render(GfxContext& context, Shader* screenShader) {
|
||||
if (fbo == nullptr) {
|
||||
throw std::runtime_error("'use(...)' was never called");
|
||||
}
|
||||
|
||||
const auto& viewport = context.getViewport();
|
||||
screenShader->use();
|
||||
screenShader->uniform2i("u_screenSize", viewport.size());
|
||||
fbo->getTexture()->bind();
|
||||
quadMesh->draw();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue