openspades/Sources/Draw/GLNonlinearizeFilter.cpp

74 lines
2.1 KiB
C++
Raw Normal View History

2014-04-08 03:36:07 +09:00
/*
Copyright (c) 2013 yvt
2014-04-08 03:36:07 +09:00
This file is part of OpenSpades.
2014-04-08 03:36:07 +09:00
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2014-04-08 03:36:07 +09:00
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2014-04-08 03:36:07 +09:00
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
2014-04-08 03:36:07 +09:00
*/
#include <vector>
2014-04-08 03:36:07 +09:00
#include <Core/Debug.h>
#include <Core/Math.h>
#include "GLNonlinearizeFilter.h"
2014-04-08 03:36:07 +09:00
#include "GLProgram.h"
#include "GLProgramAttribute.h"
#include "GLProgramUniform.h"
#include "GLQuadRenderer.h"
2014-04-08 03:36:07 +09:00
#include "GLRenderer.h"
#include "IGLDevice.h"
2014-04-08 03:36:07 +09:00
#include <Core/Settings.h>
namespace spades {
namespace draw {
GLNonlinearlizeFilter::GLNonlinearlizeFilter(GLRenderer *renderer) : renderer(renderer) {
2014-04-08 03:36:07 +09:00
lens = renderer->RegisterProgram("Shaders/PostFilters/Nonlinearize.program");
}
GLColorBuffer GLNonlinearlizeFilter::Filter(GLColorBuffer input) {
SPADES_MARK_FUNCTION();
2014-04-08 03:36:07 +09:00
IGLDevice *dev = renderer->GetGLDevice();
GLQuadRenderer qr(dev);
2014-04-08 03:36:07 +09:00
static GLProgramAttribute lensPosition("positionAttribute");
static GLProgramUniform lensTexture("mainTexture");
2015-06-20 18:32:30 +09:00
static GLProgramUniform lensGamma("gamma");
2014-04-08 03:36:07 +09:00
dev->Enable(IGLDevice::Blend, false);
2014-04-08 03:36:07 +09:00
lensPosition(lens);
lensTexture(lens);
2015-06-20 18:32:30 +09:00
lensGamma(lens);
2014-04-08 03:36:07 +09:00
lens->Use();
2014-04-08 03:36:07 +09:00
lensTexture.SetValue(0);
2016-11-19 23:22:18 +09:00
lensGamma.SetValue(1.f / (float)renderer->GetSettings().r_hdrGamma);
2014-04-08 03:36:07 +09:00
// composite to the final image
GLColorBuffer output = input.GetManager()->CreateBufferHandle();
2014-04-08 03:36:07 +09:00
qr.SetCoordAttributeIndex(lensPosition());
dev->BindTexture(IGLDevice::Texture2D, input.GetTexture());
dev->BindFramebuffer(IGLDevice::Framebuffer, output.GetFramebuffer());
dev->Viewport(0, 0, output.GetWidth(), output.GetHeight());
qr.Draw();
dev->BindTexture(IGLDevice::Texture2D, 0);
2014-04-08 03:36:07 +09:00
return output;
}
}
}