Skip to content

Commit

Permalink
Merge pull request #880 from Tom94/address-hotspots
Browse files Browse the repository at this point in the history
Avoid delegate creation in DrawQuad and DrawTriangle
  • Loading branch information
peppy committed Jul 9, 2017
2 parents 209490d + abbf191 commit 7cf41b3
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions osu.Framework/Graphics/OpenGL/Textures/TextureGLSingle.cs
Expand Up @@ -20,8 +20,20 @@ internal class TextureGLSingle : TextureGL
{
public const int MAX_MIPMAP_LEVELS = 3;

private static QuadBatch<TexturedVertex2D> quadBatch;
private static LinearBatch<TexturedVertex2D> triangleBatch;
private static readonly Action<TexturedVertex2D> default_quad_action;
private static readonly Action<TexturedVertex2D> default_triangle_action;

static TextureGLSingle()
{
QuadBatch<TexturedVertex2D> quadBatch = new QuadBatch<TexturedVertex2D>(512, 128);
default_quad_action = quadBatch.Add;

// We multiply the size param by 3 such that the amount of vertices is a multiple of the amount of vertices
// per primitive (triangles in this case). Otherwise overflowing the batch will result in wrong
// grouping of vertices into primitives.
LinearBatch<TexturedVertex2D> triangleBatch = new LinearBatch<TexturedVertex2D>(512 * 3, 128, PrimitiveType.Triangles);
default_triangle_action = triangleBatch.Add;
}

private readonly ConcurrentQueue<TextureUpload> uploadQueue = new ConcurrentQueue<TextureUpload>();

Expand Down Expand Up @@ -136,14 +148,7 @@ public override void DrawTriangle(Triangle vertexTriangle, RectangleF? textureRe
RectangleF inflatedTexRect = texRect.Inflate(inflationAmount);

if (vertexAction == null)
{
if (triangleBatch == null)
// We multiply the size param by 3 such that the amount of vertices is a multiple of the amount of vertices
// per primitive (triangles in this case). Otherwise overflowing the batch will result in wrong
// grouping of vertices into primitives.
triangleBatch = new LinearBatch<TexturedVertex2D>(512 * 3, 128, PrimitiveType.Triangles);
vertexAction = triangleBatch.Add;
}
vertexAction = default_triangle_action;

// We split the triangle into two, such that we can obtain smooth edges with our
// texture coordinate trick. We might want to revert this to drawing a single
Expand Down Expand Up @@ -218,11 +223,7 @@ public override void DrawQuad(Quad vertexQuad, RectangleF? textureRect, ColourIn
Vector2 blendRange = blendRangeOverride ?? inflationAmount;

if (vertexAction == null)
{
if (quadBatch == null)
quadBatch = new QuadBatch<TexturedVertex2D>(512, 128);
vertexAction = quadBatch.Add;
}
vertexAction = default_quad_action;

vertexAction(new TexturedVertex2D
{
Expand Down

0 comments on commit 7cf41b3

Please sign in to comment.