Skip to content

Commit

Permalink
[Framebuffer] Now correctly cleaning view framebuffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Oct 29, 2023
1 parent c18158f commit 70ef018
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
13 changes: 7 additions & 6 deletions source/client/graphics/Framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,15 @@ void Framebuffer::init(u16 width, u16 height) {

bgfx::setViewRect(view, 0, 0, width, height);
bgfx::setViewClear(view, BGFX_CLEAR_COLOR);

bgfx::setViewFrameBuffer(0, m_handle);
bgfx::setViewFrameBuffer(1, m_handle);
}

void Framebuffer::free() {
bgfx::setViewFrameBuffer(0, BGFX_INVALID_HANDLE);
bgfx::setViewFrameBuffer(1, BGFX_INVALID_HANDLE);

if (bgfx::isValid(m_handle))
bgfx::destroy(m_handle);

Expand All @@ -107,12 +113,7 @@ void Framebuffer::loadShader(const std::string &name) {
m_shader.loadFromFile(name);
}

void Framebuffer::begin() const {
bgfx::setViewFrameBuffer(0, m_handle);
bgfx::setViewFrameBuffer(1, m_handle);
}

void Framebuffer::end() const {
void Framebuffer::draw() const {
bgfx::setTexture(0, m_colorTextureSampler, m_textures[0]);
bgfx::setTexture(1, m_depthTextureSampler, m_textures[1]);

Expand Down
3 changes: 1 addition & 2 deletions source/client/graphics/Framebuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class Framebuffer : public gk::NonCopyable {

void loadShader(const std::string &name);

void begin() const;
void end() const;
void draw() const;

static const u32 view = 2;

Expand Down
6 changes: 2 additions & 4 deletions source/client/states/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ void GameState::draw(RenderTarget &target, RenderStates states) const {
}
}

m_fbo.begin();

states.shader = &m_shader;

target.setView(m_camera);
Expand All @@ -264,8 +262,8 @@ void GameState::draw(RenderTarget &target, RenderStates states) const {

target.draw(m_hud.blockCursor(), states);

m_fbo.end();

target.draw(m_hud, states);

m_fbo.draw();
}

0 comments on commit 70ef018

Please sign in to comment.