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 TransferTextureSource = 0x8, // Texture supports being a copy source
62 TransferTextureDestination = 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 , alias(CoreGraphics::InvalidTextureId)
130 {};
131
135 const void* data;
142 bool clear;
143 union
144 {
149 };
150 bool windowRelative : 1; // size is a window relative percentage if true, other wise size is an absolute size
151 bool bindless : 1;
152 bool sparse : 1; // use sparse memory
156};
157
163
168
170{
172};
173
180
182const TextureId CreateTexture(const TextureCreateInfo& info);
184void DestroyTexture(const TextureId id);
185
208
213
215void TextureWindowResized(const TextureId id);
216
219
230
232void TextureSparseEvict(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex);
234void TextureSparseMakeResident(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex);
241
243bool TextureUpdate(const CoreGraphics::CmdBufferId cmd, CoreGraphics::TextureId tex, const SizeT width, SizeT height, SizeT mip, SizeT layer, const void* data, SizeT dataSize);
244
249
252
255
256#ifdef WITH_NEBULA_EDITOR
259extern Util::Array<CoreGraphics::TextureId> TrackedTextures;
260#endif
261
262//------------------------------------------------------------------------------
265inline TextureType
267{
268 if (string == "Texture1D") return Texture1D;
269 else if (string == "Texture2D") return Texture2D;
270 else if (string == "Texture3D") return Texture3D;
271 else if (string == "TextureCube") return TextureCube;
272 else if (string == "Texture1DArray") return Texture1DArray;
273 else if (string == "Texture2DArray") return Texture2DArray;
274 else if (string == "TextureCubeArray") return TextureCubeArray;
275 else
276 {
277 n_error("Unknown texture type '%s'", string.AsCharPtr());
278 return Texture1D;
279 }
280}
281
282//------------------------------------------------------------------------------
285inline TextureUsage
287{
288 Util::Array<Util::String> comps = string.Tokenize("|");
289 TextureUsage usage = TextureUsage(0x0);
290
291 for (IndexT i = 0; i < comps.Size(); i++)
292 {
293 if (comps[i] == "Sample") usage |= SampleTexture;
294 else if (comps[i] == "Render") usage |= RenderTexture;
295 else if (comps[i] == "ReadWrite") usage |= ReadWriteTexture;
296 else if (comps[i] == "TransferSource") usage |= TransferTextureSource;
297 else if (comps[i] == "TransferDestination") usage |= TransferTextureDestination;
298 }
299
300 return usage;
301}
302
303extern TextureId White1D;
304extern TextureId Black2D;
305extern TextureId White2D;
306extern TextureId WhiteCube;
307extern TextureId White3D;
308extern TextureId White1DArray;
309extern TextureId White2DArray;
310extern TextureId WhiteCubeArray;
311extern TextureId Red2D;
312extern TextureId Green2D;
313extern TextureId Blue2D;
314
315} // 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:878
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:110
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:94
SizeT TextureSparseGetNumPages(const CoreGraphics::TextureId id, IndexT layer, IndexT mip)
get the number of pages for a given layer and mip
Definition vktexture.cc:929
TextureSparsePageSize TextureSparseGetPageSize(const CoreGraphics::TextureId id)
get the texture page size, which is constant for the whole texture
Definition vktexture.cc:875
void TextureSparseCommitChanges(const CoreGraphics::TextureId id)
commit texture sparse page updates
Definition vktexture.cc:1119
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:916
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:117
void TextureSparseEvictMip(const CoreGraphics::TextureId id, IndexT layer, IndexT mip)
evict a whole mip
Definition vktexture.cc:1037
SizeT TextureGetNumLayers(const TextureId id)
get number of layers
Definition vktexture.cc:779
CoreGraphics::PixelFormat::Code TextureGetPixelFormat(const TextureId id)
get texture pixel format
Definition vktexture.cc:752
void TextureSparseEvict(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex)
evict a page
Definition vktexture.cc:958
TextureDimensions TextureGetDimensions(const TextureId id)
get texture dimensions
Definition vktexture.cc:733
Util::StringAtom TextureGetName(const TextureId id)
Get name of texture.
Definition vktexture.cc:723
TextureId Black2D
Definition texture.cc:15
TextureType TextureTypeFromString(const Util::String &string)
Definition texture.h:266
TextureId White1D
Definition texture.cc:14
const CoreGraphics::ImageLayout TextureGetDefaultLayout(const TextureId id)
get default texture layout
Definition vktexture.cc:815
TextureId Blue2D
Definition texture.cc:24
TextureUsage
type of texture usage
Definition texture.h:56
@ TransferTextureSource
Definition texture.h:61
@ 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
@ TransferTextureDestination
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:286
void TextureSparseMakeResident(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, IndexT pageIndex)
make a page resident
Definition vktexture.cc:998
void TextureSetHighestLod(const CoreGraphics::TextureId id, uint lod)
Set highest LOD on texture.
Definition vktexture.cc:1396
TextureId White3D
Definition texture.cc:18
SizeT TextureGetNumMips(const TextureId id)
get number of mips
Definition vktexture.cc:770
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:1371
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:833
const CoreGraphics::TextureId TextureGetAlias(const TextureId id)
get texture alias, returns invalid id if not aliased
Definition vktexture.cc:797
IndexT TextureSparseGetMaxMip(const CoreGraphics::TextureId id)
get highest sparse mip
Definition vktexture.cc:946
TextureRelativeDimensions TextureGetRelativeDimensions(const TextureId id)
get texture relative dimensions
Definition vktexture.cc:743
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:1347
void DestroyTexture(const TextureId id)
destroy vertex buffer
Definition vktexture.cc:709
void TextureSparseMakeMipResident(const CoreGraphics::TextureId id, IndexT layer, IndexT mip)
make a whole mip resident
Definition vktexture.cc:1078
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:893
TextureId White2D
Definition texture.cc:16
const CoreGraphics::TextureUsage TextureGetUsage(const TextureId id)
get texture usage
Definition vktexture.cc:806
uint TextureGetBindlessHandle(const TextureId id)
get bindless texture handle
Definition vktexture.cc:824
TextureId WhiteCube
Definition texture.cc:17
const Util::Array< CoreGraphics::TextureId > & TextureGetCreated()
Definition texture.cc:208
TextureId WhiteCubeArray
Definition texture.cc:21
SizeT TextureGetNumSamples(const TextureId id)
get sample count
Definition vktexture.cc:788
TextureType TextureGetType(const TextureId id)
get texture type
Definition vktexture.cc:761
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:564
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:844
TextureCreateInfoAdjusted TextureGetAdjustedInfo(const TextureCreateInfo &info)
helper function to setup RenderTextureInfo, already implemented
Definition texture.cc:143
Compile time configuration options for the CoreGraphics subsystem.
Graphics memory interface.
#define RESOURCE_ID_TYPE(type)
Definition resourceid.h:41
#define __ImplementEnumBitOperators(type)
Neat macro to make enums act as bit flags, be able to check if bits are set, and convert to integers.
Definition rttimacros.h:376
Definition memory.h:41
Definition commandbuffer.h:148
Definition texture.h:100
uint stencil
Definition texture.h:102
float depth
Definition texture.h:101
float heightScale
Definition texture.h:160
CoreGraphics::WindowId window
Definition texture.h:161
float widthScale
Definition texture.h:160
float depthScale
Definition texture.h:160
Definition texture.h:106
float width
Definition texture.h:139
Util::StringAtom tag
Definition texture.h:134
uint mips
Definition texture.h:140
Math::uint4 clearColorU4
Definition texture.h:146
const void * data
Definition texture.h:135
bool windowRelative
Definition texture.h:150
bool sparse
Definition texture.h:152
DepthStencilClear clearDepthStencil
Definition texture.h:148
Math::float4 clearColorF4
Definition texture.h:145
CoreGraphics::TextureSwizzle swizzle
Definition texture.h:155
uint samples
Definition texture.h:141
bool clear
Definition texture.h:142
bool bindless
Definition texture.h:151
CoreGraphics::TextureType type
Definition texture.h:137
TextureCreateInfo()
Definition texture.h:107
CoreGraphics::TextureUsage usage
Definition texture.h:133
CoreGraphics::ImageLayout defaultLayout
Definition texture.h:154
CoreGraphics::PixelFormat::Code format
Definition texture.h:138
Resources::ResourceName name
Definition texture.h:132
SizeT dataSize
Definition texture.h:136
Math::int4 clearColorI4
Definition texture.h:147
float depth
Definition texture.h:139
uint minMip
Definition texture.h:140
float height
Definition texture.h:139
CoreGraphics::TextureId alias
Definition texture.h:153
uint layers
Definition texture.h:140
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:175
TextureSparsePageSize extent
Definition texture.h:177
TextureSparsePageOffset offset
Definition texture.h:176
CoreGraphics::Alloc alloc
Definition texture.h:178
uint z
Definition texture.h:171
uint y
Definition texture.h:171
uint x
Definition texture.h:171
Definition texture.h:165
uint height
Definition texture.h:166
uint depth
Definition texture.h:166
uint width
Definition texture.h:166
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.cs:8
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