# HG changeset patch # User František Kučera # Date 1703369441 -3600 # Node ID 717653cedc4ad4d6a9a3fda248c172a93a9a9433 # Parent 98d033d3ef7c63e3dc2a41e5e3adf29583acf8ea set scaling filters according to the texture file extended attributes (xattr: shader-shark.texture.mag-filter = linear | nearest) diff -r 98d033d3ef7c -r 717653cedc4a Shark.cpp --- a/Shark.cpp Sun Dec 10 22:23:32 2023 +0100 +++ b/Shark.cpp Sat Dec 23 23:10:41 2023 +0100 @@ -182,6 +182,7 @@ void log(LogLevel level, std::string message); int setNonBlocking(int fd); void loadVertices(); + void parametrizeTexture(std::shared_ptr tex); bool reloadTexture(const std::string& fileName); void loadTextures(); std::shared_ptr loadShaders(); @@ -488,6 +489,7 @@ void Shark::Impl::loadVertices() { for (int i = 0; i < textures.size(); i++) { std::shared_ptr tex = textures[i]; + // TODO: draw a rectangle for each texture GLfloat ratio = tex->getRatio(); const std::vector vertices = { // Vertex XYZ Texture XY @@ -499,7 +501,7 @@ +0.80f * ratio, -0.80f, +0.0, /**/ 1.0, 1.0, +0.80f * ratio, +0.80f, +0.0, /**/ 1.0, 0.0, - // viz glDrawArrays(), kde vybereme počátek a počet hodnot + // see glDrawArrays(), where we set start offset and count }; // Vertex data: @@ -544,6 +546,24 @@ } } +void Shark::Impl::parametrizeTexture(std::shared_ptr tex) { + XAttrs xa(tex->getFileName()); + std::string magf = xa["shader-shark.texture.mag-filter"]; + std::string minf = xa["shader-shark.texture.min-filter"]; + // TODO: std::string scale = xa["shader-shark.texture.scale"]; + // TODO: keep MappedFile locked until we read the attributes + + auto GLT2D = GL_TEXTURE_2D; + auto MAG = GL_TEXTURE_MAG_FILTER; + auto MIN = GL_TEXTURE_MIN_FILTER; + + if (magf == "linear") glTexParameteri(GLT2D, MAG, GL_LINEAR); + else if (magf == "nearest") glTexParameteri(GLT2D, MAG, GL_NEAREST); + + if (minf == "linear") glTexParameteri(GLT2D, MIN, GL_LINEAR); + else if (minf == "nearest") glTexParameteri(GLT2D, MIN, GL_NEAREST); +} + void Shark::Impl::loadTextures() { // Load default texture if there is no configured: if (cfg.textures.empty()) @@ -554,6 +574,7 @@ img(imageLoader.loadImage(MappedFile(tex.fileName))); textures.push_back(std::make_shared( img->width, img->height, *img, tex.fileName)); + parametrizeTexture(textures.back()); // static const uint32_t watchMask = IN_CLOSE_WRITE | IN_ATTRIB; // watchedFiles.push_back(fileMonitor.watch(tex.fileName, watchMask)); watchedFiles.push_back(fileMonitor.watch(tex.fileName)); @@ -570,6 +591,7 @@ std::shared_ptr img(imageLoader.loadImage(MappedFile(fileName))); tex->update(img->width, img->height, *img); + parametrizeTexture(tex); loadVertices(); return true; }