Skip to content

Commit

Permalink
fix framebuffer resize issue, add properties to decal instance builde…
Browse files Browse the repository at this point in the history
…r, fix engine define
  • Loading branch information
hotstreams committed Jun 9, 2024
1 parent 7f691db commit 4d8cb3c
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 21 deletions.
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
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;
}
4 changes: 2 additions & 2 deletions src/limitless/loaders/texture_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <limitless/assets.hpp>
#include <limitless/loaders/dds_loader.hpp>

#if GL_DEBUG
#if LIMITLESS_OPENGL_DEBUG
#include <iostream>
#endif

Expand Down Expand Up @@ -154,7 +154,7 @@ std::shared_ptr<Texture> TextureLoader::load(Assets& assets, const fs::path& _pa
throw std::runtime_error("Failed to load texture: " + path.string() + " " + stbi_failure_reason());
}

#if GL_DEBUG
#if LIMITLESS_OPENGL_DEBUG
if (!isPowerOfTwo(width, height)) {
std::cerr << path.string() << " has not 2^n size, its not recommended to have it!" << std::endl;
}
Expand Down

0 comments on commit 4d8cb3c

Please sign in to comment.