diff --git a/rts/Lua/LuaObjectRendering.cpp b/rts/Lua/LuaObjectRendering.cpp index 3060afe96cc..81d1d75be5a 100644 --- a/rts/Lua/LuaObjectRendering.cpp +++ b/rts/Lua/LuaObjectRendering.cpp @@ -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; } @@ -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; } } diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index c70bb598162..0675034a9c5 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -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); diff --git a/rts/Lua/LuaOpenGLUtils.cpp b/rts/Lua/LuaOpenGLUtils.cpp index 8cce39fc995..3fd2313fd9d 100644 --- a/rts/Lua/LuaOpenGLUtils.cpp +++ b/rts/Lua/LuaOpenGLUtils.cpp @@ -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(); } @@ -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; } } @@ -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(&data))); - } } break; case LUATEX_INFOTEX_SUFFIX: { - if (infoTextureHandler != nullptr) { + if (infoTextureHandler != nullptr) return ((static_cast(data))->GetTexSize()); - } } break; case LUATEX_INFOTEX_ACTIVE: { - if (infoTextureHandler != nullptr) { + if (infoTextureHandler != nullptr) return infoTextureHandler->GetCurrentInfoTextureSize(); - } } break; @@ -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: @@ -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; @@ -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) @@ -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; } diff --git a/rts/Lua/LuaOpenGLUtils.h b/rts/Lua/LuaOpenGLUtils.h index 68ebd842893..3e3b47187dd 100644 --- a/rts/Lua/LuaOpenGLUtils.h +++ b/rts/Lua/LuaOpenGLUtils.h @@ -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; };