MethodClear.cs 2.2 KB

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