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 aa85f9d commit 858b876
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 57 deletions.
6 changes: 3 additions & 3 deletions rts/Lua/LuaObjectRendering.cpp
Expand Up @@ -233,7 +233,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 @@ -250,12 +250,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 @@ -2553,7 +2553,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
52 changes: 18 additions & 34 deletions rts/Lua/LuaOpenGLUtils.cpp
Expand Up @@ -730,22 +730,22 @@ void LuaMatTexture::Bind() const
// needed for shaders, not wanted otherwise)
if (enable) {
switch (texType) {
case GL_TEXTURE_2D: { glEnable(texType); } break;
case GL_TEXTURE_CUBE_MAP_ARB: { /*glEnable(texType);*/ } break;
default: { } break;
case GL_TEXTURE_2D: { glEnable(texType); } break;
case GL_TEXTURE_CUBE_MAP: { /*glEnable(texType);*/ } break;
default: { } break;
}
}
}

else if (!enable) {
switch (texType) {
case GL_TEXTURE_2D: { glDisable(texType); } break;
case GL_TEXTURE_CUBE_MAP_ARB: { /*glDisable(texType);*/ } break;
default: { } break;
case GL_TEXTURE_2D: { glDisable(texType); } break;
case GL_TEXTURE_CUBE_MAP: { /*glDisable(texType);*/ } break;
default: { } break;
}
}

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

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

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

if (!enable)
return;

switch (GetTextureTarget()) {
case GL_TEXTURE_2D: { glDisable(GL_TEXTURE_2D); } break;
case GL_TEXTURE_CUBE_MAP_ARB: { /*glDisable(GL_TEXTURE_CUBE_MAP_ARB);*/ } break;
default: { } break;
case GL_TEXTURE_2D: { glDisable(GL_TEXTURE_2D); } break;
case GL_TEXTURE_CUBE_MAP: { /*glDisable(GL_TEXTURE_CUBE_MAP);*/ } break;
default: { } break;
}
}

Expand Down Expand Up @@ -853,29 +853,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 @@ -885,9 +881,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 @@ -896,9 +891,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 @@ -921,13 +915,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 @@ -939,9 +926,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 @@ -92,42 +92,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 858b876

Please sign in to comment.