texture_2d.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 "texture.h"
34 
35 namespace clan
36 {
39 
41 class Texture2D : public Texture
42 {
45 public:
48 
52  Texture2D(const std::shared_ptr<Texture_Impl> &impl) : Texture(impl) { }
53 
62  Texture2D(GraphicContext &context, int width, int height, TextureFormat format = tf_rgba8, int levels = 1);
63 
71  Texture2D(GraphicContext &context, const Size &size, TextureFormat texture_format = tf_rgba8, int levels = 1);
72 
73  Texture2D(GraphicContext &context, const std::string &fullname, const ImageImportDescription &import_desc = {});
74  Texture2D(GraphicContext &context, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc = {});
75  Texture2D(GraphicContext &context, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc = {});
76 
77  Texture2D(GraphicContext &context, const PixelBuffer &image, bool is_srgb = false);
78  Texture2D(GraphicContext &context, const PixelBuffer &image, const Rect &src_rect, bool is_srgb = false);
80 
83 public:
85  int get_width() const;
86 
88  int get_height() const;
89 
91  Size get_size() const { return Size{ get_width(), get_height() }; }
92 
97  float get_pixel_ratio() const;
98 
100  float get_dip_width() const { return get_width() / get_pixel_ratio(); }
101 
103  float get_dip_height() const { return get_height() / get_pixel_ratio(); }
104 
107 
109  PixelBuffer get_pixeldata(GraphicContext &gc, int level = 0) const;
110 
115  PixelBuffer get_pixeldata(GraphicContext &gc, TextureFormat texture_format, int level = 0) const;
116 
119 
123 
126 public:
132  void set_image(
133  GraphicContext &context,
134  const PixelBuffer &image,
135  int level = 0);
136 
147  GraphicContext &context,
148  int x,
149  int y,
150  const PixelBuffer &image,
151  const Rect &src_rect,
152  int level = 0);
153 
162  GraphicContext &context,
163  const Point &point,
164  const PixelBuffer &image,
165  const Rect &src_rect,
166  int level = 0);
167 
170  GraphicContext &context,
171  int level,
172  TextureFormat texture_format = tf_rgba8);
173 
175  GraphicContext &context,
176  int x,
177  int y,
178  int width,
179  int height,
180  int level = 0,
181  TextureFormat texture_format = tf_rgba8);
182 
184  GraphicContext &context,
185  const Rect &pos,
186  int level = 0,
187  TextureFormat texture_format = tf_rgba8);
188 
191  GraphicContext &context,
192  int offset_x,
193  int offset_y,
194  int x,
195  int y,
196  int width,
197  int height,
198  int level = 0);
199 
201  GraphicContext &context,
202  const Point &offset,
203  const Rect &pos,
204  int level = 0);
205 
207  TextureWrapMode wrap_s,
208  TextureWrapMode wrap_t);
209 
211  void set_pixel_ratio(float ratio);
212 
214 };
215 
216 }
217 
float get_dip_width() const
Returns the device independent width of this texture.
Definition: texture_2d.h:100
2D (x,y) point structure - Integer
Definition: point.h:63
Texture2D(const std::shared_ptr< Texture_Impl > &impl)
Definition: texture_2d.h:52
TextureWrapMode get_wrap_mode_t() const
Get the texture wrap mode for the t coordinate.
TextureWrapMode
Texture coordinate wrapping modes.
Definition: texture.h:66
Size get_size() const
Retrieves the actual size of the texture.
Definition: texture_2d.h:91
Texture object class.
Definition: texture.h:104
PixelBuffer get_pixeldata(GraphicContext &gc, int level=0) const
Retrieve image data from texture.
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:471
@ tf_rgba8
Definition: texture_format.h:43
Image Import Description Class.
Definition: image_import_description.h:49
TextureWrapMode get_wrap_mode_s() const
Get the texture wrap mode for the s coordinate.
I/O Device interface.
Definition: iodevice.h:51
Texture2D(GraphicContext &context, const PixelBuffer &image, bool is_srgb=false)
void set_subimage(GraphicContext &context, int x, int y, const PixelBuffer &image, const Rect &src_rect, int level=0)
2D texture object class.
Definition: texture_2d.h:42
void set_pixel_ratio(float ratio)
Sets the display pixel ratio for this texture.
int get_width() const
Retrieves the actual width of the texture in the display.
std::shared_ptr< Texture_Impl > impl
Definition: texture.h:271
Sizef get_dip_size() const
Returns the device independent size of this texture.
Definition: texture_2d.h:106
Texture2D(GraphicContext &context, const PixelBuffer &image, const Rect &src_rect, bool is_srgb=false)
Interface to drawing graphics.
Definition: graphic_context.h:258
PixelBuffer get_pixeldata(GraphicContext &gc, TextureFormat texture_format, int level=0) const
void copy_image_from(GraphicContext &context, int x, int y, int width, int height, int level=0, TextureFormat texture_format=tf_rgba8)
Texture2D()
Constructs a null instance.
void set_image(GraphicContext &context, const PixelBuffer &image, int level=0)
TextureFormat
Texture format.
Definition: texture_format.h:41
Definition: clanapp.h:36
Virtual File System (VFS).
Definition: file_system.h:48
float get_dip_height() const
Returns the device independent height of this texture.
Definition: texture_2d.h:103
void copy_image_from(GraphicContext &context, int level, TextureFormat texture_format=tf_rgba8)
Copy image data from a graphic context.
Texture2D(GraphicContext &context, const std::string &fullname, const ImageImportDescription &import_desc={})
Pixel data container.
Definition: pixel_buffer.h:69
void set_wrap_mode(TextureWrapMode wrap_s, TextureWrapMode wrap_t)
void copy_image_from(GraphicContext &context, const Rect &pos, int level=0, TextureFormat texture_format=tf_rgba8)
int get_height() const
Retrieves the actual height of the texture in the display.
void set_subimage(GraphicContext &context, const Point &point, const PixelBuffer &image, const Rect &src_rect, int level=0)
Texture2D(GraphicContext &context, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc={})
float get_pixel_ratio() const
2D (width,height) size structure - Integer
Definition: size.h:157
void copy_subimage_from(GraphicContext &context, int offset_x, int offset_y, int x, int y, int width, int height, int level=0)
Copy sub image data from a graphic context.
2D (width,height) size structure - Float
Definition: size.h:170
Texture2D(GraphicContext &context, int width, int height, TextureFormat format=tf_rgba8, int levels=1)
Texture2D(GraphicContext &context, const Size &size, TextureFormat texture_format=tf_rgba8, int levels=1)
void copy_subimage_from(GraphicContext &context, const Point &offset, const Rect &pos, int level=0)
Texture2D(GraphicContext &context, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc={})