Kiwano Engine v1.3.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
39{
40 Linear,
41 Nearest
42};
43
47
53enum class PixelFormat
54{
55 Bpp32RGBA,
56 Bpp32BGRA,
57};
58
63class KGE_API Texture : public NativeObject
64{
65public:
66 Texture();
67
70 Texture(StringView file_path);
71
74 Texture(const Resource& res);
75
78 Texture(const PixelSize& size, const BinaryData& data, PixelFormat format);
79
80 virtual ~Texture();
81
84 bool Load(StringView file_path);
85
88 bool Load(const Resource& res);
89
92 bool Load(const PixelSize& size, const BinaryData& data, PixelFormat format);
93
96 float GetWidth() const;
97
100 float GetHeight() const;
101
104 Size GetSize() const;
105
108 uint32_t GetWidthInPixels() const;
109
112 uint32_t GetHeightInPixels() const;
113
116 PixelSize GetSizeInPixels() const;
117
120 InterpolationMode GetBitmapInterpolationMode() const;
123 void SetSize(const Size& size);
124
127 void SetSizeInPixels(const PixelSize& size);
128
131 void SetInterpolationMode(InterpolationMode mode);
132
136 void CopyFrom(RefPtr<Texture> copy_from);
137
143 void CopyFrom(RefPtr<Texture> copy_from, const Rect& src_rect, const Point& dest_point);
144
147 static void SetDefaultInterpolationMode(InterpolationMode mode);
148
151 static InterpolationMode GetDefaultInterpolationMode();
152
153private:
154 Size size_;
155 PixelSize size_in_pixels_;
156 InterpolationMode interpolation_mode_;
157
158 static InterpolationMode default_interpolation_mode_;
159};
160
163inline float Texture::GetWidth() const
164{
165 return size_.x;
166}
167
168inline float Texture::GetHeight() const
169{
170 return size_.y;
171}
172
173inline Size Texture::GetSize() const
174{
175 return size_;
176}
177
178inline uint32_t Texture::GetWidthInPixels() const
179{
180 return size_in_pixels_.x;
181}
182
183inline uint32_t Texture::GetHeightInPixels() const
184{
185 return size_in_pixels_.y;
186}
187
189{
190 return size_in_pixels_;
191}
192
194{
195 return interpolation_mode_;
196}
197
198inline void Texture::SetSize(const Size& size)
199{
200 size_ = size;
201}
202
203inline void Texture::SetSizeInPixels(const PixelSize& size)
204{
205 size_in_pixels_ = size;
206}
207
208} // namespace kiwano
含有本地指针的对象
Definition: NativeObject.hpp:32
引用计数智能指针
Definition: RefBasePtr.hpp:35
资源
Definition: Resource.h:41
纹理
Definition: Texture.h:64
Size GetSize() const
获取纹理大小
Definition: Texture.h:173
uint32_t GetWidthInPixels() const
获取像素宽度
Definition: Texture.h:178
void SetSize(const Size &size)
设置大小
Definition: Texture.h:198
InterpolationMode GetBitmapInterpolationMode() const
获取像素插值方式
Definition: Texture.h:193
PixelSize GetSizeInPixels() const
获取像素大小
Definition: Texture.h:188
uint32_t GetHeightInPixels() const
获取像素高度
Definition: Texture.h:183
void SetSizeInPixels(const PixelSize &size)
设置像素大小
Definition: Texture.h:203
float GetWidth() const
获取纹理宽度
Definition: Texture.h:163
float GetHeight() const
获取纹理高度
Definition: Texture.h:168
math::Vec2T< uint32_t > PixelSize
像素大小
Definition: Texture.h:46
PixelFormat
像素格式
Definition: Texture.h:54
InterpolationMode
插值模式
Definition: Texture.h:39
@ Nearest
最邻近插值,取最邻近的像素点的颜色值
二进制数据
Definition: BinaryData.h:30