-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpriteArraySet_VeldridGen.cs
92 lines (79 loc) · 3.36 KB
/
SpriteArraySet_VeldridGen.cs
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Veldrid;
namespace VeldridGen.Example.SpriteRenderer
{
internal partial class SpriteArraySet
{
public static readonly ResourceLayoutDescription Layout = new(
new ResourceLayoutElementDescription("uSprite", global::Veldrid.ResourceKind.TextureReadOnly, (ShaderStages)17),
new ResourceLayoutElementDescription("uSpriteSampler", global::Veldrid.ResourceKind.Sampler, (ShaderStages)17),
new ResourceLayoutElementDescription("_Uniform", global::Veldrid.ResourceKind.UniformBuffer, (ShaderStages)17));
public global::VeldridGen.Interfaces.ITextureArrayHolder Texture
{
get => _texture;
set
{
if (_texture == value) return;
if (_texture != null)
_texture.PropertyChanged -= PropertyDirty;
_texture = value;
if (_texture != null)
_texture.PropertyChanged += PropertyDirty;
Dirty();
}
}
public global::VeldridGen.Interfaces.ISamplerHolder Sampler
{
get => _sampler;
set
{
if (_sampler == value)
return;
if (_sampler != null)
_sampler.PropertyChanged -= PropertyDirty;
_sampler = value;
if (_sampler != null)
_sampler.PropertyChanged += PropertyDirty;
Dirty();
}
}
public global::VeldridGen.Interfaces.IBufferHolder<global::VeldridGen.Example.SpriteRenderer.SpriteUniform> Uniform
{
get => _uniform;
set
{
if (_uniform == value)
return;
_uniform = value;
Dirty();
}
}
protected override ResourceSet Build(GraphicsDevice device, ResourceLayout layout)
{
#if DEBUG
if (_texture.DeviceTexture == null) throw new System.InvalidOperationException("Tried to construct SpriteArraySet, but Texture has not been initialised. It may not have been attached to the exchange.");
if (_sampler.Sampler == null) throw new System.InvalidOperationException("Tried to construct SpriteArraySet, but Sampler has not been initialised. It may not have been attached to the exchange.");
if (_uniform.DeviceBuffer == null) throw new System.InvalidOperationException("Tried to construct SpriteArraySet, but Uniform has not been initialised. It may not have been attached to the exchange.");
#endif
return device.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
layout,
_texture.DeviceTexture,
_sampler.Sampler,
_uniform.DeviceBuffer));
}
protected override void Resubscribe()
{
if (_texture != null)
_texture.PropertyChanged += PropertyDirty;
if (_sampler != null)
_sampler.PropertyChanged += PropertyDirty;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (_texture != null)
_texture.PropertyChanged -= PropertyDirty;
if (_sampler != null)
_sampler.PropertyChanged -= PropertyDirty;
}
}
}