mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
Move global UBO binding to Renderer implementations
This commit is contained in:
@@ -60,13 +60,13 @@ namespace osu.Framework.Tests.Shaders
|
||||
|
||||
private class TestGLRenderer : GLRenderer
|
||||
{
|
||||
protected override IShader CreateShader(string name, IShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore)
|
||||
=> new TestGLShader(this, name, parts.Cast<GLShaderPart>().ToArray(), globalUniformBuffer, compilationStore);
|
||||
protected override IShader CreateShader(string name, IShaderPart[] parts, ShaderCompilationStore compilationStore)
|
||||
=> new TestGLShader(this, name, parts.Cast<GLShaderPart>().ToArray(), compilationStore);
|
||||
|
||||
private class TestGLShader : GLShader
|
||||
{
|
||||
internal TestGLShader(GLRenderer renderer, string name, GLShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore)
|
||||
: base(renderer, name, parts, globalUniformBuffer, compilationStore)
|
||||
internal TestGLShader(GLRenderer renderer, string name, GLShaderPart[] parts, ShaderCompilationStore compilationStore)
|
||||
: base(renderer, name, parts, compilationStore)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -40,13 +40,13 @@ namespace osu.Framework.Tests.Shaders
|
||||
|
||||
private class TestGLRenderer : GLRenderer
|
||||
{
|
||||
protected override IShader CreateShader(string name, IShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore)
|
||||
=> new TestGLShader(this, name, parts.Cast<GLShaderPart>().ToArray(), globalUniformBuffer, compilationStore);
|
||||
protected override IShader CreateShader(string name, IShaderPart[] parts, ShaderCompilationStore compilationStore)
|
||||
=> new TestGLShader(this, name, parts.Cast<GLShaderPart>().ToArray(), compilationStore);
|
||||
|
||||
private class TestGLShader : GLShader
|
||||
{
|
||||
internal TestGLShader(GLRenderer renderer, string name, GLShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore)
|
||||
: base(renderer, name, parts, globalUniformBuffer, compilationStore)
|
||||
internal TestGLShader(GLRenderer renderer, string name, GLShaderPart[] parts, ShaderCompilationStore compilationStore)
|
||||
: base(renderer, name, parts, compilationStore)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -130,9 +130,7 @@ namespace osu.Framework.Graphics.OpenGL.Buffers
|
||||
public void DrawRange(int startIndex, int endIndex)
|
||||
{
|
||||
Bind(true);
|
||||
|
||||
int countVertices = endIndex - startIndex;
|
||||
GL.DrawElements(Type, ToElements(countVertices), DrawElementsType.UnsignedShort, (IntPtr)(ToElementIndex(startIndex) * sizeof(ushort)));
|
||||
Renderer.DrawVertices(Type, ToElementIndex(startIndex), ToElements(endIndex - startIndex));
|
||||
}
|
||||
|
||||
public void Update()
|
||||
|
||||
@@ -273,6 +273,15 @@ namespace osu.Framework.Graphics.OpenGL
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
|
||||
}
|
||||
|
||||
public void DrawVertices(PrimitiveType type, int vertexStart, int verticesCount)
|
||||
{
|
||||
var glShader = (GLShader)Shader!;
|
||||
|
||||
glShader.BindUniformBlock("g_GlobalUniforms", GlobalUniformBuffer!);
|
||||
|
||||
GL.DrawElements(type, verticesCount, DrawElementsType.UnsignedShort, (IntPtr)(vertexStart * sizeof(ushort)));
|
||||
}
|
||||
|
||||
protected override void SetScissorStateImplementation(bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
@@ -376,8 +385,8 @@ namespace osu.Framework.Graphics.OpenGL
|
||||
return new GLShaderPart(this, name, rawData, glType, store);
|
||||
}
|
||||
|
||||
protected override IShader CreateShader(string name, IShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore)
|
||||
=> new GLShader(this, name, parts.Cast<GLShaderPart>().ToArray(), globalUniformBuffer, compilationStore);
|
||||
protected override IShader CreateShader(string name, IShaderPart[] parts, ShaderCompilationStore compilationStore)
|
||||
=> new GLShader(this, name, parts.Cast<GLShaderPart>().ToArray(), compilationStore);
|
||||
|
||||
public override IFrameBuffer CreateFrameBuffer(RenderBufferFormat[]? renderBufferFormats = null, TextureFilteringMode filteringMode = TextureFilteringMode.Linear)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace osu.Framework.Graphics.OpenGL.Shaders
|
||||
{
|
||||
private readonly GLRenderer renderer;
|
||||
private readonly string name;
|
||||
private readonly IUniformBuffer<GlobalUniformData> globalUniformBuffer;
|
||||
private readonly GLShaderPart[] parts;
|
||||
|
||||
private readonly ScheduledDelegate shaderCompileDelegate;
|
||||
@@ -42,11 +41,10 @@ namespace osu.Framework.Graphics.OpenGL.Shaders
|
||||
private readonly GLShaderPart fragmentPart;
|
||||
private readonly VertexFragmentShaderCompilation compilation;
|
||||
|
||||
internal GLShader(GLRenderer renderer, string name, GLShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore)
|
||||
internal GLShader(GLRenderer renderer, string name, GLShaderPart[] parts, ShaderCompilationStore compilationStore)
|
||||
{
|
||||
this.renderer = renderer;
|
||||
this.name = name;
|
||||
this.globalUniformBuffer = globalUniformBuffer;
|
||||
this.parts = parts;
|
||||
|
||||
vertexPart = parts.Single(p => p.Type == ShaderType.VertexShader);
|
||||
@@ -88,8 +86,6 @@ namespace osu.Framework.Graphics.OpenGL.Shaders
|
||||
throw new ProgramLinkingFailedException(name, GetProgramLog());
|
||||
|
||||
IsLoaded = true;
|
||||
|
||||
BindUniformBlock("g_GlobalUniforms", globalUniformBuffer);
|
||||
}
|
||||
|
||||
internal void EnsureShaderCompiled()
|
||||
|
||||
@@ -9,7 +9,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using osu.Framework.Development;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Extensions.TypeExtensions;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Rendering.Vertices;
|
||||
@@ -130,7 +129,7 @@ namespace osu.Framework.Graphics.Rendering
|
||||
private readonly Lazy<TextureWhitePixel> whitePixel;
|
||||
private readonly LockedWeakList<Texture> allTextures = new LockedWeakList<Texture>();
|
||||
|
||||
private IUniformBuffer<GlobalUniformData>? globalUniformBuffer;
|
||||
protected IUniformBuffer<GlobalUniformData>? GlobalUniformBuffer { get; private set; }
|
||||
private IVertexBatch<TexturedVertex2D>? defaultQuadBatch;
|
||||
private IVertexBatch? currentActiveBatch;
|
||||
private MaskingInfo currentMaskingInfo;
|
||||
@@ -189,8 +188,8 @@ namespace osu.Framework.Graphics.Rendering
|
||||
foreach (var source in flush_source_statistics)
|
||||
source.Value = 0;
|
||||
|
||||
globalUniformBuffer ??= ((IRenderer)this).CreateUniformBuffer<GlobalUniformData>();
|
||||
globalUniformBuffer.Data = globalUniformBuffer.Data with
|
||||
GlobalUniformBuffer ??= ((IRenderer)this).CreateUniformBuffer<GlobalUniformData>();
|
||||
GlobalUniformBuffer.Data = GlobalUniformBuffer.Data with
|
||||
{
|
||||
IsDepthRangeZeroToOne = IsDepthRangeZeroToOne,
|
||||
IsClipSpaceYInverted = IsClipSpaceYInverted,
|
||||
@@ -606,7 +605,7 @@ namespace osu.Framework.Graphics.Rendering
|
||||
|
||||
FlushCurrentBatch(FlushBatchSource.SetProjection);
|
||||
|
||||
globalUniformBuffer!.Data = globalUniformBuffer.Data with { ProjMatrix = matrix };
|
||||
GlobalUniformBuffer!.Data = GlobalUniformBuffer.Data with { ProjMatrix = matrix };
|
||||
ProjectionMatrix = matrix;
|
||||
}
|
||||
|
||||
@@ -635,7 +634,7 @@ namespace osu.Framework.Graphics.Rendering
|
||||
|
||||
FlushCurrentBatch(FlushBatchSource.SetMasking);
|
||||
|
||||
globalUniformBuffer!.Data = globalUniformBuffer.Data with
|
||||
GlobalUniformBuffer!.Data = GlobalUniformBuffer.Data with
|
||||
{
|
||||
IsMasking = IsMaskingActive,
|
||||
MaskingRect = new Vector4(
|
||||
@@ -669,14 +668,14 @@ namespace osu.Framework.Graphics.Rendering
|
||||
maskingInfo.BorderColour.BottomRight.SRGB.G,
|
||||
maskingInfo.BorderColour.BottomRight.SRGB.B,
|
||||
maskingInfo.BorderColour.BottomRight.SRGB.A)
|
||||
: globalUniformBuffer.Data.BorderColour,
|
||||
: GlobalUniformBuffer.Data.BorderColour,
|
||||
MaskingBlendRange = maskingInfo.BlendRange,
|
||||
AlphaExponent = maskingInfo.AlphaExponent,
|
||||
EdgeOffset = maskingInfo.EdgeOffset,
|
||||
DiscardInner = maskingInfo.Hollow,
|
||||
InnerCornerRadius = maskingInfo.Hollow
|
||||
? maskingInfo.HollowCornerRadius
|
||||
: globalUniformBuffer.Data.InnerCornerRadius
|
||||
: GlobalUniformBuffer.Data.InnerCornerRadius
|
||||
};
|
||||
|
||||
if (isPushing)
|
||||
@@ -872,14 +871,14 @@ namespace osu.Framework.Graphics.Rendering
|
||||
if (wrapModeS != CurrentWrapModeS)
|
||||
{
|
||||
// Will flush the current batch internally.
|
||||
globalUniformBuffer!.Data = globalUniformBuffer.Data with { WrapModeS = (int)wrapModeS };
|
||||
GlobalUniformBuffer!.Data = GlobalUniformBuffer.Data with { WrapModeS = (int)wrapModeS };
|
||||
CurrentWrapModeS = wrapModeS;
|
||||
}
|
||||
|
||||
if (wrapModeT != CurrentWrapModeT)
|
||||
{
|
||||
// Will flush the current batch internally.
|
||||
globalUniformBuffer!.Data = globalUniformBuffer.Data with { WrapModeT = (int)wrapModeT };
|
||||
GlobalUniformBuffer!.Data = GlobalUniformBuffer.Data with { WrapModeT = (int)wrapModeT };
|
||||
CurrentWrapModeT = wrapModeT;
|
||||
}
|
||||
|
||||
@@ -957,7 +956,7 @@ namespace osu.Framework.Graphics.Rendering
|
||||
|
||||
SetFrameBufferImplementation(frameBuffer);
|
||||
|
||||
globalUniformBuffer!.Data = globalUniformBuffer.Data with { BackbufferDraw = UsingBackbuffer };
|
||||
GlobalUniformBuffer!.Data = GlobalUniformBuffer.Data with { BackbufferDraw = UsingBackbuffer };
|
||||
|
||||
FrameBuffer = frameBuffer;
|
||||
}
|
||||
@@ -1042,7 +1041,7 @@ namespace osu.Framework.Graphics.Rendering
|
||||
protected abstract IShaderPart CreateShaderPart(IShaderStore store, string name, byte[]? rawData, ShaderPartType partType);
|
||||
|
||||
/// <inheritdoc cref="IRenderer.CreateShader"/>
|
||||
protected abstract IShader CreateShader(string name, IShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore);
|
||||
protected abstract IShader CreateShader(string name, IShaderPart[] parts, ShaderCompilationStore compilationStore);
|
||||
|
||||
private IShader? mipmapShader;
|
||||
|
||||
@@ -1062,7 +1061,7 @@ namespace osu.Framework.Graphics.Rendering
|
||||
{
|
||||
CreateShaderPart(store, "mipmap.vs", store.GetRawData("sh_mipmap.vs"), ShaderPartType.Vertex),
|
||||
CreateShaderPart(store, "mipmap.fs", store.GetRawData("sh_mipmap.fs"), ShaderPartType.Fragment),
|
||||
}, globalUniformBuffer.AsNonNull(), shaderCompilationStore);
|
||||
}, shaderCompilationStore);
|
||||
|
||||
return mipmapShader;
|
||||
}
|
||||
@@ -1154,7 +1153,7 @@ namespace osu.Framework.Graphics.Rendering
|
||||
void IRenderer.PopQuadBatch() => PopQuadBatch();
|
||||
Image<Rgba32> IRenderer.TakeScreenshot() => TakeScreenshot();
|
||||
IShaderPart IRenderer.CreateShaderPart(IShaderStore store, string name, byte[]? rawData, ShaderPartType partType) => CreateShaderPart(store, name, rawData, partType);
|
||||
IShader IRenderer.CreateShader(string name, IShaderPart[] parts) => CreateShader(name, parts, globalUniformBuffer!, shaderCompilationStore);
|
||||
IShader IRenderer.CreateShader(string name, IShaderPart[] parts) => CreateShader(name, parts, shaderCompilationStore);
|
||||
|
||||
IVertexBatch<TVertex> IRenderer.CreateLinearBatch<TVertex>(int size, int maxBuffers, PrimitiveTopology topology)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace osu.Framework.Graphics.Veldrid.Shaders
|
||||
{
|
||||
private readonly string name;
|
||||
private readonly VeldridShaderPart[] parts;
|
||||
private readonly IUniformBuffer<GlobalUniformData> globalUniformBuffer;
|
||||
private readonly ShaderCompilationStore compilationStore;
|
||||
private readonly VeldridRenderer renderer;
|
||||
|
||||
@@ -43,11 +42,10 @@ namespace osu.Framework.Graphics.Veldrid.Shaders
|
||||
private readonly Dictionary<string, VeldridUniformLayout> uniformLayouts = new Dictionary<string, VeldridUniformLayout>();
|
||||
private readonly List<VeldridUniformLayout> textureLayouts = new List<VeldridUniformLayout>();
|
||||
|
||||
public VeldridShader(VeldridRenderer renderer, string name, VeldridShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore)
|
||||
public VeldridShader(VeldridRenderer renderer, string name, VeldridShaderPart[] parts, ShaderCompilationStore compilationStore)
|
||||
{
|
||||
this.name = name;
|
||||
this.parts = parts;
|
||||
this.globalUniformBuffer = globalUniformBuffer;
|
||||
this.compilationStore = compilationStore;
|
||||
this.renderer = renderer;
|
||||
|
||||
@@ -210,8 +208,6 @@ namespace osu.Framework.Graphics.Veldrid.Shaders
|
||||
renderer.Factory.CreateShader(vertexShaderDescription),
|
||||
renderer.Factory.CreateShader(fragmentShaderDescription)
|
||||
};
|
||||
|
||||
BindUniformBlock("g_GlobalUniforms", globalUniformBuffer);
|
||||
}
|
||||
|
||||
private bool isDisposed;
|
||||
|
||||
@@ -539,6 +539,8 @@ namespace osu.Framework.Graphics.Veldrid
|
||||
|
||||
var veldridShader = (VeldridShader)Shader!;
|
||||
|
||||
veldridShader.BindUniformBlock("g_GlobalUniforms", GlobalUniformBuffer!);
|
||||
|
||||
pipeline.PrimitiveTopology = type;
|
||||
Array.Resize(ref pipeline.ResourceLayouts, veldridShader.LayoutCount);
|
||||
|
||||
@@ -730,8 +732,8 @@ namespace osu.Framework.Graphics.Veldrid
|
||||
protected override IShaderPart CreateShaderPart(IShaderStore store, string name, byte[]? rawData, ShaderPartType partType)
|
||||
=> new VeldridShaderPart(rawData, partType, store);
|
||||
|
||||
protected override IShader CreateShader(string name, IShaderPart[] parts, IUniformBuffer<GlobalUniformData> globalUniformBuffer, ShaderCompilationStore compilationStore)
|
||||
=> new VeldridShader(this, name, parts.Cast<VeldridShaderPart>().ToArray(), globalUniformBuffer, compilationStore);
|
||||
protected override IShader CreateShader(string name, IShaderPart[] parts, ShaderCompilationStore compilationStore)
|
||||
=> new VeldridShader(this, name, parts.Cast<VeldridShaderPart>().ToArray(), compilationStore);
|
||||
|
||||
public override IFrameBuffer CreateFrameBuffer(RenderBufferFormat[]? renderBufferFormats = null, TextureFilteringMode filteringMode = TextureFilteringMode.Linear)
|
||||
=> new VeldridFrameBuffer(this, renderBufferFormats?.ToPixelFormats(), filteringMode.ToSamplerFilter());
|
||||
|
||||
Reference in New Issue
Block a user