SVGDeviceSmall.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine;
  2. // TODO: Confirm that there's actually value in this. I suspect it only appears to be smaller due to how Unity's
  3. // TODO: profiler is accounting for things. Things that may impact this:
  4. // TODO: * Whether texture is marked as readable.
  5. // TODO: * Whether rendering pipeline is GLES or Metal (not sure about analogues on the Direct3D front).
  6. // TODO: * Specifically, whether or not semantics require the GL stack to keep a local copy of the texture data in
  7. // TODO: host RAM to avoid clobbering the GPU if the GL app writes to that area again.
  8. // TODO: * Internal representation of texture (24bpp vs. 32bpp).
  9. public class SVGDeviceSmall : ISVGDevice {
  10. private Texture2D _texture;
  11. private int _width;
  12. private int _height;
  13. public int Width { get { return _width; } }
  14. public int Height { get { return _height; } }
  15. private Color _color = Color.white;
  16. public void SetDevice(int width, int height) {
  17. SetDevice(width, height, false, false);
  18. }
  19. public void SetDevice(int width, int height, bool mipmaps, bool linear) {
  20. if(_texture == null) {
  21. _texture = new Texture2D(width, height, TextureFormat.RGB24, mipmaps, linear);
  22. _texture.hideFlags = HideFlags.HideAndDontSave;
  23. _width = width;
  24. _height = height;
  25. }
  26. }
  27. public void SetPixel(int x, int y) {
  28. if((x >= 0) && (x < _width) && (y >= 0) && (y < _height))
  29. _texture.SetPixel(_width - x, y, _color);
  30. }
  31. public Color GetPixel(int x, int y) {
  32. return _texture.GetPixel(x, y);
  33. }
  34. public void SetColor(Color color) {
  35. _color.r = color.r;
  36. _color.g = color.g;
  37. _color.b = color.b;
  38. }
  39. public Texture2D Render() {
  40. _texture.Apply();
  41. return _texture;
  42. }
  43. }