Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

98 строки
3.3 KiB

  1. namespace RenderHookAPI.Hook.DX11
  2. {
  3. // Copyright (c) 2013 Justin Stenning
  4. // Adapted from original code by Alexandre Mutel
  5. //
  6. //----------------------------------------------------------------------------
  7. // Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using SharpDX;
  27. public abstract class RendererBase : Component
  28. {
  29. public DeviceManager DeviceManager { get; protected set; }
  30. public virtual bool Show { get; set; }
  31. public Matrix World;
  32. public RendererBase()
  33. {
  34. World = Matrix.Identity;
  35. Show = true;
  36. }
  37. /// <summary>
  38. /// Initialize with the provided deviceManager
  39. /// </summary>
  40. /// <param name="deviceManager"></param>
  41. public virtual void Initialize(DeviceManager dm)
  42. {
  43. this.DeviceManager = dm;
  44. // The device is already initialized, create
  45. // any device resources immediately.
  46. if (this.DeviceManager.Direct3DDevice != null)
  47. {
  48. CreateDeviceDependentResources();
  49. }
  50. }
  51. /// <summary>
  52. /// Create any resources that depend on the device or device context
  53. /// </summary>
  54. protected virtual void CreateDeviceDependentResources()
  55. {
  56. }
  57. /// <summary>
  58. /// Create any resources that depend upon the size of the render target
  59. /// </summary>
  60. protected virtual void CreateSizeDependentResources()
  61. {
  62. }
  63. /// <summary>
  64. /// Render a frame
  65. /// </summary>
  66. public void Render()
  67. {
  68. if (Show)
  69. DoRender();
  70. }
  71. /// <summary>
  72. /// Each descendant of RendererBase performs a frame
  73. /// render within the implementation of DoRender
  74. /// </summary>
  75. protected abstract void DoRender();
  76. public void Render(SharpDX.Direct3D11.DeviceContext context)
  77. {
  78. if (Show)
  79. DoRender(context);
  80. }
  81. protected virtual void DoRender(SharpDX.Direct3D11.DeviceContext context)
  82. {
  83. }
  84. }
  85. }