Added texture reload feature

This commit is contained in:
OLEGSHA 2021-03-26 02:29:25 +03:00
parent 00e110acb7
commit 4373c6aeb8
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A

View File

@ -71,6 +71,9 @@ public:
return gl_id;
}
const std::string& getName() {
return name;
}
void load_stb() {
int channels;
@ -221,6 +224,7 @@ void switch_camera();
void switch_theme();
void change_texture(int direction);
void close_texture();
void reload_texture();
void on_key(GLFWwindow*, int key, int, int action, int mods) {
if (action != GLFW_PRESS) return;
@ -242,6 +246,9 @@ void on_key(GLFWwindow*, int key, int, int action, int mods) {
case GLFW_KEY_DELETE:
close_texture();
return;
case GLFW_KEY_F5:
reload_texture();
return;
case GLFW_KEY_TAB:
switch_camera();
return;
@ -297,6 +304,24 @@ void close_texture() {
selection -= 1;
}
void reload_texture() {
if (LOADED_TEXTURES.empty()) return;
auto it = LOADED_TEXTURES.begin() + selection;
std::string name = (*it)->getName();
LOADED_TEXTURES.erase(it);
load_texture(name);
for (size_t i = 0; i < LOADED_TEXTURES.size(); ++i) {
if (LOADED_TEXTURES[i]->getName() == name) {
selection = i;
break;
}
}
}