MethodClear.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Ryujinx.Graphics.GAL;
  2. using Ryujinx.Graphics.Gpu.State;
  3. namespace Ryujinx.Graphics.Gpu.Engine
  4. {
  5. partial class Methods
  6. {
  7. /// <summary>
  8. /// Clears the current color and depth-stencil buffers.
  9. /// Which buffers should be cleared is also specified on the argument.
  10. /// </summary>
  11. /// <param name="state">Current GPU state</param>
  12. /// <param name="argument">Method call argument</param>
  13. private void Clear(GpuState state, int argument)
  14. {
  15. ConditionalRenderEnabled renderEnable = GetRenderEnable(state);
  16. if (renderEnable == ConditionalRenderEnabled.False)
  17. {
  18. return;
  19. }
  20. // Scissor affects clears aswell.
  21. if (state.QueryModified(MethodOffset.ScissorState))
  22. {
  23. UpdateScissorState(state);
  24. }
  25. UpdateRenderTargetState(state, useControl: false);
  26. TextureManager.CommitGraphicsBindings();
  27. bool clearDepth = (argument & 1) != 0;
  28. bool clearStencil = (argument & 2) != 0;
  29. uint componentMask = (uint)((argument >> 2) & 0xf);
  30. int index = (argument >> 6) & 0xf;
  31. if (componentMask != 0)
  32. {
  33. var clearColor = state.Get<ClearColors>(MethodOffset.ClearColors);
  34. ColorF color = new ColorF(
  35. clearColor.Red,
  36. clearColor.Green,
  37. clearColor.Blue,
  38. clearColor.Alpha);
  39. _context.Renderer.Pipeline.ClearRenderTargetColor(index, componentMask, color);
  40. }
  41. if (clearDepth || clearStencil)
  42. {
  43. float depthValue = state.Get<float>(MethodOffset.ClearDepthValue);
  44. int stencilValue = state.Get<int> (MethodOffset.ClearStencilValue);
  45. int stencilMask = 0;
  46. if (clearStencil)
  47. {
  48. stencilMask = state.Get<StencilTestState>(MethodOffset.StencilTestState).FrontMask;
  49. }
  50. _context.Renderer.Pipeline.ClearRenderTargetDepthStencil(
  51. depthValue,
  52. clearDepth,
  53. stencilValue,
  54. stencilMask);
  55. }
  56. UpdateRenderTargetState(state, useControl: true);
  57. if (renderEnable == ConditionalRenderEnabled.Host)
  58. {
  59. _context.Renderer.Pipeline.EndHostConditionalRendering();
  60. }
  61. }
  62. }
  63. }