Skip to content
Snippets Groups Projects

#473 resize companion window

Open Jan Delember requested to merge feature/#473_resize_companion_window into master
1 unresolved thread
4 files
+ 75
33
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -22,39 +22,74 @@
#include "phx/rendering/render_passes/blit_pass.hpp"
#include <memory>
#include "phx/suppress_warnings.hpp"
namespace phx {
SUPPRESS_WARNINGS_BEGIN
#include "gl/texture.hpp"
#include "glm/vec2.hpp"
SUPPRESS_WARNINGS_END
BlitPass::BlitPass(RenderTarget* render_target)
: render_target_(render_target) {}
namespace phx {
void BlitPass::Initialize() {
default_framebuffer_ = std::make_unique<gl::framebuffer>(0);
BlitPass::BlitPass(gl::framebuffer* source, gl::framebuffer* target)
: source_(source) {
target_ = target;
}
BlitPass::BlitPass(gl::framebuffer* source, Window* target) : source_(source) {
target_ = target;
}
void BlitPass::Initialize() {}
void BlitPass::Execute() {
const glm::uvec2& source_dims = render_target_->GetDimensions();
const GLint source_width = static_cast<int>(source_dims.x);
const GLint source_height = static_cast<int>(source_dims.y);
GLint target_dims[4] = {0};
glGetIntegerv(GL_VIEWPORT, target_dims);
const GLint target_width = target_dims[2];
const GLint target_height = target_dims[3];
GLint source_x = 0;
GLint source_y = 0;
if (target_width < source_width) {
source_x = (source_width - target_width) / 2;
gl::framebuffer default_framebuffer(0);
GLint viewport[4] = {0};
glGetIntegerv(GL_VIEWPORT, viewport);
const auto viewport_size = glm::ivec2{viewport[2], viewport[3]};
glm::ivec2 source_size;
if (source_) {
const auto type = source_->object_type(GL_COLOR_ATTACHMENT0);
const auto name = source_->object_name(GL_COLOR_ATTACHMENT0);
if (type == GL_TEXTURE) {
gl::texture_2d texture(name);
source_size = {texture.width(), texture.height()};
} else if (type == GL_RENDERBUFFER) {
gl::renderbuffer renderbuffer(name);
source_size = {renderbuffer.width(), renderbuffer.height()};
} else /* type == GL_NONE || type == GL_FRAMEBUFFER_DEFAULT */ {
source_size = viewport_size;
}
} else {
source_ = &default_framebuffer;
source_size = viewport_size;
}
if (target_height < source_height) {
source_y = (source_height - target_height) / 2;
glm::ivec2 target_size;
gl::framebuffer* target = nullptr;
if (target_.type() == typeid(gl::framebuffer*)) {
target = boost::get<gl::framebuffer*>(target_);
const auto type = target->object_type(GL_COLOR_ATTACHMENT0);
const auto name = target->object_name(GL_COLOR_ATTACHMENT0);
if (type == GL_TEXTURE) {
gl::texture_2d texture(name);
target_size = {texture.width(), texture.height()};
} else if (type == GL_RENDERBUFFER) {
gl::renderbuffer renderbuffer(name);
target_size = {renderbuffer.width(), renderbuffer.height()};
} else /* type == GL_NONE || type == GL_FRAMEBUFFER_DEFAULT */ {
target_size = viewport_size;
}
} else {
target = &default_framebuffer;
target_size = boost::get<Window*>(target_)->GetSize();
}
default_framebuffer_->blit(*render_target_, source_x, source_y, target_width,
target_height, 0, 0, target_width, target_height,
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT,
GL_NEAREST);
target->blit(*source_, 0, 0, source_size[0], source_size[1], 0, 0,
target_size[0], target_size[1],
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
}
} // namespace phx
Loading