-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathITextureStorage.cs
105 lines (90 loc) · 4.69 KB
/
ITextureStorage.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
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
namespace OpenWheels.Rendering
{
/// <summary>
/// Manages textures.
/// </summary>
public interface ITextureStorage
{
/// <summary>
/// The number of textures stored.
/// </summary>
int TextureCount { get; }
/// <summary>
/// Create a new texture and return its id.
/// </summary>
/// <param name="width">Width of the texture.</param>
/// <param name="height">Height of the texture.</param>
/// <param name="format">Format of the texture.</param>
/// <returns>Id of the new texture.</returns>
/// <exception cref="ArgumentException">If <paramref name="width" /> is zero or negative.</exception>
/// <exception cref="ArgumentException">If <paramref name="height" /> is zero or negative.</exception>
int CreateTexture(int width, int height, TextureFormat format);
/// <summary>
/// Destroy the texture with the given id.
/// </summary>
/// <param name="id">Id of the texture.</param>
void DestroyTexture(int id);
/// <summary>
/// Check if a texture exists.
/// </summary>
/// <param name="id">Id of the texture.</param>
/// <returns><c>true</c> if there is a matching texture, <c>false</c> if not.</returns>
bool HasTexture(int id);
/// <summary>
/// Get the size of a texture.
/// </summary>
/// <param name="id">Id of the texture.</param>
/// <returns>Size of the matching texture, <cref name="Size.Empty"/> if there is no matching texture.</returns>
Size GetTextureSize(int id);
/// <summary>
/// Get the format of a texture.
/// </summary>
/// <param name="id">Id of the texture.</param>
/// <returns>Format of the matching texture, undefined if there is no matching texture.</returns>
TextureFormat GetTextureFormat(int id);
/// <summary>
/// Set the pixel data of a texture. Data should be in row-major order. Does nothing if there is no matching texture.
/// </summary>
/// <param name="id">Id of the texture.</param>
/// <param name="data">Pixel data to set to the texture.</param>
/// <exception name="ArgumentException">If <see cref="data.Length"/> is not equal to <c>width * height * format.GetBytesPerPixel()</c> of the matching texture.</exception>
void SetData<T>(int id, ReadOnlySpan<T> data) where T : struct;
/// <summary>
/// Set the pixel data of a subregion of a texture. Data should be in row-major order. Does nothing if there is no matching texture.
/// </summary>
/// <param name="id">Id of the texture.</param>
/// <param name="rectangle">The subregion within the texture to copy data to.</param>
/// <param name="data">Pixel data to set to the texture.</param>
/// <exception name="ArgumentException">If (a part of) <see cref="subRect"/> falls outside the texture bounds.</exception>
/// <exception name="ArgumentException">If <c>data.Length</c> is not equal to <c>width * height</c> of <paramref name="subRect"/>.</exception>
void SetData<T>(int id, in Rectangle subRect, ReadOnlySpan<T> data) where T : struct;
/// <summary>
/// Invoked when a texture is created.
/// </summary>
event EventHandler<TextureCreatedEventArgs> TextureCreated;
/// <summary>
/// Invoked when a texture is destroyed.
/// </summary>
event EventHandler<TextureDestroyedEventArgs> TextureDestroyed;
}
/// <summary>
/// A dummy implementation of <see cref="ITextureStorage"/>. Can be useful for renderers that
/// do not use textures or in for debugging e.g. with a <see cref="TraceRenderer"/>.
/// </summary>
public class NullTextureStorage : ITextureStorage
{
public static NullTextureStorage Instance { get; } = new NullTextureStorage();
public int TextureCount => 0;
private NullTextureStorage() { }
public int CreateTexture(int width, int height, TextureFormat format) => 0;
public void DestroyTexture(int id) { }
public bool HasTexture(int id) => false;
public TextureFormat GetTextureFormat(int id) => TextureFormat.Rgba32;
public Size GetTextureSize(int id) => Size.Empty;
public void SetData<T>(int id, ReadOnlySpan<T> data) where T : struct { }
public void SetData<T>(int id, in Rectangle subRect, ReadOnlySpan<T> data) where T : struct { }
public event EventHandler<TextureCreatedEventArgs> TextureCreated { add { } remove { } }
public event EventHandler<TextureDestroyedEventArgs> TextureDestroyed { add { } remove { } }
}
}