candlewick 0.10.0
A tiny cross-platform renderer based on SDL3
Loading...
Searching...
No Matches
Texture.h
Go to the documentation of this file.
1#pragma once
2
3#include "Core.h"
4#include "Tags.h"
5#include <SDL3/SDL_gpu.h>
6
7namespace candlewick {
8
9class Texture {
10 SDL_GPUDevice *m_device = nullptr;
11 SDL_GPUTexture *m_texture = nullptr;
12 SDL_GPUTextureCreateInfo m_description;
13
14public:
16 Texture(const Device &device, SDL_GPUTextureCreateInfo texture_desc,
17 const char *name = nullptr);
18
19 Texture(const Texture &) = delete;
20 Texture &operator=(const Texture &) = delete;
21 Texture(Texture &&other) noexcept;
22 Texture &operator=(Texture &&other) noexcept;
23
24 operator SDL_GPUTexture *() const noexcept { return m_texture; }
25
26 bool operator==(const Texture &other) const noexcept {
27 return m_texture == other.m_texture;
28 }
29
30 const auto &description() const { return m_description; }
31 SDL_GPUTextureType type() const { return m_description.type; }
32 SDL_GPUTextureFormat format() const { return m_description.format; }
33 SDL_GPUTextureUsageFlags usage() const { return m_description.usage; }
34 Uint32 width() const { return m_description.width; }
35 Uint32 height() const { return m_description.height; }
36 Uint32 depth() const { return m_description.layer_count_or_depth; }
37 Uint32 layerCount() const { return m_description.layer_count_or_depth; }
38 SDL_GPUSampleCount sampleCount() const { return m_description.sample_count; }
39 std::string_view name() const {
40 return SDL_GetStringProperty(
41 m_description.props, SDL_PROP_GPU_TEXTURE_CREATE_NAME_STRING, "(null)");
42 }
43
44 SDL_GPUBlitRegion blitRegion(Uint32 offset_x, Uint32 y_offset,
45 Uint32 layer_or_depth_plane = 0) const;
46
47 Uint32 textureSize() const;
48
49 SDL_GPUDevice *device() const { return m_device; }
50
51 void destroy() noexcept;
52 ~Texture() noexcept { this->destroy(); }
53};
54
55} // namespace candlewick
SDL_GPUDevice * device() const
Definition Texture.h:49
SDL_GPUTextureFormat format() const
Definition Texture.h:32
bool operator==(const Texture &other) const noexcept
Definition Texture.h:26
Texture(Texture &&other) noexcept
SDL_GPUBlitRegion blitRegion(Uint32 offset_x, Uint32 y_offset, Uint32 layer_or_depth_plane=0) const
Texture(const Texture &)=delete
Uint32 depth() const
Definition Texture.h:36
SDL_GPUTextureType type() const
Definition Texture.h:31
std::string_view name() const
Definition Texture.h:39
Texture(NoInitT)
Definition Texture.h:15
Texture & operator=(const Texture &)=delete
Uint32 textureSize() const
Uint32 height() const
Definition Texture.h:35
Texture(const Device &device, SDL_GPUTextureCreateInfo texture_desc, const char *name=nullptr)
SDL_GPUTextureUsageFlags usage() const
Definition Texture.h:33
void destroy() noexcept
Uint32 layerCount() const
Definition Texture.h:37
Texture & operator=(Texture &&other) noexcept
Uint32 width() const
Definition Texture.h:34
const auto & description() const
Definition Texture.h:30
SDL_GPUSampleCount sampleCount() const
Definition Texture.h:38
Definition Camera.h:8
RAII wrapper for SDL_GPUDevice.
Definition Device.h:17
Tag type for non-initializing constructors (for e.g. RAII classes)
Definition Tags.h:6