Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TextureCube.cs
Go to the documentation of this file.
1using System;
5
7
9{
10 private protected int _size;
11
12 private protected bool _shouldNotRecreate;
13
14 private IntPtr[] pFaceData;
15
16 internal unsafe IDirect3DCubeTexture9* pComPtr;
17
18 public int Size => _size;
19
20 private unsafe TextureCube(IDirect3DCubeTexture9* pInterface, GraphicsDevice pDevice)
21 {
22 pComPtr = pInterface;
23 ((object)this)._002Ector();
24 try
25 {
26 _parent = pDevice;
28 return;
29 }
30 catch
31 {
32 //try-fault
33 base.Dispose(true);
34 throw;
35 }
36 }
37
38 private protected TextureCube()
39 {
40 }
41
42 public TextureCube(GraphicsDevice graphicsDevice, int size, [MarshalAs(UnmanagedType.U1)] bool mipMap, SurfaceFormat format)
43 {
44 try
45 {
46 CreateTexture(graphicsDevice, size, mipMap, 0u, (_D3DPOOL)1, format);
47 return;
48 }
49 catch
50 {
51 //try-fault
52 base.Dispose(true);
53 throw;
54 }
55 }
56
57 public void SetData<T>(CubeMapFace cubeMapFace, T[] data) where T : struct
58 {
59 Rectangle? rect = null;
60 int elementCount = ((data != null) ? data.Length : 0);
61 SetData(cubeMapFace, 0, rect, data, 0, elementCount);
62 }
63
64 public void SetData<T>(CubeMapFace cubeMapFace, T[] data, int startIndex, int elementCount) where T : struct
65 {
66 SetData(cubeMapFace, 0, null, data, startIndex, elementCount);
67 }
68
69 public void SetData<T>(CubeMapFace cubeMapFace, int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
70 {
71 CopyData(cubeMapFace, level, rect, data, startIndex, elementCount, 0u, isSetting: true);
72 }
73
74 public void GetData<T>(CubeMapFace cubeMapFace, T[] data) where T : struct
75 {
76 Rectangle? rect = null;
77 int elementCount = ((data != null) ? data.Length : 0);
78 GetData(cubeMapFace, 0, rect, data, 0, elementCount);
79 }
80
81 public void GetData<T>(CubeMapFace cubeMapFace, T[] data, int startIndex, int elementCount) where T : struct
82 {
83 GetData(cubeMapFace, 0, null, data, startIndex, elementCount);
84 }
85
86 public void GetData<T>(CubeMapFace cubeMapFace, int level, Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
87 {
88 CopyData(cubeMapFace, level, rect, data, startIndex, elementCount, 16u, isSetting: false);
89 }
90
91 private unsafe void CopyData<T>(CubeMapFace cubeMapFace, int level, Rectangle? rect, T[] data, int startIndex, int elementCount, uint options, [MarshalAs(UnmanagedType.U1)] bool isSetting) where T : struct
92 {
93 IntPtr intPtr = (IntPtr)pComPtr;
94 Helpers.CheckDisposed(this, intPtr);
95 if (data != null && data.Length != 0)
96 {
98 {
100 }
101 if (isSetting)
102 {
103 int num = 0;
104 GraphicsDevice parent = _parent;
105 if (0 < parent.Textures._maxTextures)
106 {
107 do
108 {
109 if (parent.Textures[num] != this)
110 {
111 num++;
112 parent = _parent;
113 continue;
114 }
115 throw GraphicsHelpers.GetExceptionFromResult(2147500036u);
116 }
117 while (num < parent.Textures._maxTextures);
118 }
119 int num2 = 0;
120 GraphicsDevice parent2 = _parent;
121 if (0 < parent2.VertexTextures._maxTextures)
122 {
123 do
124 {
125 if (parent2.VertexTextures[num2] != this)
126 {
127 num2++;
128 parent2 = _parent;
129 continue;
130 }
131 throw GraphicsHelpers.GetExceptionFromResult(2147500036u);
132 }
133 while (num2 < parent2.VertexTextures._maxTextures);
134 }
135 }
136 IDirect3DCubeTexture9* ptr = pComPtr;
137 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DSURFACE_DESC d3DSURFACE_DESC);
138 int num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DSURFACE_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, (uint)level, &d3DSURFACE_DESC);
139 if (num3 < 0)
140 {
141 throw GraphicsHelpers.GetExceptionFromResult((uint)num3);
142 }
143 Helpers.ValidateCopyParameters(data.Length, startIndex, elementCount);
144 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwFormatSize);
145 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwElementSize);
146 Texture.GetAndValidateSizes<T>(&d3DSURFACE_DESC, &dwFormatSize, &dwElementSize);
147 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwLockWidth);
148 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwLockHeight);
149 Texture.GetAndValidateRect(&d3DSURFACE_DESC, &dwLockWidth, &dwLockHeight, rect);
150 Texture.ValidateTotalSize(&d3DSURFACE_DESC, dwLockWidth, dwLockHeight, dwFormatSize, dwElementSize, (uint)elementCount);
151 tagRECT* ptr2 = null;
152 Rectangle rectangle = default(Rectangle);
153 if (rect.HasValue)
154 {
155 rectangle = rect.Value;
156 ptr2 = (tagRECT*)(int)(ref rectangle);
157 if (ptr2 != null)
158 {
159 *(int*)((byte*)ptr2 + 8) += *(int*)ptr2;
160 *(int*)((byte*)ptr2 + 12) += *(int*)((byte*)ptr2 + 4);
161 }
162 }
163 int num5;
164 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DLOCKED_RECT d3DLOCKED_RECT);
165 if (System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 12)) == 0)
166 {
167 if (!isSetting)
168 {
169 GraphicsDevice parent3 = _parent;
170 GraphicsDevice graphicsDevice = parent3;
171 GraphicsDevice graphicsDevice2 = parent3;
172 GraphicsDevice graphicsDevice3 = parent3;
173 int num4 = *(int*)GraphicsAdapter.pComPtr + 40;
174 if (((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DDEVTYPE, _D3DFORMAT, uint, _D3DRESOURCETYPE, _D3DFORMAT, int>)(int)(*(uint*)num4))((nint)GraphicsAdapter.pComPtr, graphicsDevice3.Adapter.adapter, graphicsDevice2._deviceType, _003CModule_003E.ConvertXnaFormatToWindowsAdapterFormat(graphicsDevice.Adapter.CurrentDisplayMode.Format), 1u, (_D3DRESOURCETYPE)3, *(_D3DFORMAT*)(&d3DSURFACE_DESC)) < 0)
175 {
177 }
178 }
179 IDirect3DSurface9* ptr3 = null;
180 IDirect3DTexture9* ptr4 = null;
181 IDirect3DSurface9* ptr5 = null;
182 IDirect3DDevice9* ptr6 = _parent.pComPtr;
183 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, uint, uint, _D3DFORMAT, _D3DPOOL, IDirect3DTexture9**, void**, int>)(int)(*(uint*)(*(int*)ptr6 + 92)))((nint)ptr6, System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 24)), System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 28)), 1u, 0u, *(_D3DFORMAT*)(&d3DSURFACE_DESC), (_D3DPOOL)2, &ptr4, null);
184 if (num5 >= 0)
185 {
186 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)ptr4 + 72)))((nint)ptr4, 0u, &ptr3);
187 if (num5 >= 0)
188 {
189 ptr = pComPtr;
190 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DCUBEMAP_FACES, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)ptr + 72)))((nint)ptr, (_D3DCUBEMAP_FACES)cubeMapFace, (uint)level, &ptr5);
191 if (num5 >= 0)
192 {
193 if (isSetting)
194 {
195 if (ptr2 != null && (*(int*)ptr2 != 0 || *(int*)((byte*)ptr2 + 4) != 0 || *(int*)((byte*)ptr2 + 8) != System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 24)) || *(int*)((byte*)ptr2 + 12) != System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 28))))
196 {
197 num5 = _003CModule_003E.D3DXLoadSurfaceFromSurface(ptr3, null, null, ptr5, null, null, 1u, 0u);
198 }
199 if (num5 >= 0)
200 {
201 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr3 + 52)))((nint)ptr3, &d3DLOCKED_RECT, ptr2, 0u);
202 if (num5 >= 0)
203 {
204 try
205 {
206 Texture.CopyData((void*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_RECT, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_RECT, 4)), *(int*)(&d3DLOCKED_RECT), data, startIndex, elementCount, &d3DSURFACE_DESC, dwLockWidth, dwLockHeight, isSetting);
207 }
208 finally
209 {
210 IDirect3DSurface9* intPtr2 = ptr3;
211 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 56)))((nint)intPtr2);
212 }
213 if (num5 >= 0)
214 {
215 num5 = _003CModule_003E.D3DXLoadSurfaceFromSurface(ptr5, null, ptr2, ptr3, null, ptr2, 1u, 0u);
216 }
217 }
218 }
219 }
220 else
221 {
222 num5 = _003CModule_003E.D3DXLoadSurfaceFromSurface(ptr3, null, ptr2, ptr5, null, ptr2, 1u, 0u);
223 if (num5 >= 0)
224 {
225 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr3 + 52)))((nint)ptr3, &d3DLOCKED_RECT, ptr2, 0u);
226 if (num5 >= 0)
227 {
228 try
229 {
230 Texture.CopyData((void*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_RECT, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_RECT, 4)), *(int*)(&d3DLOCKED_RECT), data, startIndex, elementCount, &d3DSURFACE_DESC, dwLockWidth, dwLockHeight, isSetting: false);
231 }
232 finally
233 {
234 IDirect3DSurface9* intPtr3 = ptr3;
235 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr3 + 56)))((nint)intPtr3);
236 }
237 }
238 }
239 }
240 }
241 }
242 }
243 if (ptr5 != null)
244 {
245 IDirect3DSurface9* intPtr4 = ptr5;
246 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr4 + 8)))((nint)intPtr4);
247 ptr5 = null;
248 }
249 if (ptr3 != null)
250 {
251 IDirect3DSurface9* intPtr5 = ptr3;
252 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr5 + 8)))((nint)intPtr5);
253 ptr3 = null;
254 }
255 if (ptr4 != null)
256 {
257 IDirect3DTexture9* intPtr6 = ptr4;
258 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr6 + 8)))((nint)intPtr6);
259 ptr4 = null;
260 }
261 }
262 else
263 {
264 ptr = pComPtr;
265 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DCUBEMAP_FACES, uint, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr + 76)))((nint)ptr, (_D3DCUBEMAP_FACES)cubeMapFace, (uint)level, &d3DLOCKED_RECT, ptr2, options);
266 if (num5 >= 0)
267 {
268 try
269 {
270 Texture.CopyData((void*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_RECT, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_RECT, 4)), *(int*)(&d3DLOCKED_RECT), data, startIndex, elementCount, &d3DSURFACE_DESC, dwLockWidth, dwLockHeight, isSetting);
271 }
272 finally
273 {
274 ptr = pComPtr;
275 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DCUBEMAP_FACES, uint, int>)(int)(*(uint*)(*(int*)ptr + 80)))((nint)ptr, (_D3DCUBEMAP_FACES)cubeMapFace, (uint)level);
276 }
277 }
278 }
280 {
281 if (isSetting)
282 {
283 return;
284 }
285 fixed (T* ptr7 = &data[startIndex])
286 {
287 try
288 {
289 uint num6 = (uint)(System.Runtime.CompilerServices.Unsafe.SizeOf<T>() * elementCount);
290 // IL initblk instruction
292 }
293 catch
294 {
295 //try-fault
296 ptr7 = null;
297 throw;
298 }
299 }
300 }
301 else
302 {
303 if (num5 < 0)
304 {
305 throw GraphicsHelpers.GetExceptionFromResult((uint)num5);
306 }
307 if (isSetting && this is IDynamicGraphicsResource dynamicGraphicsResource)
308 {
309 dynamicGraphicsResource.SetContentLost(isContentLost: false);
310 }
311 }
312 return;
313 }
315 }
316
317 private protected unsafe void InitializeDescription(SurfaceFormat? format)
318 {
319 IDirect3DCubeTexture9* ptr = pComPtr;
320 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DSURFACE_DESC d3DSURFACE_DESC);
321 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DSURFACE_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, 0u, &d3DSURFACE_DESC);
322 if (num < 0)
323 {
325 }
326 if (!format.HasValue)
327 {
328 format = _003CModule_003E.ConvertWindowsFormatToXna(*(_D3DFORMAT*)(&d3DSURFACE_DESC));
329 }
330 _size = System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 24));
331 int shouldNotRecreate = ((System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 12)) == 0) ? 1 : 0);
332 _shouldNotRecreate = (byte)shouldNotRecreate != 0;
333 base.InitializeDescription(format.Value);
334 }
335
336 private protected unsafe void CreateTexture(GraphicsDevice graphicsDevice, int size, [MarshalAs(UnmanagedType.U1)] bool mipMap, uint usage, _D3DPOOL pool, SurfaceFormat format)
337 {
338 if (graphicsDevice == null)
339 {
341 }
343 int num = ((!mipMap) ? 1 : 0);
344 fixed (IDirect3DCubeTexture9** ptr = &pComPtr)
345 {
346 int num2 = *(int*)graphicsDevice.pComPtr + 100;
347 int num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, uint, _D3DFORMAT, _D3DPOOL, IDirect3DCubeTexture9**, void**, int>)(int)(*(uint*)num2))((nint)graphicsDevice.pComPtr, (uint)size, (uint)num, usage, _003CModule_003E.ConvertXnaFormatToWindows(format), pool, ptr, null);
348 if (num3 < 0)
349 {
350 throw GraphicsHelpers.GetExceptionFromResult((uint)num3);
351 }
352 isDisposed = false;
353 _parent = graphicsDevice;
354 SurfaceFormat? format2 = format;
355 InitializeDescription(format2);
356 graphicsDevice.Resources.AddTrackedObject(this, pComPtr, (uint)pool, _internalHandle, ref _internalHandle);
357 }
358 }
359
360 private protected static void ValidateCreationParameters(ProfileCapabilities profile, int size, SurfaceFormat format)
361 {
362 if (size <= 0)
363 {
365 }
366 bool flag = Texture.CheckCompressedTexture(_003CModule_003E.ConvertXnaFormatToWindows(format));
367 if (!profile.ValidCubeFormats.Contains(format))
368 {
370 }
371 int maxCubeSize = profile.MaxCubeSize;
372 if (size > maxCubeSize)
373 {
375 }
376 if (!profile.NonPow2Cube && !Texture.IsPowerOfTwo((uint)size))
377 {
379 }
380 if (flag && ((uint)size & 3u) != 0)
381 {
383 }
384 }
385
386 internal unsafe virtual int SaveDataForRecreation()
387 {
388 if (pComPtr == null)
389 {
390 return 0;
391 }
393 int num = CopyOrRestoreData(isStoring: true);
394 if (num >= 0)
395 {
396 ReleaseNativeObject(disposeManagedResource: false);
397 }
398 else
399 {
401 }
402 alreadyRecreated = false;
403 return num;
404 }
405
407 {
408 //ILSpy generated this explicit interface implementation from .override directive in SaveDataForRecreation
409 return this.SaveDataForRecreation();
410 }
411
412 internal unsafe virtual int RecreateAndPopulateObject()
413 {
415 {
416 return 0;
417 }
419 {
420 return 0;
421 }
422 if (pComPtr != null)
423 {
424 return -2147467259;
425 }
426 fixed (IDirect3DCubeTexture9** ptr2 = &pComPtr)
427 {
428 IDirect3DDevice9* ptr = _parent.pComPtr;
429 int num = *(int*)ptr + 100;
430 int num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, uint, _D3DFORMAT, _D3DPOOL, IDirect3DCubeTexture9**, void**, int>)(int)(*(uint*)num))((nint)ptr, (uint)_size, (uint)_levelCount, 0u, _003CModule_003E.ConvertXnaFormatToWindows(_format), (_D3DPOOL)1, ptr2, null);
431 if (num2 >= 0)
432 {
433 num2 = CreateStateWrapper();
434 if (num2 >= 0)
435 {
436 num2 = CopyOrRestoreData(isStoring: false);
437 if (num2 >= 0)
438 {
440 }
441 }
443 }
444 alreadyRecreated = true;
445 return num2;
446 }
447 }
448
450 {
451 //ILSpy generated this explicit interface implementation from .override directive in RecreateAndPopulateObject
452 return this.RecreateAndPopulateObject();
453 }
454
455 internal unsafe virtual void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
456 {
458 if (ptr != null)
459 {
460 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)ptr + 8)))((nint)ptr);
461 pStateTracker = null;
462 }
463 GraphicsDevice parent = _parent;
464 if (parent != null && pComPtr != null)
465 {
466 parent.Resources.ReleaseAllReferences(_internalHandle, disposeManagedResource);
467 }
468 pComPtr = null;
469 }
470
471 void IGraphicsResource.ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
472 {
473 //ILSpy generated this explicit interface implementation from .override directive in ReleaseNativeObject
474 this.ReleaseNativeObject(disposeManagedResource);
475 }
476
477 internal unsafe int CopyOrRestoreData([MarshalAs(UnmanagedType.U1)] bool isStoring)
478 {
479 IDirect3DCubeTexture9* ptr = pComPtr;
480 if (ptr == null)
481 {
482 return 0;
483 }
484 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DSURFACE_DESC d3DSURFACE_DESC);
485 int num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DSURFACE_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, 0u, &d3DSURFACE_DESC);
486 if (num >= 0)
487 {
488 if (isStoring)
489 {
490 pFaceData = new IntPtr[_levelCount * 6];
491 }
492 uint num2 = System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 24));
493 uint num3 = System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 28));
494 bool flag = Texture.CheckCompressedTexture(*(_D3DFORMAT*)(&d3DSURFACE_DESC));
495 byte b = ((!flag) ? Texture.GetExpectedByteSizeFromFormat(*(_D3DFORMAT*)(&d3DSURFACE_DESC)) : ((byte)((*(int*)(&d3DSURFACE_DESC) == 827611204) ? 8u : 16u)));
496 int num4 = 0;
497 int num5 = 0;
498 if (0 < _levelCount)
499 {
500 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DLOCKED_RECT d3DLOCKED_RECT);
501 do
502 {
503 int num6 = 0;
504 do
505 {
506 byte* ptr2 = null;
507 int num7;
508 if (!isStoring)
509 {
510 ref IntPtr reference = ref pFaceData[num4];
511 num4++;
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, _D3DCUBEMAP_FACES, uint, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr + 76)))((nint)ptr, (_D3DCUBEMAP_FACES)num6, (uint)num5, &d3DLOCKED_RECT, null, (uint)num7);
521 if (num < 0)
522 {
523 break;
524 }
525 uint num8 = num2;
526 uint num9 = num3;
527 if (flag)
528 {
529 num8 = num2 + 3 >> 2;
530 num9 = num3 + 3 >> 2;
531 }
532 uint num10 = b * num8;
533 byte* ptr3 = (byte*)(int)System.Runtime.CompilerServices.Unsafe.As<_D3DLOCKED_RECT, uint>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DLOCKED_RECT, 4));
534 if (isStoring)
535 {
536 ptr2 = (byte*)_003CModule_003E.new_005B_005D(num10 * num9);
537 }
538 byte* ptr4 = ptr2;
539 if (0 < num9)
540 {
541 uint num11 = num9;
542 do
543 {
544 if (isStoring)
545 {
546 _003CModule_003E.memcpy_s(ptr4, num10 * num9, ptr3, num10);
547 }
548 else
549 {
550 _003CModule_003E.memcpy_s(ptr3, *(uint*)(&d3DLOCKED_RECT), ptr4, num10);
551 }
552 ptr3 = *(int*)(&d3DLOCKED_RECT) + ptr3;
553 ptr4 = (int)num10 + ptr4;
554 num11--;
555 }
556 while (num11 != 0);
557 }
558 ptr = pComPtr;
559 num = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DCUBEMAP_FACES, uint, int>)(int)(*(uint*)(*(int*)ptr + 80)))((nint)ptr, (_D3DCUBEMAP_FACES)num6, (uint)num5);
560 if (num < 0)
561 {
562 break;
563 }
564 if (isStoring)
565 {
566 IntPtr intPtr = (IntPtr)ptr2;
567 ref IntPtr reference2 = ref pFaceData[num4];
568 num4++;
569 reference2 = intPtr;
570 }
571 num6++;
572 }
573 while (num6 < 6);
574 num2 = ((num2 <= 1) ? 1u : (num2 >> 1));
575 num3 = ((num3 <= 1) ? 1u : (num3 >> 1));
576 num5++;
577 }
578 while (num5 < _levelCount);
579 }
580 }
581 return num;
582 }
583
584 internal unsafe void CleanupSavedData()
585 {
587 if (array == null)
588 {
589 return;
590 }
591 int num = 0;
592 if (0 < (nint)array.LongLength)
593 {
594 do
595 {
596 void* ptr = pFaceData[num].ToPointer();
597 if (ptr != null)
598 {
599 _003CModule_003E.delete_005B_005D(ptr);
600 }
601 ref IntPtr reference = ref pFaceData[num];
602 reference = IntPtr.Zero;
603 num++;
604 }
605 while (num < (nint)pFaceData.LongLength);
606 }
607 pFaceData = null;
608 }
609
610 internal unsafe override IDirect3DBaseTexture9* GetComPtr()
611 {
612 return (IDirect3DBaseTexture9*)pComPtr;
613 }
614
615 internal unsafe static TextureCube GetManagedObject(IDirect3DCubeTexture9* pInterface, GraphicsDevice pDevice, uint pool)
616 {
617 TextureCube textureCube = pDevice.Resources.GetCachedObject(pInterface) as TextureCube;
618 if (textureCube != null)
619 {
620 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)pInterface + 8)))((nint)pInterface);
621 textureCube.isDisposed = false;
622 GC.ReRegisterForFinalize(textureCube);
623 }
624 else
625 {
626 textureCube = new TextureCube(pInterface, pDevice);
627 pDevice.Resources.AddTrackedObject(textureCube, pInterface, pool, 0uL, ref textureCube._internalHandle);
628 }
629 return textureCube;
630 }
631
632 private void OnObjectCreation()
633 {
635 }
636
637 private void _0021TextureCube()
638 {
639 if (!isDisposed)
640 {
641 ReleaseNativeObject(disposeManagedResource: true);
643 }
644 }
645
646 private void _007ETextureCube()
647 {
649 }
650
651 [HandleProcessCorruptedStateExceptions]
652 protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
653 {
654 if (P_0)
655 {
656 try
657 {
659 return;
660 }
661 finally
662 {
663 base.Dispose(true);
664 }
665 }
666 try
667 {
669 }
670 finally
671 {
672 base.Dispose(false);
673 }
674 }
675}
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 void CreateTexture(GraphicsDevice graphicsDevice, int size, [MarshalAs(UnmanagedType.U1)] bool mipMap, uint usage, _D3DPOOL pool, SurfaceFormat format)
static void ValidateCreationParameters(ProfileCapabilities profile, int size, SurfaceFormat format)
static unsafe TextureCube GetManagedObject(IDirect3DCubeTexture9 *pInterface, GraphicsDevice pDevice, uint pool)
TextureCube(GraphicsDevice graphicsDevice, int size, [MarshalAs(UnmanagedType.U1)] bool mipMap, SurfaceFormat format)
unsafe void InitializeDescription(SurfaceFormat? format)
virtual unsafe void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
unsafe override IDirect3DBaseTexture9 * GetComPtr()
unsafe IDirect3DCubeTexture9 * pComPtr
override void Dispose([MarshalAs(UnmanagedType.U1)] bool P_0)
void GetData< T >(CubeMapFace cubeMapFace, T[] data)
unsafe void CopyData< T >(CubeMapFace cubeMapFace, int level, Rectangle? rect, T[] data, int startIndex, int elementCount, uint options, [MarshalAs(UnmanagedType.U1)] bool isSetting)
unsafe int CopyOrRestoreData([MarshalAs(UnmanagedType.U1)] bool isStoring)
unsafe TextureCube(IDirect3DCubeTexture9 *pInterface, GraphicsDevice pDevice)
void SetData< T >(CubeMapFace cubeMapFace, T[] data)
static unsafe void GetAndValidateRect(_D3DSURFACE_DESC *__unnamed000, uint *pdwLockWidth, uint *pdwLockHeight, Rectangle? rect)
Definition Texture.cs:221
static bool IsPowerOfTwo(uint dwNumber)
Definition Texture.cs:353
unsafe StateTrackerTexture * pStateTracker
Definition Texture.cs:20
static unsafe void ValidateTotalSize(_D3DSURFACE_DESC *__unnamed000, uint dwLockWidth, uint dwLockHeight, uint dwFormatSize, uint dwElementSize, uint elementCount)
Definition Texture.cs:253
static byte GetExpectedByteSizeFromFormat(_D3DFORMAT format)
Definition Texture.cs:72
static bool CheckCompressedTexture(_D3DFORMAT format)
Definition Texture.cs:272
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 unsafe void InitBlock(void *startAddress, byte value, uint byteCount)
Definition Unsafe.cs:117
void ReleaseNativeObject([MarshalAs(UnmanagedType.U1)] bool disposeManagedResource)
static readonly IntPtr Zero
Definition IntPtr.cs:18
unsafe void * ToPointer()
Definition IntPtr.cs:210