Minetest 5.10.0-dev
 
Loading...
Searching...
No Matches
imagesource.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include <IImage.h>
23#include <string>
24#include "settings.h"
25
26// This file is only used for internal generation of images.
27// Use texturesource.h to handle textures.
28
29// A cache used for storing source images.
30// (A "source image" is an unmodified image directly taken from the filesystem.)
31// Does not contain modified images.
33public:
35
36 void insert(const std::string &name, video::IImage *img, bool prefer_local);
37
38 video::IImage* get(const std::string &name);
39
40 // Primarily fetches from cache, secondarily tries to read from filesystem.
41 video::IImage *getOrLoad(const std::string &name);
42private:
43 std::map<std::string, video::IImage*> m_images;
44};
45
46// Generates images using texture modifiers, and caches source images.
53 video::IImage* generateImage(std::string_view name, std::set<std::string> &source_image_names);
54
55 // Insert a source image into the cache without touching the filesystem.
56 void insertSourceImage(const std::string &name, video::IImage *img, bool prefer_local);
57
58 // TODO should probably be moved elsewhere
59 static video::SColor getImageAverageColor(const video::IImage &image);
60
62 m_setting_mipmap{g_settings->getBool("mip_map")},
63 m_setting_trilinear_filter{g_settings->getBool("trilinear_filter")},
64 m_setting_bilinear_filter{g_settings->getBool("bilinear_filter")},
65 m_setting_anisotropic_filter{g_settings->getBool("anisotropic_filter")}
66 {};
67
68private:
69
70 // Generate image based on a string like "stone.png" or "[crack:1:0".
71 // If baseimg is NULL, it is created. Otherwise stuff is made on it.
72 // source_image_names is important to determine when to flush the image from a cache (dynamic media).
73 bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg,
74 std::set<std::string> &source_image_names);
75
76 // Cached settings needed for making textures from meshes
81
82 // Cache of source images
84};
Definition imagesource.h:32
video::IImage * get(const std::string &name)
Definition imagesource.cpp:79
void insert(const std::string &name, video::IImage *img, bool prefer_local)
Definition imagesource.cpp:45
video::IImage * getOrLoad(const std::string &name)
Definition imagesource.cpp:89
~SourceImageCache()
Definition imagesource.cpp:38
std::map< std::string, video::IImage * > m_images
Definition imagesource.h:43
Settings * g_settings
Definition settings.cpp:37
Definition imagesource.h:47
static video::SColor getImageAverageColor(const video::IImage &image)
Definition imagesource.cpp:1945
bool m_setting_mipmap
Definition imagesource.h:77
bool m_setting_anisotropic_filter
Definition imagesource.h:80
bool generateImagePart(std::string_view part_of_name, video::IImage *&baseimg, std::set< std::string > &source_image_names)
Definition imagesource.cpp:1015
video::IImage * generateImage(std::string_view name, std::set< std::string > &source_image_names)
Definition imagesource.cpp:1834
ImageSource()
Definition imagesource.h:61
SourceImageCache m_sourcecache
Definition imagesource.h:83
bool m_setting_bilinear_filter
Definition imagesource.h:79
void insertSourceImage(const std::string &name, video::IImage *img, bool prefer_local)
Definition imagesource.cpp:1971
bool m_setting_trilinear_filter
Definition imagesource.h:78