Unravel Engine C++ Reference
Loading...
Searching...
No Matches
texture.cpp
Go to the documentation of this file.
1#include "texture.h"
2#include "utils/bgfx_utils.h"
3namespace gfx
4{
5
6texture::texture(const char* _path,
7 std::uint64_t _flags,
8 std::uint8_t _skip /*= 0 */,
9 texture_info* _info /*= nullptr*/)
10{
11 handle_ = loadTexture(_path, _flags, _skip, &info);
12
13 if(_info != nullptr)
14 {
15 *_info = info;
16 }
17
18 flags = _flags;
19}
20
21texture::texture(std::uint16_t _width,
22 std::uint16_t _height,
23 bool _hasMips,
24 std::uint16_t _numLayers,
25 texture_format _format,
26 std::uint64_t _flags /*= BGFX_TEXTURE_NONE */,
27 const memory_view* _mem /*= nullptr */)
28 : flags(_flags)
29{
30 handle_ = create_texture_2d(_width, _height, _hasMips, _numLayers, _format, _flags, _mem);
31
32 calc_texture_size(info, _width, _height, 1, false, _hasMips, _numLayers, _format);
33
34
35}
36
37texture::texture(std::uint16_t _width,
38 std::uint16_t _height,
39 std::uint16_t _depth,
40 bool _hasMips,
41 texture_format _format,
42 std::uint64_t _flags /*= BGFX_TEXTURE_NONE */,
43 const memory_view* _mem /*= nullptr */)
44 : flags(_flags)
45{
46 handle_ = create_texture_3d(_width, _height, _depth, _hasMips, _format, _flags, _mem);
47
48 calc_texture_size(info, _width, _height, _depth, false, _hasMips, 1, _format);
49
50
51}
52
53texture::texture(std::uint16_t _size,
54 bool _hasMips,
55 std::uint16_t _numLayers,
56 texture_format _format,
57 std::uint64_t _flags /*= BGFX_TEXTURE_NONE */,
58 const memory_view* _mem /*= nullptr */)
59 : flags(_flags)
60{
61 handle_ = create_texture_cube(_size, _hasMips, _numLayers, _format, _flags, _mem);
62
63 calc_texture_size(info, _size, _size, _size, false, _hasMips, _numLayers, _format);
64
65
66}
67
69{
70 return {static_cast<std::uint32_t>(info.width), static_cast<std::uint32_t>(info.height)};
71}
72
73auto texture::is_render_target() const -> bool
74{
75 return 0 != (flags & BGFX_TEXTURE_RT_MASK);
76}
77} // namespace gfx
bgfx::TextureHandle loadTexture(bx::FileReaderI *_reader, const char *_filePath, uint64_t _flags, uint8_t _skip, bgfx::TextureInfo *_info, bimg::Orientation::Enum *_orientation)
bgfx::TextureFormat::Enum texture_format
Definition format.h:10
texture_handle create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, texture_format _format, uint64_t _flags, const memory_view *_mem)
Definition graphics.cpp:540
texture_handle create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, texture_format _format, uint64_t _flags, const memory_view *_mem)
Definition graphics.cpp:529
void calc_texture_size(texture_info &_info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, texture_format _format)
Definition graphics.cpp:492
texture_handle create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, texture_format _format, uint64_t _flags, const memory_view *_mem)
Definition graphics.cpp:509
bgfx::TextureInfo texture_info
Definition graphics.h:24
bgfx::Memory memory_view
Definition graphics.h:23
auto is_render_target() const -> bool
Definition texture.cpp:73
texture()=default
std::uint64_t flags
Creation flags.
Definition texture.h:97
auto get_size() const -> usize32_t
Definition texture.cpp:68
texture_info info
Texture detail info.
Definition texture.h:95