Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

framebuffer resize fix #57

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project(limitless-engine)
OPTION(BUILD_SAMPLES "Builds samples" ON)
OPTION(BUILD_TESTS "Builds tests" ON)

OPTION(OPENGL_DEBUG "Enables debug mode for OpenGL" OFF)
OPTION(OPENGL_DEBUG "Enables debug mode for OpenGL" ON)
OPTION(OPENGL_NO_EXTENSIONS "Disables all extensions" OFF)
OPTION(OPENGL_SHADER_OUTPUT "Outputs all source shaders for GLSLANG testing" OFF)

Expand Down
6 changes: 4 additions & 2 deletions include/limitless/core/framebuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ namespace Limitless {
RenderTarget() = default;
virtual ~RenderTarget() = default;

auto getId() { return id; }
RenderTarget(const RenderTarget&) = default;
RenderTarget(RenderTarget&&) = default;

auto getId() const { return id; }
virtual void unbind() noexcept = 0;
virtual void bind() noexcept = 0;
virtual void clear() = 0;
Expand Down Expand Up @@ -82,7 +85,6 @@ namespace Limitless {

void blit(Framebuffer& source, Texture::Filter filter, FramebufferBlit blit = FramebufferBlit::Color);

void reattach();
Framebuffer& operator<<(const TextureAttachment &attachment) noexcept;

void onFramebufferChange(glm::uvec2 size) override;
Expand Down
6 changes: 6 additions & 0 deletions include/limitless/core/texture/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,14 @@ namespace Limitless {
void bind(GLuint index) const;

// resizes texture; content becomes empty
// TODO: check some strange behavior with framebuffer found: resize + immutable attached textures
void resize(glm::uvec3 size);

// copy
std::shared_ptr<Texture> clone();
std::shared_ptr<Texture> clone(glm::uvec3 size);
std::shared_ptr<Texture> clone(glm::uvec2 size);

void accept(TextureVisitor& visitor);

class Builder;
Expand Down
9 changes: 9 additions & 0 deletions include/limitless/loaders/texture_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ namespace Limitless {
static GLFWimage loadGLFWImage(Assets& assets, const fs::path& path, const TextureLoaderFlags& flags = {});

static std::shared_ptr<Texture> load(Assets& assets, const fs::path& path, const TextureLoaderFlags& flags = {});

static std::shared_ptr<Texture> load(
Assets& assets,
const std::string& name,
const uint8_t* buffer,
size_t size,
const TextureLoaderFlags& flags = {}
);

static std::shared_ptr<Texture> loadCubemap(Assets& assets, const fs::path& path, const TextureLoaderFlags& flags = {});
};
}
6 changes: 3 additions & 3 deletions src/limitless/core/context_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ void ContextInitializer::initializeGLEW() {
throw std::runtime_error("Failed to initialize GLEW.");
}

#ifdef GL_DEBUG
#ifdef LIMITLESS_OPENGL_DEBUG
activate_debug();
#endif

getExtensions();
getLimits();

#ifdef GL_DEBUG
#ifdef LIMITLESS_OPENGL_DEBUG
printExtensions();
#endif

Expand All @@ -36,7 +36,7 @@ void ContextInitializer::initializeGLFW() {
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor_version);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

#ifdef GL_DEBUG
#ifdef LIMITLESS_OPENGL_DEBUG
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif

Expand Down
17 changes: 5 additions & 12 deletions src/limitless/core/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,11 @@ Framebuffer::~Framebuffer() {
}
}

void Framebuffer::Framebuffer::reattach() {
for (const auto& [type, attachment] : attachments) {
*this << attachment;
}
}

void Framebuffer::onFramebufferChange(glm::uvec2 size) {
for (auto& [type, attachment] : attachments) {
attachment.texture->resize({ size, attachment.texture->getSize().z });
attachment.texture = attachment.texture->clone(size);
*this << attachment;
}

reattach();
}

void Framebuffer::checkStatus() {
Expand Down Expand Up @@ -319,15 +312,15 @@ Framebuffer Framebuffer::asRGB16FNearestClampToEdgeWithDepth(glm::uvec2 size, co
}

Framebuffer::Framebuffer(Framebuffer&& rhs) noexcept
: attachments {std::move(rhs.attachments)}
: RenderTarget(std::move(rhs))
, attachments {std::move(rhs.attachments)}
, draw_state {std::move(rhs.draw_state)} {
reattach();
}

Framebuffer& Framebuffer::operator=(Framebuffer&& rhs) noexcept {
id = rhs.id;
attachments = std::move(rhs.attachments);
draw_state = std::move(rhs.draw_state);
reattach();
return *this;
}

Expand Down
42 changes: 42 additions & 0 deletions src/limitless/core/texture/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,44 @@ void Texture::bind(GLuint index) const {
texture->bind(static_cast<GLenum>(target), index);
}

std::shared_ptr<Texture> Texture::clone() {
return clone(size);
}

std::shared_ptr<Texture> Texture::clone(glm::uvec3 s) {
auto clone = std::shared_ptr<Texture>(new Texture());

clone->texture = std::unique_ptr<ExtensionTexture>(texture->clone());
clone->texture->generateId();

clone->path = path;
clone->size = s;
clone->internal_format = internal_format;
clone->data_type = data_type;
clone->format = format;
clone->target = target;
clone->min = min;
clone->mag = mag;
clone->wrap_r = wrap_r;
clone->wrap_s = wrap_s;
clone->wrap_t = wrap_t;
clone->levels = levels;
clone->anisotropic = anisotropic;
clone->mipmap = mipmap;
clone->compressed = compressed;
clone->immutable = immutable;

if (isMutable()) {
clone->image();
}

if (isImmutable()) {
clone->storage();
}

return clone;
}

void Texture::resize(glm::uvec3 _size) {
size = _size;

Expand All @@ -154,6 +192,10 @@ void Texture::resize(glm::uvec3 _size) {
}
}

std::shared_ptr<Texture> Texture::clone(glm::uvec2 s) {
return clone(glm::uvec3{s, 1});
}

void Texture::accept(TextureVisitor& visitor) {
texture->accept(visitor);
}
Expand Down
6 changes: 5 additions & 1 deletion src/limitless/instances/instance_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,9 @@ std::shared_ptr<DecalInstance> Instance::Builder::asDecal() {
throw instance_builder_exception {"Model for decal is not elementary!"};
}

return std::make_shared<DecalInstance>(model_, global_material, position_);
auto instance = std::make_shared<DecalInstance>(model_, global_material, position_);
instance->setPosition(position_);
instance->setRotation(rotation_);
instance->setScale(scale_);
return instance;
}
Loading
Loading