This repository was archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathGraphics.cs
More file actions
145 lines (114 loc) · 4.73 KB
/
Copy pathGraphics.cs
File metadata and controls
145 lines (114 loc) · 4.73 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
namespace Foster.Framework;
/// <summary>
/// The Core Graphics Module, used for Rendering
/// </summary>
public abstract class Graphics : AppModule
{
/// <summary>
/// The underlying Graphics API Name
/// </summary>
public string ApiName { get; protected set; } = "Unknown";
/// <summary>
/// The underlying Graphics API version
/// </summary>
public Version ApiVersion { get; protected set; } = new Version(0, 0, 0);
/// <summary>
/// The Underlying Graphics Device Name
/// </summary>
public string DeviceName { get; protected set; } = "Unknown";
/// <summary>
/// The Maximum Texture Width and Height supported, in pixels
/// </summary>
public int MaxTextureSize { get; protected set; } = 0;
/// <summary>
/// Whether the Frame Buffer origin is in the bottom left
/// </summary>
public bool OriginBottomLeft { get; protected set; } = false;
/// <summary>
/// The Renderer this Graphics Module implements
/// </summary>
public abstract Renderer Renderer { get; }
protected Graphics() : base(200)
{
}
protected internal override void Startup()
{
Log.Info($"{ApiName} {ApiVersion} ({DeviceName})");
}
/// <summary>
/// Clears the Color of the Target
/// </summary>
public void Clear(RenderTarget target, Color color)
{
Clear(target, Framework.Clear.Color, color, 0, 0, new RectInt(0, 0, target.RenderWidth, target.RenderHeight));
}
/// <summary>
/// Clears the Target
/// </summary>
public void Clear(RenderTarget target, Color color, float depth, int stencil)
{
Clear(target, Framework.Clear.All, color, depth, stencil, new RectInt(0, 0, target.RenderWidth, target.RenderHeight));
}
/// <summary>
/// Clears the Target
/// </summary>
public void Clear(RenderTarget target, Clear flags, Color color, float depth, int stencil, RectInt viewport)
{
if (!target.Renderable)
throw new Exception("Render Target cannot currently be drawn to");
var bounds = new RectInt(0, 0, target.RenderWidth, target.RenderHeight);
var clamped = viewport.OverlapRect(bounds);
ClearInternal(target, flags, color, depth, stencil, clamped);
}
/// <summary>
/// Clears the Target
/// </summary>
protected abstract void ClearInternal(RenderTarget target, Clear flags, Color color, float depth, int stencil, RectInt viewport);
/// <summary>
/// Draws the data from the Render pass to the Render Target.
/// This will fail if the Target is not Drawable.
/// </summary>
public void Render(ref RenderPass pass)
{
if (!pass.Target.Renderable)
throw new Exception("Render Target cannot currently be drawn to");
if (!(pass.Target is FrameBuffer) && !(pass.Target is Window))
throw new Exception("RenderTarget must be a Render Texture or a Window");
if (pass.Mesh == null)
throw new Exception("Mesh cannot be null when drawing");
if (pass.Material == null)
throw new Exception("Material cannot be null when drawing");
if (pass.Mesh.InstanceCount > 0 && (pass.Mesh.InstanceFormat == null || (pass.Mesh.InstanceCount < pass.Mesh.InstanceCount)))
throw new Exception("Trying to draw more Instances than exist in the Mesh");
if (pass.Mesh.IndexCount < pass.MeshIndexStart + pass.MeshIndexCount)
throw new Exception("Trying to draw more Indices than exist in the Mesh");
if (pass.Viewport != null)
{
var bounds = new RectInt(0, 0, pass.Target.RenderWidth, pass.Target.RenderHeight);
pass.Viewport = pass.Viewport.Value.OverlapRect(bounds);
}
RenderInternal(ref pass);
}
protected abstract void RenderInternal(ref RenderPass pass);
/// <summary>
/// Creates a new Color Texture of the given size
/// </summary>
protected internal abstract Texture.Platform CreateTexture(int width, int height, TextureFormat format);
/// <summary>
/// Creates a new render texture of the given size, with the given amount of color and depth buffers
/// </summary>
protected internal abstract FrameBuffer.Platform CreateFrameBuffer(int width, int height, TextureFormat[] attachments);
/// <summary>
/// Creates a new Shader from the Shader Source
/// </summary>
protected internal abstract Shader.Platform CreateShader(ShaderSource source);
/// <summary>
/// Creates a new Mesh
/// </summary>
protected internal abstract Mesh.Platform CreateMesh();
/// <summary>
/// Gets the Shader Source for the Batch2D
/// </summary>
protected internal abstract ShaderSource CreateShaderSourceBatch2D();
}