texture_2d.h Source File - ClanLib SDK
Description: texture_2d.h Source File

texture_2d.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
31
32#include "texture.h"
33
34namespace clan
35{
38
40 class Texture2D : public Texture
41 {
42 public:
44 Texture2D();
45
49 Texture2D(const std::shared_ptr<Texture_Impl> &impl) : Texture(impl) { }
50
59 Texture2D(GraphicContext &context, int width, int height, TextureFormat format = TextureFormat::rgba8, int levels = 1);
60
68 Texture2D(GraphicContext &context, const Size &size, TextureFormat texture_format = TextureFormat::rgba8, int levels = 1);
69
70 Texture2D(GraphicContext &context, const std::string &fullname, const ImageImportDescription &import_desc = {});
71 Texture2D(GraphicContext &context, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc = {});
72 Texture2D(GraphicContext &context, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc = {});
73
74 Texture2D(GraphicContext &context, const PixelBuffer &image, bool is_srgb = false);
75 Texture2D(GraphicContext &context, const PixelBuffer &image, const Rect &src_rect, bool is_srgb = false);
76
78 int get_width() const;
79
81 int get_height() const;
82
84 Size get_size() const { return Size{ get_width(), get_height() }; }
85
90 float get_pixel_ratio() const;
91
93 float get_dip_width() const { return get_width() / get_pixel_ratio(); }
94
96 float get_dip_height() const { return get_height() / get_pixel_ratio(); }
97
99 Sizef get_dip_size() const { return Sizef{ get_dip_width(), get_dip_height() }; }
100
102 PixelBuffer get_pixeldata(GraphicContext &gc, int level = 0) const;
103
108 PixelBuffer get_pixeldata(GraphicContext &gc, TextureFormat texture_format, int level = 0) const;
109
111 TextureWrapMode get_wrap_mode_s() const;
112
114 TextureWrapMode get_wrap_mode_t() const;
115
121 void set_image(
122 GraphicContext &context,
123 const PixelBuffer &image,
124 int level = 0);
125
135 void set_subimage(
136 GraphicContext &context,
137 int x,
138 int y,
139 const PixelBuffer &image,
140 const Rect &src_rect,
141 int level = 0);
142
150 void set_subimage(
151 GraphicContext &context,
152 const Point &point,
153 const PixelBuffer &image,
154 const Rect &src_rect,
155 int level = 0);
156
158 void copy_image_from(
159 GraphicContext &context,
160 int level,
161 TextureFormat texture_format = TextureFormat::rgba8);
162
163 void copy_image_from(
164 GraphicContext &context,
165 int x,
166 int y,
167 int width,
168 int height,
169 int level = 0,
170 TextureFormat texture_format = TextureFormat::rgba8);
171
172 void copy_image_from(
173 GraphicContext &context,
174 const Rect &pos,
175 int level = 0,
176 TextureFormat texture_format = TextureFormat::rgba8);
177
179 void copy_subimage_from(
180 GraphicContext &context,
181 int offset_x,
182 int offset_y,
183 int x,
184 int y,
185 int width,
186 int height,
187 int level = 0);
188
189 void copy_subimage_from(
190 GraphicContext &context,
191 const Point &offset,
192 const Rect &pos,
193 int level = 0);
194
195 void set_wrap_mode(
196 TextureWrapMode wrap_s,
197 TextureWrapMode wrap_t);
198
200 void set_pixel_ratio(float ratio);
201 };
202
204}
clan::FileSystem
Virtual File System (VFS).
Definition file_system.h:47
clan::GraphicContext
Interface to drawing graphics.
Definition graphic_context.h:257
clan::IODevice
I/O Device interface.
Definition iodevice.h:50
clan::ImageImportDescription
Image Import Description Class.
Definition image_import_description.h:48
clan::PixelBuffer
Pixel data container.
Definition pixel_buffer.h:68
clan::Point
2D (x,y) point structure - Integer
Definition point.h:62
clan::Rect
2D (left,top,right,bottom) rectangle structure - Integer
Definition rect.h:489
clan::Size
2D (width,height) size structure - Integer
Definition size.h:171
clan::Sizef
2D (width,height) size structure - Float
Definition size.h:184
clan::Texture2D
2D texture object class.
Definition texture_2d.h:41
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::get_dip_width
float get_dip_width() const
Returns the device independent width of this texture.
Definition texture_2d.h:93
clan::Texture2D::get_wrap_mode_s
TextureWrapMode get_wrap_mode_s() const
Get the texture wrap mode for the s coordinate.
clan::Texture2D::Texture2D
Texture2D(GraphicContext &context, const std::string &fullname, const ImageImportDescription &import_desc={})
clan::Texture2D::get_pixeldata
PixelBuffer get_pixeldata(GraphicContext &gc, int level=0) const
Retrieve image data from texture.
clan::Texture2D::Texture2D
Texture2D()
Constructs a null instance.
clan::Texture2D::Texture2D
Texture2D(GraphicContext &context, const std::string &filename, const FileSystem &fs, const ImageImportDescription &import_desc={})
clan::Texture2D::get_dip_size
Sizef get_dip_size() const
Returns the device independent size of this texture.
Definition texture_2d.h:99
clan::Texture2D::Texture2D
Texture2D(GraphicContext &context, const Size &size, TextureFormat texture_format=TextureFormat::rgba8, int levels=1)
clan::Texture2D::get_height
int get_height() const
Retrieves the actual height of the texture in the display.
clan::Texture2D::copy_subimage_from
void copy_subimage_from(GraphicContext &context, const Point &offset, const Rect &pos, int level=0)
clan::Texture2D::get_pixeldata
PixelBuffer get_pixeldata(GraphicContext &gc, TextureFormat texture_format, int level=0) const
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_height
float get_dip_height() const
Returns the device independent height of this texture.
Definition texture_2d.h:96
clan::Texture2D::Texture2D
Texture2D(GraphicContext &context, const PixelBuffer &image, bool is_srgb=false)
clan::Texture2D::set_wrap_mode
void set_wrap_mode(TextureWrapMode wrap_s, TextureWrapMode wrap_t)
clan::Texture2D::copy_image_from
void copy_image_from(GraphicContext &context, int level, TextureFormat texture_format=TextureFormat::rgba8)
Copy image data from a graphic context.
clan::Texture2D::copy_image_from
void copy_image_from(GraphicContext &context, const Rect &pos, int level=0, TextureFormat texture_format=TextureFormat::rgba8)
clan::Texture2D::Texture2D
Texture2D(GraphicContext &context, int width, int height, TextureFormat format=TextureFormat::rgba8, int levels=1)
clan::Texture2D::Texture2D
Texture2D(const std::shared_ptr< Texture_Impl > &impl)
Definition texture_2d.h:49
clan::Texture2D::Texture2D
Texture2D(GraphicContext &context, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc={})
clan::Texture2D::get_size
Size get_size() const
Retrieves the actual size of the texture.
Definition texture_2d.h:84
clan::Texture2D::Texture2D
Texture2D(GraphicContext &context, const PixelBuffer &image, const Rect &src_rect, bool is_srgb=false)
clan::Texture2D::set_image
void set_image(GraphicContext &context, const PixelBuffer &image, int level=0)
clan::Texture2D::get_width
int get_width() const
Retrieves the actual width of the texture in the display.
clan::Texture2D::set_pixel_ratio
void set_pixel_ratio(float ratio)
Sets the display pixel ratio for this texture.
clan::Texture2D::get_pixel_ratio
float get_pixel_ratio() const
clan::Texture2D::copy_image_from
void copy_image_from(GraphicContext &context, int x, int y, int width, int height, int level=0, TextureFormat texture_format=TextureFormat::rgba8)
clan::Texture2D::get_wrap_mode_t
TextureWrapMode get_wrap_mode_t() const
Get the texture wrap mode for the t coordinate.
clan::Texture2D::set_subimage
void set_subimage(GraphicContext &context, const Point &point, const PixelBuffer &image, const Rect &src_rect, int level=0)
clan::Texture
Texture object class.
Definition texture.h:103
clan::Texture::impl
std::shared_ptr< Texture_Impl > impl
Definition texture.h:250
clan::TextureFormat
TextureFormat
Texture format.
Definition texture_format.h:39
clan::TextureWrapMode
TextureWrapMode
Texture coordinate wrapping modes.
Definition texture.h:65
clan::TextureFormat::rgba8
@ rgba8
clan::FillMode::point
@ point
clan
Definition clanapp.h:36
clan::BrushType::image
@ image
clan::Key::y
@ y
clan::Key::x
@ x