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:
47 Texture2D();
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
106 Sizef get_dip_size() const { return Sizef{ get_dip_width(), get_dip_height() }; }
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
118 TextureWrapMode get_wrap_mode_s() const;
119
121 TextureWrapMode get_wrap_mode_t() const;
123
126 public:
132 void set_image(
133 GraphicContext &context,
134 const PixelBuffer &image,
135 int level = 0);
136
146 void set_subimage(
147 GraphicContext &context,
148 int x,
149 int y,
150 const PixelBuffer &image,
151 const Rect &src_rect,
152 int level = 0);
153
161 void set_subimage(
162 GraphicContext &context,
163 const Point &point,
164 const PixelBuffer &image,
165 const Rect &src_rect,
166 int level = 0);
167
169 void copy_image_from(
170 GraphicContext &context,
171 int level,
172 TextureFormat texture_format = tf_rgba8);
173
174 void copy_image_from(
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
183 void copy_image_from(
184 GraphicContext &context,
185 const Rect &pos,
186 int level = 0,
187 TextureFormat texture_format = tf_rgba8);
188
190 void copy_subimage_from(
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
200 void copy_subimage_from(
201 GraphicContext &context,
202 const Point &offset,
203 const Rect &pos,
204 int level = 0);
205
206 void set_wrap_mode(
207 TextureWrapMode wrap_s,
208 TextureWrapMode wrap_t);
209
211 void set_pixel_ratio(float ratio);
212
214 };
215
216 }
217
clan::Texture2D::Texture2D
Texture2D(const std::shared_ptr< Texture_Impl > &impl)
Definition: texture_2d.h:52
clan
Definition: clanapp.h:35
clan::Texture2D::get_pixeldata
PixelBuffer get_pixeldata(GraphicContext &gc, int level=0) const
Retrieve image data from texture.
clan::TextureWrapMode
TextureWrapMode
Texture coordinate wrapping modes.
Definition: texture.h:65
clan::Texture
Texture object class.
Definition: texture.h:103
clan::PixelBuffer
Pixel data container.
Definition: pixel_buffer.h:68
clan::Key::x
clan::ImageImportDescription
Image Import Description Class.
Definition: image_import_description.h:48
clan::BrushType::image
clan::Texture2D::get_width
int get_width() const
Retrieves the actual width of the texture in the display.
clan::Texture2D::set_subimage
void set_subimage(GraphicContext &context, int x, int y, const PixelBuffer &image, const Rect &src_rect, int level=0)
clan::Texture2D::set_pixel_ratio
void set_pixel_ratio(float ratio)
Sets the display pixel ratio for this texture.
clan::StyleTokenType::string
@ keyword
clan::Rect
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:470
clan::Texture2D::get_wrap_mode_t
TextureWrapMode get_wrap_mode_t() const
Get the texture wrap mode for the t coordinate.
clan::Texture2D
2D texture object class.
Definition: texture_2d.h:41
clan::Texture2D::get_wrap_mode_s
TextureWrapMode get_wrap_mode_s() const
Get the texture wrap mode for the s coordinate.
clan::Texture::impl
std::shared_ptr< Texture_Impl > impl
Definition: texture.h:271
clan::Texture2D::get_pixel_ratio
float get_pixel_ratio() const
clan::Key::y
clan::Texture2D::get_size
Size get_size() const
Retrieves the actual size of the texture.
Definition: texture_2d.h:91
clan::Texture2D::get_dip_width
float get_dip_width() const
Returns the device independent width of this texture.
Definition: texture_2d.h:100
clan::TextureFormat
TextureFormat
Texture format.
Definition: texture_format.h:40
clan::Texture2D::Texture2D
Texture2D()
Constructs a null instance.
clan::Texture2D::set_image
void set_image(GraphicContext &context, const PixelBuffer &image, int level=0)
clan::Texture2D::copy_image_from
void copy_image_from(GraphicContext &context, int level, TextureFormat texture_format=tf_rgba8)
Copy image data from a graphic context.
clan::GraphicContext
Interface to drawing graphics.
Definition: graphic_context.h:257
clan::Point
2D (x,y) point structure - Integer
Definition: point.h:62
clan::Texture2D::get_height
int get_height() const
Retrieves the actual height of the texture in the display.
clan::Texture2D::set_wrap_mode
void set_wrap_mode(TextureWrapMode wrap_s, TextureWrapMode wrap_t)
clan::Size
2D (width,height) size structure - Integer
Definition: size.h:156
clan::Texture2D::copy_subimage_from
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.
clan::Texture2D::get_dip_size
Sizef get_dip_size() const
Returns the device independent size of this texture.
Definition: texture_2d.h:106
clan::Texture2D::get_dip_height
float get_dip_height() const
Returns the device independent height of this texture.
Definition: texture_2d.h:103
clan::tf_rgba8
Definition: texture_format.h:43
clan::Sizef
2D (width,height) size structure - Float
Definition: size.h:169