Luanti 5.16.0-dev
Loading...
Searching...
No Matches
imagesource.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <IImage.h>
8#include <unordered_map>
9#include <set>
10#include <string>
11
12
13// This file is only used for internal generation of images.
14// Use texturesource.h to handle textures.
15
16// A cache used for storing source images.
17// (A "source image" is an unmodified image directly taken from the filesystem.)
18// Does not contain modified images.
20public:
22
23 void insert(const std::string &name, video::IImage *img, bool prefer_local);
24
25 video::IImage* get(const std::string &name);
26
27 // Primarily fetches from cache, secondarily tries to read from filesystem.
28 video::IImage *getOrLoad(const std::string &name);
29private:
30 std::unordered_map<std::string, video::IImage*> m_images;
31};
32
33// Generates images using texture modifiers, and caches source images.
36
42 video::IImage* generateImage(std::string_view name, std::set<std::string> &source_image_names);
43
44 // Insert a source image into the cache without touching the filesystem.
45 void insertSourceImage(const std::string &name, video::IImage *img, bool prefer_local);
46
47 // This was picked so that the image buffer size fits in an s32 (assuming 32bpp).
48 // The exact value is 23170 but this provides some leeway.
49 // In theory something like 33333x123 could be allowed, but there is no strong
50 // need or argument. Irrlicht also has the same limit.
51 // IMPORTANT: If you change this value, you MUST also update the [imagesize]
52 // range in doc/lua_api.md.
53 static constexpr int MAX_IMAGE_DIMENSION = 23000;
54
55private:
56
57 // Generate image based on a string like "stone.png" or "[crack:1:0".
58 // If baseimg is NULL, it is created. Otherwise stuff is made on it.
59 // source_image_names is important to determine when to flush the image from a cache (dynamic media).
60 bool generateImagePart(std::string_view part_of_name, video::IImage *& baseimg,
61 std::set<std::string> &source_image_names);
62
63 // Cached settings needed for making textures from meshes
68
69 // Cache of source images
71};
Definition imagesource.h:19
video::IImage * get(const std::string &name)
Definition imagesource.cpp:65
void insert(const std::string &name, video::IImage *img, bool prefer_local)
Definition imagesource.cpp:32
video::IImage * getOrLoad(const std::string &name)
Definition imagesource.cpp:74
~SourceImageCache()
Definition imagesource.cpp:25
std::unordered_map< std::string, video::IImage * > m_images
Definition imagesource.h:30
bool m_setting_mipmap
Definition imagesource.h:64
bool m_setting_anisotropic_filter
Definition imagesource.h:67
bool generateImagePart(std::string_view part_of_name, video::IImage *&baseimg, std::set< std::string > &source_image_names)
Definition imagesource.cpp:982
video::IImage * generateImage(std::string_view name, std::set< std::string > &source_image_names)
Definition imagesource.cpp:1809
ImageSource()
Definition imagesource.cpp:1802
static constexpr int MAX_IMAGE_DIMENSION
Definition imagesource.h:53
SourceImageCache m_sourcecache
Definition imagesource.h:70
bool m_setting_bilinear_filter
Definition imagesource.h:66
void insertSourceImage(const std::string &name, video::IImage *img, bool prefer_local)
Definition imagesource.cpp:1922
bool m_setting_trilinear_filter
Definition imagesource.h:65