Skip to content

Commit

Permalink
[SettingsMenuState] Added menu option to change mipmap levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Mar 29, 2020
1 parent e491c94 commit 825a29c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cameraFOV = 70.0
screenWidth = 1600
screenHeight = 1050
guiScale = 3
mipmapLevels = 0

-- Input
mouseSensitivity = 8
Expand Down
2 changes: 2 additions & 0 deletions source/client/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions source/client/core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace Config {
extern u16 screenWidth;
extern u16 screenHeight;
extern u8 guiScale;
extern u8 mipmapLevels;

// Input
extern u8 mouseSensitivity;
Expand Down
12 changes: 12 additions & 0 deletions source/client/graphics/TextureAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions source/client/states/SettingsMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions source/client/world/ChunkBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
};
Expand Down
5 changes: 3 additions & 2 deletions source/client/world/ChunkBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t, layers> buildChunk(const ClientChunk &chunk, const std::array<gk::VertexBuffer, layers> &vbo);

enum Layer {
Solid,
Liquid,
NoMipMap,
Flora,
Glass,
Liquid,
};

private:
Expand Down
4 changes: 4 additions & 0 deletions source/client/world/ClientChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 825a29c

Please sign in to comment.