MethodClear.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 and rasterizer discard also affect clears.
  21. if (state.QueryModified(MethodOffset.ScissorState))
  22. {
  23. UpdateScissorState(state);
  24. }
  25. if (state.QueryModified(MethodOffset.RasterizeEnable))
  26. {
  27. UpdateRasterizerState(state);
  28. }
  29. int index = (argument >> 6) & 0xf;
  30. UpdateRenderTargetState(state, useControl: false, singleUse: index);
  31. TextureManager.UpdateRenderTargets();
  32. bool clearDepth = (argument & 1) != 0;
  33. bool clearStencil = (argument & 2) != 0;
  34. uint componentMask = (uint)((argument >> 2) & 0xf);
  35. if (componentMask != 0)
  36. {
  37. var clearColor = state.Get<ClearColors>(MethodOffset.ClearColors);
  38. ColorF color = new ColorF(
  39. clearColor.Red,
  40. clearColor.Green,
  41. clearColor.Blue,
  42. clearColor.Alpha);
  43. _context.Renderer.Pipeline.ClearRenderTargetColor(index, componentMask, color);
  44. }
  45. if (clearDepth || clearStencil)
  46. {
  47. float depthValue = state.Get<float>(MethodOffset.ClearDepthValue);
  48. int stencilValue = state.Get<int> (MethodOffset.ClearStencilValue);
  49. int stencilMask = 0;
  50. if (clearStencil)
  51. {
  52. stencilMask = state.Get<StencilTestState>(MethodOffset.StencilTestState).FrontMask;
  53. }
  54. _context.Renderer.Pipeline.ClearRenderTargetDepthStencil(
  55. depthValue,
  56. clearDepth,
  57. stencilValue,
  58. stencilMask);
  59. }
  60. UpdateRenderTargetState(state, useControl: true);
  61. if (renderEnable == ConditionalRenderEnabled.Host)
  62. {
  63. _context.Renderer.Pipeline.EndHostConditionalRendering();
  64. }
  65. }
  66. }
  67. }