ClanLib  2.3.7
texture.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 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 
32 
33 #pragma once
34 
35 #include "../api_display.h"
36 #include "../../Core/System/sharedptr.h"
37 #include "../../Core/Text/string_types.h"
38 #include "../../Core/IOData/virtual_directory.h"
39 #include "../../Core/Resources/resource_data_session.h"
40 #include "graphic_context.h"
41 #include "compare_function.h"
42 #include "../Image/image_import_description.h"
43 #include "../Image/texture_format.h"
44 
45 class CL_Color;
46 class CL_Point;
47 class CL_PixelBuffer;
48 class CL_PixelFormat;
49 class CL_TextureProvider;
50 class CL_DataBuffer;
51 class CL_Texture_Impl;
52 class CL_SharedGCData_Impl;
53 
58 {
62 };
63 
68 {
75 };
76 
81 {
84 };
85 
90 {
95 };
96 
101 {
104 public:
106  CL_Texture();
107 
112  CL_Texture(CL_GraphicContext &context, CL_TextureDimensions texture_dimensions);
113 
120  CL_Texture(CL_GraphicContext &context, int width, int height, CL_TextureFormat internal_format = cl_rgba);
121 
129  CL_Texture(CL_GraphicContext &context, int width, int height, int depth, CL_TextureFormat internal_format = cl_rgba);
130 
136  CL_Texture(CL_GraphicContext &context, const CL_Size &size, CL_TextureFormat internal_format = cl_rgba);
137 
138  CL_Texture(
139  CL_GraphicContext &context,
140  const CL_StringRef &fullname, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
141 
142  CL_Texture(
143  CL_GraphicContext &context,
144  const CL_StringRef &filename,
145  const CL_VirtualDirectory &directory, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
146 
147  CL_Texture(
148  CL_GraphicContext &context,
149  CL_IODevice &file, const CL_String &image_type, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
150 
151  CL_Texture(
152  CL_GraphicContext &gc,
153  const CL_StringRef &resource_id,
154  CL_ResourceManager *resources,
155  const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
156 
160  CL_Texture(CL_SharedPtr<CL_Texture_Impl> &impl);
161 
162  virtual ~CL_Texture();
163 
167 public:
169  bool operator==(const CL_Texture &other) const
170  {
171  return impl==other.impl;
172  }
173 
175  bool operator!=(const CL_Texture &other) const
176  {
177  return impl!=other.impl;
178  }
179 
181  bool operator<(const CL_Texture &other) const
182  {
183  return impl < other.impl;
184  }
185 
189 public:
191  bool is_null() const { return !impl; }
192 
194  void throw_if_null() const;
195 
197  int get_width() const;
198 
200  int get_height() const;
201 
203  CL_Size get_size() const;
204 
206  int get_depth() const;
207 
209  CL_PixelBuffer get_pixeldata(int level = 0) const;
210 
217  CL_PixelBuffer get_pixeldata(CL_TextureFormat sized_format, int level = 0) const;
218 
220  float get_min_lod() const;
221 
223  float get_max_lod() const;
224 
226  float get_lod_bias() const;
227 
229  int get_base_level() const;
230 
232  int get_max_level() const;
233 
235  CL_TextureWrapMode get_wrap_mode_s() const;
236 
238  CL_TextureWrapMode get_wrap_mode_t() const;
239 
241  CL_TextureWrapMode get_wrap_mode_r() const;
242 
244  CL_TextureFilter get_min_filter() const;
245 
247  CL_TextureFilter get_mag_filter() const;
248 
250  bool is_resident() const;
251 
253  CL_TextureCompareMode get_compare_mode() const;
254 
256  CL_CompareFunction get_compare_function() const;
257 
261  CL_TextureProvider *get_provider() const;
262 
266  CL_WeakPtr<CL_Texture_Impl> get_impl() const;
267 
271 public:
273  void generate_mipmap();
274 
279  void set_image(
280  CL_PixelBuffer &image,
281  int level = 0);
282 
284  void set_cube_map(
285  CL_PixelBuffer &cube_map_positive_x,
286  CL_PixelBuffer &cube_map_negative_x,
287  CL_PixelBuffer &cube_map_positive_y,
288  CL_PixelBuffer &cube_map_negative_y,
289  CL_PixelBuffer &cube_map_positive_z,
290  CL_PixelBuffer &cube_map_negative_z,
291  int level = 0);
292 
293  void set_compressed_image(
294  int level,
295  CL_TextureFormat internal_format,
296  int width,
297  int height,
298  CL_DataBuffer &image);
299 
304  void set_subimage(
305  int x,
306  int y,
307  const CL_PixelBuffer &image,
308  const CL_Rect &src_rect,
309  int level = 0);
310 
311  void set_subimage(
312  const CL_Point &point,
313  const CL_PixelBuffer &image,
314  const CL_Rect &src_rect,
315  int level = 0);
316 
318  void copy_image_from(
319  CL_GraphicContext &context,
320  int level,
321  CL_TextureFormat internal_format = cl_rgba);
322 
323  void copy_image_from(
324  CL_GraphicContext &context,
325  int x,
326  int y,
327  int width,
328  int height,
329  int level = 0,
330  CL_TextureFormat internal_format = cl_rgba);
331 
332  void copy_image_from(
333  CL_GraphicContext &context,
334  const CL_Rect &pos,
335  int level = 0,
336  CL_TextureFormat internal_format = cl_rgba);
337 
339  void copy_subimage_from(
340  CL_GraphicContext &context,
341  int offset_x,
342  int offset_y,
343  int x,
344  int y,
345  int width,
346  int height,
347  int level = 0);
348 
349  void copy_subimage_from(
350  CL_GraphicContext &context,
351  const CL_Point &offset,
352  const CL_Rect &pos,
353  int level = 0);
354 
356  void set_min_lod(float min_lod);
357 
359  void set_max_lod(float max_lod);
360 
362  void set_lod_bias(float lod_bias);
363 
365  void set_base_level(int base_level);
366 
368  void set_max_level(int max_level);
369 
371  void set_wrap_mode(
372  CL_TextureWrapMode wrap_s,
373  CL_TextureWrapMode wrap_t,
374  CL_TextureWrapMode wrap_r);
375 
376  void set_wrap_mode(
377  CL_TextureWrapMode wrap_s,
378  CL_TextureWrapMode wrap_t);
379 
380  void set_wrap_mode(
381  CL_TextureWrapMode wrap_s);
382 
384  void set_min_filter(CL_TextureFilter filter);
385 
387  void set_mag_filter(CL_TextureFilter filter);
388 
390  void set_max_anisotropy(float max_anisotropy);
391 
393  void set_texture_compare(CL_TextureCompareMode mode, CL_CompareFunction func);
394 
398 private:
399  CL_SharedPtr<CL_Texture_Impl> impl;
401 };
402