Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion engine/includes/pipelinetasks/shadowmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, std::pair<RenderTarget *, std::vector<AtlasNode *>>> m_tiles;
struct AtlasData {
std::vector<AtlasNode *> nodes;

RenderTarget *target = nullptr;

AtlasNode *sub = nullptr;

bool unused = true;
};

std::unordered_map<uint32_t, AtlasData> m_tiles;
std::unordered_map<RenderTarget *, AtlasNode *> m_shadowPages;

std::vector<Quaternion> m_directions;
Expand Down
14 changes: 4 additions & 10 deletions engine/includes/utils/atlas.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef ATLAS_H
#define ATLAS_H

#include "engine.h"
#include <cstdint>

class AtlasNode {
public:
Expand All @@ -10,6 +10,8 @@ class AtlasNode {

AtlasNode *insert(uint32_t width, uint32_t height);

bool clean();

AtlasNode *left;
AtlasNode *right;
AtlasNode *parent;
Expand All @@ -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
32 changes: 10 additions & 22 deletions engine/src/pipelinetasks/shadowmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,46 +395,34 @@ 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;
}
}

RenderTarget *ShadowMap::requestShadowTiles(uint32_t id, uint32_t lod, int32_t *x, int32_t *y, int32_t *w, int32_t *h, uint32_t count) {
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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions engine/src/resources/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -109,7 +109,7 @@ void Sprite::packSheets(int padding) {
root.right = nullptr;
}

root.fill = false;
root.occupied = false;

break;
}
Expand Down
19 changes: 16 additions & 3 deletions engine/src/utils/atlas.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "utils/atlas.h"

#include "global.h"

AtlasNode::AtlasNode() :
left(nullptr),
right(nullptr),
Expand All @@ -8,8 +10,7 @@ AtlasNode::AtlasNode() :
y(0),
w(1),
h(1),
fill(false),
dirty(false) {
occupied(false) {

}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
4 changes: 0 additions & 4 deletions modules/renders/rendergl/src/renderglsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

#include <log.h>

#define MAX_RESOLUTION 8192

static int32_t registered = 0;

void _CheckGLError(const char* file, int line) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions thirdparty/next/inc/core/astring.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <list>
#include <string>
#include <vector>
#include <cstdint>

#include <global.h>

Expand Down
Loading