texture_2d.h
1 /*
2 ** UICore
3 ** Copyright (c) 1997-2015 The UICore 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 UICore 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 
34 namespace uicore
35 {
36  class IODevice;
37 
39  class Texture2D : public virtual Texture
40  {
41  public:
50  static std::shared_ptr<Texture2D> create(const GraphicContextPtr &context, int width, int height, TextureFormat format = tf_rgba8, int levels = 1);
51  static std::shared_ptr<Texture2D> create(const GraphicContextPtr &context, const Size &size, TextureFormat texture_format = tf_rgba8, int levels = 1);
52 
53  static std::shared_ptr<Texture2D> create(const GraphicContextPtr &context, const std::string &filename, const ImageImportDescription &import_desc = {});
54  static std::shared_ptr<Texture2D> create(const GraphicContextPtr &context, const IODevicePtr &file, const std::string &image_type, const ImageImportDescription &import_desc = {});
55 
56  static std::shared_ptr<Texture2D> create(const GraphicContextPtr &context, const PixelBufferPtr &image, bool is_srgb = false);
57  static std::shared_ptr<Texture2D> create(const GraphicContextPtr &context, const PixelBufferPtr &image, const Rect &src_rect, bool is_srgb = false);
58 
60  virtual int width() const = 0;
61 
63  virtual int height() const = 0;
64 
66  Size size() const { return Size{ width(), height() }; }
67 
72  virtual PixelBufferPtr pixeldata(const GraphicContextPtr &gc, int level = 0) const = 0;
73  virtual PixelBufferPtr pixeldata(const GraphicContextPtr &gc, TextureFormat texture_format, int level = 0) const = 0;
74 
76  virtual TextureWrapMode wrap_mode_s() const = 0;
77 
79  virtual TextureWrapMode wrap_mode_t() const = 0;
80 
86  virtual void set_image(const GraphicContextPtr &context, const PixelBufferPtr &image, int level = 0) = 0;
87 
96  virtual void set_subimage(const GraphicContextPtr &context, int x, int y, const PixelBufferPtr &image, const Rect &src_rect, int level = 0) = 0;
97 
103  void set_subimage(const GraphicContextPtr &context, const Point &point, const PixelBufferPtr &image, const Rect &src_rect, int level = 0)
104  {
105  set_subimage(context, point.x, point.y, image, src_rect, level);
106  }
107 
109  virtual void copy_image_from(const GraphicContextPtr &context, int level, TextureFormat texture_format = tf_rgba8) = 0;
110  virtual void copy_image_from(const GraphicContextPtr &context, int x, int y, int width, int height, int level = 0, TextureFormat texture_format = tf_rgba8) = 0;
111  void copy_image_from(const GraphicContextPtr &context, const Rect &pos, int level = 0, TextureFormat texture_format = tf_rgba8)
112  {
113  copy_image_from(context, pos.left, pos.top, pos.width(), pos.height(), level, texture_format);
114  }
115 
117  virtual void copy_subimage_from(const GraphicContextPtr &context, int offset_x, int offset_y, int x, int y, int width, int height, int level = 0) = 0;
118  virtual void copy_subimage_from(const GraphicContextPtr &context, const Point &offset, const Rect &pos, int level = 0)
119  {
120  copy_subimage_from(context, offset.x, offset.y, pos.left, pos.top, pos.width(), pos.height(), level);
121  }
122 
123  virtual void set_wrap_mode(TextureWrapMode wrap_s, TextureWrapMode wrap_t) = 0;
124  };
125 }
Texture object class.
Definition: texture.h:94
2D (width,height) size structure - Integer
Definition: size.h:167
virtual int width() const =0
Retrieves the actual width of the texture in the display.
virtual PixelBufferPtr pixeldata(const GraphicContextPtr &gc, int level=0) const =0
Size size() const
Retrieves the actual size of the texture.
Definition: texture_2d.h:66
Type top
Y1-coordinate (top point inside the rectangle)
Definition: rect.h:133
Type x
Definition: vec2.h:75
virtual void copy_image_from(const GraphicContextPtr &context, int level, TextureFormat texture_format=tf_rgba8)=0
Copy image data from a graphic context.
Image Import Description Class.
Definition: image_import_description.h:45
TextureFormat
Texture format.
Definition: texture_format.h:35
Definition: texture_format.h:38
virtual void set_subimage(const GraphicContextPtr &context, int x, int y, const PixelBufferPtr &image, const Rect &src_rect, int level=0)=0
void copy_image_from(const GraphicContextPtr &context, const Rect &pos, int level=0, TextureFormat texture_format=tf_rgba8)
Definition: texture_2d.h:111
virtual TextureWrapMode wrap_mode_s() const =0
Get the texture wrap mode for the s coordinate.
std::shared_ptr< IODevice > IODevicePtr
Definition: iodevice.h:85
2D (x,y) point structure - Integer
Definition: point.h:58
Type y
Definition: vec2.h:76
virtual void set_image(const GraphicContextPtr &context, const PixelBufferPtr &image, int level=0)=0
Type height() const
Returns the height of the rectangle.
Definition: rect.h:145
virtual TextureWrapMode wrap_mode_t() const =0
Get the texture wrap mode for the t coordinate.
Type left
X1-coordinate (left point inside the rectangle)
Definition: rect.h:130
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:491
virtual void set_wrap_mode(TextureWrapMode wrap_s, TextureWrapMode wrap_t)=0
virtual int height() const =0
Retrieves the actual height of the texture in the display.
std::shared_ptr< PixelBuffer > PixelBufferPtr
Definition: d3d_target.h:39
std::shared_ptr< GraphicContext > GraphicContextPtr
Definition: d3d_target.h:49
virtual void copy_subimage_from(const GraphicContextPtr &context, const Point &offset, const Rect &pos, int level=0)
Definition: texture_2d.h:118
void set_subimage(const GraphicContextPtr &context, const Point &point, const PixelBufferPtr &image, const Rect &src_rect, int level=0)
Definition: texture_2d.h:103
TextureWrapMode
Texture coordinate wrapping modes.
Definition: texture.h:56
Type width() const
Returns the width of the rectangle.
Definition: rect.h:142
virtual void copy_subimage_from(const GraphicContextPtr &context, int offset_x, int offset_y, int x, int y, int width, int height, int level=0)=0
Copy sub image data from a graphic context.
static std::shared_ptr< Texture2D > create(const GraphicContextPtr &context, int width, int height, TextureFormat format=tf_rgba8, int levels=1)
Definition: Application/application.h:35
2D texture object class.
Definition: texture_2d.h:39