Graphics v0.0.0
A simple abstraction layer for the modern graphics APIs.
载入中...
搜索中...
未找到
Texture.h
1// Copyright 2022 ShenMian
2// License(Apache-2.0)
3
4#pragma once
5
6#include "Core/Platform.h"
7#include "Format.h"
8#include "math/math.hpp"
9#include <cstdint>
10#include <filesystem>
11#include <memory>
12#include <unordered_map>
13#include <vector>
14
15// TODO: 一个想法
16// create(const std::vector<Image>& image /* mipmaps */, Format fmt = Format::Unknown, Type type = Type::_2D);
17
18class Image;
19
25uint32_t GetMaxMipmapLevel(const Vector2i& size);
26
31{
32public:
33 // 纹理过滤方式
34 enum class Filter
35 {
36 Nearest,
37 Bilinear,
39 };
40
41 // 纹理环绕方式(纹理寻址方式)
42 enum class Warp
43 {
44 Repeat,
47 };
48
49 // 纹理类型
50 enum class Type
51 {
52 _2D,
53 _3D,
54 Cube,
55 };
56
65 [[nodiscard]] static std::shared_ptr<Texture> create(const std::filesystem::path& path,
66 Format fmt = Format::Unknown, uint32_t mipmapLevel = -1,
67 Type type = Type::_2D);
68
77 [[nodiscard]] static std::shared_ptr<Texture> create(const Image& image, Format fmt = Format::Unknown,
78 uint32_t mipmapLevel = -1, Type type = Type::_2D);
79
86 [[nodiscard]] static std::shared_ptr<Texture> create(const std::vector<Image>& images);
87
88 virtual void bind(uint32_t binding) = 0;
89
95 virtual void set_min_filter(Filter filter) = 0;
96
102 virtual void set_mag_filter(Filter filter) = 0;
103
109 virtual void set_s_warp(Warp warp) = 0;
110
116 virtual void set_t_warp(Warp warp) = 0;
117
123 virtual void set_r_warp(Warp warp) = 0;
124
128 [[nodiscard]] Type get_type() const;
129
133 [[nodiscard]] Format get_format() const;
134
135protected:
136 Texture(Type type, Format fmt);
137
138 Type type_;
139 Format format_;
140
146 inline static std::unordered_map<std::filesystem::path, std::shared_ptr<Texture>> cache_;
147};
图像.
Definition: Image.h:19
Vector2i size() const noexcept
获取图像分辨率.
Definition: Image.cpp:154
纹理.
Definition: Texture.h:31
static std::unordered_map< std::filesystem::path, std::shared_ptr< Texture > > cache_
Definition: Texture.h:146
virtual void set_t_warp(Warp warp)=0
设置 T 环绕方式.
Filter
Definition: Texture.h:35
@ Nearest
最近点采样, 临近过滤.
@ Trilinear
三线性过滤.
@ Bilinear
双线性过滤.
Format get_format() const
获取像素格式.
Definition: Texture.cpp:94
virtual void set_r_warp(Warp warp)=0
设置 R 环绕方式.
Type get_type() const
获取纹理类型.
Definition: Texture.cpp:89
virtual void set_s_warp(Warp warp)=0
设置 S 环绕方式.
virtual void set_mag_filter(Filter filter)=0
设置放大过滤方式.
virtual void set_min_filter(Filter filter)=0
设置缩小过滤方式.
static std::shared_ptr< Texture > create(const std::filesystem::path &path, Format fmt=Format::Unknown, uint32_t mipmapLevel=-1, Type type=Type::_2D)
从图像文件创建纹理.
Warp
Definition: Texture.h:43
@ MirrorRepeat
镜像重复, 正像/镜像交替.
@ Repeat
重复.
@ ClampToEdge
超出边界后重复边缘, 产生边缘被拉伸的效果.