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/platform/NativeObject.hpp>
24
25namespace kiwano
26{
27
28KGE_DECLARE_SMART_PTR(Texture);
29
41{
42 Linear,
43 Nearest
44};
45
49
55enum class PixelFormat
56{
57 Bpp32RGBA,
58 Bpp32BGRA,
59};
60
65class KGE_API Texture : public NativeObject
66{
67public:
68 Texture();
69
72 Texture(const String& file_path);
73
76 Texture(const Resource& res);
77
80 Texture(const PixelSize& size, const BinaryData& data, PixelFormat format);
81
82 virtual ~Texture();
83
86 bool Load(const String& file_path);
87
90 bool Load(const Resource& res);
91
94 bool Load(const PixelSize& size, const BinaryData& data, PixelFormat format);
95
98 float GetWidth() const;
99
102 float GetHeight() const;
103
106 Size GetSize() const;
107
110 uint32_t GetWidthInPixels() const;
111
114 uint32_t GetHeightInPixels() const;
115
118 PixelSize GetSizeInPixels() const;
119
122 InterpolationMode GetBitmapInterpolationMode() const;
125 void SetSize(const Size& size);
126
129 void SetSizeInPixels(const PixelSize& size);
130
133 void SetInterpolationMode(InterpolationMode mode);
134
138 void CopyFrom(TexturePtr copy_from);
139
145 void CopyFrom(TexturePtr copy_from, const Rect& src_rect, const Point& dest_point);
146
149 static void SetDefaultInterpolationMode(InterpolationMode mode);
150
153 static InterpolationMode GetDefaultInterpolationMode();
154
155private:
156 Size size_;
157 PixelSize size_in_pixels_;
158 InterpolationMode interpolation_mode_;
159
160 static InterpolationMode default_interpolation_mode_;
161};
162
165inline float Texture::GetWidth() const
166{
167 return size_.x;
168}
169
170inline float Texture::GetHeight() const
171{
172 return size_.y;
173}
174
175inline Size Texture::GetSize() const
176{
177 return size_;
178}
179
180inline uint32_t Texture::GetWidthInPixels() const
181{
182 return size_in_pixels_.x;
183}
184
185inline uint32_t Texture::GetHeightInPixels() const
186{
187 return size_in_pixels_.y;
188}
189
191{
192 return size_in_pixels_;
193}
194
196{
197 return interpolation_mode_;
198}
199
200inline void Texture::SetSize(const Size& size)
201{
202 size_ = size;
203}
204
205inline void Texture::SetSizeInPixels(const PixelSize& size)
206{
207 size_in_pixels_ = size;
208}
209
210} // namespace kiwano
含有本地指针的对象
Definition: NativeObject.hpp:34
资源
Definition: Resource.h:41
纹理
Definition: Texture.h:66
Size GetSize() const
获取纹理大小
Definition: Texture.h:175
uint32_t GetWidthInPixels() const
获取像素宽度
Definition: Texture.h:180
void SetSize(const Size &size)
设置大小
Definition: Texture.h:200
InterpolationMode GetBitmapInterpolationMode() const
获取像素插值方式
Definition: Texture.h:195
PixelSize GetSizeInPixels() const
获取像素大小
Definition: Texture.h:190
uint32_t GetHeightInPixels() const
获取像素高度
Definition: Texture.h:185
void SetSizeInPixels(const PixelSize &size)
设置像素大小
Definition: Texture.h:205
float GetWidth() const
获取纹理宽度
Definition: Texture.h:165
float GetHeight() const
获取纹理高度
Definition: Texture.h:170
math::Vec2T< uint32_t > PixelSize
像素大小
Definition: Texture.h:48
PixelFormat
像素格式
Definition: Texture.h:56
InterpolationMode
插值模式
Definition: Texture.h:41
@ Nearest
最邻近插值,取最邻近的像素点的颜色值
二进制数据
Definition: BinaryData.h:30