diff --git a/engine/includes/pipelinetasks/shadowmap.h b/engine/includes/pipelinetasks/shadowmap.h index 99af56a4f..c97ba65f6 100644 --- a/engine/includes/pipelinetasks/shadowmap.h +++ b/engine/includes/pipelinetasks/shadowmap.h @@ -35,7 +35,17 @@ class ShadowMap : public PipelineTask { RenderTarget *requestShadowTiles(uint32_t id, uint32_t lod, int32_t *x, int32_t *y, int32_t *w, int32_t *h, uint32_t count); private: - std::unordered_map>> m_tiles; + struct AtlasData { + std::vector nodes; + + RenderTarget *target = nullptr; + + AtlasNode *sub = nullptr; + + bool unused = true; + }; + + std::unordered_map m_tiles; std::unordered_map m_shadowPages; std::vector m_directions; diff --git a/engine/includes/utils/atlas.h b/engine/includes/utils/atlas.h index c04396b63..b69da7d89 100644 --- a/engine/includes/utils/atlas.h +++ b/engine/includes/utils/atlas.h @@ -1,7 +1,7 @@ #ifndef ATLAS_H #define ATLAS_H -#include "engine.h" +#include class AtlasNode { public: @@ -10,6 +10,8 @@ class AtlasNode { AtlasNode *insert(uint32_t width, uint32_t height); + bool clean(); + AtlasNode *left; AtlasNode *right; AtlasNode *parent; @@ -19,15 +21,7 @@ class AtlasNode { uint32_t w; uint32_t h; - bool fill; - bool dirty; - -}; - -class Atlas { -public: - void packSheets(int padding); - + bool occupied; }; #endif // ATLAS_H diff --git a/engine/src/pipelinetasks/shadowmap.cpp b/engine/src/pipelinetasks/shadowmap.cpp index 00f64b9ad..96eb81b1e 100644 --- a/engine/src/pipelinetasks/shadowmap.cpp +++ b/engine/src/pipelinetasks/shadowmap.cpp @@ -395,31 +395,19 @@ void ShadowMap::spotLightUpdate(SpotLight *light, const RenderList &components) void ShadowMap::cleanShadowCache() { for(auto tiles = m_tiles.begin(); tiles != m_tiles.end(); ) { - bool outdate = false; - for(auto &it : tiles->second.second) { - if(it->dirty == true) { - outdate = true; - break; - } - } - if(outdate) { - for(auto &it : tiles->second.second) { - delete it; + if(tiles->second.unused) { + for(auto &it : tiles->second.nodes) { + it->occupied = false; } + tiles->second.sub->clean(); tiles = m_tiles.erase(tiles); } else { ++tiles; } } - /// \todo This activity leads to crash - //for(auto &it : m_shadowPages) { - // it.second->clean(); - //} for(auto &tile : m_tiles) { - for(auto &it : tile.second.second) { - it->dirty = true; - } + tile.second.unused = true; } } @@ -427,14 +415,14 @@ RenderTarget *ShadowMap::requestShadowTiles(uint32_t id, uint32_t lod, int32_t * auto tile = m_tiles.find(id); if(tile != m_tiles.end()) { for(uint32_t i = 0; i < count; i++) { - AtlasNode *node = tile->second.second[i]; + AtlasNode *node = tile->second.nodes[i]; x[i] = node->x; y[i] = node->y; w[i] = node->w; h[i] = node->h; - node->dirty = false; } - return tile->second.first; + tile->second.unused = false; + return tile->second.target; } int32_t width = (m_shadowResolution >> lod); @@ -489,12 +477,12 @@ RenderTarget *ShadowMap::requestShadowTiles(uint32_t id, uint32_t lod, int32_t * y[i] = node->y; w[i] = node->w; h[i] = node->h; - node->fill = true; + node->occupied = true; tiles.push_back(node); } } if(tiles.size() == count) { - m_tiles[id] = make_pair(target, tiles); + m_tiles[id] = {tiles, target, sub, false}; } target->setRenderArea(x[0], y[0], width * columns, height * rows); diff --git a/engine/src/resources/sprite.cpp b/engine/src/resources/sprite.cpp index cc2a6137f..1a4c4ca42 100644 --- a/engine/src/resources/sprite.cpp +++ b/engine/src/resources/sprite.cpp @@ -87,12 +87,12 @@ void Sprite::packSheets(int padding) { for(i = 0; i < m_sources.size(); i++) { Texture *texture = m_sources[i]; - int32_t width = (texture->width() + padding * 2); + int32_t width = (texture->width() + padding * 2); int32_t height = (texture->height() + padding * 2); AtlasNode *node = root.insert(width, height); if(node) { - node->fill = true; + node->occupied = true; nodes[i] = node; } else { @@ -109,7 +109,7 @@ void Sprite::packSheets(int padding) { root.right = nullptr; } - root.fill = false; + root.occupied = false; break; } diff --git a/engine/src/utils/atlas.cpp b/engine/src/utils/atlas.cpp index 34a4875db..d31c85eb6 100644 --- a/engine/src/utils/atlas.cpp +++ b/engine/src/utils/atlas.cpp @@ -1,5 +1,7 @@ #include "utils/atlas.h" +#include "global.h" + AtlasNode::AtlasNode() : left(nullptr), right(nullptr), @@ -8,8 +10,7 @@ AtlasNode::AtlasNode() : y(0), w(1), h(1), - fill(false), - dirty(false) { + occupied(false) { } @@ -36,7 +37,7 @@ AtlasNode *AtlasNode::insert(uint32_t width, uint32_t height) { return right->insert(width, height); } - if(fill || w < width || h < height) { + if(occupied || w < width || h < height) { return nullptr; } @@ -76,3 +77,15 @@ AtlasNode *AtlasNode::insert(uint32_t width, uint32_t height) { return left->insert(width, height); } + +bool AtlasNode::clean() { + if(parent) { + if(left && right && left->clean() && right->clean()) { + delete left; + delete right; + } + + return !occupied; + } + return false; +} diff --git a/modules/renders/rendergl/src/renderglsystem.cpp b/modules/renders/rendergl/src/renderglsystem.cpp index 3c188ad8b..bc20910ed 100644 --- a/modules/renders/rendergl/src/renderglsystem.cpp +++ b/modules/renders/rendergl/src/renderglsystem.cpp @@ -19,8 +19,6 @@ #include -#define MAX_RESOLUTION 8192 - static int32_t registered = 0; void _CheckGLError(const char* file, int line) { @@ -102,8 +100,6 @@ bool RenderGLSystem::init() { glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texture); CheckGLError(); - texture = MIN(texture, MAX_RESOLUTION); - Texture::setMaxTextureSize(texture); glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &texture); diff --git a/thirdparty/next/inc/core/astring.h b/thirdparty/next/inc/core/astring.h index 0fa5c46ef..2a4ecdc0a 100644 --- a/thirdparty/next/inc/core/astring.h +++ b/thirdparty/next/inc/core/astring.h @@ -22,6 +22,7 @@ #include #include #include +#include #include