Skip to content

Commit

Permalink
fix #6414
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Aug 4, 2020
1 parent b82580c commit d3c0012
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 40 deletions.
2 changes: 1 addition & 1 deletion rts/Rendering/Models/3DModel.cpp
Expand Up @@ -164,7 +164,7 @@ void S3DModelPiece::CreateShatterPiecesVariation(const int num)
const size_t mapSize = indices.size() * sizeof(unsigned int);
size_t vboPos = 0;

if (auto* vboMem = reinterpret_cast<unsigned char*>(vboShatterIndices.MapBuffer(num * mapSize, mapSize, GL_WRITE_ONLY)); vboMem != nullptr) {
for (auto* vboMem = reinterpret_cast<unsigned char*>(vboShatterIndices.MapBuffer(num * mapSize, mapSize, GL_WRITE_ONLY)); vboMem != nullptr; vboMem = nullptr) {
for (ShatterPartDataPair& cp: shatterPartsBuf) {
S3DModelPiecePart::RenderData& rd = cp.first;

Expand Down
9 changes: 4 additions & 5 deletions rts/Rendering/Textures/IAtlasAllocator.h
Expand Up @@ -14,7 +14,7 @@
class IAtlasAllocator
{
public:
IAtlasAllocator() : maxsize(2048, 2048), npot(false) {}
IAtlasAllocator() = default;
virtual ~IAtlasAllocator() {}

void SetMaxSize(int xsize, int ysize) { maxsize = int2(xsize, ysize); }
Expand Down Expand Up @@ -67,8 +67,7 @@ class IAtlasAllocator
{
entries.clear();
}
//auto begin() { return entries.begin(); }
//auto end() { return entries.end(); }


int2 GetMaxSize() const { return maxsize; }
int2 GetAtlasSize() const { return atlasSize; }
Expand All @@ -87,9 +86,9 @@ class IAtlasAllocator
spring::unordered_map<std::string, SAtlasEntry> entries;

int2 atlasSize;
int2 maxsize;
int2 maxsize = {2048, 2048};

bool npot;
bool npot = false;
};

#endif // IATLAS_ALLOC_H
12 changes: 2 additions & 10 deletions rts/Rendering/Textures/RowAtlasAlloc.cpp
Expand Up @@ -7,15 +7,7 @@
#include <vector>

// texture spacing in the atlas (in pixels)
static const int ATLAS_PADDING = 1;


CRowAtlasAlloc::CRowAtlasAlloc()
: nextRowPos(0)
{
atlasSize.x = 256;
atlasSize.y = 256;
}
static constexpr int ATLAS_PADDING = 1;


inline int CRowAtlasAlloc::CompareTex(SAtlasEntry* tex1, SAtlasEntry* tex2)
Expand All @@ -33,7 +25,7 @@ void CRowAtlasAlloc::EstimateNeededSize()
int spaceNeeded = 0;
int spaceFree = atlasSize.x * (atlasSize.y - nextRowPos);

for (auto it: entries) {
for (const auto& it: entries) {
spaceNeeded += it.second.size.x * it.second.size.y;
}
for (auto& row: imageRows) {
Expand Down
6 changes: 4 additions & 2 deletions rts/Rendering/Textures/RowAtlasAlloc.h
Expand Up @@ -11,7 +11,9 @@
class CRowAtlasAlloc : public IAtlasAllocator
{
public:
CRowAtlasAlloc();
CRowAtlasAlloc() {
atlasSize = {256, 256};
}

virtual bool Allocate();
virtual int GetMaxMipMaps() { return 0; }
Expand All @@ -30,7 +32,7 @@ class CRowAtlasAlloc : public IAtlasAllocator
};

private:
int nextRowPos;
int nextRowPos = 0;
std::vector<Row> imageRows;

private:
Expand Down
24 changes: 12 additions & 12 deletions rts/Rendering/Textures/TextureAtlas.cpp
Expand Up @@ -9,39 +9,39 @@
#include "Rendering/GlobalRendering.h"
#include "Rendering/GL/myGL.h"
#include "Rendering/GL/PBO.h"
#include "System/FileSystem/FileHandler.h"
#include "System/Config/ConfigHandler.h"
#include "System/Log/ILog.h"
#include "System/StringUtil.h"
#include "System/Exceptions.h"

#include <cstring>

CONFIG(int, MaxTextureAtlasSizeX).defaultValue(2048).minimumValue(512).maximumValue(32768);
CONFIG(int, MaxTextureAtlasSizeY).defaultValue(2048).minimumValue(512).maximumValue(32768);

CR_BIND(AtlasedTexture, )
CR_REG_METADATA(AtlasedTexture, (CR_MEMBER(x), CR_MEMBER(y), CR_MEMBER(z), CR_MEMBER(w)))

// texture spacing in the atlas (in pixels)
#define TEXMARGIN 2


static AtlasedTexture dummy;

bool CTextureAtlas::debug;
bool CTextureAtlas::debug = false;


CTextureAtlas::CTextureAtlas(unsigned int allocType)
: atlasAllocator(nullptr)
, atlasTexID(0)
, initialized(false)
, freeTexture(true)
{
switch (allocType) {
case ATLAS_ALLOC_LEGACY: { atlasAllocator = new CLegacyAtlasAlloc(); } break;
case ATLAS_ALLOC_LEGACY : { atlasAllocator = new CLegacyAtlasAlloc(); } break;
case ATLAS_ALLOC_QUADTREE: { atlasAllocator = new CQuadtreeAtlasAlloc(); } break;
default: { assert(false); } break;
default : { assert(false); } break;
}

// NB: maxTextureSize can be as large as 32768, resulting in a 4GB atlas
const int atlasSizeX = std::min(globalRendering->maxTextureSize, configHandler->GetInt("MaxTextureAtlasSizeX"));
const int atlasSizeY = std::min(globalRendering->maxTextureSize, configHandler->GetInt("MaxTextureAtlasSizeY"));

atlasAllocator->SetNonPowerOfTwo(globalRendering->supportNonPowerOfTwoTex);
// atlasAllocator->SetMaxSize(globalRendering->maxTextureSize, globalRendering->maxTextureSize);
atlasAllocator->SetMaxSize(atlasSizeX, atlasSizeY);

textures.reserve(256);
memTextures.reserve(128);
Expand Down
12 changes: 6 additions & 6 deletions rts/Rendering/Textures/TextureAtlas.h
Expand Up @@ -110,7 +110,7 @@ class CTextureAtlas
bool CreateTexture();

protected:
IAtlasAllocator* atlasAllocator;
IAtlasAllocator* atlasAllocator = nullptr;

struct MemTex {
public:
Expand Down Expand Up @@ -147,13 +147,13 @@ class CTextureAtlas
spring::unordered_map<std::string, size_t> files;
spring::unordered_map<std::string, AtlasedTexture> textures;

unsigned int atlasTexID;
unsigned int atlasTexID = 0;

//! set to true to write finalized texture atlas to disk
static bool debug;
bool initialized = false;
bool freeTexture = true; // free texture on atlas destruction?

bool initialized;
bool freeTexture; //! free texture on atlas destruction?
// set to true to write finalized texture atlas to disk
static bool debug;
};

#endif // TEXTURE_ATLAS_H
6 changes: 2 additions & 4 deletions rts/Sim/Units/Scripts/UnitScript.cpp
Expand Up @@ -938,12 +938,10 @@ int CUnitScript::GetUnitVal(int val, int p1, int p2, int p3, int p4)
case UPRIGHT:
return !!unit->upright;
case POW:
return int(math::pow(((float)p1)/COBSCALE,((float)p2)/COBSCALE)*COBSCALE);
return int(math::pow((p1 * 1.0f) / COBSCALE, (p2 * 1.0f) / COBSCALE) * COBSCALE);
case PRINT: {
const CCobInstance* cobScript = dynamic_cast<CCobInstance*>(unit->script);

const char* unitName = unit->unitDef->name.c_str();
const char* scriptName = (cobScript != nullptr)? cobScript->cobFile->name.c_str(): "Lua";
const char* scriptName = unit->unitDef->scriptName.c_str();

LOG("[UnitScript::PRINT][unit=%s script=%s] p1=%d p2=%d p3=%d p4=%d", unitName, scriptName, p1, p2, p3, p4);
} break;
Expand Down

0 comments on commit d3c0012

Please sign in to comment.