--- a/Shark.cpp Sat Dec 02 23:11:56 2023 +0100
+++ b/Shark.cpp Sun Dec 03 00:17:48 2023 +0100
@@ -193,6 +193,7 @@
int setNonBlocking(int fd);
void loadVertices();
Texture loadTexture(const std::string& fileName);
+ void updateTexture(Texture& tex, const Buffer& file);
bool reloadTexture(const std::string& fileName);
void loadTextures();
std::shared_ptr<Program> loadShaders();
@@ -554,7 +555,11 @@
Texture tex;
tex.fileName = fileName;
MappedFile file(tex.fileName);
+ updateTexture(tex, file);
+ return tex;
+}
+void Shark::Impl::updateTexture(Texture& tex, const Buffer& file) {
std::shared_ptr<ImageLoader::ImageBuffer> img(imageLoader.loadImage(file));
tex.width = img->width;
@@ -572,10 +577,9 @@
glTexParameteri(GLT2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GLT2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GLT2D);
- std::cerr << "loadTexture(\"" << fileName.c_str() << "\", "
+ std::cerr << "loadTexture(\"" << tex.fileName.c_str() << "\", "
<< tex.width << ", " << tex.height << ") = " << tex.id << std::endl;
checkError(&std::cerr);
- return tex;
}
void Shark::Impl::loadTextures() {
@@ -594,9 +598,10 @@
}
bool Shark::Impl::reloadTexture(const std::string& fileName) {
- for (const Configuration::Texture& tex : cfg.textures) {
+ for (Texture& tex : textures) {
if (tex.fileName == fileName) {
- logOutput << "TODO: reload texture: " << fileName.c_str() << "\n";
+ updateTexture(tex, MappedFile(fileName));
+ loadVertices();
return true;
}
}