feat: add anisotropic filtering control

This commit is contained in:
2026-04-26 17:29:58 +08:00
parent e34a20599d
commit 59ab47d317
5 changed files with 103 additions and 36 deletions

View File

@@ -8,13 +8,18 @@ class App;
class Player;
class DevPanel {
struct ConfigView {
float fov;
bool fullscreen;
bool v_sync;
float mouse_sensitivity;
int width;
int height;
int rendering_distance;
float fov = 70.0f;
bool fullscreen = false;
bool v_sync = true;
float mouse_sensitivity = 0.15f;
int width = 800;
int height = 600;
int rendering_distance = 24;
int aniso = 1;
int max_aniso = 1;
bool is_enable_aniso = false;
bool is_support_aniso = true;
bool is_reload = true;
};
struct PlayerProfile {
int game_mode = 0;
@@ -42,6 +47,7 @@ private:
void show_world_tab_item();
void show_player_tab_item();
void update_config_view();
void update_player_profile();
};

View File

@@ -12,6 +12,8 @@ private:
GLuint m_block_status_array;
GLuint m_texture_array;
GLuint m_ui_array;
GLfloat m_max_aniso = 0.0f;
int m_aniso = 1;
void load_block_status(unsigned status_id);
void load_block_texture(unsigned block_id);
void load_ui_texture(unsigned id);
@@ -29,7 +31,7 @@ public:
void hot_reload();
void need_reload();
void update();
int max_aniso() const;
};

View File

@@ -46,6 +46,10 @@ void Config::create_config() {
[devpanel]
theme = 0 # 0 is Dark Theme, 1 is Light Theme
[texture]
aniso = 1 # i is the minimun value, indicating off
)"sv;
try {

View File

@@ -50,18 +50,7 @@ DevPanel::DevPanel(App& app) :
void DevPanel::init() {
m_player = &m_app.world().get_player("TestPlayer");
auto config = Config::get();
m_config.fov = static_cast<float>(config.val_view("player.fov").value_or(70.0));
m_config.fullscreen = config.val_view("window.fullscreen").value_or(false);
m_config.v_sync = config.val_view("window.V-Sync").value_or(true);
m_config.mouse_sensitivity = static_cast<float>(config.val_view("player.mouse_sensitivity").value_or(0.15));
m_config.width = config.val_view("window.width").value_or(800);
m_config.height = config.val_view("window.height").value_or(600);
m_config.rendering_distance = config.val_view("world.rendering_distance").value_or(24);
m_theme = config.val_view("devpanel.theme").value_or(0);
if (m_theme != 1 && m_theme != 0) {
m_theme = 0;
}
update_config_view();
update_player_profile();
}
@@ -186,7 +175,47 @@ void DevPanel::show_settings_tab_item() {
Config::get().set("window.V-Sync", m_config.v_sync);
m_app.window().hot_reload();
}
if (ImGui::Checkbox("Aniso", &m_config.is_enable_aniso)) {
m_config.is_reload = false;
if (m_config.is_enable_aniso) {
m_config.max_aniso = m_app.texture_manager().max_aniso();
if (m_config.max_aniso < 2) {
m_config.is_support_aniso = false;
} else {
m_config.aniso = 2;
}
} else {
m_config.aniso = 1;
}
}
if (m_config.is_enable_aniso) {
ImGui::SameLine();
if (!m_config.is_support_aniso) {
ImGui::Text("Not Support\n");
} else {
if (ImGui::SliderInt("##aniso", &m_config.aniso, 2, m_config.max_aniso)) {
m_config.is_reload = false;
int log = static_cast<int>(std::log2(m_config.aniso) + 0.5f);
m_config.aniso = static_cast<int>(std::pow(2, log));
if (m_config.aniso < 2) {
m_config.aniso = 2;
}
if (m_config.aniso > m_config.max_aniso) {
m_config.aniso = m_config.max_aniso;
}
}
}
}
if (ImGui::Button("ReloadTexture")) {
Config::get().set("texture.aniso", m_config.aniso);
m_app.texture_manager().hot_reload();
m_config.is_reload = true;
}
if (!m_config.is_reload) {
ImGui::SameLine();
ImGui::Text("Your need to click this button to apply config\n");
}
if (ImGui::Combo("Theme", &m_theme, THEMES, IM_ARRAYSIZE(THEMES))) {
if (m_theme == 0) {
ImGui::StyleColorsDark();
@@ -311,7 +340,27 @@ void DevPanel::show_player_tab_item() {
ImGui::EndTabItem();
}
}
void DevPanel::update_config_view() {
auto config = Config::get();
m_config.fov = static_cast<float>(config.val_view("player.fov").value_or(70.0));
m_config.fullscreen = config.val_view("window.fullscreen").value_or(false);
m_config.v_sync = config.val_view("window.V-Sync").value_or(true);
m_config.mouse_sensitivity = static_cast<float>(config.val_view("player.mouse_sensitivity").value_or(0.15));
m_config.width = config.val_view("window.width").value_or(800);
m_config.height = config.val_view("window.height").value_or(600);
m_config.rendering_distance = config.val_view("world.rendering_distance").value_or(24);
m_theme = config.val_view("devpanel.theme").value_or(0);
if (m_theme != 1 && m_theme != 0) {
m_theme = 0;
}
m_config.aniso = config.val_view("texture.aniso").value_or(1);
m_config.max_aniso = m_app.texture_manager().max_aniso();
if (m_config.aniso <= 1) {
m_config.is_enable_aniso = false;
} else {
m_config.is_enable_aniso = true;
}
}
void DevPanel::update_player_profile() {
if (!m_player) {
Logger::error("Player is Nullptr");

View File

@@ -99,7 +99,13 @@ void TextureManager::load_ui_texture(unsigned id) {
}
void TextureManager::init_texture() {
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &m_max_aniso);
if (m_max_aniso > 0.0f) {
Logger::info("Support anisotropic filtering max_aniso is {}", m_max_aniso);
}
m_aniso = Config::get().get<int>("texture.aniso");
m_aniso = std::min(static_cast<int>(m_max_aniso), m_aniso);
Logger::info("Setting Texture Aniso is {}", m_aniso);
MapTable::init_map();
Logger::info("Map Init Success");
glGenTextures(1, &m_texture_array);
@@ -125,12 +131,8 @@ void TextureManager::init_texture() {
Tools::check_opengl_error();
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
Tools::check_opengl_error();
GLfloat max_aniso = 0.0f;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &max_aniso);
if (max_aniso > 0.0f) {
Logger::info("Support anisotropic filtering max_aniso is {}", max_aniso);
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, max_aniso);
if (m_aniso >= 1) {
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, static_cast<GLfloat>(m_aniso));
}
glGenTextures(1, &m_block_status_array);
@@ -157,9 +159,8 @@ void TextureManager::init_texture() {
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
Tools::check_opengl_error();
if (max_aniso > 0.0f) {
Logger::info("Support anisotropic filtering max_aniso is {}", max_aniso);
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, max_aniso);
if (m_aniso >= 1) {
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY, static_cast<GLfloat>(m_aniso));
}
glGenTextures(1, &m_ui_array);
@@ -196,8 +197,13 @@ void TextureManager::need_reload() {
void TextureManager::hot_reload() {
delet_texture();
init_texture();
m_need_reload = false;
}
int TextureManager::max_aniso() const {
return static_cast<int>(m_max_aniso);
}
}