KDGpu::TextureView
Module: Public API
Provides a specific view into a texture for rendering or sampling. More...
#include <KDGpu/texture_view.h>
Public Functions
Friends
Detailed Description
| class KDGpu::TextureView;
|
Provides a specific view into a texture for rendering or sampling.
Vulkan equivalent:VkImageView
TextureView represents a way to access a texture's data. It can view the entire texture or just a subset (specific mip levels, array layers, or aspect). Views are required for using textures in rendering, sampling, or storage.
Key features:
- View specific mip levels or array layers
- Reinterpret texture format
- Access specific aspects (color, depth, stencil)
- Required for binding textures to pipelines
Lifetime: TextureViews are created from Textures and must not outlive their parent texture. They use RAII and clean up automatically.
Usage
Creating a default texture view:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | KDGpu::Texture texture1 = device.createTexture(textureOptions);
KDGpu::TextureView view = texture1.createView(); // View entire texture
// Use in bind group
KDGpu::BindGroup bindGroupTex = device.createBindGroup(KDGpu::BindGroupOptions{
.layout = layout.handle(),
.resources = {
{
.binding = 0,
.resource = KDGpu::TextureViewSamplerBinding{
.textureView = view.handle(),
.sampler = sampler.handle(),
},
},
},
});
|
Filename: kdgpu_doc_snippets.cpp
Viewing a specific mip level:
| // Create view for mip level 2 only
KDGpu::TextureView mipView = texture1.createView(KDGpu::TextureViewOptions{
.range = {
.aspectMask = KDGpu::TextureAspectFlagBits::ColorBit,
.baseMipLevel = 2,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
},
});
|
Filename: kdgpu_doc_snippets.cpp
Cube map face views:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 | KDGpu::Texture cubemap = device.createTexture(KDGpu::TextureOptions{
.type = KDGpu::TextureType::TextureTypeCube,
.format = KDGpu::Format::R8G8B8A8_SRGB,
.extent = { 1024, 1024, 1 },
.arrayLayers = 6,
});
// View as cube map (all 6 faces)
KDGpu::TextureView cubeView = cubemap.createView(KDGpu::TextureViewOptions{
.viewType = KDGpu::ViewType::ViewTypeCube,
});
// View individual faces as 2D textures
std::array<KDGpu::TextureView, 6> faceViews;
for (uint32_t face = 0; face < 6; ++face) {
faceViews[face] = cubemap.createView(KDGpu::TextureViewOptions{
.viewType = KDGpu::ViewType::ViewType2D,
.range = {
.aspectMask = KDGpu::TextureAspectFlagBits::ColorBit,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = face,
.layerCount = 1,
},
});
}
|
Filename: kdgpu_doc_snippets.cpp
Depth and stencil views:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 | KDGpu::Texture depthStencil = device.createTexture(KDGpu::TextureOptions{
.type = KDGpu::TextureType::TextureType2D,
.format = KDGpu::Format::D24_UNORM_S8_UINT,
.extent = { width, height, 1 },
.usage = KDGpu::TextureUsageFlagBits::DepthStencilAttachmentBit,
});
// View depth and stencil together
KDGpu::TextureView depthStencilView = depthStencil.createView(KDGpu::TextureViewOptions{
.range = {
.aspectMask = KDGpu::TextureAspectFlagBits::DepthBit |
KDGpu::TextureAspectFlagBits::StencilBit,
},
});
// View depth aspect only
KDGpu::TextureView depthOnlyView = depthStencil.createView(KDGpu::TextureViewOptions{
.range = { .aspectMask = KDGpu::TextureAspectFlagBits::DepthBit },
});
// View stencil aspect only
KDGpu::TextureView stencilOnlyView = depthStencil.createView(KDGpu::TextureViewOptions{
.range = { .aspectMask = KDGpu::TextureAspectFlagBits::StencilBit },
});
|
Filename: kdgpu_doc_snippets.cpp
Array texture views:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 | KDGpu::Texture textureArray = device.createTexture(KDGpu::TextureOptions{
.type = KDGpu::TextureType::TextureType2D,
.format = KDGpu::Format::R8G8B8A8_SRGB,
.extent = { 512, 512, 1 },
.arrayLayers = 10 // 10 layers
});
// View entire array
KDGpu::TextureView arrayView = textureArray.createView(KDGpu::TextureViewOptions{
.viewType = KDGpu::ViewType::ViewType2DArray,
.range = {
.aspectMask = KDGpu::TextureAspectFlagBits::ColorBit,
.baseArrayLayer = 0,
.layerCount = 10,
},
});
// View single layer
KDGpu::TextureView singleLayer = textureArray.createView(KDGpu::TextureViewOptions{
.viewType = KDGpu::ViewType::ViewType2D,
.range = {
.aspectMask = KDGpu::TextureAspectFlagBits::ColorBit,
.baseArrayLayer = 3, // Layer 3
.layerCount = 1,
},
});
|
Filename: kdgpu_doc_snippets.cpp
Using views in render passes:
1
2
3
4
5
6
7
8
9
10
11
12
13 | auto renderPass = recorder.beginRenderPass(KDGpu::RenderPassCommandRecorderOptions{
.colorAttachments = {
{
.view = colorTextureView, // TextureView, not Texture
.loadOperation = KDGpu::AttachmentLoadOperation::Clear,
.storeOperation = KDGpu::AttachmentStoreOperation::Store,
.clearValue = { 0.0f, 0.0f, 0.0f, 1.0f },
},
},
.depthStencilAttachment = {
.view = depthTextureView,
},
});
|
Filename: kdgpu_doc_snippets.cpp
Storage image views (compute shaders):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 | KDGpu::Texture storageTexture = device.createTexture(KDGpu::TextureOptions{
.type = KDGpu::TextureType::TextureType2D,
.format = KDGpu::Format::R32G32B32A32_SFLOAT,
.extent = { width, height, 1 },
.usage = KDGpu::TextureUsageFlagBits::StorageBit,
});
KDGpu::TextureView storageView = storageTexture.createView();
KDGpu::BindGroup bindGroupStorage = device.createBindGroup(KDGpu::BindGroupOptions{
.layout = layout.handle(),
.resources = {
{
.binding = 0,
.resource = KDGpu::ImageBinding{
.textureView = storageView.handle(),
},
},
},
});
|
Filename: kdgpu_doc_snippets.cpp
Vulkan mapping:
- TextureView creation -> vkCreateImageView()
- Used in VkDescriptorImageInfo
- Used in VkFramebufferCreateInfo
See also:
Texture, Sampler, BindGroup, Device
KDGpu API Overview
KDGpu to Vulkan API Mapping
Public Functions Documentation
function TextureView
function ~TextureView
function TextureView
| TextureView(
TextureView && other
)
|
function operator=
| TextureView & operator=(
TextureView && other
)
|
function TextureView
| TextureView(
const TextureView &
) =delete
|
function operator=
| TextureView & operator=(
const TextureView &
) =delete
|
function handle
| inline const Handle< TextureView_t > handle() const
|
function isValid
| inline bool isValid() const
|
function operator Handle< TextureView_t >
| inline operator Handle< TextureView_t >() const
|
Friends
friend Texture
| friend class Texture(
Texture
);
|
friend operator==
| friend KDGPU_EXPORT bool operator==(
const TextureView & a,
const TextureView & b
);
|
Updated on 2026-03-31 at 00:02:07 +0000