Skip to content

Commit

Permalink
Fix up GLRenderer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Jul 21, 2023
1 parent e781ca7 commit 7cbd76e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
10 changes: 7 additions & 3 deletions osu.Framework/Graphics/OpenGL/Buffers/GLArrayBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

namespace osu.Framework.Graphics.OpenGL.Buffers
{
internal class GLArrayBuffer<TData> : IArrayBuffer<TData>, IGLUniformBuffer
internal interface IGLArrayBuffer : IGLUniformBuffer
{
}

internal class GLArrayBuffer<TData> : IArrayBuffer<TData>, IGLArrayBuffer
where TData : unmanaged, IEquatable<TData>
{
public int Size { get; }
Expand Down Expand Up @@ -74,13 +78,13 @@ public void Flush()
if (renderer.UseStructuredBuffers)
{
GL.BindBuffer(BufferTarget.UniformBuffer, Id);
GL.BufferSubData(BufferTarget.UniformBuffer, (IntPtr)(changeBeginIndex * elementSize), (IntPtr)(elementSize * changeCount), ref data[0]);
GL.BufferSubData(BufferTarget.UniformBuffer, (IntPtr)(changeBeginIndex * elementSize), (IntPtr)(elementSize * changeCount), ref data[changeBeginIndex]);
GL.BindBuffer(BufferTarget.UniformBuffer, 0);
}
else
{
GL.BindBuffer(BufferTarget.UniformBuffer, Id);
GL.BufferSubData(BufferTarget.UniformBuffer, (IntPtr)(changeBeginIndex * elementSize), (IntPtr)(elementSize * changeCount), ref data[0]);
GL.BufferSubData(BufferTarget.UniformBuffer, (IntPtr)(changeBeginIndex * elementSize), (IntPtr)(elementSize * changeCount), ref data[changeBeginIndex]);
GL.BindBuffer(BufferTarget.UniformBuffer, 0);
}

Expand Down
5 changes: 4 additions & 1 deletion osu.Framework/Graphics/OpenGL/Buffers/GLVertexBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ public bool SetVertex(int vertexIndex, T vertex)
{
ref var currentVertex = ref getMemory().Span[vertexIndex];

bool isNewVertex = !currentVertex.Vertex.Equals(vertex) || currentVertex.BackbufferDrawDepth != Renderer.BackbufferDrawDepth;
bool isNewVertex = !currentVertex.Vertex.Equals(vertex)
|| currentVertex.BackbufferDrawDepth != Renderer.BackbufferDrawDepth
|| currentVertex.MaskingIndex != Renderer.CurrentMaskingIndex;

currentVertex.Vertex = vertex;
currentVertex.BackbufferDrawDepth = Renderer.BackbufferDrawDepth;
currentVertex.MaskingIndex = Renderer.CurrentMaskingIndex;

return isNewVertex;
}
Expand Down
32 changes: 31 additions & 1 deletion osu.Framework/Graphics/OpenGL/Buffers/GLVertexUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,37 @@ public static void SetAttributes()
for (int i = 0; i < attributes.Count; i++)
{
GL.EnableVertexAttribArray(i);
GL.VertexAttribPointer(i, attributes[i].Count, attributes[i].Type, attributes[i].Normalized, STRIDE, attributes[i].Offset);

switch (attributes[i].Type)
{
case VertexAttribPointerType.Int:
GL.VertexAttribIPointer(i, attributes[i].Count, VertexAttribIntegerType.Int, STRIDE, attributes[i].Offset);
break;

case VertexAttribPointerType.UnsignedInt:
GL.VertexAttribIPointer(i, attributes[i].Count, VertexAttribIntegerType.UnsignedInt, STRIDE, attributes[i].Offset);
break;

case VertexAttribPointerType.Byte:
GL.VertexAttribIPointer(i, attributes[i].Count, VertexAttribIntegerType.Byte, STRIDE, attributes[i].Offset);
break;

case VertexAttribPointerType.UnsignedByte:
GL.VertexAttribIPointer(i, attributes[i].Count, VertexAttribIntegerType.UnsignedByte, STRIDE, attributes[i].Offset);
break;

case VertexAttribPointerType.Short:
GL.VertexAttribIPointer(i, attributes[i].Count, VertexAttribIntegerType.Short, STRIDE, attributes[i].Offset);
break;

case VertexAttribPointerType.UnsignedShort:
GL.VertexAttribIPointer(i, attributes[i].Count, VertexAttribIntegerType.UnsignedShort, STRIDE, attributes[i].Offset);
break;

default:
GL.VertexAttribPointer(i, attributes[i].Count, attributes[i].Type, attributes[i].Normalized, STRIDE, attributes[i].Offset);
break;
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion osu.Framework/Graphics/OpenGL/Shaders/GLShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ public virtual void BindUniformBlock(string blockName, IUniformBuffer buffer)
EnsureShaderCompiled();

renderer.FlushCurrentBatch(FlushBatchSource.BindBuffer);
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, uniformBlocks[blockName].Binding, glBuffer.Id);

if (buffer is IGLArrayBuffer)
osuTK.Graphics.OpenGL.GL.BindBufferBase(osuTK.Graphics.OpenGL.BufferRangeTarget.ShaderStorageBuffer, uniformBlocks[blockName].Binding, glBuffer.Id);
else
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, uniformBlocks[blockName].Binding, glBuffer.Id);
}

private protected virtual bool CompileInternal()
Expand Down

0 comments on commit 7cbd76e

Please sign in to comment.