texture.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 "../api_display.h"
34 #include <memory>
35 #include "../../Core/IOData/file_system.h"
36 #include "../../Core/Resources/resource.h"
37 #include "graphic_context.h"
38 #include "../Image/image_import_description.h"
39 #include "../Image/texture_format.h"
40 
41 namespace clan
42 {
45 
46 class Color;
47 class Point;
48 class PixelBuffer;
49 class PixelBufferSet;
50 class PixelFormat;
51 class TextureProvider;
52 class DataBuffer;
53 class Texture1D;
54 class Texture1DArray;
55 class Texture2D;
56 class Texture2DArray;
57 class Texture3D;
58 class TextureCube;
59 class TextureCubeArray;
60 class Texture_Impl;
61 class SharedGCData_Impl;
62 class ResourceManager;
63 class XMLResourceDocument;
64 
67 {
71 };
72 
75 {
82 };
83 
86 {
89 };
90 
93 {
101 };
102 
104 class CL_API_DISPLAY Texture
105 {
108 public:
110  Texture();
111 
113  Texture(GraphicContext &gc, PixelBufferSet pixelbuffer_set);
114 
118  Texture(const std::shared_ptr<Texture_Impl> &impl);
119 
123  Texture(TextureProvider *provider);
124 
125  virtual ~Texture();
127 
130 public:
136  static Resource<Texture> resource(GraphicContext &gc, const std::string &id, const ResourceManager &resources);
137 
139  static Texture load(GraphicContext &gc, const std::string &id, const XMLResourceDocument &doc);
141 
144 public:
146  bool operator==(const Texture &other) const
147  {
148  return impl==other.impl;
149  }
150 
152  bool operator!=(const Texture &other) const
153  {
154  return impl!=other.impl;
155  }
156 
158  bool operator<(const Texture &other) const
159  {
160  return impl < other.impl;
161  }
163 
166 public:
168  bool is_null() const { return !impl; }
169 
171  void throw_if_null() const;
172 
174  float get_min_lod() const;
175 
177  float get_max_lod() const;
178 
180  float get_lod_bias() const;
181 
183  int get_base_level() const;
184 
186  int get_max_level() const;
187 
189  TextureFilter get_min_filter() const;
190 
192  TextureFilter get_mag_filter() const;
193 
195  bool is_resident() const;
196 
198  TextureCompareMode get_compare_mode() const;
199 
201  CompareFunction get_compare_function() const;
202 
206  TextureProvider *get_provider() const;
207 
211  std::weak_ptr<Texture_Impl> get_impl() const;
213 
216 public:
218  void generate_mipmap();
219 
221  void set_min_lod(float min_lod);
222 
224  void set_max_lod(float max_lod);
225 
227  void set_lod_bias(float lod_bias);
228 
230  void set_base_level(int base_level);
231 
233  void set_max_level(int max_level);
234 
236  void set_min_filter(TextureFilter filter);
237 
239  void set_mag_filter(TextureFilter filter);
240 
242  void set_max_anisotropy(float max_anisotropy);
243 
245  void set_texture_compare(TextureCompareMode mode, CompareFunction func);
246 
248  Texture1D to_texture_1d() const;
249 
251  Texture1DArray to_texture_1d_array() const;
252 
254  Texture2D to_texture_2d() const;
255 
257  Texture2DArray to_texture_2d_array() const;
258 
260  Texture3D to_texture_3d() const;
261 
263  TextureCube to_texture_cube() const;
264 
266  TextureCubeArray to_texture_cube_array() const;
268 
271 protected:
272  std::shared_ptr<Texture_Impl> impl;
273 
274  friend class Texture2DArray;
276 };
277 
278 }
279 
3D texture object class.
Definition: texture_3d.h:42
bool is_null() const
Returns true if this object is invalid.
Definition: texture.h:168
Definition: texture.h:99
Definition: texture.h:77
Definition: texture.h:98
Resource proxy of a specific type.
Definition: resource.h:59
TextureFilter
Texture filters.
Definition: texture.h:74
Definition: texture.h:69
Definition: texture.h:94
TextureWrapMode
Texture coordinate wrapping modes.
Definition: texture.h:66
Texture object class.
Definition: texture.h:104
TextureDimensions
Texture dimensions.
Definition: texture.h:92
bool operator==(const Texture &other) const
Equality operator.
Definition: texture.h:146
Definition: texture.h:76
1D texture array object class.
Definition: texture_1d_array.h:42
bool operator<(const Texture &other) const
Less than operator.
Definition: texture.h:158
Definition: texture.h:70
2D texture cube object class.
Definition: texture_cube.h:53
bool operator!=(const Texture &other) const
Inequality operator.
Definition: texture.h:152
TextureCompareMode
Texture compare modes.
Definition: texture.h:85
Set of images that combined form a complete texture.
Definition: pixel_buffer_set.h:47
Definition: texture.h:78
2D texture object class.
Definition: texture_2d.h:42
Definition: texture.h:68
Definition: texture.h:80
std::shared_ptr< Texture_Impl > impl
Definition: texture.h:272
Resource manager.
Definition: resource_manager.h:45
Definition: texture.h:100
Definition: texture.h:81
Interface for implementing a Texture target.
Definition: texture_provider.h:51
2D texture cube array object class.
Definition: texture_cube_array.h:42
Interface to drawing graphics.
Definition: graphic_context.h:257
Definition: texture.h:96
Definition: texture.h:79
CompareFunction
Compare functions.
Definition: graphic_context.h:93
XML Resource Document.
Definition: xml_resource_document.h:49
Definition: texture.h:87
1D texture object class.
Definition: texture_1d.h:42
2D texture array object class.
Definition: texture_2d_array.h:44
Definition: texture.h:95
Definition: texture.h:97