texture.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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
31 #pragma once
32
33 #include <memory>
34 #include "../../Core/IOData/file_system.h"
35 #include "../../Core/Resources/resource.h"
36 #include "graphic_context.h"
37 #include "../Image/image_import_description.h"
38 #include "../Image/texture_format.h"
39
40 namespace clan
41 {
44
45 class Color;
46 class Point;
47 class PixelBuffer;
48 class PixelBufferSet;
49 class PixelFormat;
50 class TextureProvider;
51 class DataBuffer;
52 class Texture1D;
53 class Texture1DArray;
54 class Texture2D;
55 class Texture2DArray;
56 class Texture3D;
57 class TextureCube;
58 class TextureCubeArray;
59 class Texture_Impl;
60 class SharedGCData_Impl;
61 class ResourceManager;
62 class XMLResourceDocument;
63
65 enum TextureWrapMode
66 {
67 wrap_clamp_to_edge,
68 wrap_repeat,
69 wrap_mirrored_repeat
70 };
71
73 enum TextureFilter
74 {
75 filter_nearest,
76 filter_linear,
77 filter_nearest_mipmap_nearest,
78 filter_nearest_mipmap_linear,
79 filter_linear_mipmap_nearest,
80 filter_linear_mipmap_linear
81 };
82
84 enum TextureCompareMode
85 {
86 comparemode_none,
87 comparemode_compare_r_to_texture
88 };
89
91 enum TextureDimensions
92 {
93 texture_1d,
94 texture_1d_array,
95 texture_2d,
96 texture_2d_array,
97 texture_3d,
98 texture_cube,
99 texture_cube_array
100 };
101
103 class Texture
104 {
107 public:
109 Texture();
110
112 Texture(GraphicContext &gc, PixelBufferSet pixelbuffer_set);
113
117 Texture(const std::shared_ptr<Texture_Impl> &impl);
118
122 Texture(TextureProvider *provider);
123
124 virtual ~Texture();
126
129 public:
135 static Resource<Texture> resource(GraphicContext &gc, const std::string &id, const ResourceManager &resources);
136
138 static Texture load(GraphicContext &gc, const std::string &id, const XMLResourceDocument &doc, const ImageImportDescription &import_desc = ImageImportDescription());
140
143 public:
145 bool operator==(const Texture &other) const
146 {
147 return impl==other.impl;
148 }
149
151 bool operator!=(const Texture &other) const
152 {
153 return impl!=other.impl;
154 }
155
157 bool operator<(const Texture &other) const
158 {
159 return impl < other.impl;
160 }
162
165 public:
167 bool is_null() const { return !impl; }
168
170 void throw_if_null() const;
171
173 float get_min_lod() const;
174
176 float get_max_lod() const;
177
179 float get_lod_bias() const;
180
182 int get_base_level() const;
183
185 int get_max_level() const;
186
188 TextureFilter get_min_filter() const;
189
191 TextureFilter get_mag_filter() const;
192
194 bool is_resident() const;
195
197 TextureCompareMode get_compare_mode() const;
198
200 CompareFunction get_compare_function() const;
201
205 TextureProvider *get_provider() const;
206
210 std::weak_ptr<Texture_Impl> get_impl() const;
212
215 public:
217 void generate_mipmap();
218
220 void set_min_lod(float min_lod);
221
223 void set_max_lod(float max_lod);
224
226 void set_lod_bias(float lod_bias);
227
229 void set_base_level(int base_level);
230
232 void set_max_level(int max_level);
233
235 void set_min_filter(TextureFilter filter);
236
238 void set_mag_filter(TextureFilter filter);
239
241 void set_max_anisotropy(float max_anisotropy);
242
244 void set_texture_compare(TextureCompareMode mode, CompareFunction func);
245
247 Texture1D to_texture_1d() const;
248
250 Texture1DArray to_texture_1d_array() const;
251
253 Texture2D to_texture_2d() const;
254
256 Texture2DArray to_texture_2d_array() const;
257
259 Texture3D to_texture_3d() const;
260
262 TextureCube to_texture_cube() const;
263
265 TextureCubeArray to_texture_cube_array() const;
267
270 protected:
271 std::shared_ptr<Texture_Impl> impl;
272
273 friend class Texture2DArray;
275 };
276
277 }
278
clan::Texture::set_mag_filter
void set_mag_filter(TextureFilter filter)
Set the magnification filter.
clan::Texture3D
3D texture object class.
Definition: texture_3d.h:41
clan::Texture::is_null
bool is_null() const
Returns true if this object is invalid.
Definition: texture.h:167
clan::Texture::Texture
Texture()
Constructs a null instance.
clan
Definition: clanapp.h:35
clan::texture_cube
Definition: texture.h:98
clan::Texture::get_mag_filter
TextureFilter get_mag_filter() const
Get the texture magnification filter.
clan::filter_linear
Definition: texture.h:76
clan::Texture::set_max_lod
void set_max_lod(float max_lod)
Set the maximum level of detail texture parameter.
clan::Texture::set_min_lod
void set_min_lod(float min_lod)
Set the minimum level of detail texture parameter.
clan::texture_3d
Definition: texture.h:97
clan::Resource
Resource proxy of a specific type.
Definition: resource.h:58
clan::Texture::is_resident
bool is_resident() const
Returns true if texture is resident in texture memory.
clan::TextureFilter
TextureFilter
Texture filters.
Definition: texture.h:73
clan::Texture::set_max_anisotropy
void set_max_anisotropy(float max_anisotropy)
Set the maximum degree of anisotropy.
clan::wrap_repeat
Definition: texture.h:68
clan::texture_1d
Definition: texture.h:93
clan::TextureWrapMode
TextureWrapMode
Texture coordinate wrapping modes.
Definition: texture.h:65
clan::Texture
Texture object class.
Definition: texture.h:103
clan::Texture::get_max_level
int get_max_level() const
Get the texture max level.
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::TextureDimensions
TextureDimensions
Texture dimensions.
Definition: texture.h:91
clan::comparemode_compare_r_to_texture
Definition: texture.h:87
clan::Texture::throw_if_null
void throw_if_null() const
Throw an exception if this object is invalid.
clan::ImageImportDescription
Image Import Description Class.
Definition: image_import_description.h:48
clan::Texture::get_max_lod
float get_max_lod() const
Get the maximum level of detail.
clan::Texture::operator==
bool operator==(const Texture &other) const
Equality operator.
Definition: texture.h:145
clan::filter_nearest
Definition: texture.h:75
clan::Texture::get_impl
std::weak_ptr< Texture_Impl > get_impl() const
Get the implementation weakptr.
clan::Texture1DArray
1D texture array object class.
Definition: texture_1d_array.h:41
clan::Texture::get_compare_function
CompareFunction get_compare_function() const
Get the texture compare function.
clan::Texture::set_max_level
void set_max_level(int max_level)
Sets the texture max level texture parameter.
clan::Texture::operator<
bool operator<(const Texture &other) const
Less than operator.
Definition: texture.h:157
clan::Texture::get_provider
TextureProvider * get_provider() const
Get Provider.
clan::Texture::generate_mipmap
void generate_mipmap()
Generate the mipmap.
clan::Texture::get_min_filter
TextureFilter get_min_filter() const
Get the texture minification filter.
clan::wrap_mirrored_repeat
Definition: texture.h:69
clan::Texture::set_base_level
void set_base_level(int base_level)
Sets the texture base level texture parameter.
clan::TextureCube
2D texture cube object class.
Definition: texture_cube.h:52
clan::StyleTokenType::string
@ keyword
clan::Texture::operator!=
bool operator!=(const Texture &other) const
Inequality operator.
Definition: texture.h:151
clan::Texture::to_texture_1d
Texture1D to_texture_1d() const
Dynamic cast to Texture1D.
clan::TextureCompareMode
TextureCompareMode
Texture compare modes.
Definition: texture.h:84
clan::PixelBufferSet
Set of images that combined form a complete texture.
Definition: pixel_buffer_set.h:46
clan::filter_nearest_mipmap_nearest
Definition: texture.h:77
clan::Texture2D
2D texture object class.
Definition: texture_2d.h:41
clan::wrap_clamp_to_edge
Definition: texture.h:67
clan::filter_linear_mipmap_nearest
Definition: texture.h:79
clan::Texture::impl
std::shared_ptr< Texture_Impl > impl
Definition: texture.h:271
clan::Texture::set_texture_compare
void set_texture_compare(TextureCompareMode mode, CompareFunction func)
Sets the texture compare mode and compare function texture parameters.
clan::ResourceManager
Resource manager.
Definition: resource_manager.h:44
clan::Texture::to_texture_1d_array
Texture1DArray to_texture_1d_array() const
Dynamic cast to Texture1DArray.
clan::Texture::to_texture_cube_array
TextureCubeArray to_texture_cube_array() const
Dynamic cast to TextureCubeArray.
clan::texture_cube_array
Definition: texture.h:99
clan::filter_linear_mipmap_linear
Definition: texture.h:80
clan::TextureProvider
Interface for implementing a Texture target.
Definition: texture_provider.h:50
clan::TextureCubeArray
2D texture cube array object class.
Definition: texture_cube_array.h:41
clan::Texture::~Texture
virtual ~Texture()
clan::GraphicContext
Interface to drawing graphics.
Definition: graphic_context.h:257
clan::texture_2d
Definition: texture.h:95
clan::filter_nearest_mipmap_linear
Definition: texture.h:78
clan::CompareFunction
CompareFunction
Compare functions.
Definition: graphic_context.h:92
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::get_base_level
int get_base_level() const
Get the texture base level.
clan::XMLResourceDocument
XML Resource Document.
Definition: xml_resource_document.h:48
clan::Texture::get_compare_mode
TextureCompareMode get_compare_mode() const
Get the texture compare mode.
clan::Texture::set_min_filter
void set_min_filter(TextureFilter filter)
Set the minification filter.
clan::Texture::to_texture_3d
Texture3D to_texture_3d() const
Dynamic cast to Texture3D.
clan::comparemode_none
Definition: texture.h:86
clan::Texture::set_lod_bias
void set_lod_bias(float lod_bias)
Sets the level of detail bias constant.
clan::Texture::get_lod_bias
float get_lod_bias() const
Get the level of detail bias constant.
clan::Texture::to_texture_cube
TextureCube to_texture_cube() const
Dynamic cast to TextureCube.
clan::Texture1D
1D texture object class.
Definition: texture_1d.h:41
clan::Texture::to_texture_2d_array
Texture2DArray to_texture_2d_array() const
Dynamic cast to Texture2DArray.
clan::Texture2DArray
2D texture array object class.
Definition: texture_2d_array.h:43
clan::Texture::to_texture_2d
Texture2D to_texture_2d() const
Dynamic cast to Texture2D.
clan::texture_1d_array
Definition: texture.h:94
clan::Texture::get_min_lod
float get_min_lod() const
Get the minimum level of detail.
clan::texture_2d_array
Definition: texture.h:96