Kiwano Engine  v1.2.x
Texture.h
1 // Copyright (c) 2016-2018 Kiwano - Nomango
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #pragma once
22 #include <kiwano/core/Resource.h>
23 #include <kiwano/render/NativeObject.h>
24 
25 namespace kiwano
26 {
27 
28 KGE_DECLARE_SMART_PTR(Texture);
29 
41 {
42  Linear,
43  Nearest
44 };
45 
49 
54 class KGE_API Texture : public NativeObject
55 {
56 public:
59  static TexturePtr Preload(const String& file_path);
60 
63  static TexturePtr Preload(const Resource& res);
64 
65  Texture();
66 
69  Texture(const String& file_path);
70 
73  Texture(const Resource& res);
74 
75  virtual ~Texture();
76 
79  bool Load(const String& file_path);
80 
83  bool Load(const Resource& res);
84 
87  float GetWidth() const;
88 
91  float GetHeight() const;
92 
95  Size GetSize() const;
96 
99  uint32_t GetWidthInPixels() const;
100 
103  uint32_t GetHeightInPixels() const;
104 
107  PixelSize GetSizeInPixels() const;
108 
111  InterpolationMode GetBitmapInterpolationMode() const;
114  void SetSize(const Size& size);
115 
118  void SetSizeInPixels(const PixelSize& size);
119 
122  void SetInterpolationMode(InterpolationMode mode);
123 
127  void CopyFrom(TexturePtr copy_from);
128 
134  void CopyFrom(TexturePtr copy_from, const Rect& src_rect, const Point& dest_point);
135 
138  static void SetDefaultInterpolationMode(InterpolationMode mode);
139 
142  static InterpolationMode GetDefaultInterpolationMode();
143 
144 private:
145  Size size_;
146  PixelSize size_in_pixels_;
147  InterpolationMode interpolation_mode_;
148 
149  static InterpolationMode default_interpolation_mode_;
150 };
151 
154 inline float Texture::GetWidth() const
155 {
156  return size_.x;
157 }
158 
159 inline float Texture::GetHeight() const
160 {
161  return size_.y;
162 }
163 
164 inline Size Texture::GetSize() const
165 {
166  return size_;
167 }
168 
169 inline uint32_t Texture::GetWidthInPixels() const
170 {
171  return size_in_pixels_.x;
172 }
173 
174 inline uint32_t Texture::GetHeightInPixels() const
175 {
176  return size_in_pixels_.y;
177 }
178 
179 inline PixelSize Texture::GetSizeInPixels() const
180 {
181  return size_in_pixels_;
182 }
183 
185 {
186  return interpolation_mode_;
187 }
188 
189 inline void Texture::SetSize(const Size& size)
190 {
191  size_ = size;
192 }
193 
194 inline void Texture::SetSizeInPixels(const PixelSize& size)
195 {
196  size_in_pixels_ = size;
197 }
198 
199 } // namespace kiwano
纹理
Definition: Texture.h:54
资源
Definition: Resource.h:40
含有本地指针的对象
Definition: NativeObject.h:42
math::Vec2T< uint32_t > PixelSize
像素大小
Definition: Texture.h:48
uint32_t GetHeightInPixels() const
获取像素高度
Definition: Texture.h:174
uint32_t GetWidthInPixels() const
获取像素宽度
Definition: Texture.h:169
float GetHeight() const
获取纹理高度
Definition: Texture.h:159
最邻近插值,取最邻近的像素点的颜色值
Definition: Actor.cpp:26
Size GetSize() const
获取纹理大小
Definition: Texture.h:164
float GetWidth() const
获取纹理宽度
Definition: Texture.h:154
InterpolationMode
插值模式
Definition: Texture.h:40
InterpolationMode GetBitmapInterpolationMode() const
获取像素插值方式
Definition: Texture.h:184
PixelSize GetSizeInPixels() const
获取像素大小
Definition: Texture.h:179
void SetSizeInPixels(const PixelSize &size)
设置像素大小
Definition: Texture.h:194
void SetSize(const Size &size)
设置大小
Definition: Texture.h:189
双线性插值,对周围四个像素进行两次线性插值计算,在图像放大时可能会模糊