Skip to content

Commit

Permalink
fix #6098
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Dec 15, 2018
1 parent 34aa3f9 commit 286be00
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 61 deletions.
6 changes: 3 additions & 3 deletions rts/Lua/LuaObjectRendering.cpp
Expand Up @@ -266,7 +266,7 @@ static void ParseTexture(lua_State* L, int index, LuaMatTexture& texUnit) {

if (lua_isstring(L, index)) {
LuaOpenGLUtils::ParseTextureImage(L, texUnit, lua_tostring(L, index));
texUnit.enable = true;
texUnit.Enable(true);
return;
}

Expand All @@ -283,12 +283,12 @@ static void ParseTexture(lua_State* L, int index, LuaMatTexture& texUnit) {

if (key == "tex") {
LuaOpenGLUtils::ParseTextureImage(L, texUnit, lua_tostring(L, -1));
texUnit.enable = true;
texUnit.Enable(true);
continue;
}

if (key == "enable") {
texUnit.enable = lua_isboolean(L, -1) && lua_toboolean(L, -1);
texUnit.Enable(lua_isboolean(L, -1) && lua_toboolean(L, -1));
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion rts/Lua/LuaOpenGL.cpp
Expand Up @@ -3062,7 +3062,7 @@ int LuaOpenGL::Texture(lua_State* L)
if (LuaOpenGLUtils::ParseTextureImage(L, tex, lua_tostring(L, nextArg))) {
lua_pushboolean(L, true);

tex.enable = true;
tex.Enable(true);
tex.Bind();
} else {
lua_pushboolean(L, false);
Expand Down
62 changes: 24 additions & 38 deletions rts/Lua/LuaOpenGLUtils.cpp
Expand Up @@ -507,8 +507,9 @@ GLuint LuaMatTexture::GetTextureID() const
} break;

// object icon-textures
case LUATEX_UNITBUILDPIC: if (unitDefHandler != nullptr) {
texID = unitDrawer->GetUnitDefImage(reinterpret_cast<const UnitDef*>(data));
case LUATEX_UNITBUILDPIC: {
if (unitDefHandler != nullptr)
texID = unitDrawer->GetUnitDefImage(reinterpret_cast<const UnitDef*>(data));
} break;
case LUATEX_UNITRADARICON: {
texID = (reinterpret_cast<const UnitDef*>(data))->iconType->GetTextureID();
Expand Down Expand Up @@ -550,29 +551,30 @@ GLuint LuaMatTexture::GetTextureID() const
case LUATEX_SSMF_SKYREFL:
case LUATEX_SSMF_EMISSION:
case LUATEX_SSMF_PARALLAX: {
if (readMap != nullptr) {
// convert type=LUATEX_* to MAP_*
// convert type=LUATEX_* to MAP_*
if (readMap != nullptr)
texID = readMap->GetTexture(type - LUATEX_SMF_GRASS);
}
} break;

case LUATEX_SSMF_SNORMALS: {
if (readMap != nullptr) {
if (readMap != nullptr)
texID = readMap->GetTexture((LUATEX_SSMF_SNORMALS - LUATEX_SMF_GRASS), *reinterpret_cast<const int*>(&data));
}
} break;


// map info-overlay textures
case LUATEX_INFOTEX_SUFFIX: if (infoTextureHandler != nullptr) {
const CInfoTexture* cInfoTex = static_cast<const CInfoTexture*>(data);
CInfoTexture* mInfoTex = const_cast<CInfoTexture*>(cInfoTex);
case LUATEX_INFOTEX_SUFFIX: {
if (infoTextureHandler != nullptr) {
const CInfoTexture* cInfoTex = static_cast<const CInfoTexture*>(data);
CInfoTexture* mInfoTex = const_cast<CInfoTexture*>(cInfoTex);

texID = mInfoTex->GetTexture();
texID = mInfoTex->GetTexture();
}
} break;

case LUATEX_INFOTEX_ACTIVE: if (infoTextureHandler != nullptr) {
texID = infoTextureHandler->GetCurrentInfoTexture();
case LUATEX_INFOTEX_ACTIVE: {
if (infoTextureHandler != nullptr)
texID = infoTextureHandler->GetCurrentInfoTexture();
} break;


Expand Down Expand Up @@ -728,7 +730,7 @@ void LuaMatTexture::Bind() const
}
}

if (enableTexParams && type == LUATEX_SHADOWMAP)
if (type == LUATEX_SHADOWMAP)
shadowHandler.SetupShadowTexSamplerRaw();

}
Expand All @@ -739,7 +741,7 @@ void LuaMatTexture::Unbind() const
if (type == LUATEX_NONE)
return;

if (enableTexParams && type == LUATEX_SHADOWMAP)
if (type == LUATEX_SHADOWMAP)
shadowHandler.ResetShadowTexSamplerRaw();

if (!enable)
Expand Down Expand Up @@ -839,29 +841,25 @@ int2 LuaMatTexture::GetSize() const
case LUATEX_SSMF_SKYREFL:
case LUATEX_SSMF_EMISSION:
case LUATEX_SSMF_PARALLAX: {
if (readMap != nullptr) {
// convert type=LUATEX_* to MAP_*
// convert type=LUATEX_* to MAP_*
if (readMap != nullptr)
return (readMap->GetTextureSize(type - LUATEX_SMF_GRASS));
}
} break;

case LUATEX_SSMF_SNORMALS: {
if (readMap != nullptr) {
if (readMap != nullptr)
return (readMap->GetTextureSize((LUATEX_SSMF_SNORMALS - LUATEX_SMF_GRASS), *reinterpret_cast<const int*>(&data)));
}
} break;


case LUATEX_INFOTEX_SUFFIX: {
if (infoTextureHandler != nullptr) {
if (infoTextureHandler != nullptr)
return ((static_cast<const CInfoTexture*>(data))->GetTexSize());
}
} break;

case LUATEX_INFOTEX_ACTIVE: {
if (infoTextureHandler != nullptr) {
if (infoTextureHandler != nullptr)
return infoTextureHandler->GetCurrentInfoTextureSize();
}
} break;


Expand All @@ -871,9 +869,8 @@ int2 LuaMatTexture::GetSize() const
case LUATEX_MAP_GBUFFER_EMIT:
case LUATEX_MAP_GBUFFER_MISC:
case LUATEX_MAP_GBUFFER_ZVAL: {
if (readMap != nullptr) {
if (readMap != nullptr)
return (gdGeomBuff->GetWantedSize(readMap->GetGroundDrawer()->DrawDeferred()));
}
} break;

case LUATEX_MODEL_GBUFFER_NORM:
Expand All @@ -882,9 +879,8 @@ int2 LuaMatTexture::GetSize() const
case LUATEX_MODEL_GBUFFER_EMIT:
case LUATEX_MODEL_GBUFFER_MISC:
case LUATEX_MODEL_GBUFFER_ZVAL: {
if (unitDrawer != nullptr) {
if (unitDrawer != nullptr)
return (udGeomBuff->GetWantedSize(unitDrawer->DrawDeferred()));
}
} break;


Expand All @@ -907,13 +903,6 @@ int2 LuaMatTexture::GetSize() const



void LuaMatTexture::Finalize()
{
// enable &= (type != LUATEX_NONE);
enableTexParams = true;
}


int LuaMatTexture::Compare(const LuaMatTexture& a, const LuaMatTexture& b)
{
if (a.type != b.type)
Expand All @@ -925,9 +914,6 @@ int LuaMatTexture::Compare(const LuaMatTexture& a, const LuaMatTexture& b)
if (a.enable != b.enable)
return a.enable ? -1 : +1;

if (a.enableTexParams != b.enableTexParams)
return a.enableTexParams ? -1 : +1;

return 0;
}

Expand Down
32 changes: 13 additions & 19 deletions rts/Lua/LuaOpenGLUtils.h
Expand Up @@ -85,42 +85,36 @@ class LuaMatTexture {
};

public:
LuaMatTexture()
: type(LUATEX_NONE), data(nullptr), state(nullptr), enable(false), enableTexParams(false) {}

void Finalize();
LuaMatTexture() = default;

void Enable(bool b) { enable = b; }
void Finalize() { /*enableTexParams = true;*/ }
void Bind() const;
void Unbind() const;

void Print(const std::string& indent) const;

static int Compare(const LuaMatTexture& a, const LuaMatTexture& b);
bool operator <(const LuaMatTexture& mt) const {
return Compare(*this, mt) < 0;
}
bool operator==(const LuaMatTexture& mt) const {
return Compare(*this, mt) == 0;
}
bool operator!=(const LuaMatTexture& mt) const {
return Compare(*this, mt) != 0;
}

bool operator <(const LuaMatTexture& mt) const { return (Compare(*this, mt) < 0); }
bool operator==(const LuaMatTexture& mt) const { return (Compare(*this, mt) == 0); }
bool operator!=(const LuaMatTexture& mt) const { return (Compare(*this, mt) != 0); }

public:
Type type;
Type type = LUATEX_NONE;

const void* data;
void* state;
const void* data = nullptr;
void* state = nullptr;

bool enable;
bool enableTexParams;
bool enable = false;
// bool enableTexParams = false;

int2 GetSize() const;
GLuint GetTextureID() const;
GLuint GetTextureTarget() const;

public:
static const int maxTexUnits = 16;
static constexpr int maxTexUnits = 16;
};


Expand Down

0 comments on commit 286be00

Please sign in to comment.