Skip to content

Commit

Permalink
fix: temporary framebuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah authored Nov 23, 2023
1 parent 229ab54 commit 12b7201
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 105 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ set(SOURCE_FILES
framework/graphics/drawpoolmanager.cpp
framework/graphics/fontmanager.cpp
framework/graphics/framebuffer.cpp
framework/graphics/framebuffermanager.cpp
framework/graphics/graphics.cpp
framework/graphics/hardwarebuffer.cpp
framework/graphics/image.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/framework/core/asyncdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void AsyncDispatcher::init(uint8_t maxThreads)

// -2 = Main Thread and Map Thread
int_fast8_t threads = std::clamp<int_fast8_t>(std::thread::hardware_concurrency() - 2, 1, maxThreads);
for (; --threads >= 0;)
while (--threads >= 0)
m_threads.emplace_back([this] { m_ioService.run(); });
}

Expand Down
2 changes: 1 addition & 1 deletion src/framework/core/eventdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::thread::id g_eventThreadId;

void EventDispatcher::init() {
m_threads.reserve(g_asyncDispatcher.getNumberOfThreads() + 1);
for (uint_fast16_t i = 1; i < m_threads.capacity(); ++i) {
for (uint_fast16_t i = 0, s = m_threads.capacity(); i < s; ++i) {
m_threads.emplace_back(std::make_unique<ThreadTask>());
}
};
Expand Down
23 changes: 17 additions & 6 deletions src/framework/graphics/drawpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

#include "drawpool.h"
#include "framebuffermanager.h"

DrawPool* DrawPool::create(const DrawPoolType type)
{
Expand All @@ -32,9 +31,11 @@ DrawPool* DrawPool::create(const DrawPoolType type)
if (type == DrawPoolType::MAP) {
pool->m_framebuffer->m_useAlphaWriting = false;
pool->m_framebuffer->disableBlend();
pool->m_bindedFramebuffers = 0; // forces to use only framebuffer without smoothing.
} else if (type == DrawPoolType::FOREGROUND) {
pool->setFPS(FPS10);

// creates a temporary framebuffer with smoothing.
pool->m_temporaryFramebuffers.emplace_back(std::make_shared<FrameBuffer>());
}
} else {
pool->m_alwaysGroupDrawings = true; // CREATURE_INFORMATION & TEXT
Expand Down Expand Up @@ -373,9 +374,9 @@ void DrawPool::bindFrameBuffer(const Size& size)

m_oldState = std::move(m_state);
m_state = {};
addAction([size, frameIndex = m_bindedFramebuffers, drawState = m_state] {
addAction([this, size, frameIndex = m_bindedFramebuffers, drawState = m_state] {
drawState.execute();
const auto& frame = g_framebuffers.getTemporaryFrameBuffer(frameIndex);
const auto& frame = getTemporaryFrameBuffer(frameIndex);
frame->resize(size);
frame->bind();
});
Expand All @@ -384,12 +385,22 @@ void DrawPool::releaseFrameBuffer(const Rect& dest)
{
m_state = std::move(m_oldState);
m_oldState = {};
addAction([dest, frameIndex = m_bindedFramebuffers, drawState = m_state] {
const auto& frame = g_framebuffers.getTemporaryFrameBuffer(frameIndex);
addAction([this, dest, frameIndex = m_bindedFramebuffers, drawState = m_state] {
const auto& frame = getTemporaryFrameBuffer(frameIndex);
frame->release();
drawState.execute();
frame->draw(dest);
});
if (hasFrameBuffer() && !dest.isNull()) stdext::hash_union(m_status.second, dest.hash());
--m_bindedFramebuffers;
}

const FrameBufferPtr& DrawPool::getTemporaryFrameBuffer(const uint8_t index) {
if (index < m_temporaryFramebuffers.size()) {
return m_temporaryFramebuffers[index];
}

const auto& tempfb = m_temporaryFramebuffers.emplace_back(std::make_shared<FrameBuffer>());
tempfb->setSmooth(false);
return tempfb;
}
7 changes: 5 additions & 2 deletions src/framework/graphics/drawpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,12 @@ class DrawPool

bool canRepaint(bool autoUpdateStatus);

const FrameBufferPtr& getTemporaryFrameBuffer(const uint8_t index);

bool m_enabled{ true };
bool m_alwaysGroupDrawings{ false };

int8_t m_bindedFramebuffers{ -1 };
int_fast8_t m_bindedFramebuffers{ -1 };
uint8_t m_depthLevel{ 0 };

uint16_t m_refreshDelay{ 0 }, m_shaderRefreshDelay{ 0 };
Expand All @@ -245,6 +247,7 @@ class DrawPool
std::pair<size_t, size_t> m_status{ 1, 0 };

std::vector<Matrix3> m_transformMatrixStack;
std::vector<FrameBufferPtr> m_temporaryFramebuffers;
std::vector<DrawObject> m_objects[MAX_DRAW_DEPTH + 1][static_cast<uint8_t>(DrawOrder::LAST)];

stdext::map<size_t, CoordsBuffer*> m_coords;
Expand All @@ -259,7 +262,7 @@ class DrawPool

std::mutex m_mutex;

friend DrawPoolManager;
friend class DrawPoolManager;
};

extern DrawPoolManager g_drawPool;
4 changes: 1 addition & 3 deletions src/framework/graphics/drawpoolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#include "drawpoolmanager.h"
#include "declarations.h"
#include "painter.h"
#include <framework/graphics/framebuffermanager.h>

thread_local static uint8_t CURRENT_POOL;

Expand Down Expand Up @@ -83,7 +81,7 @@ void DrawPoolManager::draw()
// m_drawing = false;
}

bool DrawPoolManager::drawPool(const auto& pool) {
bool DrawPoolManager::drawPool(DrawPool* pool) {
if (!pool->isEnabled())
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/framework/graphics/drawpoolmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class DrawPoolManager
void terminate() const;
void drawObject(const DrawPool::DrawObject& obj);

bool drawPool(const auto& pool);
bool drawPool(DrawPool* pool);

std::atomic_bool m_drawing{ false };

Expand Down
45 changes: 0 additions & 45 deletions src/framework/graphics/framebuffermanager.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions src/framework/graphics/framebuffermanager.h

This file was deleted.

4 changes: 1 addition & 3 deletions src/framework/graphics/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "fontmanager.h"

#include <framework/platform/platformwindow.h>
#include "framebuffermanager.h"
#include "texturemanager.h"
#include "painter.h"

Graphics g_graphics;

Expand Down Expand Up @@ -80,13 +80,11 @@ void Graphics::init()
g_painter = new Painter;

g_textures.init();
g_framebuffers.init();
}

void Graphics::terminate()
{
g_fonts.terminate();
g_framebuffers.terminate();
g_textures.terminate();

delete g_painter;
Expand Down
4 changes: 1 addition & 3 deletions vc17/otclient.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ cmd /c "start ../vcpkg_installed\$(VcpkgTriplet)\$(VcpkgTriplet)\tools\protobuf\
<ClCompile Include="..\src\framework\graphics\drawpoolmanager.cpp" />
<ClCompile Include="..\src\framework\graphics\fontmanager.cpp" />
<ClCompile Include="..\src\framework\graphics\framebuffer.cpp" />
<ClCompile Include="..\src\framework\graphics\framebuffermanager.cpp" />
<ClCompile Include="..\src\framework\graphics\graphics.cpp" />
<ClCompile Include="..\src\framework\graphics\hardwarebuffer.cpp" />
<ClCompile Include="..\src\framework\graphics\image.cpp" />
Expand Down Expand Up @@ -438,7 +437,6 @@ cmd /c "start ../vcpkg_installed\$(VcpkgTriplet)\$(VcpkgTriplet)\tools\protobuf\
<ClInclude Include="..\src\framework\graphics\drawpoolmanager.h" />
<ClInclude Include="..\src\framework\graphics\fontmanager.h" />
<ClInclude Include="..\src\framework\graphics\framebuffer.h" />
<ClInclude Include="..\src\framework\graphics\framebuffermanager.h" />
<ClInclude Include="..\src\framework\graphics\glutil.h" />
<ClInclude Include="..\src\framework\graphics\graphics.h" />
<ClInclude Include="..\src\framework\graphics\hardwarebuffer.h" />
Expand Down Expand Up @@ -539,4 +537,4 @@ cmd /c "start ../vcpkg_installed\$(VcpkgTriplet)\$(VcpkgTriplet)\tools\protobuf\
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

0 comments on commit 12b7201

Please sign in to comment.