Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renderer|LensFX: Added a resizing filter (pixel density)
fx::Resize changes the size of the frame buffer to produce a pixelated appearance, either for performance or aesthetic reasons. The variables "Config.render.pixelDensity" and "Config.render.fx.resize.factor" control the amount of resizing. The former applies globally, however is only shown in Video Settings when using a HiDPI display mode. The latter is accessible via the Renderer Appearance editor. The global pixel density setting replaces video mode resolution config on OS X (changing the desktop video mode is not supported on OS X).
- Loading branch information
Showing
9 changed files
with
364 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** @file fx/resize.h Change the size (pixel density) of the view. | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program 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 2 of the License, or (at your | ||
* option) any later version. This program 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. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#ifndef DENG_CLIENT_FX_RESIZE_H | ||
#define DENG_CLIENT_FX_RESIZE_H | ||
|
||
#include "render/consoleeffect.h" | ||
#include <de/Time> | ||
|
||
namespace fx { | ||
|
||
/** | ||
* Post-processing of rendered camera lens frames. Maintains an offscreen | ||
* render target and provides a way to draw it back to the regular target | ||
* with shader effects applied. | ||
*/ | ||
class Resize : public ConsoleEffect | ||
{ | ||
public: | ||
Resize(int console); | ||
|
||
/** | ||
* Determines whether the effect is active. If it isn't, it can be skipped | ||
* altogether when post processing a frame. | ||
*/ | ||
bool isActive() const; | ||
|
||
void glInit(); | ||
void glDeinit(); | ||
|
||
void beginFrame(); | ||
void endFrame(); | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
} // namespace fx | ||
|
||
#endif // DENG_CLIENT_FX_RESIZE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/** @file fx/resize.cpp Change the size (pixel density) of the view. | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program 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 2 of the License, or (at your | ||
* option) any later version. This program 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. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, see: | ||
* http://www.gnu.org/licenses</small> | ||
*/ | ||
|
||
#include "render/fx/resize.h" | ||
#include "ui/clientwindow.h" | ||
#include "clientapp.h" | ||
|
||
#include <de/VRConfig> | ||
#include <de/Drawable> | ||
#include <de/GLFramebuffer> | ||
#include <de/Variable> | ||
|
||
#include <QList> | ||
|
||
using namespace de; | ||
|
||
namespace fx { | ||
|
||
static ddouble const MIN_FACTOR = 1.0 / 16.0; | ||
|
||
DENG2_PIMPL(Resize) | ||
{ | ||
Variable const &pixelDensity; | ||
Variable const &resizeFactor; | ||
|
||
GLFramebuffer framebuf; | ||
Drawable frame; | ||
GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 }; | ||
GLUniform uFrame { "uTex", GLUniform::Sampler2D }; | ||
|
||
typedef GLBufferT<Vertex2Tex> VBuf; | ||
|
||
Instance(Public *i) | ||
: Base(i) | ||
, pixelDensity { App::config("render.pixelDensity") } | ||
, resizeFactor { App::config("render.fx.resize.factor") } | ||
{} | ||
|
||
GuiRootWidget &root() const | ||
{ | ||
return ClientWindow::main().game().root(); | ||
} | ||
|
||
float factor() const | ||
{ | ||
return max(MIN_FACTOR, pixelDensity * resizeFactor); | ||
} | ||
|
||
/// Determines if the post-processing shader will be applied. | ||
bool isActive() const | ||
{ | ||
// This kind of scaling is not compatible with Oculus Rift -- LibOVR does its | ||
// own pixel density scaling. | ||
if(ClientApp::vr().mode() == VRConfig::OculusRift) return false; | ||
|
||
return !fequal(factor(), 1.f); | ||
} | ||
|
||
void glInit() | ||
{ | ||
framebuf.glInit(); | ||
|
||
uMvpMatrix = Matrix4f::ortho(0, 1, 0, 1); | ||
uFrame = framebuf.colorTexture(); | ||
|
||
// Drawable for drawing stuff back to the original target. | ||
VBuf *buf = new VBuf; | ||
buf->setVertices(gl::TriangleStrip, | ||
VBuf::Builder().makeQuad(Rectanglef(0, 0, 1, 1), | ||
Rectanglef(0, 1, 1, -1)), | ||
gl::Static); | ||
frame.addBuffer(buf); | ||
|
||
ClientApp::shaders().build(frame.program(), "generic.texture") | ||
<< uMvpMatrix << uFrame; | ||
} | ||
|
||
void glDeinit() | ||
{ | ||
LOGDEV_GL_XVERBOSE("Releasing GL resources"); | ||
framebuf.glDeinit(); | ||
frame.clear(); | ||
} | ||
|
||
void update() | ||
{ | ||
framebuf.resize(GLState::current().target().rectInUse().size() * factor()); | ||
framebuf.setSampleCount(GLFramebuffer::defaultMultisampling()); | ||
} | ||
|
||
void begin() | ||
{ | ||
if(!isActive()) return; | ||
|
||
update(); | ||
|
||
GLState::push() | ||
.setTarget(framebuf.target()) | ||
.setViewport(Rectangleui::fromSize(framebuf.size())) | ||
.setColorMask(gl::WriteAll) | ||
.apply(); | ||
framebuf.target().clear(GLTarget::ColorDepthStencil); | ||
} | ||
|
||
void end() | ||
{ | ||
if(!isActive()) return; | ||
|
||
GLState::pop().apply(); | ||
} | ||
|
||
void draw() | ||
{ | ||
if(!isActive()) return; | ||
|
||
glEnable(GL_TEXTURE_2D); | ||
glDisable(GL_ALPHA_TEST); | ||
|
||
GLState::push() | ||
.setBlend(false) | ||
.setDepthTest(false) | ||
.setViewport(Rectangleui::fromSize(GLState::current().target().size())) | ||
.apply(); | ||
|
||
frame.draw(); | ||
|
||
GLState::pop().apply(); | ||
|
||
glEnable(GL_ALPHA_TEST); | ||
glDisable(GL_TEXTURE_2D); | ||
glEnable(GL_BLEND); | ||
} | ||
}; | ||
|
||
Resize::Resize(int console) | ||
: ConsoleEffect(console), d(new Instance(this)) | ||
{} | ||
|
||
bool Resize::isActive() const | ||
{ | ||
return d->isActive(); | ||
} | ||
|
||
void Resize::glInit() | ||
{ | ||
if(!d->isActive()) return; | ||
|
||
LOG_AS("fx::Resize"); | ||
|
||
ConsoleEffect::glInit(); | ||
d->glInit(); | ||
} | ||
|
||
void Resize::glDeinit() | ||
{ | ||
LOG_AS("fx::Resize"); | ||
|
||
d->glDeinit(); | ||
ConsoleEffect::glDeinit(); | ||
} | ||
|
||
void Resize::beginFrame() | ||
{ | ||
d->begin(); | ||
} | ||
|
||
void Resize::endFrame() | ||
{ | ||
LOG_AS("fx::Resize"); | ||
|
||
d->end(); | ||
d->draw(); | ||
|
||
if(!d->isActive() && isInited()) | ||
{ | ||
glDeinit(); | ||
} | ||
} | ||
|
||
} // namespace fx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.