-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Texture.cs
1817 lines (1518 loc) · 89.3 KB
/
Texture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using uei = UnityEngine.Internal;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Scripting;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.Rendering;
namespace UnityEngine
{
public struct RenderTextureDescriptor
{
public int width { get; set; }
public int height { get; set; }
public int msaaSamples { get; set; }
public int volumeDepth { get; set; }
public int mipCount { get; set; }
private GraphicsFormat _graphicsFormat;// { get; set; }
public GraphicsFormat graphicsFormat
{
get { return _graphicsFormat; }
set
{
_graphicsFormat = value;
SetOrClearRenderTextureCreationFlag(GraphicsFormatUtility.IsSRGBFormat(value), RenderTextureCreationFlags.SRGB);
//To avoid that the order of setting a property changes the end result, we need to update the depthbufferbits because the setter depends on the graphicsformat.
depthBufferBits = depthBufferBits;
}
}
public GraphicsFormat stencilFormat { get; set; }
public GraphicsFormat depthStencilFormat { get; set; }
public RenderTextureFormat colorFormat
{
get { return GraphicsFormatUtility.GetRenderTextureFormat(graphicsFormat); }
set
{
GraphicsFormat requestedFormat = GraphicsFormatUtility.GetGraphicsFormat(value, sRGB);
graphicsFormat = SystemInfo.GetCompatibleFormat(requestedFormat, FormatUsage.Render);
}
}
public bool sRGB
{
get { return GraphicsFormatUtility.IsSRGBFormat(graphicsFormat); }
set { graphicsFormat = GraphicsFormatUtility.GetGraphicsFormat(colorFormat, value); }
// The code below does not work (while it feels like it should)
// This is because it does not take the project settings into account (unlike GraphicsFormatUtility.GetGraphicsFormat) and so we don't have the fallback kicking in (problem when some formats are not supported)
// We should fix this once we do a cleanup of colorspace management inside Unity
//set { graphicsFormat = (value) ? GraphicsFormatUtility.GetSRGBFormat(graphicsFormat) : GraphicsFormatUtility.GetLinearFormat(graphicsFormat); }
}
public int depthBufferBits
{
get { return GraphicsFormatUtility.GetDepthBits(depthStencilFormat); }
//Ideally we deprecate the setter but keeping it for now because its a very commonly used api
//It is very bad practice to use the graphicsFormat property here because that makes the result depend on the order of setting the properties
//However, it's the best what we can do to make sure this is functionally correct.
//We now need to set depthBufferBits after we set graphicsFormat, see that property.
set { depthStencilFormat = RenderTexture.GetDepthStencilFormatLegacy(value, graphicsFormat); }
}
public Rendering.TextureDimension dimension { get; set; }
public Rendering.ShadowSamplingMode shadowSamplingMode { get; set; }
public VRTextureUsage vrUsage { get; set; }
private RenderTextureCreationFlags _flags;
public RenderTextureCreationFlags flags { get { return _flags; } }
public RenderTextureMemoryless memoryless { get; set; }
public RenderTextureDescriptor(int width, int height)
: this(width, height, RenderTextureFormat.Default)
{
}
public RenderTextureDescriptor(int width, int height, RenderTextureFormat colorFormat)
: this(width, height, colorFormat, 0)
{
}
public RenderTextureDescriptor(int width, int height, RenderTextureFormat colorFormat, int depthBufferBits)
: this(width, height, colorFormat, depthBufferBits, Texture.GenerateAllMips)
{
}
[uei.ExcludeFromDocs]
public RenderTextureDescriptor(int width, int height, GraphicsFormat colorFormat, int depthBufferBits)
: this(width, height, colorFormat, depthBufferBits, Texture.GenerateAllMips)
{
}
public RenderTextureDescriptor(int width, int height, RenderTextureFormat colorFormat, int depthBufferBits, int mipCount)
{
GraphicsFormat requestedFormat = GraphicsFormatUtility.GetGraphicsFormat(colorFormat, false);
GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(requestedFormat, FormatUsage.Render);
if (requestedFormat != compatibleFormat)
{
Debug.LogWarning(String.Format("'{0}' is not supported. RenderTexture::GetTemporary fallbacks to {1} format on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", requestedFormat.ToString(), compatibleFormat.ToString()));
}
this = new RenderTextureDescriptor(width, height, compatibleFormat, depthBufferBits, mipCount);
}
[uei.ExcludeFromDocs]
public RenderTextureDescriptor(int width, int height, GraphicsFormat colorFormat, int depthBufferBits, int mipCount) : this()
{
_flags = RenderTextureCreationFlags.AutoGenerateMips | RenderTextureCreationFlags.AllowVerticalFlip; // Set before graphicsFormat to avoid erasing the flag set by graphicsFormat
this.width = width;
this.height = height;
volumeDepth = 1;
msaaSamples = 1;
this.graphicsFormat = colorFormat;
this.depthStencilFormat = RenderTexture.GetDepthStencilFormatLegacy(depthBufferBits, colorFormat);
this.mipCount = mipCount;
dimension = Rendering.TextureDimension.Tex2D;
shadowSamplingMode = Rendering.ShadowSamplingMode.None;
vrUsage = VRTextureUsage.None;
memoryless = RenderTextureMemoryless.None;
}
[uei.ExcludeFromDocs]
public RenderTextureDescriptor(int width, int height, GraphicsFormat colorFormat, GraphicsFormat depthStencilFormat) : this(width, height, colorFormat, depthStencilFormat, Texture.GenerateAllMips)
{
}
[uei.ExcludeFromDocs]
public RenderTextureDescriptor(int width, int height, GraphicsFormat colorFormat, GraphicsFormat depthStencilFormat, int mipCount) : this()
{
_flags = RenderTextureCreationFlags.AutoGenerateMips | RenderTextureCreationFlags.AllowVerticalFlip; // Set before graphicsFormat to avoid erasing the flag set by graphicsFormat
this.width = width;
this.height = height;
volumeDepth = 1;
msaaSamples = 1;
this.graphicsFormat = colorFormat;
this.depthStencilFormat = depthStencilFormat;
this.mipCount = mipCount;
dimension = Rendering.TextureDimension.Tex2D;
shadowSamplingMode = Rendering.ShadowSamplingMode.None;
vrUsage = VRTextureUsage.None;
memoryless = RenderTextureMemoryless.None;
}
private void SetOrClearRenderTextureCreationFlag(bool value, RenderTextureCreationFlags flag)
{
if (value)
{
_flags |= flag;
}
else
{
_flags &= ~flag;
}
}
public bool useMipMap
{
get { return (_flags & RenderTextureCreationFlags.MipMap) != 0; }
set { SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.MipMap); }
}
public bool autoGenerateMips
{
get { return (_flags & RenderTextureCreationFlags.AutoGenerateMips) != 0; }
set { SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.AutoGenerateMips); }
}
public bool enableRandomWrite
{
get { return (_flags & RenderTextureCreationFlags.EnableRandomWrite) != 0; }
set { SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.EnableRandomWrite); }
}
public bool bindMS
{
get { return (_flags & RenderTextureCreationFlags.BindMS) != 0; }
set { SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.BindMS); }
}
internal bool createdFromScript
{
get { return (_flags & RenderTextureCreationFlags.CreatedFromScript) != 0; }
set { SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.CreatedFromScript); }
}
public bool useDynamicScale
{
get { return (_flags & RenderTextureCreationFlags.DynamicallyScalable) != 0; }
set { SetOrClearRenderTextureCreationFlag(value, RenderTextureCreationFlags.DynamicallyScalable); }
}
}
public partial class RenderTexture : Texture
{
[RequiredByNativeCode] // used to create builtin textures
internal protected RenderTexture()
{
}
public RenderTexture(RenderTextureDescriptor desc)
{
ValidateRenderTextureDesc(desc);
Internal_Create(this);
SetRenderTextureDescriptor(desc);
}
public RenderTexture(RenderTexture textureToCopy)
{
if (textureToCopy == null)
throw new ArgumentNullException("textureToCopy");
ValidateRenderTextureDesc(textureToCopy.descriptor);
Internal_Create(this);
SetRenderTextureDescriptor(textureToCopy.descriptor);
}
[uei.ExcludeFromDocs]
public RenderTexture(int width, int height, int depth, DefaultFormat format)
: this(width, height, depth, SystemInfo.GetGraphicsFormat(format))
{
}
[uei.ExcludeFromDocs]
public RenderTexture(int width, int height, int depth, GraphicsFormat format)
: this(width, height, depth, format, Texture.GenerateAllMips)
{
}
[uei.ExcludeFromDocs]
public RenderTexture(int width, int height, int depth, GraphicsFormat format, int mipCount)
{
// Note: the code duplication here is because you can't set a descriptor with
// zero width/height, which our own code (and possibly existing user code) relies on.
if (!ValidateFormat(format, FormatUsage.Render))
return;
Internal_Create(this);
this.depthStencilFormat = GetDepthStencilFormatLegacy(depth, format);
this.width = width; this.height = height; this.graphicsFormat = format; SetMipMapCount(mipCount);
SetSRGBReadWrite(GraphicsFormatUtility.IsSRGBFormat(format));
}
[uei.ExcludeFromDocs]
public RenderTexture(int width, int height, GraphicsFormat colorFormat, GraphicsFormat depthStencilFormat, int mipCount)
{
// Note: the code duplication here is because you can't set a descriptor with
// zero width/height, which our own code (and possibly existing user code) relies on.
// None is valid here as it indicates a depth only rendertexture.
if (colorFormat != GraphicsFormat.None && !ValidateFormat(colorFormat, FormatUsage.Render))
return;
Internal_Create(this);
this.width = width; this.height = height; this.depthStencilFormat = depthStencilFormat; this.graphicsFormat = colorFormat; SetMipMapCount(mipCount);
SetSRGBReadWrite(GraphicsFormatUtility.IsSRGBFormat(colorFormat));
}
[uei.ExcludeFromDocs]
public RenderTexture(int width, int height, GraphicsFormat colorFormat, GraphicsFormat depthStencilFormat)
: this(width, height, colorFormat, depthStencilFormat, Texture.GenerateAllMips)
{
}
public RenderTexture(int width, int height, int depth, [uei.DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format, [uei.DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite)
{
Initialize(width, height, depth, format, readWrite, Texture.GenerateAllMips);
}
[uei.ExcludeFromDocs]
public RenderTexture(int width, int height, int depth, RenderTextureFormat format)
: this(width, height, depth, format, Texture.GenerateAllMips)
{
}
[uei.ExcludeFromDocs]
public RenderTexture(int width, int height, int depth)
: this(width, height, depth, RenderTextureFormat.Default)
{
}
[uei.ExcludeFromDocs]
public RenderTexture(int width, int height, int depth, RenderTextureFormat format, int mipCount)
{
Initialize(width, height, depth, format, RenderTextureReadWrite.Default, mipCount);
}
private void Initialize(int width, int height, int depth, RenderTextureFormat format, RenderTextureReadWrite readWrite, int mipCount)
{
// Note this may return the deprecated GraphicsFormat.ShadowAuto & DepthAuto for now. They will be filtered out internally
// by RenderTexture creation code on the c++ side.
GraphicsFormat colorFormat = GetCompatibleFormat(format, readWrite);
GraphicsFormat depthStencilFormat = GetDepthStencilFormatLegacy(depth, colorFormat);
// Note: the code duplication here is because you can't set a descriptor with
// zero width/height, which our own code (and possibly existing user code) relies on.
if (colorFormat != GraphicsFormat.None)
{
if (!ValidateFormat(colorFormat, FormatUsage.Render))
return;
}
Internal_Create(this);
this.width = width; this.height = height; this.depthStencilFormat = depthStencilFormat; this.graphicsFormat = colorFormat;
SetMipMapCount(mipCount);
SetSRGBReadWrite(GraphicsFormatUtility.IsSRGBFormat(colorFormat));
}
internal static GraphicsFormat GetDepthStencilFormatLegacy(int depthBits, GraphicsFormat colorFormat)
{
#pragma warning disable 618 // Disable deprecation warnings on the ShadowAuto and DepthAuto formats
return (colorFormat == GraphicsFormat.ShadowAuto) ?
#pragma warning restore 618
GraphicsFormatUtility.GetDepthStencilFormat(depthBits, 0)
: GraphicsFormatUtility.GetDepthStencilFormat(depthBits);
}
public RenderTextureDescriptor descriptor
{
get { return GetDescriptor(); }
set { ValidateRenderTextureDesc(value); SetRenderTextureDescriptor(value); }
}
private static void ValidateRenderTextureDesc(RenderTextureDescriptor desc)
{
if (desc.graphicsFormat == GraphicsFormat.None && desc.depthStencilFormat == GraphicsFormat.None)
throw new ArgumentException("RenderTextureDesc graphicsFormat and depthStencilFormat cannot both be None.");
if (desc.graphicsFormat != GraphicsFormat.None && !SystemInfo.IsFormatSupported(desc.graphicsFormat, FormatUsage.Render))
throw new ArgumentException("RenderTextureDesc graphicsFormat must be a supported GraphicsFormat. " + desc.graphicsFormat + " is not supported on this platform.", "desc.graphicsFormat");
if (desc.depthStencilFormat != GraphicsFormat.None && !GraphicsFormatUtility.IsDepthStencilFormat(desc.depthStencilFormat))
throw new ArgumentException("RenderTextureDesc depthStencilFormat must be a supported depth/stencil GraphicsFormat. " + desc.depthStencilFormat + " is not supported on this platform.", "desc.depthStencilFormat");
if (desc.width <= 0)
throw new ArgumentException("RenderTextureDesc width must be greater than zero.", "desc.width");
if (desc.height <= 0)
throw new ArgumentException("RenderTextureDesc height must be greater than zero.", "desc.height");
if (desc.volumeDepth <= 0)
throw new ArgumentException("RenderTextureDesc volumeDepth must be greater than zero.", "desc.volumeDepth");
if (desc.msaaSamples != 1 && desc.msaaSamples != 2 && desc.msaaSamples != 4 && desc.msaaSamples != 8)
throw new ArgumentException("RenderTextureDesc msaaSamples must be 1, 2, 4, or 8.", "desc.msaaSamples");
if (desc.dimension == TextureDimension.CubeArray && desc.volumeDepth % 6 != 0)
throw new ArgumentException("RenderTextureDesc volumeDepth must be a multiple of 6 when dimension is CubeArray", "desc.volumeDepth");
// Disable deprecation warnings on the ShadowAuto and DepthAuto formats
#pragma warning disable 618
if (desc.graphicsFormat != GraphicsFormat.ShadowAuto && desc.graphicsFormat != GraphicsFormat.DepthAuto
&& GraphicsFormatUtility.IsDepthStencilFormat(desc.graphicsFormat))
throw new ArgumentException("RenderTextureDesc graphicsFormat must not be a depth/stencil format. " + desc.graphicsFormat + " is not supported.", "desc.graphicsFormat");
#pragma warning restore 618
}
}
public partial class RenderTexture : Texture
{
internal static GraphicsFormat GetCompatibleFormat(RenderTextureFormat renderTextureFormat, RenderTextureReadWrite readWrite)
{
GraphicsFormat requestedFormat = GraphicsFormatUtility.GetGraphicsFormat(renderTextureFormat, readWrite);
GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(requestedFormat, FormatUsage.Render);
if (requestedFormat == compatibleFormat)
{
return requestedFormat;
}
else
{
Debug.LogWarning(String.Format("'{0}' is not supported. RenderTexture::GetTemporary fallbacks to {1} format on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", requestedFormat.ToString(), compatibleFormat.ToString()));
return compatibleFormat;
}
}
public static RenderTexture GetTemporary(RenderTextureDescriptor desc)
{
ValidateRenderTextureDesc(desc); desc.createdFromScript = true;
return GetTemporary_Internal(desc);
}
// in old bindings "default args" were expanded into overloads and we must mimic that when migrating to new bindings
// to keep things sane we will do internal methods WITH default args and do overloads that simply call it
private static RenderTexture GetTemporaryImpl(int width, int height, int depthBuffer,
GraphicsFormat colorFormat,
int antiAliasing = 1, RenderTextureMemoryless memorylessMode = RenderTextureMemoryless.None,
VRTextureUsage vrUsage = VRTextureUsage.None, bool useDynamicScale = false)
{
RenderTextureDescriptor desc = new RenderTextureDescriptor(width, height, colorFormat, GetDepthStencilFormatLegacy(depthBuffer, colorFormat));
desc.msaaSamples = antiAliasing;
desc.memoryless = memorylessMode;
desc.vrUsage = vrUsage;
desc.useDynamicScale = useDynamicScale;
return GetTemporary(desc);
}
// most detailed overload: use it to specify default values for docs
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format,
[uei.DefaultValue("1")] int antiAliasing,
[uei.DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode,
[uei.DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage,
[uei.DefaultValue("false")] bool useDynamicScale)
{
return GetTemporaryImpl(width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage, useDynamicScale);
}
// the rest will be excluded from docs (to "pretend" we have one method with default args)
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing, RenderTextureMemoryless memorylessMode, VRTextureUsage vrUsage)
{
return GetTemporaryImpl(width, height, depthBuffer, format, antiAliasing, memorylessMode, vrUsage);
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing, RenderTextureMemoryless memorylessMode)
{
return GetTemporaryImpl(width, height, depthBuffer, format, antiAliasing, memorylessMode);
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format, int antiAliasing)
{
return GetTemporaryImpl(width, height, depthBuffer, format, antiAliasing);
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, GraphicsFormat format)
{
return GetTemporaryImpl(width, height, depthBuffer, format);
}
// most detailed overload: use it to specify default values for docs
public static RenderTexture GetTemporary(int width, int height,
[uei.DefaultValue("0")] int depthBuffer, [uei.DefaultValue("RenderTextureFormat.Default")] RenderTextureFormat format,
[uei.DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite, [uei.DefaultValue("1")] int antiAliasing,
[uei.DefaultValue("RenderTextureMemoryless.None")] RenderTextureMemoryless memorylessMode,
[uei.DefaultValue("VRTextureUsage.None")] VRTextureUsage vrUsage, [uei.DefaultValue("false")] bool useDynamicScale
)
{
return GetTemporaryImpl(width, height, depthBuffer, GetCompatibleFormat(format, readWrite), antiAliasing, memorylessMode, vrUsage, useDynamicScale);
}
// the rest will be excluded from docs (to "pretend" we have one method with default args)
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing, RenderTextureMemoryless memorylessMode, VRTextureUsage vrUsage)
{
return GetTemporaryImpl(width, height, depthBuffer, GetCompatibleFormat(format, readWrite), antiAliasing, memorylessMode, vrUsage);
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing, RenderTextureMemoryless memorylessMode)
{
return GetTemporaryImpl(width, height, depthBuffer, GetCompatibleFormat(format, readWrite), antiAliasing, memorylessMode);
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite, int antiAliasing)
{
return GetTemporaryImpl(width, height, depthBuffer, GetCompatibleFormat(format, readWrite), antiAliasing);
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format, RenderTextureReadWrite readWrite)
{
return GetTemporaryImpl(width, height, depthBuffer, GetCompatibleFormat(format, readWrite));
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer, RenderTextureFormat format)
{
return GetTemporaryImpl(width, height, depthBuffer, GetCompatibleFormat(format, RenderTextureReadWrite.Default));
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height, int depthBuffer)
{
return GetTemporaryImpl(width, height, depthBuffer, GetCompatibleFormat(RenderTextureFormat.Default, RenderTextureReadWrite.Default));
}
[uei.ExcludeFromDocs]
public static RenderTexture GetTemporary(int width, int height)
{
return GetTemporaryImpl(width, height, 0, GetCompatibleFormat(RenderTextureFormat.Default, RenderTextureReadWrite.Default));
}
}
public sealed partial class CustomRenderTexture : RenderTexture
{
// Be careful. We can't call base constructor here because it would create the native object twice.
public CustomRenderTexture(int width, int height, RenderTextureFormat format, [uei.DefaultValue("RenderTextureReadWrite.Default")] RenderTextureReadWrite readWrite)
: this(width, height, GetCompatibleFormat(format, readWrite))
{
}
[uei.ExcludeFromDocs]
public CustomRenderTexture(int width, int height, RenderTextureFormat format)
: this(width, height, GetCompatibleFormat(format, RenderTextureReadWrite.Default))
{
}
[uei.ExcludeFromDocs]
public CustomRenderTexture(int width, int height)
: this(width, height, SystemInfo.GetGraphicsFormat(DefaultFormat.LDR))
{
}
[uei.ExcludeFromDocs]
public CustomRenderTexture(int width, int height, [uei.DefaultValue("DefaultFormat.LDR")] DefaultFormat defaultFormat)
: this(width, height, SystemInfo.GetGraphicsFormat(defaultFormat))
{
}
[uei.ExcludeFromDocs]
public CustomRenderTexture(int width, int height, GraphicsFormat format)
{
if (!ValidateFormat(format, FormatUsage.Render))
return;
Internal_CreateCustomRenderTexture(this);
this.width = width;
this.height = height;
this.graphicsFormat = format;
SetSRGBReadWrite(GraphicsFormatUtility.IsSRGBFormat(format));
}
}
public struct MipmapLimitDescriptor
{
public bool useMipmapLimit { get; }
public string groupName { get; }
public MipmapLimitDescriptor(bool useMipmapLimit, string groupName)
{
this.useMipmapLimit = useMipmapLimit;
this.groupName = groupName;
}
}
public partial class Texture : Object
{
public static readonly int GenerateAllMips = -1;
internal bool ValidateFormat(RenderTextureFormat format)
{
if (SystemInfo.SupportsRenderTextureFormat(format))
{
return true;
}
else
{
Debug.LogError(String.Format("RenderTexture creation failed. '{0}' is not supported on this platform. Use 'SystemInfo.SupportsRenderTextureFormat' C# API to check format support.", format.ToString()), this);
return false;
}
}
internal bool ValidateFormat(TextureFormat format)
{
// If GPU support is detected, pass validation. Caveat support can also be used for uncompressed/non-IEEE754 formats.
// In contrast to GraphicsFormat, TextureFormat can use fallbacks by design.
if (SystemInfo.SupportsTextureFormat(format))
{
return true;
}
// If a compressed format is not supported natively, we check for decompressor support here.
// If we are able to decompress, the data is decoded into a raw format. Otherwise, validation fails.
else if (GraphicsFormatUtility.IsCompressedFormat(format) && GraphicsFormatUtility.CanDecompressFormat(GraphicsFormatUtility.GetGraphicsFormat(format, false)))
{
return true;
}
else
{
Debug.LogError(String.Format("Texture creation failed. '{0}' is not supported on this platform. Use 'SystemInfo.SupportsTextureFormat' C# API to check format support.", format.ToString()), this);
return false;
}
}
internal bool ValidateFormat(GraphicsFormat format, FormatUsage usage)
{
//The auto formats are allowed to set as RenderTexture color format.
#pragma warning disable 618 // Disable deprecation warnings on the ShadowAuto and DepthAuto formats, when finally removing them remove the whole if statement.
if (usage != FormatUsage.Render && (format == GraphicsFormat.ShadowAuto || format == GraphicsFormat.DepthAuto))
#pragma warning restore 618
{
Debug.LogWarning(String.Format("'{0}' is not allowed because it is an auto format and not an exact format. Use GraphicsFormatUtility.GetDepthStencilFormat to get an exact depth/stencil format.", format.ToString()), this);
return false;
}
// *ONLY* GPU support is checked here. If it is not available, fail validation.
// GraphicsFormat does not use fallbacks by design.
if (SystemInfo.IsFormatSupported(format, usage))
{
return true;
}
else
{
Debug.LogError(String.Format("Texture creation failed. '{0}' is not supported for {1} usage on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", format.ToString(), usage.ToString()), this);
return false;
}
}
internal UnityException CreateNonReadableException(Texture t)
{
return new UnityException(
String.Format("Texture '{0}' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.", t.name)
);
}
internal UnityException IgnoreMipmapLimitCannotBeToggledException(Texture t)
{
return new UnityException(
String.Format("Failed to toggle ignoreMipmapLimit, Texture '{0}' is not readable. You can make the texture readable in the Texture Import Settings.", t.name)
);
}
internal UnityException CreateNativeArrayLengthOverflowException()
{
return new UnityException("Failed to create NativeArray, length exceeds the allowed maximum of Int32.MaxValue. Use a larger type as template argument to reduce the array length.");
}
}
public partial class Texture2D : Texture
{
internal bool ValidateFormat(TextureFormat format, int width, int height)
{
bool isValid = ValidateFormat(format);
if (isValid)
{
bool requireSquarePOT = (TextureFormat.PVRTC_RGB2 <= format && format <= TextureFormat.PVRTC_RGBA4);
if (requireSquarePOT && !(width == height && Mathf.IsPowerOfTwo(width)))
throw new UnityException(String.Format("'{0}' demands texture to be square and have power-of-two dimensions", format.ToString()));
}
return isValid;
}
internal bool ValidateFormat(GraphicsFormat format, int width, int height)
{
bool isValid = ValidateFormat(format, FormatUsage.Sample);
if (isValid)
{
bool requireSquarePOT = GraphicsFormatUtility.IsPVRTCFormat(format);
if (requireSquarePOT && !(width == height && Mathf.IsPowerOfTwo(width)))
throw new UnityException(String.Format("'{0}' demands texture to be square and have power-of-two dimensions", format.ToString()));
}
return isValid;
}
internal Texture2D(int width, int height, GraphicsFormat format, TextureCreationFlags flags, int mipCount, IntPtr nativeTex, MipmapLimitDescriptor mipmapLimitDescriptor)
{
bool useMipmapLimit = mipmapLimitDescriptor.useMipmapLimit;
string mipmapLimitGroupName = mipmapLimitDescriptor.groupName;
// Obsolete, see TextureCreationFlags::IgnoreMipmapLimit (1 << 11)
// No additional warning, deprecation warning was already shown
bool deprecatedIgnoreFlagWasSet = ((int)flags & (1 << 11)) != 0;
if (deprecatedIgnoreFlagWasSet) useMipmapLimit = false;
if (ValidateFormat(format, width, height))
Internal_Create(this, width, height, mipCount, format, flags, nativeTex, !useMipmapLimit, mipmapLimitGroupName);
}
[uei.ExcludeFromDocs]
public Texture2D(int width, int height, DefaultFormat format, TextureCreationFlags flags)
: this(width, height, SystemInfo.GetGraphicsFormat(format), flags)
{
}
[uei.ExcludeFromDocs]
public Texture2D(int width, int height, DefaultFormat format, int mipCount, TextureCreationFlags flags)
: this(width, height, SystemInfo.GetGraphicsFormat(format), flags, mipCount, IntPtr.Zero, default)
{
}
[uei.ExcludeFromDocs]
// In theory, users were able to create a group without actually having mipmap limits enabled (and to enable it later on, at runtime);
// this will no longer be supported (which allows us to rename that boolean flag)
[Obsolete("Please provide mipmap limit information using a MipmapLimitDescriptor argument", false)]
public Texture2D(int width, int height, DefaultFormat format, int mipCount, string mipmapLimitGroupName, TextureCreationFlags flags)
: this(width, height, SystemInfo.GetGraphicsFormat(format), flags, mipCount, IntPtr.Zero, new MipmapLimitDescriptor(true, mipmapLimitGroupName))
{
}
[uei.ExcludeFromDocs]
public Texture2D(int width, int height, DefaultFormat format, int mipCount, TextureCreationFlags flags, MipmapLimitDescriptor mipmapLimitDescriptor)
: this(width, height, SystemInfo.GetGraphicsFormat(format), flags, mipCount, IntPtr.Zero, mipmapLimitDescriptor)
{
}
[uei.ExcludeFromDocs]
public Texture2D(int width, int height, GraphicsFormat format, TextureCreationFlags flags)
: this(width, height, format, flags, Texture.GenerateAllMips, IntPtr.Zero, default)
{
}
[uei.ExcludeFromDocs]
public Texture2D(int width, int height, GraphicsFormat format, int mipCount, TextureCreationFlags flags)
: this(width, height, format, flags, mipCount, IntPtr.Zero, default)
{
}
[uei.ExcludeFromDocs]
[Obsolete("Please provide mipmap limit information using a MipmapLimitDescriptor argument", false)]
public Texture2D(int width, int height, GraphicsFormat format, int mipCount, string mipmapLimitGroupName, TextureCreationFlags flags)
: this(width, height, format, flags, mipCount, IntPtr.Zero, new MipmapLimitDescriptor(true, mipmapLimitGroupName))
{
}
[uei.ExcludeFromDocs]
public Texture2D(int width, int height, GraphicsFormat format, int mipCount, TextureCreationFlags flags, MipmapLimitDescriptor mipmapLimitDescriptor)
: this(width, height, format, flags, mipCount, IntPtr.Zero, mipmapLimitDescriptor)
{
}
internal Texture2D(int width, int height, TextureFormat textureFormat, int mipCount, bool linear, IntPtr nativeTex, bool createUninitialized, MipmapLimitDescriptor mipmapLimitDescriptor)
{
if (!ValidateFormat(textureFormat, width, height))
return;
GraphicsFormat format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
TextureCreationFlags flags = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;
if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
flags |= TextureCreationFlags.Crunch;
if (createUninitialized)
flags |= TextureCreationFlags.DontUploadUponCreate | TextureCreationFlags.DontInitializePixels;
Internal_Create(this, width, height, mipCount, format, flags, nativeTex, !mipmapLimitDescriptor.useMipmapLimit, mipmapLimitDescriptor.groupName);
}
public Texture2D(int width, int height, [uei.DefaultValue("TextureFormat.RGBA32")] TextureFormat textureFormat, [uei.DefaultValue("-1")] int mipCount, [uei.DefaultValue("false")] bool linear)
: this(width, height, textureFormat, mipCount, linear, IntPtr.Zero, false, default)
{
}
public Texture2D(int width, int height, [uei.DefaultValue("TextureFormat.RGBA32")] TextureFormat textureFormat, [uei.DefaultValue("-1")] int mipCount, [uei.DefaultValue("false")] bool linear, [uei.DefaultValue("false")] bool createUninitialized)
: this(width, height, textureFormat, mipCount, linear, IntPtr.Zero, createUninitialized, default)
{
}
public Texture2D(int width, int height, [uei.DefaultValue("TextureFormat.RGBA32")] TextureFormat textureFormat, [uei.DefaultValue("-1")] int mipCount, [uei.DefaultValue("false")] bool linear, [uei.DefaultValue("false")] bool createUninitialized, MipmapLimitDescriptor mipmapLimitDescriptor)
: this(width, height, textureFormat, mipCount, linear, IntPtr.Zero, createUninitialized, mipmapLimitDescriptor)
{
}
// In theory, users were able to create a group without actually having mipmap limits enabled (and to enable it later on, at runtime);
// this will no longer be supported (which allows us to rename that boolean flag)
[Obsolete("Please provide mipmap limit information using a MipmapLimitDescriptor argument", false)]
public Texture2D(int width, int height, [uei.DefaultValue("TextureFormat.RGBA32")] TextureFormat textureFormat, [uei.DefaultValue("-1")] int mipCount, [uei.DefaultValue("false")] bool linear, [uei.DefaultValue("false")] bool createUninitialized, [uei.DefaultValue("true")] bool ignoreMipmapLimit, [uei.DefaultValue("null")] string mipmapLimitGroupName)
: this(width, height, textureFormat, mipCount, linear, IntPtr.Zero, createUninitialized, new MipmapLimitDescriptor(!ignoreMipmapLimit, mipmapLimitGroupName))
{
}
public Texture2D(int width, int height, [uei.DefaultValue("TextureFormat.RGBA32")] TextureFormat textureFormat, [uei.DefaultValue("true")] bool mipChain, [uei.DefaultValue("false")] bool linear)
: this(width, height, textureFormat, mipChain ? Texture.GenerateAllMips : 1, linear, IntPtr.Zero, false, default)
{
}
public Texture2D(int width, int height, [uei.DefaultValue("TextureFormat.RGBA32")] TextureFormat textureFormat, [uei.DefaultValue("true")] bool mipChain, [uei.DefaultValue("false")] bool linear, [uei.DefaultValue("false")] bool createUninitialized)
: this(width, height, textureFormat, mipChain ? Texture.GenerateAllMips : 1, linear, IntPtr.Zero, createUninitialized, default)
{
}
public Texture2D(int width, int height, TextureFormat textureFormat, bool mipChain)
: this(width, height, textureFormat, mipChain ? Texture.GenerateAllMips : 1, false, IntPtr.Zero, false, default)
{
}
public Texture2D(int width, int height)
{
TextureFormat format = TextureFormat.RGBA32;
if (width == 0 && height == 0)
Internal_CreateEmptyImpl(this);
else if (ValidateFormat(format, width, height))
Internal_Create(this, width, height, Texture.GenerateAllMips, GraphicsFormatUtility.GetGraphicsFormat(format, true), TextureCreationFlags.MipChain, IntPtr.Zero, true, null);
}
public static Texture2D CreateExternalTexture(int width, int height, TextureFormat format, bool mipChain, bool linear, IntPtr nativeTex)
{
if (nativeTex == IntPtr.Zero)
throw new ArgumentException("nativeTex can not be null");
return new Texture2D(width, height, format, mipChain ? -1 : 1, linear, nativeTex, false, default);
}
[uei.ExcludeFromDocs]
public void SetPixel(int x, int y, Color color)
{
if (!isReadable) throw CreateNonReadableException(this);
SetPixelImpl(0, 0, x, y, color);
}
public void SetPixel(int x, int y, Color color, [uei.DefaultValue("0")] int mipLevel)
{
if (!isReadable) throw CreateNonReadableException(this);
SetPixelImpl(0, mipLevel, x, y, color);
}
public void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors, [uei.DefaultValue("0")] int miplevel)
{
if (!isReadable) throw CreateNonReadableException(this);
SetPixelsImpl(x, y, blockWidth, blockHeight, colors, miplevel, 0);
}
[uei.ExcludeFromDocs]
public void SetPixels(int x, int y, int blockWidth, int blockHeight, Color[] colors)
{
SetPixels(x, y, blockWidth, blockHeight, colors, 0);
}
public void SetPixels(Color[] colors, [uei.DefaultValue("0")] int miplevel)
{
int w = width >> miplevel; if (w < 1) w = 1;
int h = height >> miplevel; if (h < 1) h = 1;
SetPixels(0, 0, w, h, colors, miplevel);
}
[uei.ExcludeFromDocs]
public void SetPixels(Color[] colors)
{
SetPixels(0, 0, width, height, colors, 0);
}
[uei.ExcludeFromDocs]
public Color GetPixel(int x, int y)
{
if (!isReadable) throw CreateNonReadableException(this);
return GetPixelImpl(0, 0, x, y);
}
public Color GetPixel(int x, int y, [uei.DefaultValue("0")] int mipLevel)
{
if (!isReadable) throw CreateNonReadableException(this);
return GetPixelImpl(0, mipLevel, x, y);
}
[uei.ExcludeFromDocs]
public Color GetPixelBilinear(float u, float v)
{
if (!isReadable) throw CreateNonReadableException(this);
return GetPixelBilinearImpl(0, 0, u, v);
}
public Color GetPixelBilinear(float u, float v, [uei.DefaultValue("0")] int mipLevel)
{
if (!isReadable) throw CreateNonReadableException(this);
return GetPixelBilinearImpl(0, mipLevel, u, v);
}
public void LoadRawTextureData(IntPtr data, int size)
{
if (!isReadable) throw CreateNonReadableException(this);
if (data == IntPtr.Zero || size == 0) { Debug.LogError("No texture data provided to LoadRawTextureData", this); return; }
if (!LoadRawTextureDataImpl(data, (ulong)size))
throw new UnityException("LoadRawTextureData: not enough data provided (will result in overread).");
}
public void LoadRawTextureData(byte[] data)
{
if (!isReadable) throw CreateNonReadableException(this);
if (data == null || data.Length == 0) { Debug.LogError("No texture data provided to LoadRawTextureData", this); return; }
if (!LoadRawTextureDataImplArray(data))
throw new UnityException("LoadRawTextureData: not enough data provided (will result in overread).");
}
unsafe public void LoadRawTextureData<T>(NativeArray<T> data) where T : struct
{
if (!isReadable) throw CreateNonReadableException(this);
if (!data.IsCreated || data.Length == 0) throw new UnityException("No texture data provided to LoadRawTextureData");
if (!LoadRawTextureDataImpl((IntPtr)data.GetUnsafeReadOnlyPtr(), (ulong)data.Length * (ulong)UnsafeUtility.SizeOf<T>()))
throw new UnityException("LoadRawTextureData: not enough data provided (will result in overread).");
}
public void SetPixelData<T>(T[] data, int mipLevel, [uei.DefaultValue("0")] int sourceDataStartIndex = 0)
{
if (sourceDataStartIndex < 0) throw new UnityException("SetPixelData: sourceDataStartIndex cannot be less than 0.");
if (!isReadable) throw CreateNonReadableException(this);
if (data == null || data.Length == 0) throw new UnityException("No texture data provided to SetPixelData.");
var elemSize = System.Runtime.InteropServices.Marshal.SizeOf(data[0]);
SetPixelDataImplArray(UnsafeUtility.GetByteSpanFromArray(data, elemSize), mipLevel, elemSize, data.Length, sourceDataStartIndex);
}
unsafe public void SetPixelData<T>(NativeArray<T> data, int mipLevel, [uei.DefaultValue("0")] int sourceDataStartIndex = 0) where T : struct
{
if (sourceDataStartIndex < 0) throw new UnityException("SetPixelData: sourceDataStartIndex cannot be less than 0.");
if (!isReadable) throw CreateNonReadableException(this);
if (!data.IsCreated || data.Length == 0) throw new UnityException("No texture data provided to SetPixelData.");
SetPixelDataImpl((IntPtr)data.GetUnsafeReadOnlyPtr(), mipLevel, UnsafeUtility.SizeOf<T>(), data.Length, sourceDataStartIndex);
}
public unsafe NativeArray<T> GetPixelData<T>(int mipLevel) where T : struct
{
if (!isReadable) throw CreateNonReadableException(this);
if (mipLevel < 0 || mipLevel >= mipmapCount) throw new ArgumentException("The passed in miplevel " + mipLevel + " is invalid. It needs to be in the range 0 and " + (mipmapCount - 1));
if (GetWritableImageData(0).ToInt64() == 0) throw new UnityException($"Texture '{name}' has no data.");
ulong chainOffset = GetPixelDataOffset(mipLevel);
ulong arraySize = GetPixelDataSize(mipLevel);
int stride = UnsafeUtility.SizeOf<T>();
ulong arrayLength = arraySize / (ulong)stride;
if (arrayLength > Int32.MaxValue) throw CreateNativeArrayLengthOverflowException();
IntPtr dataPtr = new IntPtr((long)((ulong)GetWritableImageData(0) + chainOffset));
var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>((void*)dataPtr, (int)arrayLength, Allocator.None);
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, this.GetSafetyHandleForSlice(mipLevel));
return array;
}
public unsafe NativeArray<T> GetRawTextureData<T>() where T : struct
{
if (!isReadable) throw CreateNonReadableException(this);
int stride = UnsafeUtility.SizeOf<T>();
ulong arrayLength = GetRawImageDataSize() / (ulong)stride;
if (arrayLength > Int32.MaxValue) throw CreateNativeArrayLengthOverflowException();
var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>((void*)GetWritableImageData(0), (int)arrayLength, Allocator.None);
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, Texture2D.GetSafetyHandle(this));
return array;
}
public void Apply([uei.DefaultValue("true")] bool updateMipmaps, [uei.DefaultValue("false")] bool makeNoLongerReadable)
{
if (!isReadable) throw CreateNonReadableException(this);
ApplyImpl(updateMipmaps, makeNoLongerReadable);
}
[uei.ExcludeFromDocs] public void Apply(bool updateMipmaps) { Apply(updateMipmaps, false); }
[uei.ExcludeFromDocs] public void Apply() { Apply(true, false); }
public bool Reinitialize(int width, int height)
{
if (!isReadable) throw CreateNonReadableException(this);
return ReinitializeImpl(width, height);
}
public bool Reinitialize(int width, int height, TextureFormat format, bool hasMipMap)
{
return ReinitializeWithTextureFormatImpl(width, height, format, hasMipMap);
}
public bool Reinitialize(int width, int height, GraphicsFormat format, bool hasMipMap)
{
if (!isReadable) throw CreateNonReadableException(this);
return ReinitializeWithFormatImpl(width, height, format, hasMipMap);
}
[Obsolete("Texture2D.Resize(int, int) has been deprecated because it actually reinitializes the texture. Use Texture2D.Reinitialize(int, int) instead (UnityUpgradable) -> Reinitialize([*] System.Int32, [*] System.Int32)", false)]
public bool Resize(int width, int height)
{
return Reinitialize(width, height);
}
[Obsolete("Texture2D.Resize(int, int, TextureFormat, bool) has been deprecated because it actually reinitializes the texture. Use Texture2D.Reinitialize(int, int, TextureFormat, bool) instead (UnityUpgradable) -> Reinitialize([*] System.Int32, [*] System.Int32, UnityEngine.TextureFormat, [*] System.Boolean)", false)]
public bool Resize(int width, int height, TextureFormat format, bool hasMipMap)
{
return Reinitialize(width, height, format, hasMipMap);
}
[Obsolete("Texture2D.Resize(int, int, GraphicsFormat, bool) has been deprecated because it actually reinitializes the texture. Use Texture2D.Reinitialize(int, int, GraphicsFormat, bool) instead (UnityUpgradable) -> Reinitialize([*] System.Int32, [*] System.Int32, UnityEngine.Experimental.Rendering.GraphicsFormat, [*] System.Boolean)", false)]
public bool Resize(int width, int height, GraphicsFormat format, bool hasMipMap)
{
return Reinitialize(width, height, format, hasMipMap);
}
public void ReadPixels(Rect source, int destX, int destY, [uei.DefaultValue("true")] bool recalculateMipMaps)
{
//if (ValidateFormat(GraphicsFormatUtility.GetGraphicsFormat(format, ), FormatUsage.ReadPixels))
// Debug.LogError("No texture data provided to LoadRawTextureData", this);
if (!isReadable) throw CreateNonReadableException(this);
ReadPixelsImpl(source, destX, destY, recalculateMipMaps);
}
[uei.ExcludeFromDocs] public void ReadPixels(Rect source, int destX, int destY) { ReadPixels(source, destX, destY, true); }
public static bool GenerateAtlas(Vector2[] sizes, int padding, int atlasSize, List<Rect> results)
{
if (sizes == null)
throw new ArgumentException("sizes array can not be null");
if (results == null)
throw new ArgumentException("results list cannot be null");
if (padding < 0)
throw new ArgumentException("padding can not be negative");
if (atlasSize <= 0)
throw new ArgumentException("atlas size must be positive");
results.Clear();