texture_group.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 ** Kenneth Gangstoe
27 ** Magnus Norddahl
28 */
29 
30 #pragma once
31 
32 #include <memory>
33 #include "../../Core/Math/size.h"
34 #include "../../Core/Math/rect.h"
35 
36 namespace uicore
37 {
38  class Texture2D;
39  typedef std::shared_ptr<Texture2D> Texture2DPtr;
40  class GraphicContext;
41  typedef std::shared_ptr<GraphicContext> GraphicContextPtr;
42 
45  {
46  public:
48  TextureGroupImage(const Texture2DPtr &texture, const Rect &geometry) : _texture(texture), _geometry(geometry) { }
49 
50  explicit operator bool() { return (bool)texture(); }
51 
52  const Texture2DPtr &texture() const { return _texture; }
53  const Rect &geometry() const { return _geometry; }
54 
55  private:
56  Texture2DPtr _texture;
57  Rect _geometry;
58  };
59 
62  {
65  };
66 
69  {
70  public:
72  static std::shared_ptr<TextureGroup> create(const Size &texture_size);
73 
75  virtual int subtexture_count() const = 0;
76 
78  virtual int subtexture_count(unsigned int texture_index) const = 0;
79 
81  virtual int texture_count() const = 0;
82 
85 
87  virtual Size texture_size() const = 0;
88 
90  virtual std::vector<Texture2DPtr> textures() const = 0;
91 
93  virtual TextureGroupImage add(const GraphicContextPtr &context, const Size &size) = 0;
94 
100  virtual void remove(const TextureGroupImage &subtexture) = 0;
101 
103  virtual void set_allocation_policy(TextureGroupAllocationPolicy policy) = 0;
104 
109  virtual void insert_texture(const Texture2DPtr &texture, const Rect &texture_rect) = 0;
110  };
111 
112  typedef std::shared_ptr<TextureGroup> TextureGroupPtr;
113 }
std::shared_ptr< Texture2D > Texture2DPtr
Definition: image.h:42
2D (width,height) size structure - Integer
Definition: size.h:167
TextureGroupImage(const Texture2DPtr &texture, const Rect &geometry)
Definition: texture_group.h:48
virtual void insert_texture(const Texture2DPtr &texture, const Rect &texture_rect)=0
Insert an existing texture into the texture group.
virtual std::vector< Texture2DPtr > textures() const =0
Returns the textures.
virtual Size texture_size() const =0
Returns the size of the textures used by this texture group.
TextureGroupImage()
Definition: texture_group.h:47
virtual int subtexture_count() const =0
Returns the amount of sub-textures allocated in group.
virtual TextureGroupAllocationPolicy allocation_policy() const =0
Returns the texture allocation policy.
virtual void set_allocation_policy(TextureGroupAllocationPolicy policy)=0
Set the texture allocation policy.
const Texture2DPtr & texture() const
Definition: texture_group.h:52
virtual TextureGroupImage add(const GraphicContextPtr &context, const Size &size)=0
Allocate space for another sub texture.
TextureGroupAllocationPolicy
TextureGroup allocation policy.
Definition: texture_group.h:61
Dynamic atlas texture class.
Definition: texture_group.h:68
static std::shared_ptr< TextureGroup > create(const Size &texture_size)
Constructs a texture group.
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:491
std::shared_ptr< TextureGroup > TextureGroupPtr
Definition: texture_group.h:112
std::shared_ptr< GraphicContext > GraphicContextPtr
Definition: d3d_target.h:49
const Rect & geometry() const
Definition: texture_group.h:53
Definition: Application/application.h:35
Image position in a TextureGroup.
Definition: texture_group.h:44
virtual int texture_count() const =0
Returns the amount of textures used by group.