ProfileWindowBars.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using OpenTK;
  4. using OpenTK.Graphics.OpenGL;
  5. namespace Ryujinx.Profiler.UI
  6. {
  7. public partial class ProfileWindow
  8. {
  9. private void DrawBars(float xOffset, float yOffset, float width)
  10. {
  11. if (_sortedProfileData.Count != 0)
  12. {
  13. long maxAverage;
  14. long maxTotal;
  15. int verticalIndex = 0;
  16. float barHeight = (LineHeight - LinePadding) / 3.0f;
  17. // Get max values
  18. long maxInstant = maxAverage = maxTotal = 0;
  19. foreach (KeyValuePair<ProfileConfig, TimingInfo> kvp in _sortedProfileData)
  20. {
  21. maxInstant = Math.Max(maxInstant, kvp.Value.Instant);
  22. maxAverage = Math.Max(maxAverage, kvp.Value.AverageTime);
  23. maxTotal = Math.Max(maxTotal, kvp.Value.TotalTime);
  24. }
  25. GL.Enable(EnableCap.ScissorTest);
  26. GL.Begin(PrimitiveType.Triangles);
  27. foreach (var entry in _sortedProfileData)
  28. {
  29. // Instant
  30. GL.Color3(Color.Blue);
  31. float bottom = GetLineY(yOffset, LineHeight, LinePadding, true, verticalIndex++);
  32. float top = bottom + barHeight;
  33. float right = (float)entry.Value.Instant / maxInstant * width + xOffset;
  34. // Skip rendering out of bounds bars
  35. if (top < 0 || bottom > Height)
  36. continue;
  37. GL.Vertex2(xOffset, bottom);
  38. GL.Vertex2(xOffset, top);
  39. GL.Vertex2(right, top);
  40. GL.Vertex2(right, top);
  41. GL.Vertex2(right, bottom);
  42. GL.Vertex2(xOffset, bottom);
  43. // Average
  44. GL.Color3(Color.Green);
  45. top += barHeight;
  46. bottom += barHeight;
  47. right = (float)entry.Value.AverageTime / maxAverage * width + xOffset;
  48. GL.Vertex2(xOffset, bottom);
  49. GL.Vertex2(xOffset, top);
  50. GL.Vertex2(right, top);
  51. GL.Vertex2(right, top);
  52. GL.Vertex2(right, bottom);
  53. GL.Vertex2(xOffset, bottom);
  54. // Total
  55. GL.Color3(Color.Red);
  56. top += barHeight;
  57. bottom += barHeight;
  58. right = (float)entry.Value.TotalTime / maxTotal * width + xOffset;
  59. GL.Vertex2(xOffset, bottom);
  60. GL.Vertex2(xOffset, top);
  61. GL.Vertex2(right, top);
  62. GL.Vertex2(right, top);
  63. GL.Vertex2(right, bottom);
  64. GL.Vertex2(xOffset, bottom);
  65. }
  66. GL.End();
  67. GL.Disable(EnableCap.ScissorTest);
  68. }
  69. }
  70. }
  71. }