Fix scaling issue with screenspace renderables (#939)

This commit is contained in:
Emil Axelsson
2019-07-19 11:09:04 +02:00
committed by Alexander Bock
parent 852115e309
commit 9934fc03b9
6 changed files with 13 additions and 25 deletions

View File

@@ -212,7 +212,6 @@ void ScreenSpaceDashboard::update() {
if (global::windowDelegate.windowHasResized()) {
const glm::ivec2 size = global::windowDelegate.currentWindowResolution();
_size = { 0.f, 0.f, size.x, size.y };
_originalViewportSize = size;
createFramebuffer();
}
}

View File

@@ -106,15 +106,15 @@ void ScreenSpaceFramebuffer::render() {
const glm::vec2& resolution = global::windowDelegate.currentWindowResolution();
const glm::vec4& size = _size.value();
const float xratio = _originalViewportSize.x / (size.z - size.x);
const float yratio = _originalViewportSize.y / (size.w - size.y);;
const float xratio = resolution.x / (size.z - size.x);
const float yratio = resolution.y / (size.w - size.y);;
if (!_renderFunctions.empty()) {
glViewport(
static_cast<GLint>(-size.x * xratio),
static_cast<GLint>(-size.y * yratio),
static_cast<GLsizei>(_originalViewportSize.x * xratio),
static_cast<GLsizei>(_originalViewportSize.y * yratio)
static_cast<GLsizei>(resolution.x * xratio),
static_cast<GLsizei>(resolution.y * yratio)
);
GLint defaultFBO = _framebuffer->getActiveObject();
_framebuffer->activate();
@@ -170,14 +170,16 @@ void ScreenSpaceFramebuffer::removeAllRenderFunctions() {
}
void ScreenSpaceFramebuffer::createFramebuffer() {
glm::vec2 resolution = global::windowDelegate.currentWindowResolution();
_framebuffer = std::make_unique<ghoul::opengl::FramebufferObject>();
_framebuffer->activate();
_texture = std::make_unique<ghoul::opengl::Texture>(glm::uvec3(
_originalViewportSize.x,
_originalViewportSize.y,
resolution.x,
resolution.y,
1
));
_objectSize = glm::ivec2(_originalViewportSize);
_objectSize = glm::ivec2(resolution);
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap);

View File

@@ -29,10 +29,8 @@ in vec2 vs_st;
in vec4 vs_position;
uniform sampler2D texture1;
uniform float OcclusionDepth;
uniform float Alpha;
Fragment getFragment() {
Fragment frag;

View File

@@ -113,7 +113,6 @@ ScreenSpaceBrowser::ScreenSpaceBrowser(const ghoul::Dictionary &dictionary)
}
bool ScreenSpaceBrowser::initialize() {
_originalViewportSize = global::windowDelegate.currentWindowSize();
_renderHandler->setTexture(*_texture);
createShaders();
@@ -164,7 +163,6 @@ void ScreenSpaceBrowser::update() {
if (_isDimensionsDirty) {
_browserInstance->reshape(_dimensions.value());
_originalViewportSize = _dimensions.value();
_isDimensionsDirty = false;
}
}