CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
RendererTexture.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
12
14
18
20
21namespace CeresEngine {
22
27 Compressed = 1u << 0u,
28
31 Converted = 1u << 1u,
32 };
33
35 using RendererTextureFlags = Flags<RendererTextureFlag>;
37
38
60
65
68
71
73 CubeMap,
74 };
75
79 HasMipMaps = (1u << 0u),
80 };
81
85
86
89
105 private:
108
112
115
118
121
125
131
132 public:
134 explicit RendererTexture(RendererTextureManager& manager, const TexturePtr& engineImage);
135
140
141 public:
148
149 public:
152
155
158
161
164
167
170
173
176
179
182
184 [[nodiscard]] bool isReady() const noexcept { return isRelocating() || isUploaded(); }
185
187 [[nodiscard]] explicit operator bool() const noexcept { return isReady(); }
188
190 [[nodiscard]] const SPtr<Texture>& getResource() const noexcept { return mResource; }
191
193 [[nodiscard]] const GPUImagePtr& getImage() const noexcept { return mImage; }
194
196 [[nodiscard]] static const GPUImagePtr& getImage(const RendererTexture& texture) { return texture.getImage(); }
197
199 [[nodiscard]] static GPUImagePtr getImage(const RendererTexture* const texture) { return texture != nullptr ? texture->getImage() : nullptr; }
200
202 [[nodiscard]] static GPUImagePtr getImage(const RendererTexturePtr& texture) { return texture != nullptr ? texture->getImage() : nullptr; }
203
204 private:
206
209
212
214 void setImage(GPUImagePtr&& image);
215
216 public:
218 };
219
222
226 private:
231
232 private:
235
238
242
246
248 bool mDirty = false;
249
250 private: // Bindless
252
255
256 public:
258 explicit RendererTextureManager(Renderer& renderer, GPUDevice& device);
259
263
264 public:
265 void prepare();
266
267 public:
278
291 [[nodiscard]] RendererTexturePtr get(const TexturePtr& image) { return getOrCreate(image); }
292
293 public: // Bindless rendering
298
299 public:
301 [[nodiscard]] Renderer& getRenderer() const { return mRenderer; }
302
303 private:
304 friend class RendererTexture;
305
309
312
314 void notifyDestroy(RendererTexture* texture) noexcept;
315 };
316} // namespace CeresEngine
#define CE_FLAGS_OPERATORS(Enum)
Defines global operators for a Flags<Enum, Storage> implementation.
Definition Flags.hpp:216
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUDevice.hpp:357
A RenderAPI object that holds a set of resources that can be bound into shader.
Definition GPUResourceSet.hpp:735
A simple reference counter base class.
Definition SmartPtr.hpp:438
The CeresEngine renderer.
Definition Renderer.hpp:35
A texture that is usable by the renderer and the GPU.
Definition RendererTexture.hpp:104
RendererTextureState getState() const noexcept
The state the renderer texture is currently in.
Definition RendererTexture.hpp:160
UInt32 mID
A ID that uniquely identifies the texture in the renderer.
Definition RendererTexture.hpp:111
Event< void()> didChangeImage
An event triggered internally in the renderer whenever the GPU image for the texture has changed.
Definition RendererTexture.hpp:147
const SPtr< Texture > & getResource() const noexcept
A pointer to the image resource object that will be uploaded to the GPU.
Definition RendererTexture.hpp:190
bool isUploading() const noexcept
The texture is in the process of being uploaded to the GPU, but the asynchronous upload operation has...
Definition RendererTexture.hpp:166
bool is2D() const noexcept
The texture represents a regular 2D texture.
Definition RendererTexture.hpp:178
bool isPending() const noexcept
The texture is not uploaded to the GPU and the upload process hasn't started yet.
Definition RendererTexture.hpp:163
GPUImagePtr mImage
The current image instance as allocated by the texture manager.
Definition RendererTexture.hpp:130
RendererTextureType getType() const noexcept
The type of renderer texture.
Definition RendererTexture.hpp:175
RendererTextureFlags getFlags() const noexcept
A set of flags for the renderer texture.
Definition RendererTexture.hpp:151
RendererTextureManager & mManager
The texture manager that owns and manages this texture instance.
Definition RendererTexture.hpp:107
RendererTextureFlags mFlags
A set of flags for the renderer texture.
Definition RendererTexture.hpp:114
~RendererTexture()
Destroys the renderer texture instance.
bool isCubeMap() const noexcept
The texture represents a cube map texture with 6 faces.
Definition RendererTexture.hpp:181
bool isCompressed() const noexcept
Definition RendererTexture.hpp:154
bool isReady() const noexcept
Checks if the texture is ready to be used by the renderer.
Definition RendererTexture.hpp:184
static const GPUImagePtr & getImage(const RendererTexture &texture)
The current image instance as allocated by the texture manager.
Definition RendererTexture.hpp:196
bool isConverted() const noexcept
Definition RendererTexture.hpp:157
TexturePtr mResource
A pointer to the image resource object that will be uploaded to the GPU.
Definition RendererTexture.hpp:124
void setImage(GPUImagePtr &&image)
The current image instance as allocated by the texture manager.
RendererTexture(RendererTextureManager &manager, const TexturePtr &engineImage)
Creates a new renderer texture instance.
void setFlags(RendererTextureFlags flags)
A set of flags for the renderer texture.
const GPUImagePtr & getImage() const noexcept
The current image instance as allocated by the texture manager.
Definition RendererTexture.hpp:193
static GPUImagePtr getImage(const RendererTexturePtr &texture)
The current image instance as allocated by the texture manager.
Definition RendererTexture.hpp:202
static GPUImagePtr getImage(const RendererTexture *const texture)
The current image instance as allocated by the texture manager.
Definition RendererTexture.hpp:199
void setState(RendererTextureState state)
The state the renderer texture is currently in.
bool isRelocating() const noexcept
The texture is uploaded to the GPU but is in the process of being relocated to another image.
Definition RendererTexture.hpp:169
bool isUploaded() const noexcept
The texture is uploaded to the GPU and is ready to be used by the renderer.
Definition RendererTexture.hpp:172
A manager class that creates, manages and handles GPU images for images and textures used by the rend...
Definition RendererTexture.hpp:225
GPUDevice & mDevice
The device to which the textures will be uploaded to.
Definition RendererTexture.hpp:237
~RendererTextureManager()
Destroys the RendererTextureManager and releases all GPU resources managed and allocated by it.
GPUResourceSetPtr mResourceSet
A pointer to the global texture resource set.
Definition RendererTexture.hpp:254
HashMap< Texture *, TextureInfo > mTexturesByResource
A map that holds texture information for each engine texture used by the renderer.
Definition RendererTexture.hpp:241
GPUResourceSetDescriptor mResourceSetDescriptor
Definition RendererTexture.hpp:251
RendererTexturePtr create(const TexturePtr &image)
Creates a new renderer texture instance for the given engine image.
void notifyDestroy(RendererTexture *texture) noexcept
Notifies the manager that the renderer texture is being destroyed.
bool mDirty
Determines if the bindless resource set set is empty.
Definition RendererTexture.hpp:248
Renderer & mRenderer
The renderer that owns this manager instance.
Definition RendererTexture.hpp:234
Renderer & getRenderer() const
The renderer that owns this manager instance.
Definition RendererTexture.hpp:301
RendererTexturePtr get(const TexturePtr &image)
Gets a renderer texture object.
Definition RendererTexture.hpp:291
RendererTextureManager(Renderer &renderer, GPUDevice &device)
Creates a new instance of the RendererTextureManager.
RendererTexturePtr getOrCreate(const TexturePtr &image)
Gets an existing or creates a new renderer texture instance for the given engine image.
Vector< RendererTexture * > mTextures
A vector that holds all renderer texture instances.
Definition RendererTexture.hpp:245
GPUImagePtr getImage(const TexturePtr &image)
Tries to locate a GPU Image for the given image.
GPUResourceSet & getResourceSet() const
Gets the resource set for the global texture table.
Definition RendererTexture.hpp:297
Base template for the event class.
Definition Event.hpp:27
Definition Application.hpp:19
Flags< RendererTextureFlag > RendererTextureFlags
Flags that can be either set by the renderer or by the user to customize the behavior of the texture.
Definition Forward.hpp:25
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
RendererTextureInternalFlag
Internal flags set by the renderer to represent the current state of the texture.
Definition RendererTexture.hpp:78
RendererTextureState
An enumeration that contains possible states for a renderer texture.
Definition RendererTexture.hpp:40
@ Pending
The texture is not uploaded to the GPU and the upload process hasn't started yet.
@ Uploading
The texture is in the process of being uploaded to the GPU, but the asynchronous upload operation has...
@ Relocating
The texture is uploaded to the GPU but is in the process of being relocated to another image.
@ Uploaded
The texture is uploaded to the GPU and is ready to be used by the renderer.
struct CeresEngine::GLState state
SPtr< Texture > TexturePtr
Definition Forward.hpp:17
RendererTextureType
An enumeration that contains possible types for a renderer texture.
Definition RendererTexture.hpp:62
@ CubeMap
The texture represents a cube map texture with 6 faces.
@ Texture3D
The texture represents a 3D texture.
@ Texture2D
The texture represents a regular 2D texture.
@ Texture1D
The texture represents a 1D texture.
@ Pending
The mesh is not uploaded to the GPU and the upload process hasn't started yet.
@ Uploading
The mesh is in the process of being uploaded to the GPU, but the asynchronous upload operation hasn't...
@ Relocating
The mesh is uploaded to the GPU but is in the process of being relocated to another vertex and index ...
@ Uploaded
The mesh is uploaded to the GPU and is ready to be used by the renderer.
RendererTextureFlag
Flags that can be either set by the renderer or by the user to customize the behavior of the texture.
Definition RendererTexture.hpp:25
@ Compressed
If set, the texture is compressed on the GPU.
@ Converted
If set, the texture required format conversion before being uploaded to the GPU.
std::uint32_t UInt32
Definition DataTypes.hpp:23
UInt32 RendererTextureID
A type that uniquely identifies a renderer texture in the bindless resource set.
Definition RendererTexture.hpp:88
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Wrapper around an enum that allows simple use of bitwise logic operations.
Definition Flags.hpp:19
constexpr bool isSet(Enum value) const noexcept
Checks whether all of the provided bits are set.
Definition Flags.hpp:54
Definition GPUResourceSet.hpp:716
Definition RendererTexture.hpp:227
RendererTexture * rendererTexture
An instance of the renderer texture.
Definition RendererTexture.hpp:229