Skip to content

Commit d44dfb5

Browse files
authored
Merge pull request #6658 from EVAST9919/path-no-depth
Further reduce vertex count in `Path`
2 parents 87ab1e0 + ae1ba34 commit d44dfb5

File tree

6 files changed

+310
-248
lines changed

6 files changed

+310
-248
lines changed

osu.Framework/Graphics/Lines/Path.cs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
using osu.Framework.Graphics.Shaders;
1111
using osu.Framework.Allocation;
1212
using System.Collections.Generic;
13+
using System.Runtime.InteropServices;
1314
using osu.Framework.Caching;
1415
using osu.Framework.Extensions.EnumExtensions;
1516
using osu.Framework.Graphics.Rendering;
17+
using osu.Framework.Graphics.Shaders.Types;
1618
using osu.Framework.Layout;
1719
using osuTK.Graphics;
1820

@@ -34,8 +36,8 @@ public Path()
3436
[BackgroundDependencyLoader]
3537
private void load(ShaderManager shaders)
3638
{
37-
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE);
38-
pathShader = shaders.Load(VertexShaderDescriptor.TEXTURE_3, FragmentShaderDescriptor.TEXTURE);
39+
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "Path");
40+
pathShader = shaders.Load("PathPrepass", "PathPrepass");
3941
}
4042

4143
private readonly List<Vector2> vertices = new List<Vector2>();
@@ -291,20 +293,12 @@ protected Texture Texture
291293
// The path should not receive the true colour to avoid colour doubling when the frame-buffer is rendered to the back-buffer.
292294
public override DrawColourInfo DrawColourInfo => new DrawColourInfo(Color4.White, base.DrawColourInfo.Blending);
293295

294-
private Color4 backgroundColour = new Color4(0, 0, 0, 0);
296+
private static readonly Color4 background_colour = new Color4(0, 0, 0, 0);
295297

296298
/// <summary>
297299
/// The background colour to be used for the frame buffer this path is rendered to.
298300
/// </summary>
299-
public virtual Color4 BackgroundColour
300-
{
301-
get => backgroundColour;
302-
set
303-
{
304-
backgroundColour = value;
305-
Invalidate(Invalidation.DrawNode);
306-
}
307-
}
301+
public Color4 BackgroundColour => background_colour;
308302

309303
public long PathInvalidationID { get; private set; }
310304

@@ -321,7 +315,7 @@ protected override bool OnInvalidate(Invalidation invalidation, InvalidationSour
321315
return result;
322316
}
323317

324-
private readonly BufferedDrawNodeSharedData sharedData = new BufferedDrawNodeSharedData(new[] { RenderBufferFormat.D16 }, clipToRootNode: true);
318+
private readonly BufferedDrawNodeSharedData sharedData = new BufferedDrawNodeSharedData(clipToRootNode: true);
325319

326320
protected override DrawNode CreateDrawNode() => new PathBufferedDrawNode(this, new PathDrawNode(this), sharedData);
327321

@@ -335,11 +329,38 @@ public PathBufferedDrawNode(Path source, PathDrawNode child, BufferedDrawNodeSha
335329
}
336330

337331
private long pathInvalidationID = -1;
332+
private Texture texture;
333+
private Vector4 textureRect;
334+
private IUniformBuffer<PathTextureParameters> parametersBuffer;
338335

339336
public override void ApplyState()
340337
{
341338
base.ApplyState();
342339
pathInvalidationID = Source.PathInvalidationID;
340+
texture = Source.Texture;
341+
342+
var rect = texture.GetTextureRect();
343+
textureRect = new Vector4(rect.Left, rect.Top, rect.Width, rect.Height);
344+
}
345+
346+
protected override void BindUniformResources(IShader shader, IRenderer renderer)
347+
{
348+
base.BindUniformResources(shader, renderer);
349+
350+
parametersBuffer ??= renderer.CreateUniformBuffer<PathTextureParameters>();
351+
parametersBuffer.Data = new PathTextureParameters
352+
{
353+
TexRect1 = textureRect,
354+
};
355+
shader.BindUniformBlock("m_PathTextureParameters", parametersBuffer);
356+
357+
texture?.Bind(1);
358+
}
359+
360+
[StructLayout(LayoutKind.Sequential, Pack = 1)]
361+
private record struct PathTextureParameters
362+
{
363+
public UniformVector4 TexRect1;
343364
}
344365

345366
protected override long GetDrawVersion() => pathInvalidationID;

0 commit comments

Comments
 (0)