Nebula
Loading...
Searching...
No Matches
texture.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
12#include "coregraphics/config.h"
13#include "coregraphics/window.h"
14#include "coregraphics/memory.h"
15#include "math/rectangle.h"
16#include "ids/idallocator.h"
17
18namespace CoreGraphics
19{
20
21struct CmdBufferId;
22struct TextureSubresourceInfo;
23
27
30{
32
33 Texture1D, //> a 1-dimensional texture
34 Texture2D, //> a 2-dimensional texture
35 Texture3D, //> a 3-dimensional texture
36 TextureCube, //> a cube texture
37
38 Texture1DArray, //> a 1-dimensional texture array, depth represents array size
39 Texture2DArray, //> a 2-dimensional texture array, depth represents array size
40 TextureCubeArray, //> a cube texture array, depth represents array size * 6
41};
42
53
56{
57 InvalidTextureUsage = 0x0, // Invalid usage
58 SampleTexture = 0x1, // Texture is a shader sampleable 1D, 2D, 3D or Cube texture
59 RenderTexture = 0x2, // Texture supports to be rendered to as an attachment, also supports sampling
60 ReadWriteTexture = 0x4, // Texture supports to be bound as an RWTexture (DX) or Image (GL/Vulkan), also supports sampling
61 TransferSourceTexture = 0x8, // Texture supports being a copy source
62 TransferDestinationTexture = 0x10, // Texture supports being a copy destination
63 DeviceExclusive = 0x20 // Texture will be managed entirely by the device (copy target, RW target, etc)
64};
66
68{
70
71 bool operator==(const TextureDimensions& dims) const
72 {
73 return this->width == dims.width && this->height == dims.height && this->depth == dims.depth;
74 }
75};
76
81
83{
84 None, // No swizzle
85 Red,
86 Green,
87 Blue,
88 Alpha,
89 Zero,
90 One
91};
92
97
98static const ubyte TextureAutoMips = 0xFF;
100{
101 float depth;
103};
104
106{
108 : name(""_atm)
110 , tag(""_atm)
111 , data(nullptr)
112 , dataSize(0)
113 , type(Texture2D)
114 , format(CoreGraphics::PixelFormat::R8G8B8A8)
115 , width(1)
116 , height(1)
117 , depth(1)
118 , mips(1)
119 , minMip(0)
120 , layers(1)
121 , samples(1)
122 , clear(false)
123 , clearColorF4{0,0,0,0}
124 , windowRelative(false)
125 , bindless(true)
126 , sparse(false)
127 , allowCast(false)
128 , alias(CoreGraphics::InvalidTextureId)
131 {};
132
136 const void* data;
143 bool clear;
144 union
145 {
150 };
151 bool windowRelative : 1; // size is a window relative percentage if true, other wise size is an absolute size
152 bool bindless : 1;
153 bool sparse : 1; // use sparse memory
154 bool allowCast : 1; // Allow view to cast format, also enables access modes not available for original format
158};
159
165
170
172{
174};
175
182
184const TextureId CreateTexture(const TextureCreateInfo& info);
186void DestroyTexture(const TextureId id);
187
210
215
217void TextureWindowResized(const TextureId id);
218
221
232
234void TextureSparseEvict(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex);
236void TextureSparseMakeResident(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex);
243
245bool TextureUpdate(const CoreGraphics::CmdBufferId cmd, CoreGraphics::TextureId tex, const SizeT width, SizeT height, SizeT mip, SizeT layer, const void* data, SizeT dataSize);
246
251
254
257
258#ifdef WITH_NEBULA_EDITOR
261extern Util::Array<CoreGraphics::TextureId> TrackedTextures;
262#endif
263
264//------------------------------------------------------------------------------
267inline TextureType
269{
270 if (string == "Texture1D") return Texture1D;
271 else if (string == "Texture2D") return Texture2D;
272 else if (string == "Texture3D") return Texture3D;
273 else if (string == "TextureCube") return TextureCube;
274 else if (string == "Texture1DArray") return Texture1DArray;
275 else if (string == "Texture2DArray") return Texture2DArray;
276 else if (string == "TextureCubeArray") return TextureCubeArray;
277 else
278 {
279 n_error("Unknown texture type '%s'", string.AsCharPtr());
280 return Texture1D;
281 }
282}
283
284//------------------------------------------------------------------------------
287inline TextureUsage
289{
290 Util::Array<Util::String> comps = string.Tokenize("|");
291 TextureUsage usage = TextureUsage(0x0);
292
293 for (IndexT i = 0; i < comps.Size(); i++)
294 {
295 if (comps[i] == "Sample") usage |= SampleTexture;
296 else if (comps[i] == "Render") usage |= RenderTexture;
297 else if (comps[i] == "ReadWrite") usage |= ReadWriteTexture;
298 else if (comps[i] == "TransferSource") usage |= TransferSourceTexture;
299 else if (comps[i] == "TransferDestination") usage |= TransferDestinationTexture;
300 }
301
302 return usage;
303}
304
305extern TextureId White1D;
306extern TextureId Black2D;
307extern TextureId White2D;
308extern TextureId WhiteCube;
309extern TextureId White3D;
310extern TextureId White1DArray;
311extern TextureId White2DArray;
312extern TextureId WhiteCubeArray;
313extern TextureId Red2D;
314extern TextureId Green2D;
315extern TextureId Blue2D;
316
317} // CoreGraphics
Pixel format enumeration.
Definition pixelformat.h:22
Code
enums
Definition pixelformat.h:26
Nebula's dynamic array class.
Definition array.h:60
const SizeT Size() const
get number of elements in array
Definition array.h:880
A StringAtom.
Definition stringatom.h:22
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
#define _DECL_ACQUIRE_RELEASE(ty)
Definition idallocator.h:88
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
ImageLayout
Definition config.h:97
SizeT TextureSparseGetNumPages(const CoreGraphics::TextureId id, IndexT layer, IndexT mip)
get the number of pages for a given layer and mip
Definition vktexture.cc:972
TextureSparsePageSize TextureSparseGetPageSize(const CoreGraphics::TextureId id)
get the texture page size, which is constant for the whole texture
Definition vktexture.cc:918
void TextureSparseCommitChanges(const CoreGraphics::TextureId id)
commit texture sparse page updates
Definition vktexture.cc:1162
TextureType
texture types
Definition texture.h:30
@ Texture3D
Definition texture.h:35
@ Texture1D
Definition texture.h:33
@ Texture1DArray
Definition texture.h:38
@ InvalidTextureType
Definition texture.h:31
@ TextureCube
Definition texture.h:36
@ TextureCubeArray
Definition texture.h:40
@ Texture2DArray
Definition texture.h:39
@ Texture2D
Definition texture.h:34
const TextureSparsePage & TextureSparseGetPage(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex)
get texture page
Definition vktexture.cc:959
void TextureGenerateMipmaps(const CoreGraphics::CmdBufferId cmdBuf, const TextureId id)
generate mipmaps for texture
Definition texture.cc:33
bool TextureUpdate(const CoreGraphics::CmdBufferId cmd, CoreGraphics::TextureId tex, const SizeT width, SizeT height, SizeT mip, SizeT layer, const void *data, SizeT dataSize)
Update texture from data buffer, returns true if there is enough upload heap space.
Definition texture.cc:119
void TextureSparseEvictMip(const CoreGraphics::TextureId id, IndexT layer, IndexT mip)
evict a whole mip
Definition vktexture.cc:1080
SizeT TextureGetNumLayers(const TextureId id)
get number of layers
Definition vktexture.cc:822
CoreGraphics::PixelFormat::Code TextureGetPixelFormat(const TextureId id)
get texture pixel format
Definition vktexture.cc:795
void TextureSparseEvict(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex)
evict a page
Definition vktexture.cc:1001
TextureDimensions TextureGetDimensions(const TextureId id)
get texture dimensions
Definition vktexture.cc:776
Util::StringAtom TextureGetName(const TextureId id)
Get name of texture.
Definition vktexture.cc:766
TextureId Black2D
Definition texture.cc:15
TextureType TextureTypeFromString(const Util::String &string)
Definition texture.h:268
TextureId White1D
Definition texture.cc:14
const CoreGraphics::ImageLayout TextureGetDefaultLayout(const TextureId id)
get default texture layout
Definition vktexture.cc:858
TextureId Blue2D
Definition texture.cc:24
TextureUsage
type of texture usage
Definition texture.h:56
@ SampleTexture
Definition texture.h:58
@ InvalidTextureUsage
Definition texture.h:57
@ RenderTexture
Definition texture.h:59
@ ReadWriteTexture
Definition texture.h:60
@ DeviceExclusive
Definition texture.h:63
@ TransferSourceTexture
Definition texture.h:61
@ TransferDestinationTexture
Definition texture.h:62
TextureCubeFace
cube map face
Definition texture.h:45
@ NegX
Definition texture.h:47
@ NegY
Definition texture.h:49
@ NegZ
Definition texture.h:51
@ PosY
Definition texture.h:48
@ PosX
Definition texture.h:46
@ PosZ
Definition texture.h:50
TextureId White1DArray
Definition texture.cc:19
static const ubyte TextureAutoMips
Definition texture.h:98
TextureUsage TextureUsageFromString(const Util::String &string)
Definition texture.h:288
void TextureSparseMakeResident(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex)
make a page resident
Definition vktexture.cc:1041
void TextureSetHighestLod(const CoreGraphics::TextureId id, uint lod)
Set highest LOD on texture.
Definition vktexture.cc:1439
TextureId White3D
Definition texture.cc:18
SizeT TextureGetNumMips(const TextureId id)
get number of mips
Definition vktexture.cc:813
void TextureClearDepthStencil(const CoreGraphics::CmdBufferId cmd, const CoreGraphics::TextureId id, float depth, uint stencil, const CoreGraphics::ImageLayout layout, const CoreGraphics::TextureSubresourceInfo &subres)
clear texture with depth-stencil
Definition vktexture.cc:1414
TextureId White2DArray
Definition texture.cc:20
TextureId Red2D
Definition texture.cc:22
TextureId Green2D
Definition texture.cc:23
uint TextureGetStencilBindlessHandle(const TextureId id)
get bindless texture handle
Definition vktexture.cc:876
const CoreGraphics::TextureId TextureGetAlias(const TextureId id)
get texture alias, returns invalid id if not aliased
Definition vktexture.cc:840
IndexT TextureSparseGetMaxMip(const CoreGraphics::TextureId id)
get highest sparse mip
Definition vktexture.cc:989
TextureRelativeDimensions TextureGetRelativeDimensions(const TextureId id)
get texture relative dimensions
Definition vktexture.cc:786
void TextureClearColor(const CoreGraphics::CmdBufferId cmd, const CoreGraphics::TextureId id, Math::vec4 color, const CoreGraphics::ImageLayout layout, const CoreGraphics::TextureSubresourceInfo &subres)
clear texture with color
Definition vktexture.cc:1390
void DestroyTexture(const TextureId id)
destroy vertex buffer
Definition vktexture.cc:752
void TextureSparseMakeMipResident(const CoreGraphics::TextureId id, IndexT layer, IndexT mip)
make a whole mip resident
Definition vktexture.cc:1121
TextureChannelMapping
Definition texture.h:83
IndexT TextureSparseGetPageIndex(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT x, IndexT y, IndexT z)
get the page index at a given coordinate
Definition vktexture.cc:936
TextureId White2D
Definition texture.cc:16
const CoreGraphics::TextureUsage TextureGetUsage(const TextureId id)
get texture usage
Definition vktexture.cc:849
uint TextureGetBindlessHandle(const TextureId id)
get bindless texture handle
Definition vktexture.cc:867
TextureId WhiteCube
Definition texture.cc:17
const Util::Array< CoreGraphics::TextureId > & TextureGetCreated()
Definition texture.cc:214
TextureId WhiteCubeArray
Definition texture.cc:21
SizeT TextureGetNumSamples(const TextureId id)
get sample count
Definition vktexture.cc:831
TextureType TextureGetType(const TextureId id)
get texture type
Definition vktexture.cc:804
const TextureId CreateTexture(const TextureCreateInfo &info)
create new vertex buffer with intended usage, access and CPU syncing parameters, together with size o...
Definition vktexture.cc:606
void TextureWindowResized(const TextureId id)
If texture is bound to the window resolution, reset the internal texture without mucking with the tex...
Definition vktexture.cc:887
TextureCreateInfoAdjusted TextureGetAdjustedInfo(const TextureCreateInfo &info)
helper function to setup RenderTextureInfo, already implemented
Definition texture.cc:149
@ None
Definition resourceloader.h:51
Compile time configuration options for the CoreGraphics subsystem.
Graphics memory interface.
#define RESOURCE_ID_TYPE(type)
Definition resourceid.h:41
#define __ImplementEnumBitOperators(type)
Definition memory.h:41
Definition commandbuffer.h:155
Definition texture.h:100
uint stencil
Definition texture.h:102
float depth
Definition texture.h:101
float heightScale
Definition texture.h:162
CoreGraphics::WindowId window
Definition texture.h:163
float widthScale
Definition texture.h:162
float depthScale
Definition texture.h:162
Definition texture.h:106
float width
Definition texture.h:140
Util::StringAtom tag
Definition texture.h:135
uint mips
Definition texture.h:141
Math::uint4 clearColorU4
Definition texture.h:147
const void * data
Definition texture.h:136
bool windowRelative
Definition texture.h:151
bool sparse
Definition texture.h:153
DepthStencilClear clearDepthStencil
Definition texture.h:149
Math::float4 clearColorF4
Definition texture.h:146
CoreGraphics::TextureSwizzle swizzle
Definition texture.h:157
bool allowCast
Definition texture.h:154
uint samples
Definition texture.h:142
bool clear
Definition texture.h:143
bool bindless
Definition texture.h:152
CoreGraphics::TextureType type
Definition texture.h:138
TextureCreateInfo()
Definition texture.h:107
CoreGraphics::TextureUsage usage
Definition texture.h:134
CoreGraphics::ImageLayout defaultLayout
Definition texture.h:156
CoreGraphics::PixelFormat::Code format
Definition texture.h:139
Resources::ResourceName name
Definition texture.h:133
SizeT dataSize
Definition texture.h:137
Math::int4 clearColorI4
Definition texture.h:148
float depth
Definition texture.h:140
uint minMip
Definition texture.h:141
float height
Definition texture.h:140
CoreGraphics::TextureId alias
Definition texture.h:155
uint layers
Definition texture.h:141
Definition texture.h:68
SizeT width
Definition texture.h:69
SizeT height
Definition texture.h:69
bool operator==(const TextureDimensions &dims) const
Definition texture.h:71
SizeT depth
Definition texture.h:69
texture type
Definition texture.h:25
float height
Definition texture.h:79
float width
Definition texture.h:79
float depth
Definition texture.h:79
Definition texture.h:177
TextureSparsePageSize extent
Definition texture.h:179
TextureSparsePageOffset offset
Definition texture.h:178
CoreGraphics::Alloc alloc
Definition texture.h:180
uint z
Definition texture.h:173
uint y
Definition texture.h:173
uint x
Definition texture.h:173
Definition texture.h:167
uint height
Definition texture.h:168
uint depth
Definition texture.h:168
uint width
Definition texture.h:168
Definition texture.h:94
TextureChannelMapping alpha
Definition texture.h:95
TextureChannelMapping red
Definition texture.h:95
TextureChannelMapping blue
Definition texture.h:95
TextureChannelMapping green
Definition texture.h:95
Definition window.h:25
Definition scalar.h:76
Definition scalar.h:103
Definition scalar.h:130
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition string.h:50
unsigned char ubyte
Definition types.h:34
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48