texture.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Harry Storbacka
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 #include "../api_display.h"
00036 #include "../../Core/System/sharedptr.h"
00037 #include "../../Core/Text/string_types.h"
00038 #include "../../Core/IOData/virtual_directory.h"
00039 #include "../../Core/Resources/resource_data_session.h"
00040 #include "graphic_context.h"
00041 #include "compare_function.h"
00042 #include "../Image/image_import_description.h"
00043 #include "../Image/texture_format.h"
00044 
00045 class CL_Color;
00046 class CL_Point;
00047 class CL_PixelBuffer;
00048 class CL_PixelFormat;
00049 class CL_TextureProvider;
00050 class CL_DataBuffer;
00051 class CL_Texture_Impl;
00052 class CL_SharedGCData_Impl;
00053 
00057 enum CL_TextureWrapMode
00058 {
00059         cl_wrap_clamp_to_edge,
00060         cl_wrap_repeat,
00061         cl_wrap_mirrored_repeat
00062 };
00063 
00067 enum CL_TextureFilter
00068 {
00069         cl_filter_nearest,
00070         cl_filter_linear,
00071         cl_filter_nearest_mipmap_nearest,
00072         cl_filter_nearest_mipmap_linear,
00073         cl_filter_linear_mipmap_nearest,
00074         cl_filter_linear_mipmap_linear
00075 };
00076 
00080 enum CL_TextureCompareMode
00081 {
00082         cl_comparemode_none,
00083         cl_comparemode_compare_r_to_texture
00084 };
00085 
00089 enum CL_TextureDimensions
00090 {
00091         cl_texture_1d,
00092         cl_texture_2d,
00093         cl_texture_3d,
00094         cl_texture_cube_map
00095 };
00096 
00100 class CL_API_DISPLAY CL_Texture
00101 {
00104 public:
00106         CL_Texture();
00107 
00112         CL_Texture(CL_GraphicContext &context, CL_TextureDimensions texture_dimensions);
00113 
00120         CL_Texture(CL_GraphicContext &context, int width, int height, CL_TextureFormat internal_format = cl_rgba);
00121 
00129         CL_Texture(CL_GraphicContext &context, int width, int height, int depth, CL_TextureFormat internal_format = cl_rgba);
00130 
00136         CL_Texture(CL_GraphicContext &context, const CL_Size &size, CL_TextureFormat internal_format = cl_rgba);
00137 
00138         CL_Texture(
00139                 CL_GraphicContext &context,
00140                 const CL_StringRef &fullname, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00141 
00142         CL_Texture(
00143                 CL_GraphicContext &context,
00144                 const CL_StringRef &filename,
00145                 const CL_VirtualDirectory &directory, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00146 
00147         CL_Texture(
00148                 CL_GraphicContext &context,
00149                 CL_IODevice &file, const CL_String &image_type, const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00150 
00151         CL_Texture(
00152                 CL_GraphicContext &gc,
00153                 const CL_StringRef &resource_id,
00154                 CL_ResourceManager *resources,
00155                 const CL_ImageImportDescription &import_desc = CL_ImageImportDescription ());
00156 
00160         CL_Texture(CL_SharedPtr<CL_Texture_Impl> &impl);
00161 
00162         virtual ~CL_Texture();
00163 
00167 public:
00169         bool operator==(const CL_Texture &other) const
00170         {
00171                 return impl==other.impl;
00172         }
00173 
00175         bool operator!=(const CL_Texture &other) const
00176         {
00177                 return impl!=other.impl;
00178         }
00179 
00181         bool operator<(const CL_Texture &other) const
00182         {
00183                 return impl < other.impl;
00184         }
00185 
00189 public:
00191         bool is_null() const { return !impl; }
00192 
00194         void throw_if_null() const;
00195 
00197         int get_width() const;
00198 
00200         int get_height() const;
00201 
00203         CL_Size get_size() const;
00204 
00206         int get_depth() const;
00207 
00209         CL_PixelBuffer get_pixeldata(int level = 0) const;
00210 
00217         CL_PixelBuffer get_pixeldata(CL_TextureFormat sized_format, int level = 0) const;
00218 
00220         float get_min_lod() const;
00221 
00223         float get_max_lod() const;
00224 
00226         float get_lod_bias() const;
00227 
00229         int get_base_level() const;
00230 
00232         int get_max_level() const;
00233 
00235         CL_TextureWrapMode get_wrap_mode_s() const;
00236 
00238         CL_TextureWrapMode get_wrap_mode_t() const;
00239 
00241         CL_TextureWrapMode get_wrap_mode_r() const;
00242 
00244         CL_TextureFilter get_min_filter() const;
00245 
00247         CL_TextureFilter get_mag_filter() const;
00248 
00250         bool is_resident() const;
00251 
00253         CL_TextureCompareMode get_compare_mode() const;
00254 
00256         CL_CompareFunction get_compare_function() const;
00257 
00261         CL_TextureProvider *get_provider() const;
00262 
00266         CL_WeakPtr<CL_Texture_Impl> get_impl() const;
00267 
00271 public:
00273         void generate_mipmap();
00274 
00279         void set_image(
00280                 CL_PixelBuffer &image,
00281                 int level = 0);
00282 
00284         void set_cube_map(
00285                 CL_PixelBuffer &cube_map_positive_x,
00286                 CL_PixelBuffer &cube_map_negative_x,
00287                 CL_PixelBuffer &cube_map_positive_y,
00288                 CL_PixelBuffer &cube_map_negative_y,
00289                 CL_PixelBuffer &cube_map_positive_z,
00290                 CL_PixelBuffer &cube_map_negative_z,
00291                 int level = 0);
00292 
00293         void set_compressed_image(
00294                 int level,
00295                 CL_TextureFormat internal_format,
00296                 int width,
00297                 int height,
00298                 CL_DataBuffer &image);
00299 
00304         void set_subimage(
00305                 int x,
00306                 int y,
00307                 const CL_PixelBuffer &image,
00308                 const CL_Rect &src_rect,
00309                 int level = 0);
00310 
00311         void set_subimage(
00312                 const CL_Point &point,
00313                 const CL_PixelBuffer &image,
00314                 const CL_Rect &src_rect,
00315                 int level = 0);
00316 
00318         void copy_image_from(
00319                 CL_GraphicContext &context,
00320                 int level,
00321                 CL_TextureFormat internal_format = cl_rgba);
00322 
00323         void copy_image_from(
00324                 CL_GraphicContext &context,
00325                 int x,
00326                 int y,
00327                 int width,
00328                 int height,
00329                 int level = 0,
00330                 CL_TextureFormat internal_format = cl_rgba);
00331 
00332         void copy_image_from(
00333                 CL_GraphicContext &context,
00334                 const CL_Rect &pos,
00335                 int level = 0,
00336                 CL_TextureFormat internal_format = cl_rgba);
00337 
00339         void copy_subimage_from(
00340                 CL_GraphicContext &context,
00341                 int offset_x,
00342                 int offset_y,
00343                 int x,
00344                 int y,
00345                 int width,
00346                 int height,
00347                 int level = 0);
00348 
00349         void copy_subimage_from(
00350                 CL_GraphicContext &context,
00351                 const CL_Point &offset,
00352                 const CL_Rect &pos,
00353                 int level = 0);
00354 
00356         void set_min_lod(float min_lod);
00357 
00359         void set_max_lod(float max_lod);
00360 
00362         void set_lod_bias(float lod_bias);
00363 
00365         void set_base_level(int base_level);
00366 
00368         void set_max_level(int max_level);
00369 
00371         void set_wrap_mode(
00372                 CL_TextureWrapMode wrap_s,
00373                 CL_TextureWrapMode wrap_t,
00374                 CL_TextureWrapMode wrap_r);
00375 
00376         void set_wrap_mode(
00377                 CL_TextureWrapMode wrap_s,
00378                 CL_TextureWrapMode wrap_t);
00379 
00380         void set_wrap_mode(
00381                 CL_TextureWrapMode wrap_s);
00382 
00384         void set_min_filter(CL_TextureFilter filter);
00385 
00387         void set_mag_filter(CL_TextureFilter filter);
00388 
00390         void set_max_anisotropy(float max_anisotropy);
00391 
00393         void set_texture_compare(CL_TextureCompareMode mode, CL_CompareFunction func);
00394 
00398 private:
00399         CL_SharedPtr<CL_Texture_Impl> impl;
00401 };
00402