Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Texture3D.cs
Go to the documentation of this file.
1using System;
5
7
9{
10 private int _width;
11
12 private int _height;
13
14 private int _depth;
15
16 private IntPtr[] pFaceData;
17
18 internal unsafe IDirect3DVolumeTexture9* pComPtr;
19
20 public int Depth => _depth;
21
22 public int Height => _height;
23
24 public int Width => _width;
25
27 {
28 IntPtr intPtr = (IntPtr)pComPtr;
29 Helpers.CheckDisposed(this, intPtr);
30 IDirect3DVolumeTexture9* ptr = pComPtr;
31 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DVOLUME_DESC d3DVOLUME_DESC);
32 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DVOLUME_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, 0u, &d3DVOLUME_DESC);
33 if (num < 0)
34 {
36 }
37 if (!format.HasValue)
38 {
39 format = _003CModule_003E.ConvertWindowsFormatToXna(*(_D3DFORMAT*)(&d3DVOLUME_DESC));
40 }
41 _width = System.Runtime.CompilerServices.Unsafe.As<_D3DVOLUME_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVOLUME_DESC, 16));
42 _height = System.Runtime.CompilerServices.Unsafe.As<_D3DVOLUME_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVOLUME_DESC, 20));
43 _depth = System.Runtime.CompilerServices.Unsafe.As<_D3DVOLUME_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVOLUME_DESC, 24));
44 base.InitializeDescription(format.Value);
45 }
46
47 private unsafe Texture3D(IDirect3DVolumeTexture9* pInterface, GraphicsDevice pDevice)
48 {
49 pComPtr = pInterface;
50 ((object)this)._002Ector();
51 try
52 {
53 _parent = pDevice;
55 return;
56 }
57 catch
58 {
59 //try-fault
60 base.Dispose(true);
61 throw;
62 }
63 }
64
65 public Texture3D(GraphicsDevice graphicsDevice, int width, int height, int depth, [MarshalAs(UnmanagedType.U1)] bool mipMap, SurfaceFormat format)
66 {
67 try
68 {
69 CreateTexture(graphicsDevice, width, height, depth, mipMap, format);
70 return;
71 }
72 catch
73 {
74 //try-fault
75 base.Dispose(true);
76 throw;
77 }
78 }
79
80 public void SetData<T>(T[] data) where T : struct
81 {
82 SetData<T>(elementCount: (data != null) ? data.Length : 0, level: 0, left: 0, top: 0, right: _width, bottom: _height, front: 0, back: _depth, data: data, startIndex: 0);
83 }
84
85 public void SetData<T>(T[] data, int startIndex, int elementCount) where T : struct
86 {
87 SetData(0, 0, 0, _width, _height, 0, _depth, data, startIndex, elementCount);
88 }
89
90 public void SetData<T>(int level, int left, int top, int right, int bottom, int front, int back, T[] data, int startIndex, int elementCount) where T : struct
91 {
92 CopyData(level, left, top, right, bottom, front, back, data, startIndex, elementCount, 0u, isSetting: true);
93 }
94
95 public void GetData<T>(T[] data) where T : struct
96 {
97 GetData<T>(elementCount: (data != null) ? data.Length : 0, level: 0, left: 0, top: 0, right: _width, bottom: _height, front: 0, back: _depth, data: data, startIndex: 0);
98 }
99
100 public void GetData<T>(T[] data, int startIndex, int elementCount) where T : struct
101 {
102 GetData(0, 0, 0, _width, _height, 0, _depth, data, startIndex, elementCount);
103 }
104
105 public void GetData<T>(int level, int left, int top, int right, int bottom, int front, int back, T[] data, int startIndex, int elementCount) where T : struct
106 {
107 CopyData(level, left, top, right, bottom, front, back, data, startIndex, elementCount, 16u, isSetting: false);
108 }
109
110 internal unsafe static void CopyData<T>(void* pData, int rowPitch, int slicePitch, T[] data, int dataIndex, int elementCount, _D3DVOLUME_DESC* pVolume, uint dwLockWidth, uint dwLockHeight, uint dwLockDepth, [MarshalAs(UnmanagedType.U1)] bool isSetting) where T : struct
111 {
112 if (pVolume == null)
113 {
114 return;
115 }
116 fixed (T* ptr2 = &data[dataIndex])
117 {
118 byte* ptr = (byte*)pData;
119 byte* ptr3 = (byte*)ptr2;
120 uint num = (uint)System.Runtime.CompilerServices.Unsafe.SizeOf<T>();
121 uint num2 = Texture.GetExpectedByteSizeFromFormat(*(_D3DFORMAT*)pVolume) / num * num * dwLockWidth;
122 if (0 >= dwLockDepth)
123 {
124 return;
125 }
126 uint num3 = dwLockDepth;
127 do
128 {
129 byte* ptr4 = ptr;
130 if (0 < dwLockHeight)
131 {
132 uint num4 = dwLockHeight;
133 do
134 {
135 if (*(int*)pVolume == 21)
136 {
137 if (isSetting)
138 {
139 Texture.SwapBgr(ptr4, ptr3, num2);
140 }
141 else
142 {
143 Texture.SwapBgr(ptr3, ptr4, num2);
144 }
145 }
146 else if (isSetting)
147 {
148 _003CModule_003E.memcpy_s(ptr4, num2, ptr3, num2);
149 }
150 else
151 {
152 _003CModule_003E.memcpy_s(ptr3, num2, ptr4, num2);
153 }
154 ptr4 = rowPitch + ptr4;
155 ptr3 = (int)num2 + ptr3;
156 num4--;
157 }
158 while (num4 != 0);
159 }
160 ptr = slicePitch + ptr;
161 num3--;
162 }
163 while (num3 != 0);
164 }
165 }
166
167 private unsafe void CopyData<T>(int level, int left, int top, int right, int bottom, int front, int back, T[] data, int startIndex, int elementCount, uint options, [MarshalAs(UnmanagedType.U1)] bool isSetting) where T : struct
168 {
169 IntPtr intPtr = (IntPtr)pComPtr;
170 Helpers.CheckDisposed(this, intPtr);
171 if (data != null && data.Length != 0)
172 {
173 if (isSetting)
174 {
175 int num = 0;
176 GraphicsDevice parent = _parent;
177 if (0 < parent.Textures._maxTextures)
178 {
179 do
180 {
181 if (parent.Textures[num] != this)
182 {
183 num++;
184 parent = _parent;
185 continue;
186 }
187 throw GraphicsHelpers.GetExceptionFromResult(2147500036u);
188 }
189 while (num < parent.Textures._maxTextures);
190 }
191 int num2 = 0;
192 GraphicsDevice parent2 = _parent;
193 if (0 < parent2.VertexTextures._maxTextures)
194 {
195 do
196 {
197 if (parent2.VertexTextures[num2] != this)
198 {
199 num2++;
200 parent2 = _parent;
201 continue;
202 }
203 throw GraphicsHelpers.GetExceptionFromResult(2147500036u);
204 }
205 while (num2 < parent2.VertexTextures._maxTextures);
206 }
207 }
208 IDirect3DVolumeTexture9* ptr = pComPtr;
209 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DVOLUME_DESC d3DVOLUME_DESC);
210 int num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DVOLUME_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, (uint)level, &d3DVOLUME_DESC);
211 if (num3 < 0)
212 {
213 throw GraphicsHelpers.GetExceptionFromResult((uint)num3);
214 }
215 Helpers.ValidateCopyParameters(data.Length, startIndex, elementCount);
216 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DBOX d3DBOX);
217 *(int*)(&d3DBOX) = left;
218 System.Runtime.CompilerServices.Unsafe.As<_D3DBOX, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DBOX, 8)) = right;
219 System.Runtime.CompilerServices.Unsafe.As<_D3DBOX, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DBOX, 4)) = top;
220 System.Runtime.CompilerServices.Unsafe.As<_D3DBOX, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DBOX, 12)) = bottom;
221 System.Runtime.CompilerServices.Unsafe.As<_D3DBOX, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DBOX, 16)) = front;
222 System.Runtime.CompilerServices.Unsafe.As<_D3DBOX, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DBOX, 20)) = back;
223 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint num4);
224 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint num5);
225 GetAndValidateSizes<T>(&d3DVOLUME_DESC, &num4, &num5);
226 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint num6);
227 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint num7);
228 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint num8);
229 GetAndValidateBox(&d3DVOLUME_DESC, &num6, &num7, &num8, &d3DBOX);
230 uint num9 = num6 * num7 * num8 * num4;
231 if ((int)num5 * elementCount != (int)num9)
232 {
234 }
235 IDirect3DVolumeTexture9* ptr2 = pComPtr;
236 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DLOCKED_BOX d3DLOCKED_BOX);
237 num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DLOCKED_BOX*, _D3DBOX*, uint, int>)(int)(*(uint*)(*(int*)ptr2 + 76)))((nint)ptr2, (uint)level, &d3DLOCKED_BOX, &d3DBOX, options);
238 if (num3 >= 0)
239 {
240 try
241 {
242 CopyData((void*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_BOX, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_BOX, 8)), *(int*)(&d3DLOCKED_BOX), System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_BOX, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_BOX, 4)), data, startIndex, elementCount, &d3DVOLUME_DESC, num6, num7, num8, isSetting);
243 }
244 finally
245 {
246 if (num3 >= 0)
247 {
248 ptr2 = pComPtr;
249 num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, int>)(int)(*(uint*)(*(int*)ptr2 + 80)))((nint)ptr2, (uint)level);
250 }
251 }
252 if (num3 >= 0)
253 {
254 return;
255 }
256 }
257 throw GraphicsHelpers.GetExceptionFromResult((uint)num3);
258 }
260 }
261
262 private unsafe void CreateTexture(GraphicsDevice graphicsDevice, int width, int height, int depth, [MarshalAs(UnmanagedType.U1)] bool mipMap, SurfaceFormat format)
263 {
264 if (graphicsDevice == null)
265 {
267 }
268 if (width <= 0)
269 {
271 }
272 if (height <= 0)
273 {
275 }
276 if (depth <= 0)
277 {
279 }
280 ProfileCapabilities profileCapabilities = graphicsDevice._profileCapabilities;
281 if (profileCapabilities.MaxVolumeExtent == 0)
282 {
284 }
285 if (!profileCapabilities.ValidVolumeFormats.Contains(format))
286 {
288 }
289 int maxVolumeExtent = profileCapabilities.MaxVolumeExtent;
290 if (width > maxVolumeExtent || height > maxVolumeExtent || depth > maxVolumeExtent)
291 {
292 profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileTooBig, typeof(Texture3D).Name, maxVolumeExtent);
293 }
294 int num = Math.Max(Math.Max(width, height), depth);
295 int num2 = Math.Min(Math.Min(width, height), depth);
296 int num3 = (num + num2 - 1) / num2;
297 int maxTextureAspectRatio = profileCapabilities.MaxTextureAspectRatio;
298 if (num3 > maxTextureAspectRatio)
299 {
300 profileCapabilities.ThrowNotSupportedException(FrameworkResources.ProfileAspectRatio, typeof(Texture3D).Name, maxTextureAspectRatio);
301 }
302 if (!profileCapabilities.NonPow2Volume && (!Texture.IsPowerOfTwo((uint)width) || !Texture.IsPowerOfTwo((uint)height) || !Texture.IsPowerOfTwo((uint)depth)))
303 {
305 }
306 int num4 = ((!mipMap) ? 1 : 0);
307 fixed (IDirect3DVolumeTexture9** ptr = &pComPtr)
308 {
309 int num5 = *(int*)graphicsDevice.pComPtr + 96;
310 int num6 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, uint, uint, uint, _D3DFORMAT, _D3DPOOL, IDirect3DVolumeTexture9**, void**, int>)(int)(*(uint*)num5))((nint)graphicsDevice.pComPtr, (uint)width, (uint)height, (uint)depth, (uint)num4, 0u, _003CModule_003E.ConvertXnaFormatToWindows(format), (_D3DPOOL)1, ptr, null);
311 if (num6 < 0)
312 {
313 throw GraphicsHelpers.GetExceptionFromResult((uint)num6);
314 }
315 isDisposed = false;
316 _parent = graphicsDevice;
317 SurfaceFormat? format2 = format;
318 InitializeDescription(format2);
319 graphicsDevice.Resources.AddTrackedObject(this, pComPtr, 1u, _internalHandle, ref _internalHandle);
320 }
321 }
322
323 internal unsafe static void GetAndValidateSizes<T>(_D3DVOLUME_DESC* pVolume, uint* pdwFormatSize, uint* pdwElementSize) where T : struct
324 {
325 if (pVolume == null || pdwFormatSize == null || pdwElementSize == null)
326 {
327 return;
328 }
329 *pdwFormatSize = Texture.GetExpectedByteSizeFromFormat(*(_D3DFORMAT*)pVolume);
330 uint num = (*pdwElementSize = (uint)System.Runtime.CompilerServices.Unsafe.SizeOf<T>());
331 uint num2 = *pdwFormatSize;
332 if (num != num2)
333 {
334 if (num2 <= num)
335 {
337 }
338 if (num2 % num != 0)
339 {
341 }
342 }
343 }
344
345 internal unsafe static void GetAndValidateBox(_D3DVOLUME_DESC* pVolume, uint* pdwLockWidth, uint* pdwLockHeight, uint* pdwLockDepth, _D3DBOX* pBox)
346 {
347 if (pVolume == null || pdwLockHeight == null || pdwLockWidth == null || pdwLockDepth == null)
348 {
349 return;
350 }
351 *pdwLockWidth = *(uint*)((byte*)pVolume + 16);
352 *pdwLockHeight = *(uint*)((byte*)pVolume + 20);
353 *pdwLockDepth = *(uint*)((byte*)pVolume + 24);
354 if (pBox == null)
355 {
356 return;
357 }
358 uint num = *(uint*)((byte*)pBox + 8);
359 if (num <= (uint)(*(int*)((byte*)pVolume + 16)))
360 {
361 uint num2 = *(uint*)pBox;
362 if (num2 < num)
363 {
364 uint num3 = *(uint*)((byte*)pBox + 12);
365 if (num3 <= (uint)(*(int*)((byte*)pVolume + 20)) && (uint)(*(int*)((byte*)pBox + 4)) < num3)
366 {
367 uint num4 = *(uint*)((byte*)pBox + 20);
368 if (num4 <= (uint)(*(int*)((byte*)pVolume + 24)) && (uint)(*(int*)((byte*)pBox + 16)) < num4)
369 {
370 *pdwLockWidth = num - num2;
371 *pdwLockHeight = (uint)(*(int*)((byte*)pBox + 12) - *(int*)((byte*)pBox + 4));
372 *pdwLockDepth = (uint)(*(int*)((byte*)pBox + 20) - *(int*)((byte*)pBox + 16));
373 return;
374 }
375 }
376 }
377 }
379 }
380
381 internal unsafe static void ValidateTotalSize(_D3DVOLUME_DESC* pVolume, uint dwLockWidth, uint dwLockHeight, uint dwLockDepth, uint dwFormatSize, uint dwElementSize, uint elementCount)
382 {
383 if (pVolume != null)
384 {
385 uint num = dwLockWidth * dwLockHeight * dwLockDepth * dwFormatSize;
386 if (dwElementSize * elementCount != num)
387 {
389 }
390 }
391 }
392
393 internal unsafe virtual int SaveDataForRecreation()
394 {
395 if (pComPtr == null)
396 {
397 return 0;
398 }
400 int num = CopyOrRestoreData(isStoring: true);
401 if (num >= 0)
402 {
403 ReleaseNativeObject(disposeManagedResource: false);
404 }
405 else
406 {
408 }
409 alreadyRecreated = false;
410 return num;
411 }
412
414 {
415 //ILSpy generated this explicit interface implementation from .override directive in SaveDataForRecreation
416 return this.SaveDataForRecreation();
417 }
418
419 internal unsafe virtual int RecreateAndPopulateObject()
420 {
422 {
423 return 0;
424 }
425 if (pComPtr != null)
426 {
427 return -2147467259;
428 }
429 fixed (IDirect3DVolumeTexture9** ptr2 = &pComPtr)
430 {
431 IDirect3DDevice9* ptr = _parent.pComPtr;
432 int num = *(int*)ptr + 96;
433 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, uint, uint, uint, _D3DFORMAT, _D3DPOOL, IDirect3DVolumeTexture9**, void**, int>)(int)(*(uint*)num))((nint)ptr, (uint)_width, (uint)_height, (uint)_depth, (uint)_levelCount, 0u, _003CModule_003E.ConvertXnaFormatToWindows(_format), (_D3DPOOL)1, ptr2, null);
434 if (num2 >= 0)
435 {
436 num2 = CreateStateWrapper();
437 if (num2 >= 0)
438 {
439 num2 = CopyOrRestoreData(isStoring: false);
440 if (num2 >= 0)
441 {
443 }
444 }
446 }
447 alreadyRecreated = true;
448 return num2;
449 }
450 }
451
453 {
454 //ILSpy generated this explicit interface implementation from .override directive in RecreateAndPopulateObject
455 return this.RecreateAndPopulateObject();
456 }
457
458 internal unsafe virtual void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
459 {
461 if (ptr != null)
462 {
463 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr + 8)))((nint)ptr);
464 pStateTracker = null;
465 }
466 GraphicsDevice parent = _parent;
467 if (parent != null && pComPtr != null)
468 {
469 parent.Resources.ReleaseAllReferences(_internalHandle, disposeManagedResource);
470 }
471 pComPtr = null;
472 }
473
474 void IGraphicsResource.ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
475 {
476 //ILSpy generated this explicit interface implementation from .override directive in ReleaseNativeObject
477 this.ReleaseNativeObject(disposeManagedResource);
478 }
479
480 internal unsafe int CopyOrRestoreData([MarshalAs(UnmanagedType.U1)] bool isStoring)
481 {
482 IDirect3DVolumeTexture9* ptr = pComPtr;
483 if (ptr == null)
484 {
485 return 0;
486 }
487 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DVOLUME_DESC d3DVOLUME_DESC);
488 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DVOLUME_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, 0u, &d3DVOLUME_DESC);
489 if (num >= 0)
490 {
491 if (isStoring)
492 {
494 }
495 uint num2 = System.Runtime.CompilerServices.Unsafe.As<_D3DVOLUME_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVOLUME_DESC, 16));
496 uint num3 = System.Runtime.CompilerServices.Unsafe.As<_D3DVOLUME_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVOLUME_DESC, 20));
497 uint num4 = System.Runtime.CompilerServices.Unsafe.As<_D3DVOLUME_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DVOLUME_DESC, 24));
498 byte expectedByteSizeFromFormat = Texture.GetExpectedByteSizeFromFormat(*(_D3DFORMAT*)(&d3DVOLUME_DESC));
499 int num5 = 0;
500 int num6 = 0;
501 if (0 < _levelCount)
502 {
503 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DLOCKED_BOX d3DLOCKED_BOX);
504 do
505 {
506 byte* ptr2 = null;
507 int num7;
508 if (!isStoring)
509 {
510 ref IntPtr reference = ref pFaceData[num5];
511 num5++;
512 ptr2 = (byte*)reference.ToPointer();
513 num7 = 0;
514 }
515 else
516 {
517 num7 = 16;
518 }
519 ptr = pComPtr;
520 num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DLOCKED_BOX*, _D3DBOX*, uint, int>)(int)(*(uint*)(*(int*)ptr + 76)))((nint)ptr, (uint)num6, &d3DLOCKED_BOX, null, (uint)num7);
521 if (num < 0)
522 {
523 break;
524 }
525 uint num8 = expectedByteSizeFromFormat * num2;
526 if (isStoring)
527 {
528 ptr2 = (byte*)_003CModule_003E.new_005B_005D(num8 * num4 * num3);
529 }
530 byte* ptr3 = ptr2;
531 byte* ptr4 = (byte*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_BOX, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_BOX, 8));
532 if (0 < num4)
533 {
534 uint num9 = num4;
535 do
536 {
537 byte* ptr5 = ptr4;
538 if (0 < num3)
539 {
540 uint num10 = num3;
541 do
542 {
543 if (isStoring)
544 {
545 _003CModule_003E.memcpy_s(ptr3, num8 * num3, ptr5, num8);
546 }
547 else
548 {
549 _003CModule_003E.memcpy_s(ptr5, *(uint*)(&d3DLOCKED_BOX), ptr3, num8);
550 }
551 ptr5 = *(int*)(&d3DLOCKED_BOX) + ptr5;
552 ptr3 = (int)num8 + ptr3;
553 num10--;
554 }
555 while (num10 != 0);
556 }
557 ptr4 = System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_BOX, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_BOX, 4)) + ptr4;
558 num9--;
559 }
560 while (num9 != 0);
561 }
562 ptr = pComPtr;
563 num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, int>)(int)(*(uint*)(*(int*)ptr + 80)))((nint)ptr, (uint)num6);
564 if (num < 0)
565 {
566 break;
567 }
568 if (isStoring)
569 {
570 IntPtr intPtr = (IntPtr)ptr2;
571 ref IntPtr reference2 = ref pFaceData[num5];
572 num5++;
573 reference2 = intPtr;
574 }
575 num2 = ((num2 <= 1) ? 1u : (num2 >> 1));
576 num3 = ((num3 <= 1) ? 1u : (num3 >> 1));
577 num4 = ((num4 <= 1) ? 1u : (num4 >> 1));
578 num6++;
579 }
580 while (num6 < _levelCount);
581 }
582 }
583 return num;
584 }
585
586 internal unsafe void CleanupSavedData()
587 {
589 if (array == null)
590 {
591 return;
592 }
593 int num = 0;
594 if (0 < (nint)array.LongLength)
595 {
596 do
597 {
598 void* ptr = pFaceData[num].ToPointer();
599 if (ptr != null)
600 {
601 _003CModule_003E.delete_005B_005D(ptr);
602 }
603 ref IntPtr reference = ref pFaceData[num];
604 reference = IntPtr.Zero;
605 num++;
606 }
607 while (num < (nint)pFaceData.LongLength);
608 }
609 pFaceData = null;
610 }
611
612 internal unsafe override IDirect3DBaseTexture9* GetComPtr()
613 {
614 return (IDirect3DBaseTexture9*)pComPtr;
615 }
616
617 internal unsafe static Texture3D GetManagedObject(IDirect3DVolumeTexture9* pInterface, GraphicsDevice pDevice, uint pool)
618 {
619 Texture3D texture3D = pDevice.Resources.GetCachedObject(pInterface) as Texture3D;
620 if (texture3D != null)
621 {
622 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)pInterface + 8)))((nint)pInterface);
623 texture3D.isDisposed = false;
624 GC.ReRegisterForFinalize(texture3D);
625 }
626 else
627 {
628 texture3D = new Texture3D(pInterface, pDevice);
629 pDevice.Resources.AddTrackedObject(texture3D, pInterface, pool, 0uL, ref texture3D._internalHandle);
630 }
631 return texture3D;
632 }
633
634 private void OnObjectCreation()
635 {
637 }
638
639 private void _0021Texture3D()
640 {
641 if (!isDisposed)
642 {
643 ReleaseNativeObject(disposeManagedResource: true);
645 }
646 }
647
648 private void _007ETexture3D()
649 {
651 }
652
653 [HandleProcessCorruptedStateExceptions]
654 protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
655 {
656 if (P_0)
657 {
658 try
659 {
661 return;
662 }
663 finally
664 {
665 base.Dispose(true);
666 }
667 }
668 try
669 {
671 }
672 finally
673 {
674 base.Dispose(false);
675 }
676 }
677}
unsafe void AddTrackedObject(object managedObject, void *pComPtr, uint resourceManagementMode, ulong handle, ref ulong updatedHandle)
unsafe void ReleaseAllReferences(ulong handle, [MarshalAs(UnmanagedType.U1)] bool dispose)
static Exception GetExceptionFromResult(uint result)
unsafe IDirect3DVolumeTexture9 * pComPtr
Definition Texture3D.cs:18
static unsafe Texture3D GetManagedObject(IDirect3DVolumeTexture9 *pInterface, GraphicsDevice pDevice, uint pool)
Definition Texture3D.cs:617
unsafe override IDirect3DBaseTexture9 * GetComPtr()
Definition Texture3D.cs:612
static unsafe void GetAndValidateBox(_D3DVOLUME_DESC *pVolume, uint *pdwLockWidth, uint *pdwLockHeight, uint *pdwLockDepth, _D3DBOX *pBox)
Definition Texture3D.cs:345
static unsafe void GetAndValidateSizes< T >(_D3DVOLUME_DESC *pVolume, uint *pdwFormatSize, uint *pdwElementSize)
Definition Texture3D.cs:323
unsafe int CopyOrRestoreData([MarshalAs(UnmanagedType.U1)] bool isStoring)
Definition Texture3D.cs:480
static unsafe void ValidateTotalSize(_D3DVOLUME_DESC *pVolume, uint dwLockWidth, uint dwLockHeight, uint dwLockDepth, uint dwFormatSize, uint dwElementSize, uint elementCount)
Definition Texture3D.cs:381
unsafe void CreateTexture(GraphicsDevice graphicsDevice, int width, int height, int depth, [MarshalAs(UnmanagedType.U1)] bool mipMap, SurfaceFormat format)
Definition Texture3D.cs:262
Texture3D(GraphicsDevice graphicsDevice, int width, int height, int depth, [MarshalAs(UnmanagedType.U1)] bool mipMap, SurfaceFormat format)
Definition Texture3D.cs:65
static unsafe void CopyData< T >(void *pData, int rowPitch, int slicePitch, T[] data, int dataIndex, int elementCount, _D3DVOLUME_DESC *pVolume, uint dwLockWidth, uint dwLockHeight, uint dwLockDepth, [MarshalAs(UnmanagedType.U1)] bool isSetting)
Definition Texture3D.cs:110
unsafe Texture3D(IDirect3DVolumeTexture9 *pInterface, GraphicsDevice pDevice)
Definition Texture3D.cs:47
unsafe void InitializeDescription(SurfaceFormat? format)
Definition Texture3D.cs:26
virtual unsafe int RecreateAndPopulateObject()
Definition Texture3D.cs:419
virtual unsafe void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
Definition Texture3D.cs:458
override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
Definition Texture3D.cs:654
static bool IsPowerOfTwo(uint dwNumber)
Definition Texture.cs:353
unsafe StateTrackerTexture * pStateTracker
Definition Texture.cs:20
static unsafe void SwapBgr(void *pDest, void *pSrc, uint dwSize)
Definition Texture.cs:334
static byte GetExpectedByteSizeFromFormat(_D3DFORMAT format)
Definition Texture.cs:72
static void CheckDisposed(object obj, IntPtr pComPtr)
Definition Helpers.cs:188
static void ValidateCopyParameters(int dataLength, int dataIndex, int elementCount)
Definition Helpers.cs:66
static void ReRegisterForFinalize(object obj)
Definition GC.cs:214
Definition GC.cs:8
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
static readonly IntPtr Zero
Definition IntPtr.cs:18
unsafe void * ToPointer()
Definition IntPtr.cs:210