Texture2D.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. public sealed class Texture2D : Texture
  6. {
  7. // For internal use by the runtime
  8. private Texture2D()
  9. { }
  10. public Texture2D(int width, int height, PixelFormat format = PixelFormat.R8G8B8A8, TextureUsage usage = TextureUsage.Default,
  11. int numSamples = 1, bool hasMipmaps = false, bool gammaCorrection = false)
  12. {
  13. Internal_CreateInstance(this, format, width, height, usage, numSamples, hasMipmaps, gammaCorrection);
  14. }
  15. public PixelData GetPixels(int mipLevel = 0)
  16. {
  17. return Internal_GetPixels(mCachedPtr, mipLevel);
  18. }
  19. public void SetPixels(PixelData data, int mipLevel = 0)
  20. {
  21. Internal_SetPixels(mCachedPtr, data, mipLevel);
  22. }
  23. public void SetPixels(Color[] data, int mipLevel = 0)
  24. {
  25. Internal_SetPixelsArray(mCachedPtr, data, mipLevel);
  26. }
  27. public AsyncOp GetGPUPixels(int mipLevel = 0)
  28. {
  29. return Internal_GetGPUPixels(mCachedPtr, mipLevel);
  30. }
  31. [MethodImpl(MethodImplOptions.InternalCall)]
  32. private static extern void Internal_CreateInstance(Texture2D instance, PixelFormat format, int width,
  33. int height, TextureUsage usage, int numSamples, bool hasMipmaps, bool gammaCorrection);
  34. [MethodImpl(MethodImplOptions.InternalCall)]
  35. private static extern PixelData Internal_GetPixels(IntPtr thisPtr, int mipLevel);
  36. [MethodImpl(MethodImplOptions.InternalCall)]
  37. private static extern AsyncOp Internal_GetGPUPixels(IntPtr thisPtr, int mipLevel);
  38. [MethodImpl(MethodImplOptions.InternalCall)]
  39. private static extern void Internal_SetPixels(IntPtr thisPtr, PixelData data, int mipLevel);
  40. [MethodImpl(MethodImplOptions.InternalCall)]
  41. private static extern void Internal_SetPixelsArray(IntPtr thisPtr, Color[] data, int mipLevel);
  42. }
  43. }