Skip to content

Commit

Permalink
Implement FramebufferStack
Browse files Browse the repository at this point in the history
  • Loading branch information
Isti01 committed Jul 24, 2022
1 parent b47ef5c commit d490fc1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Rendering/FramebufferStack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "FramebufferStack.h"

void FramebufferStack::push(const Ref<Framebuffer>& framebuffer) {
stack.push_back(framebuffer);
framebuffer->bind();
}

Ref<Framebuffer> FramebufferStack::peek() const {
return empty() ? nullptr : stack.back();
}

Ref<Framebuffer> FramebufferStack::pop() {
assert(!empty());

Ref<Framebuffer> framebuffer = peek();
stack.pop_back();

auto current = peek();
if (current != nullptr) {
current->bind();
} else {
framebuffer->unbind(); // binds the default framebuffer
}

return framebuffer;
}

bool FramebufferStack::empty() const {
return stack.empty();
}

size_t FramebufferStack::size() const {
return stack.size();
}
19 changes: 19 additions & 0 deletions src/Rendering/FramebufferStack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef FRAMEBUFFERSTACK_H
#define FRAMEBUFFERSTACK_H

#include "../glCraft.h"
#include "FrameBuffer.h"

class FramebufferStack {
std::vector<Ref<Framebuffer>> stack;

public:
void push(const Ref<Framebuffer>& framebuffer);
[[nodiscard]] Ref<Framebuffer> peek() const;
Ref<Framebuffer> pop();

[[nodiscard]] bool empty() const;
[[nodiscard]] size_t size() const;
};

#endif

0 comments on commit d490fc1

Please sign in to comment.