texture.h Source File - ClanLib SDK
Description: texture.h Source File

texture.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 The ClanLib Team
4**
5** This software is provided 'as-is', without any express or implied
6** warranty. In no event will the authors be held liable for any damages
7** arising from the use of this software.
8**
9** Permission is granted to anyone to use this software for any purpose,
10** including commercial applications, and to alter it and redistribute it
11** freely, subject to the following restrictions:
12**
13** 1. The origin of this software must not be misrepresented; you must not
14** claim that you wrote the original software. If you use this software
15** in a product, an acknowledgment in the product documentation would be
16** appreciated but is not required.
17** 2. Altered source versions must be plainly marked as such, and must not be
18** misrepresented as being the original software.
19** 3. This notice may not be removed or altered from any source distribution.
20**
21** Note: Some of the libraries ClanLib may link to may have additional
22** requirements or restrictions.
23**
24** File Author(s):
25**
26** Magnus Norddahl
27** Harry Storbacka
28*/
29
30#pragma once
31
32#include <memory>
33#include "../../Core/IOData/file_system.h"
34#include "../../Core/Resources/resource.h"
35#include "graphic_context.h"
36#include "../Image/image_import_description.h"
37#include "../Image/texture_format.h"
38
39namespace clan
40{
43
44 class Color;
45 class Point;
46 class PixelBuffer;
47 class PixelBufferSet;
48 class PixelFormat;
49 class TextureProvider;
50 class DataBuffer;
51 class Texture1D;
52 class Texture1DArray;
53 class Texture2D;
54 class Texture2DArray;
55 class Texture3D;
56 class TextureCube;
57 class TextureCubeArray;
58 class Texture_Impl;
59 class SharedGCData_Impl;
60 class ResourceManager;
61 class XMLResourceDocument;
62
64 enum class TextureWrapMode
65 {
66 clamp_to_edge,
67 repeat,
68 mirrored_repeat
69 };
70
72 enum class TextureFilter
73 {
74 nearest,
75 linear,
76 nearest_mipmap_nearest,
77 nearest_mipmap_linear,
78 linear_mipmap_nearest,
79 linear_mipmap_linear
80 };
81
83 enum class TextureCompareMode
84 {
85 none,
86 compare_r_to_texture
87 };
88
90 enum class TextureDimensions
91 {
92 _1d,
93 _1d_array,
94 _2d,
95 _2d_array,
96 _3d,
97 _cube,
98 _cube_array
99 };
100
102 class Texture
103 {
104 public:
106 Texture();
107
109 Texture(GraphicContext &gc, PixelBufferSet pixelbuffer_set);
110
114 Texture(const std::shared_ptr<Texture_Impl> &impl);
115
119 Texture(std::unique_ptr<TextureProvider> provider);
120
121 virtual ~Texture();
122
128 static Resource<Texture> resource(GraphicContext &gc, const std::string &id, const ResourceManager &resources);
129
131 static Texture load(GraphicContext &gc, const std::string &id, const XMLResourceDocument &doc, const ImageImportDescription &import_desc = ImageImportDescription());
132
134 bool operator==(const Texture &other) const
135 {
136 return impl == other.impl;
137 }
138
140 bool operator!=(const Texture &other) const
141 {
142 return impl != other.impl;
143 }
144
146 bool operator<(const Texture &other) const
147 {
148 return impl < other.impl;
149 }
150
152 bool is_null() const { return !impl; }
153 explicit operator bool() const { return bool(impl); }
154
156 void throw_if_null() const;
157
159 float get_min_lod() const;
160
162 float get_max_lod() const;
163
165 float get_lod_bias() const;
166
168 int get_base_level() const;
169
171 int get_max_level() const;
172
174 TextureFilter get_min_filter() const;
175
177 TextureFilter get_mag_filter() const;
178
180 bool is_resident() const;
181
183 TextureCompareMode get_compare_mode() const;
184
186 CompareFunction get_compare_function() const;
187
191 TextureProvider *get_provider() const;
192
196 std::weak_ptr<Texture_Impl> get_impl() const;
197
199 void generate_mipmap();
200
202 void set_min_lod(float min_lod);
203
205 void set_max_lod(float max_lod);
206
208 void set_lod_bias(float lod_bias);
209
211 void set_base_level(int base_level);
212
214 void set_max_level(int max_level);
215
217 void set_min_filter(TextureFilter filter);
218
220 void set_mag_filter(TextureFilter filter);
221
223 void set_max_anisotropy(float max_anisotropy);
224
226 void set_texture_compare(TextureCompareMode mode, CompareFunction func);
227
229 Texture1D to_texture_1d() const;
230
232 Texture1DArray to_texture_1d_array() const;
233
235 Texture2D to_texture_2d() const;
236
238 Texture2DArray to_texture_2d_array() const;
239
241 Texture3D to_texture_3d() const;
242
244 TextureCube to_texture_cube() const;
245
247 TextureCubeArray to_texture_cube_array() const;
248
249 protected:
250 std::shared_ptr<Texture_Impl> impl;
251
252 friend class Texture2DArray;
253 };
254
256}
clan::Color
Color description class.
Definition color.h:46
clan::DataBuffer
General purpose data buffer.
Definition databuffer.h:42
clan::GraphicContext
Interface to drawing graphics.
Definition graphic_context.h:257
clan::ImageImportDescription
Image Import Description Class.
Definition image_import_description.h:48
clan::PixelBufferSet
Set of images that combined form a complete texture.
Definition pixel_buffer_set.h:46
clan::PixelBuffer
Pixel data container.
Definition pixel_buffer.h:68
clan::Point
2D (x,y) point structure - Integer
Definition point.h:62
clan::ResourceManager
Resource manager.
Definition resource_manager.h:44
clan::Resource
Resource proxy of a specific type.
Definition resource.h:58
clan::Texture1DArray
1D texture array object class.
Definition texture_1d_array.h:41
clan::Texture1D
1D texture object class.
Definition texture_1d.h:41
clan::Texture2DArray
2D texture array object class.
Definition texture_2d_array.h:43
clan::Texture2D
2D texture object class.
Definition texture_2d.h:41
clan::Texture3D
3D texture object class.
Definition texture_3d.h:41
clan::TextureCubeArray
2D texture cube array object class.
Definition texture_cube_array.h:41
clan::TextureCube
2D texture cube object class.
Definition texture_cube.h:52
clan::TextureProvider
Interface for implementing a Texture target.
Definition texture_provider.h:50
clan::Texture::operator!=
bool operator!=(const Texture &other) const
Inequality operator.
Definition texture.h:140
clan::Texture::impl
std::shared_ptr< Texture_Impl > impl
Definition texture.h:250
clan::Texture::get_lod_bias
float get_lod_bias() const
Get the level of detail bias constant.
clan::Texture::Texture
Texture(GraphicContext &gc, PixelBufferSet pixelbuffer_set)
Constructs a texture as described in a pixelbuffer set.
clan::Texture::set_min_filter
void set_min_filter(TextureFilter filter)
Set the minification filter.
clan::Texture::is_resident
bool is_resident() const
Returns true if texture is resident in texture memory.
clan::Texture::to_texture_cube_array
TextureCubeArray to_texture_cube_array() const
Dynamic cast to TextureCubeArray.
clan::Texture::get_impl
std::weak_ptr< Texture_Impl > get_impl() const
Get the implementation weakptr.
clan::Texture::resource
static Resource< Texture > resource(GraphicContext &gc, const std::string &id, const ResourceManager &resources)
Retrieves a Texture resource from the resource manager.
clan::Texture::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::Texture::get_compare_function
CompareFunction get_compare_function() const
Get the texture compare function.
clan::Texture::set_texture_compare
void set_texture_compare(TextureCompareMode mode, CompareFunction func)
Sets the texture compare mode and compare function texture parameters.
clan::Texture::operator==
bool operator==(const Texture &other) const
Equality operator.
Definition texture.h:134
clan::Texture::load
static Texture load(GraphicContext &gc, const std::string &id, const XMLResourceDocument &doc, const ImageImportDescription &import_desc=ImageImportDescription())
Loads a Texture from a XML resource definition.
clan::Texture::to_texture_2d_array
Texture2DArray to_texture_2d_array() const
Dynamic cast to Texture2DArray.
clan::Texture::set_max_anisotropy
void set_max_anisotropy(float max_anisotropy)
Set the maximum degree of anisotropy.
clan::Texture::to_texture_2d
Texture2D to_texture_2d() const
Dynamic cast to Texture2D.
clan::Texture::get_min_lod
float get_min_lod() const
Get the minimum level of detail.
clan::Texture::get_max_level
int get_max_level() const
Get the texture max level.
clan::Texture::Texture
Texture(std::unique_ptr< TextureProvider > provider)
Constructs a texture from a texture provider.
clan::Texture::Texture
Texture(const std::shared_ptr< Texture_Impl > &impl)
Constructs a texture from an implementation.
clan::Texture::to_texture_1d_array
Texture1DArray to_texture_1d_array() const
Dynamic cast to Texture1DArray.
clan::Texture::get_mag_filter
TextureFilter get_mag_filter() const
Get the texture magnification filter.
clan::Texture::set_max_lod
void set_max_lod(float max_lod)
Set the maximum level of detail texture parameter.
clan::Texture::set_mag_filter
void set_mag_filter(TextureFilter filter)
Set the magnification filter.
clan::Texture::set_min_lod
void set_min_lod(float min_lod)
Set the minimum level of detail texture parameter.
clan::Texture::set_base_level
void set_base_level(int base_level)
Sets the texture base level texture parameter.
clan::Texture::operator<
bool operator<(const Texture &other) const
Less than operator.
Definition texture.h:146
clan::Texture::set_max_level
void set_max_level(int max_level)
Sets the texture max level texture parameter.
clan::Texture::Texture
Texture()
Constructs a null instance.
clan::Texture::get_max_lod
float get_max_lod() const
Get the maximum level of detail.
clan::Texture::get_compare_mode
TextureCompareMode get_compare_mode() const
Get the texture compare mode.
clan::Texture::to_texture_3d
Texture3D to_texture_3d() const
Dynamic cast to Texture3D.
clan::Texture::get_provider
TextureProvider * get_provider() const
Get Provider.
clan::Texture::get_min_filter
TextureFilter get_min_filter() const
Get the texture minification filter.
clan::Texture::to_texture_cube
TextureCube to_texture_cube() const
Dynamic cast to TextureCube.
clan::Texture::generate_mipmap
void generate_mipmap()
Generate the mipmap.
clan::Texture::is_null
bool is_null() const
Returns true if this object is invalid.
Definition texture.h:152
clan::Texture::~Texture
virtual ~Texture()
clan::Texture::get_base_level
int get_base_level() const
Get the texture base level.
clan::Texture::to_texture_1d
Texture1D to_texture_1d() const
Dynamic cast to Texture1D.
clan::Texture::Texture2DArray
friend class Texture2DArray
Definition texture.h:252
clan::Texture::set_lod_bias
void set_lod_bias(float lod_bias)
Sets the level of detail bias constant.
clan::XMLResourceDocument
XML Resource Document.
Definition xml_resource_document.h:48
clan::CompareFunction
CompareFunction
Compare functions.
Definition graphic_context.h:92
clan::TextureDimensions
TextureDimensions
Texture dimensions.
Definition texture.h:91
clan::TextureCompareMode
TextureCompareMode
Texture compare modes.
Definition texture.h:84
clan::TextureFilter
TextureFilter
Texture filters.
Definition texture.h:73
clan::TextureWrapMode
TextureWrapMode
Texture coordinate wrapping modes.
Definition texture.h:65
clan::TextureDimensions::_2d_array
@ _2d_array
Definition texture.h:95
clan::TextureDimensions::_1d
@ _1d
Definition texture.h:92
clan::TextureDimensions::_3d
@ _3d
Definition texture.h:96
clan::TextureDimensions::_1d_array
@ _1d_array
Definition texture.h:93
clan::TextureDimensions::_cube
@ _cube
Definition texture.h:97
clan::TextureDimensions::_2d
@ _2d
Definition texture.h:94
clan::TextureDimensions::_cube_array
@ _cube_array
Definition texture.h:98
clan::TextureCompareMode::compare_r_to_texture
@ compare_r_to_texture
Definition texture.h:86
clan::DrawBuffer::none
@ none
Definition graphic_context.h:119
clan::TextureFilter::linear_mipmap_linear
@ linear_mipmap_linear
Definition texture.h:79
clan::TextureFilter::nearest_mipmap_nearest
@ nearest_mipmap_nearest
Definition texture.h:76
clan::TextureFilter::linear_mipmap_nearest
@ linear_mipmap_nearest
Definition texture.h:78
clan::TextureFilter::nearest_mipmap_linear
@ nearest_mipmap_linear
Definition texture.h:77
clan::TextureWrapMode::mirrored_repeat
@ mirrored_repeat
Definition texture.h:68
clan::TextureWrapMode::repeat
@ repeat
Definition texture.h:67
clan::TextureWrapMode::clamp_to_edge
@ clamp_to_edge
Definition texture.h:66
clan
Definition clanapp.h:36
clan::BrushInterpolateMode::nearest
@ nearest
Definition brush.h:66
clan::BrushType::linear
@ linear
Definition brush.h:52