MethodClear.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. if (!GetRenderEnable(state))
  16. {
  17. return;
  18. }
  19. // Scissor affects clears aswell.
  20. if (state.QueryModified(MethodOffset.ScissorState))
  21. {
  22. UpdateScissorState(state);
  23. }
  24. UpdateRenderTargetState(state, useControl: false);
  25. TextureManager.CommitGraphicsBindings();
  26. bool clearDepth = (argument & 1) != 0;
  27. bool clearStencil = (argument & 2) != 0;
  28. uint componentMask = (uint)((argument >> 2) & 0xf);
  29. int index = (argument >> 6) & 0xf;
  30. if (componentMask != 0)
  31. {
  32. var clearColor = state.Get<ClearColors>(MethodOffset.ClearColors);
  33. ColorF color = new ColorF(
  34. clearColor.Red,
  35. clearColor.Green,
  36. clearColor.Blue,
  37. clearColor.Alpha);
  38. _context.Renderer.Pipeline.ClearRenderTargetColor(index, componentMask, color);
  39. }
  40. if (clearDepth || clearStencil)
  41. {
  42. float depthValue = state.Get<float>(MethodOffset.ClearDepthValue);
  43. int stencilValue = state.Get<int> (MethodOffset.ClearStencilValue);
  44. int stencilMask = 0;
  45. if (clearStencil)
  46. {
  47. stencilMask = state.Get<StencilTestState>(MethodOffset.StencilTestState).FrontMask;
  48. }
  49. _context.Renderer.Pipeline.ClearRenderTargetDepthStencil(
  50. depthValue,
  51. clearDepth,
  52. stencilValue,
  53. stencilMask);
  54. }
  55. UpdateRenderTargetState(state, useControl: true);
  56. }
  57. }
  58. }