Avara3D 0.2.0
C++ API reference
Texture.h
1//
2// Texture.h
3// avara3d
4//
5// Created by Morgan Davis on 2/7/24.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_VISUAL_MATERIAL_TEXTURE_H
10#define AVARA3D_VISUAL_MATERIAL_TEXTURE_H
11
12#include <atomic>
13#include <climits>
14#include <memory>
15#include <variant>
16
17#include "a3d/Id.h"
18#include "a3d/util/Bitmask.h"
19#include "a3d/visual/material/Sampler.h"
20
21namespace a3d {
22
23 class CubeImage;
24 class Image;
25
32 class Texture {
33
34 public:
35 // [Public Types]
36
38 using Contents = std::variant<std::monostate, std::shared_ptr<Image>, std::shared_ptr<CubeImage>>;
39
40 // [Public Lifecycle Functions]
41
44
50 explicit Texture(const Contents& contents,
51 const std::shared_ptr<Sampler>& sampler = std::make_shared<Sampler>(),
52 unsigned mappingChannel = 0);
53
54 Texture(const Texture& other);
55 Texture& operator=(const Texture& other);
56
57 Texture(Texture&& other) noexcept;
58 Texture& operator=(Texture&& other) noexcept;
59
60 ~Texture();
61
62 // [Public Member Functions]
63
65 std::shared_ptr<Sampler> sampler() const;
66
68 void sampler(const std::shared_ptr<Sampler>& sampler);
69
71 const Contents& contents() const;
72
75
76 // TODO: move to TextureBinding
78 unsigned mappingChannel() const;
79
81 void mappingChannel(unsigned channel);
82
83 // [Internal Types]
84
85 enum class DirtyMask : uint32_t {
86 None = 0,
87 Contents = 1 << 0,
88 Sampler = 1 << 1, // TODO: move to MaterialBinding dirty mask?
89 All = UINT_MAX
90 };
91
92 // [Internal Member Functions]
93
94 TextureId id() const noexcept;
95
96 DirtyMask dirtyMask() const;
97 void dirtyMask(DirtyMask mask);
98
99 private:
100 // [Private Member Variables]
101
102 TextureId _id;
103 std::shared_ptr<Sampler> _sampler;
104 Contents _contents;
105 unsigned _mappingChannel;
106 DirtyMask _dirtyMask;
107 };
108
109 namespace util::bitmask {
110
111 template<>
112 struct enable_ops<Texture::DirtyMask> : std::true_type {};
113
114 }
115}
116
117#endif // AVARA3D_VISUAL_MATERIAL_TEXTURE_H
Describes filtering, anisotropy, and coordinate wrapping for a Texture.
Definition: Sampler.h:23
Image or cubemap data together with the Sampler used to read it.
Definition: Texture.h:32
void contents(const Contents &contents)
Sets the shared image or cubemap contents.
Texture(const Contents &contents, const std::shared_ptr< Sampler > &sampler=std::make_shared< Sampler >(), unsigned mappingChannel=0)
Creates a Texture with shared contents, sampler, and mapping channel.
void sampler(const std::shared_ptr< Sampler > &sampler)
Sets the shared Sampler; nullptr removes the explicit Sampler.
std::shared_ptr< Sampler > sampler() const
Returns the shared Sampler, or nullptr if none is assigned.
const Contents & contents() const
Returns the shared image or cubemap contents.
std::variant< std::monostate, std::shared_ptr< Image >, std::shared_ptr< CubeImage > > Contents
Texture contents: empty, a 2D Image, or a CubeImage.
Definition: Texture.h:38
unsigned mappingChannel() const
Returns the stored texture-coordinate mapping channel.
void mappingChannel(unsigned channel)
Sets the stored texture-coordinate mapping channel.
Texture()
Creates an empty Texture with no contents or Sampler and mapping channel 0.