# HG changeset patch # User František Kučera # Date 1701559068 -3600 # Node ID 076e3b2d97ac1fdd43c5f7516c56b67bfe3d4b90 # Parent 0aeedc35ebedd346afb133c3ab687102ede18410 monitor texture and shader file writes using inotify: reload textures diff -r 0aeedc35ebed -r 076e3b2d97ac Shark.cpp --- 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 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 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; } }