RenderTexture2D.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Text;
  6. namespace BansheeEngine
  7. {
  8. public class RenderTexture2D : RenderTexture
  9. {
  10. public RenderTexture2D(PixelFormat format, int width, int height, int numSamples = 1,
  11. bool gammaCorrection = false, bool createDepth = true, PixelFormat depthStencilFormat = PixelFormat.D24S8)
  12. {
  13. Internal_CreateDetailed(this, format, width, height, numSamples, gammaCorrection, createDepth, depthStencilFormat);
  14. }
  15. public RenderTexture2D(Texture2D colorSurface, Texture2D depthStencilSurface = null)
  16. {
  17. IntPtr[] colorSurfaceInstances = new IntPtr[1];
  18. colorSurfaceInstances[0] = colorSurface.GetCachedPtr();
  19. IntPtr depthStencilInstance = IntPtr.Zero;
  20. if (depthStencilSurface != null)
  21. depthStencilInstance = depthStencilSurface.GetCachedPtr();
  22. Internal_Create(this, colorSurfaceInstances, depthStencilInstance);
  23. }
  24. public RenderTexture2D(Texture2D[] colorSurfaces, Texture2D depthStencilSurface = null)
  25. {
  26. IntPtr[] colorSurfaceInstances = new IntPtr[colorSurfaces.Length];
  27. for(int i = 0; i < colorSurfaces.Length; i++)
  28. colorSurfaceInstances[i] = colorSurfaces[i] != null ? colorSurfaces[i].GetCachedPtr() : IntPtr.Zero;
  29. IntPtr depthStencilInstance = IntPtr.Zero;
  30. if (depthStencilSurface != null)
  31. depthStencilInstance = depthStencilSurface.GetCachedPtr();
  32. Internal_Create(this, colorSurfaceInstances, depthStencilInstance);
  33. }
  34. public Texture2D colorSurface
  35. {
  36. get
  37. {
  38. Texture2D[] surfaces;
  39. Internal_GetColorSurfaces(mCachedPtr, out surfaces);
  40. return surfaces[0];
  41. }
  42. }
  43. public Texture2D[] colorSurfaces
  44. {
  45. get
  46. {
  47. Texture2D[] surfaces;
  48. Internal_GetColorSurfaces(mCachedPtr, out surfaces);
  49. return surfaces;
  50. }
  51. }
  52. public Texture2D depthStencilSurface
  53. {
  54. get
  55. {
  56. Texture2D surface;
  57. Internal_GetDepthStencilSurface(mCachedPtr, out surface);
  58. return surface;
  59. }
  60. }
  61. [MethodImpl(MethodImplOptions.InternalCall)]
  62. private static extern void Internal_CreateDetailed(RenderTexture2D instance, PixelFormat format,
  63. int width, int height, int numSamples, bool gammaCorrection, bool createDepth, PixelFormat depthStencilFormat);
  64. [MethodImpl(MethodImplOptions.InternalCall)]
  65. private static extern void Internal_Create(RenderTexture2D instance, IntPtr[] colorSurfaces, IntPtr depthStencilSurface);
  66. [MethodImpl(MethodImplOptions.InternalCall)]
  67. private static extern void Internal_GetColorSurfaces(IntPtr thisPtr, out Texture2D[] surfaces);
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. private static extern void Internal_GetDepthStencilSurface(IntPtr thisPtr, out Texture2D surface);
  70. }
  71. }