Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
texturesource.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 "irrlichttypes.h"
8#include <SColor.h>
9#include <dimension2d.h>
10#include <string>
11#include <vector>
12
13namespace video
14{
15 class IImage;
16 class ITexture;
17}
18
19typedef std::vector<video::SColor> Palette;
20
21/*
22 TextureSource creates and caches textures, which are created from images.
23
24 Terminology:
25 texture string = e.g. "dirt.png^grass_side.png"
26 texture name = can be the same as the texture string
27 or something abstract like "<texture12>"
28 texture ID = unique numeric identifier for a texture
29 standard texture = refers to a normal 2D texture as you would expect.
30 depending on the support, 2D array textures can exist too.
31*/
32
34{
35public:
37 virtual ~ISimpleTextureSource() = default;
38
40 virtual video::ITexture *getTexture(
41 const std::string &name, u32 *id = nullptr) = 0;
42};
43
45{
46public:
47 ITextureSource() = default;
48 virtual ~ITextureSource() = default;
49
51
54 virtual u32 getTextureId(const std::string &image)=0;
55
58 virtual std::string getTextureName(u32 id)=0;
59
61 virtual video::ITexture *getTexture(u32 id)=0;
62
66 virtual video::ITexture *addArrayTexture(
67 const std::vector<std::string> &images, u32 *id = nullptr) = 0;
68
75 inline video::ITexture *getTextureForMesh(
76 const std::string &image, u32 *id = nullptr)
77 {
78 if (needFilterForMesh() && !image.empty())
79 return getTexture(image + FILTER_FOR_MESH, id);
80 return getTexture(image, id);
81 }
82
84 virtual bool needFilterForMesh() const = 0;
85
87 static constexpr const char *FILTER_FOR_MESH = "^[applyfiltersformesh";
88
95 virtual Palette *getPalette(const std::string &image) = 0;
96
98 virtual bool isKnownSourceImage(const std::string &name)=0;
99
102 virtual core::dimension2du getTextureDimensions(const std::string &image)=0;
103
105 virtual video::SColor getTextureAverageColor(const std::string &image)=0;
106
107 // Note: this method is here because caching is the decision of the
108 // API user, even if his access is read-only.
109
116 virtual void setImageCaching(bool enabled) {};
117};
118
120{
121public:
123 virtual ~IWritableTextureSource() = default;
124
126 virtual void processQueue()=0;
127
132 virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
133
139 virtual void rebuildImagesAndTextures()=0;
140};
141
Definition texturesource.h:34
virtual ~ISimpleTextureSource()=default
virtual video::ITexture * getTexture(const std::string &name, u32 *id=nullptr)=0
Generates a texture string into a standard texture.
ISimpleTextureSource()=default
Definition texturesource.h:45
ITextureSource()=default
virtual video::ITexture * getTexture(u32 id)=0
Returns existing texture by ID.
virtual std::string getTextureName(u32 id)=0
Returns name of existing texture by ID.
static constexpr const char * FILTER_FOR_MESH
Filter needed for mesh-suitable textures, including leading ^.
Definition texturesource.h:87
virtual void setImageCaching(bool enabled)
Enables or disables the caching of finished texture images.
Definition texturesource.h:116
virtual video::SColor getTextureAverageColor(const std::string &image)=0
Return average color of a texture string.
video::ITexture * getTextureForMesh(const std::string &image, u32 *id=nullptr)
Generates a texture string into a standard texture Filters will be applied to make the texture suitab...
Definition texturesource.h:75
virtual video::ITexture * addArrayTexture(const std::vector< std::string > &images, u32 *id=nullptr)=0
Generates texture string(s) into an array texture.
virtual u32 getTextureId(const std::string &image)=0
Generates a texture string into a standard texture.
virtual Palette * getPalette(const std::string &image)=0
Returns a palette from the given texture string.
virtual core::dimension2du getTextureDimensions(const std::string &image)=0
Return dimensions of a texture string (will avoid actually creating the texture)
virtual ~ITextureSource()=default
virtual bool needFilterForMesh() const =0
virtual bool isKnownSourceImage(const std::string &name)=0
Check if given image name exists.
Definition texturesource.h:120
virtual void insertSourceImage(const std::string &name, video::IImage *img)=0
Inserts a source image.
IWritableTextureSource()=default
virtual void processQueue()=0
Fulfil texture requests from other threads.
virtual ~IWritableTextureSource()=default
virtual void rebuildImagesAndTextures()=0
Rebuilds all textures (in case-source images have changed)
Definition clientmap.h:36
std::vector< video::SColor > Palette
Definition texturesource.h:19
IWritableTextureSource * createTextureSource()
Definition texturesource.cpp:182