Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CopyData< T >() [1/2]

unsafe void Microsoft.Xna.Framework.Graphics.Texture2D.CopyData< T > ( int level,
Rectangle? rect,
T[] data,
int startIndex,
int elementCount,
uint options,
[MarshalAs(UnmanagedType.U1)] bool isSetting )
inlineprivate
Type Constraints
T :struct 

Definition at line 220 of file Texture2D.cs.

220 : struct
221 {
222 IntPtr intPtr = (IntPtr)pComPtr;
223 Helpers.CheckDisposed(this, intPtr);
224 if (data != null && data.Length != 0)
225 {
227 {
228 throw new InvalidOperationException(FrameworkResources.MustResolveRenderTarget);
229 }
230 if (isSetting)
231 {
232 int num = 0;
234 {
235 do
236 {
237 if (_parent.Textures[num] != this)
238 {
239 num++;
240 continue;
241 }
242 throw GraphicsHelpers.GetExceptionFromResult(2147500036u);
243 }
244 while (num < _parent.Textures._maxTextures);
245 }
246 int num2 = 0;
248 {
249 do
250 {
251 if (_parent.VertexTextures[num2] != this)
252 {
253 num2++;
254 continue;
255 }
256 throw GraphicsHelpers.GetExceptionFromResult(2147500036u);
257 }
258 while (num2 < _parent.VertexTextures._maxTextures);
259 }
260 }
261 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DSURFACE_DESC d3DSURFACE_DESC);
262 // IL initblk instruction
263 System.Runtime.CompilerServices.Unsafe.InitBlock(ref d3DSURFACE_DESC, 0, 32);
264 IDirect3DTexture9* ptr = pComPtr;
265 int num3 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DSURFACE_DESC*, int>)(int)(*(uint*)(*(int*)ptr + 68)))((nint)ptr, (uint)level, &d3DSURFACE_DESC);
266 if (num3 < 0)
267 {
268 throw GraphicsHelpers.GetExceptionFromResult((uint)num3);
269 }
270 Helpers.ValidateCopyParameters(data.Length, startIndex, elementCount);
271 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwFormatSize);
272 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwElementSize);
273 Texture.GetAndValidateSizes<T>(&d3DSURFACE_DESC, &dwFormatSize, &dwElementSize);
274 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwLockWidth);
275 System.Runtime.CompilerServices.Unsafe.SkipInit(out uint dwLockHeight);
276 Texture.GetAndValidateRect(&d3DSURFACE_DESC, &dwLockWidth, &dwLockHeight, rect);
277 Texture.ValidateTotalSize(&d3DSURFACE_DESC, dwLockWidth, dwLockHeight, dwFormatSize, dwElementSize, (uint)elementCount);
278 tagRECT* ptr2 = null;
279 Rectangle rectangle = default(Rectangle);
280 if (rect.HasValue)
281 {
282 rectangle = rect.Value;
283 ptr2 = (tagRECT*)(int)(ref rectangle);
284 if (ptr2 != null)
285 {
286 *(int*)((byte*)ptr2 + 8) += *(int*)ptr2;
287 *(int*)((byte*)ptr2 + 12) += *(int*)((byte*)ptr2 + 4);
288 }
289 }
290 int num5;
291 System.Runtime.CompilerServices.Unsafe.SkipInit(out _D3DLOCKED_RECT d3DLOCKED_RECT);
292 if (System.Runtime.CompilerServices.Unsafe.As<_D3DSURFACE_DESC, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref d3DSURFACE_DESC, 12)) == 0)
293 {
294 if (!isSetting)
295 {
296 GraphicsDevice parent = _parent;
297 GraphicsDevice graphicsDevice = parent;
298 GraphicsDevice graphicsDevice2 = parent;
299 GraphicsDevice graphicsDevice3 = parent;
300 int num4 = *(int*)GraphicsAdapter.pComPtr + 40;
301 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)
302 {
303 throw new InvalidOperationException(FrameworkResources.CannotUseFormatTypeAsManualWhenLocking);
304 }
305 }
306 IDirect3DSurface9* ptr3 = null;
307 IDirect3DTexture9* ptr4 = null;
308 IDirect3DSurface9* ptr5 = null;
309 IDirect3DDevice9* ptr6 = _parent.pComPtr;
310 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);
311 if (num5 >= 0)
312 {
313 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)ptr4 + 72)))((nint)ptr4, 0u, &ptr3);
314 if (num5 >= 0)
315 {
316 ptr = pComPtr;
317 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, IDirect3DSurface9**, int>)(int)(*(uint*)(*(int*)ptr + 72)))((nint)ptr, (uint)level, &ptr5);
318 if (num5 >= 0)
319 {
320 if (isSetting)
321 {
322 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))))
323 {
324 num5 = _003CModule_003E.D3DXLoadSurfaceFromSurface(ptr3, null, null, ptr5, null, null, 1u, 0u);
325 }
326 if (num5 >= 0)
327 {
328 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr3 + 52)))((nint)ptr3, &d3DLOCKED_RECT, ptr2, 0u);
329 if (num5 >= 0)
330 {
331 try
332 {
333 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);
334 }
335 finally
336 {
337 IDirect3DSurface9* intPtr2 = ptr3;
338 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 56)))((nint)intPtr2);
339 }
340 if (num5 >= 0)
341 {
342 num5 = _003CModule_003E.D3DXLoadSurfaceFromSurface(ptr5, null, ptr2, ptr3, null, ptr2, 1u, 0u);
343 }
344 }
345 }
346 }
347 else
348 {
349 num5 = _003CModule_003E.D3DXLoadSurfaceFromSurface(ptr3, null, ptr2, ptr5, null, ptr2, 1u, 0u);
350 if (num5 >= 0)
351 {
352 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr3 + 52)))((nint)ptr3, &d3DLOCKED_RECT, ptr2, 0u);
353 if (num5 >= 0)
354 {
355 try
356 {
357 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);
358 }
359 finally
360 {
361 IDirect3DSurface9* intPtr3 = ptr3;
362 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr3 + 56)))((nint)intPtr3);
363 }
364 }
365 }
366 }
367 }
368 }
369 }
370 if (ptr5 != null)
371 {
372 IDirect3DSurface9* intPtr4 = ptr5;
373 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr4 + 8)))((nint)intPtr4);
374 ptr5 = null;
375 }
376 if (ptr3 != null)
377 {
378 IDirect3DSurface9* intPtr5 = ptr3;
379 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr5 + 8)))((nint)intPtr5);
380 ptr3 = null;
381 }
382 if (ptr4 != null)
383 {
384 IDirect3DTexture9* intPtr6 = ptr4;
385 ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint>)(int)(*(uint*)(*(int*)intPtr6 + 8)))((nint)intPtr6);
386 ptr4 = null;
387 }
388 }
389 else
390 {
391 ptr = pComPtr;
392 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, _D3DLOCKED_RECT*, tagRECT*, uint, int>)(int)(*(uint*)(*(int*)ptr + 76)))((nint)ptr, (uint)level, &d3DLOCKED_RECT, ptr2, options);
393 if (num5 >= 0)
394 {
395 try
396 {
397 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);
398 }
399 finally
400 {
401 ptr = pComPtr;
402 num5 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, int>)(int)(*(uint*)(*(int*)ptr + 80)))((nint)ptr, (uint)level);
403 }
404 }
405 }
407 {
408 if (isSetting)
409 {
410 return;
411 }
412 fixed (T* ptr7 = &data[startIndex])
413 {
414 try
415 {
416 uint num6 = (uint)(System.Runtime.CompilerServices.Unsafe.SizeOf<T>() * elementCount);
417 // IL initblk instruction
419 }
420 catch
421 {
422 //try-fault
423 ptr7 = null;
424 throw;
425 }
426 }
427 return;
428 }
429 if (num5 < 0)
430 {
431 throw GraphicsHelpers.GetExceptionFromResult((uint)num5);
432 }
433 if (isSetting)
434 {
435 if (this is IDynamicGraphicsResource dynamicGraphicsResource)
436 {
437 dynamicGraphicsResource.SetContentLost(isContentLost: false);
438 }
440 }
441 return;
442 }
443 throw new ArgumentNullException("data", FrameworkResources.NullNotAllowed);
444 }
unsafe IDirect3DTexture9 * pComPtr
Definition Texture2D.cs:22
static unsafe void InitBlock(void *startAddress, byte value, uint byteCount)
Definition Unsafe.cs:117

References Microsoft.Xna.Framework.Graphics.GraphicsDevice._deviceType, Microsoft.Xna.Framework.Graphics.TextureCollection._maxTextures, Microsoft.Xna.Framework.Graphics.GraphicsResource._parent, Microsoft.Xna.Framework.Graphics.GraphicsAdapter.adapter, Microsoft.Xna.Framework.Graphics.GraphicsDevice.Adapter, Microsoft.Xna.Framework.FrameworkResources.CannotUseFormatTypeAsManualWhenLocking, Microsoft.Xna.Framework.Helpers.CheckDisposed(), Microsoft.Xna.Framework.Graphics.GraphicsAdapter.CurrentDisplayMode, Microsoft.Xna.Framework.Graphics.DisplayMode.Format, Microsoft.Xna.Framework.Graphics.Texture.GetAndValidateRect(), Microsoft.Xna.Framework.Graphics.GraphicsHelpers.GetExceptionFromResult(), System.Runtime.CompilerServices.Unsafe.InitBlock(), Microsoft.Xna.Framework.Graphics.Texture.isActiveRenderTarget, Microsoft.Xna.Framework.Graphics.GraphicsDevice.IsDeviceLost, Microsoft.Xna.Framework.FrameworkResources.MustResolveRenderTarget, Microsoft.Xna.Framework.FrameworkResources.NullNotAllowed, System.options, Microsoft.Xna.Framework.Graphics.GraphicsAdapter.pComPtr, Microsoft.Xna.Framework.Graphics.GraphicsDevice.pComPtr, Microsoft.Xna.Framework.Graphics.Texture2D.pComPtr, Microsoft.Xna.Framework.Graphics.Texture.renderTargetContentsDirty, System.startIndex, Microsoft.Xna.Framework.Graphics.GraphicsDevice.Textures, Microsoft.Xna.Framework.Helpers.ValidateCopyParameters(), Microsoft.Xna.Framework.Graphics.Texture.ValidateTotalSize(), and Microsoft.Xna.Framework.Graphics.GraphicsDevice.VertexTextures.