diff --git a/config.example.lua b/config.example.lua index 4ca131471..bdd5e6ab2 100644 --- a/config.example.lua +++ b/config.example.lua @@ -24,6 +24,7 @@ cameraFOV = 70.0 screenWidth = 1600 screenHeight = 1050 guiScale = 3 +mipmapLevels = 0 -- Input mouseSensitivity = 8 diff --git a/source/client/core/Config.cpp b/source/client/core/Config.cpp index ba12aee7e..8c2298ea4 100644 --- a/source/client/core/Config.cpp +++ b/source/client/core/Config.cpp @@ -48,6 +48,7 @@ float Config::cameraFOV = 70.0f; u16 Config::screenWidth = 1600; u16 Config::screenHeight = 1050; u8 Config::guiScale = 3; +u8 Config::mipmapLevels = 0; // Input u8 Config::mouseSensitivity = 8; @@ -84,6 +85,7 @@ void Config::loadConfigFromFile(const char *file) { screenWidth = lua["screenWidth"].get_or(screenWidth); screenHeight = lua["screenHeight"].get_or(screenHeight); guiScale = lua["guiScale"].get_or(guiScale); + mipmapLevels = lua["mipmapLevels"].get_or(mipmapLevels); mouseSensitivity = lua["mouseSensitivity"].get_or(mouseSensitivity); diff --git a/source/client/core/Config.hpp b/source/client/core/Config.hpp index 875261efd..911dcb1d9 100644 --- a/source/client/core/Config.hpp +++ b/source/client/core/Config.hpp @@ -52,6 +52,7 @@ namespace Config { extern u16 screenWidth; extern u16 screenHeight; extern u8 guiScale; + extern u8 mipmapLevels; // Input extern u8 mouseSensitivity; diff --git a/source/client/graphics/TextureAtlas.cpp b/source/client/graphics/TextureAtlas.cpp index ac951ffd8..65d551668 100644 --- a/source/client/graphics/TextureAtlas.cpp +++ b/source/client/graphics/TextureAtlas.cpp @@ -104,6 +104,18 @@ void TextureAtlas::packTextures() { throw EXCEPTION("Failed to save texture to: test_atlas.png. Reason:", IMG_GetError()); m_texture.loadFromSurface(atlas.get()); + + gk::Texture::bind(&m_texture); + + glGenerateMipmap(GL_TEXTURE_2D); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + gk::Texture::bind(nullptr); } void TextureAtlas::loadFromRegistry(const std::string &texturePack) { diff --git a/source/client/states/SettingsMenuState.cpp b/source/client/states/SettingsMenuState.cpp index aaaf9a7a4..f6beb0319 100644 --- a/source/client/states/SettingsMenuState.cpp +++ b/source/client/states/SettingsMenuState.cpp @@ -191,6 +191,11 @@ void SettingsMenuState::addGraphicsButtons() { }); addToggleButton("Use VSync", Config::isVerticalSyncEnabled, false); + + m_menuWidget.addButton("Mipmap Levels: " + std::to_string(Config::mipmapLevels), [] (TextButton &button) { + Config::mipmapLevels = (Config::mipmapLevels + 1) % 5; + button.setText("Mipmap Levels: " + std::to_string(Config::mipmapLevels)); + }); } void SettingsMenuState::addInputButtons() { diff --git a/source/client/world/ChunkBuilder.cpp b/source/client/world/ChunkBuilder.cpp index d1dcd1bd5..3e1af7e89 100644 --- a/source/client/world/ChunkBuilder.cpp +++ b/source/client/world/ChunkBuilder.cpp @@ -260,6 +260,8 @@ inline void ChunkBuilder::addFace(s8f x, s8f y, s8f z, s8f f, const ClientChunk m_vertices[Layer::Liquid].emplace_back(vertices[v]); else if (block.drawType() == BlockDrawType::Glass) m_vertices[Layer::Glass].emplace_back(vertices[v]); + else if (block.colorMultiplier() != gk::Color::White) + m_vertices[Layer::NoMipMap].emplace_back(vertices[v]); else m_vertices[Layer::Solid].emplace_back(vertices[v]); }; diff --git a/source/client/world/ChunkBuilder.hpp b/source/client/world/ChunkBuilder.hpp index 89c1892e7..75d49695e 100644 --- a/source/client/world/ChunkBuilder.hpp +++ b/source/client/world/ChunkBuilder.hpp @@ -44,15 +44,16 @@ class ChunkBuilder { public: ChunkBuilder(TextureAtlas &textureAtlas) : m_textureAtlas(textureAtlas) {} - static constexpr u8 layers = 4; + static constexpr u8 layers = 5; std::array buildChunk(const ClientChunk &chunk, const std::array &vbo); enum Layer { Solid, - Liquid, + NoMipMap, Flora, Glass, + Liquid, }; private: diff --git a/source/client/world/ClientChunk.cpp b/source/client/world/ClientChunk.cpp index d30c0f514..317985fbc 100644 --- a/source/client/world/ClientChunk.cpp +++ b/source/client/world/ClientChunk.cpp @@ -48,6 +48,10 @@ void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u else glCheck(glEnable(GL_CULL_FACE)); + gk::Texture::bind(states.texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, (layer == ChunkBuilder::Layer::NoMipMap || layer == ChunkBuilder::Layer::Flora) ? 0 : Config::mipmapLevels); + gk::Texture::bind(nullptr); + glCheck(glEnable(GL_DEPTH_TEST)); if(Config::isWireframeModeEnabled) glCheck(glPolygonMode(GL_FRONT_AND_BACK, GL_LINE));