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

◆ CopyData< T >()

unsafe void Microsoft.Xna.Framework.Graphics.VertexBuffer.CopyData< T > ( int offsetInBytes,
T[] data,
int startIndex,
int elementCount,
int vertexStride,
uint options,
[MarshalAs(UnmanagedType.U1)] bool isSetting )
inlinepackage
Type Constraints
T :struct 

Definition at line 139 of file VertexBuffer.cs.

139 : struct
140 {
141 IntPtr intPtr = (IntPtr)pComPtr;
142 Helpers.CheckDisposed(this, intPtr);
143 if (data != null)
144 {
145 int num = data.Length;
146 if (num != 0)
147 {
148 int num2 = -2147467259;
149 if ((options & 0x3010) == 0)
150 {
151 int num3 = 0;
152 GraphicsDevice parent = _parent;
153 int currentVertexBufferCount = parent.currentVertexBufferCount;
154 if (0 < currentVertexBufferCount)
155 {
156 VertexBufferBinding[] currentVertexBuffers = parent.currentVertexBuffers;
157 do
158 {
159 if (currentVertexBuffers[num3]._vertexBuffer != this)
160 {
161 num3++;
162 continue;
163 }
164 throw GraphicsHelpers.GetExceptionFromResult(2147500036u);
165 }
166 while (num3 < currentVertexBufferCount);
167 }
168 }
169 if (!isSetting && (_usage & 8) == 8)
170 {
171 throw new NotSupportedException(FrameworkResources.WriteOnlyGetNotSupported);
172 }
173 Helpers.ValidateCopyParameters(num, startIndex, elementCount);
174 try
175 {
176 uint num4 = (uint)System.Runtime.CompilerServices.Unsafe.SizeOf<T>();
177 uint num5 = num4 * (uint)elementCount;
178 int num6;
179 if (vertexStride != 0)
180 {
181 num6 = vertexStride - (int)num4;
182 if (num6 < 0)
183 {
184 throw new ArgumentOutOfRangeException("vertexStride", FrameworkResources.VertexStrideTooSmall);
185 }
186 if (elementCount > 1)
187 {
188 num5 = (uint)((elementCount - 1) * num6) + num5;
189 }
190 }
191 else
192 {
193 num6 = 0;
194 }
195 if ((uint)((int)num5 + offsetInBytes) > _size)
196 {
197 throw new InvalidOperationException(FrameworkResources.ResourceDataMustBeCorrectSize);
198 }
200 {
201 if (isSetting)
202 {
203 return;
204 }
205 fixed (T* ptr = &data[startIndex])
206 {
207 try
208 {
209 // IL initblk instruction
211 }
212 catch
213 {
214 //try-fault
215 ptr = null;
216 throw;
217 }
218 }
219 return;
220 }
221 void* ptr2 = null;
222 byte* ptr3 = (byte*)pBufferData;
223 if (IsWriteOnly && _pool == 1)
224 {
225 ptr3 = offsetInBytes + ptr3;
226 }
227 IDirect3DVertexBuffer9* ptr4 = pComPtr;
228 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, uint, uint, void**, uint, int>)(int)(*(uint*)(*(int*)ptr4 + 44)))((nint)ptr4, (uint)offsetInBytes, num5, &ptr2, options);
229 if (num2 >= 0)
230 {
231 if (num6 == 0)
232 {
233 fixed (T* ptr5 = &data[startIndex])
234 {
235 try
236 {
237 if (isSetting)
238 {
239 _003CModule_003E.memcpy_s(ptr2, _size - (uint)offsetInBytes, ptr5, num5);
240 if (IsWriteOnly && _pool == 1)
241 {
242 _003CModule_003E.memcpy_s(ptr3, _size - (uint)offsetInBytes, ptr5, num5);
243 }
244 }
245 else
246 {
247 _003CModule_003E.memcpy_s(ptr5, num5, ptr2, num5);
248 }
249 }
250 catch
251 {
252 //try-fault
253 ptr5 = null;
254 throw;
255 }
256 }
257 }
258 else
259 {
260 byte* ptr6 = (byte*)ptr2;
261 byte* ptr7 = ptr3;
262 for (int i = 0; i < elementCount; i++)
263 {
264 fixed (T* ptr8 = &data[i + startIndex])
265 {
266 try
267 {
268 if (isSetting)
269 {
270 _003CModule_003E.memcpy_s(ptr6, _size - (uint)offsetInBytes, ptr8, (uint)System.Runtime.CompilerServices.Unsafe.SizeOf<T>());
271 if (IsWriteOnly && _pool == 1)
272 {
273 _003CModule_003E.memcpy_s(ptr7, _size - (uint)offsetInBytes, ptr8, (uint)System.Runtime.CompilerServices.Unsafe.SizeOf<T>());
274 }
275 }
276 else
277 {
278 _003CModule_003E.memcpy_s(ptr8, num5, ptr6, (uint)System.Runtime.CompilerServices.Unsafe.SizeOf<T>());
279 }
280 ptr6 = vertexStride + ptr6;
281 if (IsWriteOnly && _pool == 1)
282 {
283 ptr7 = vertexStride + ptr7;
284 }
285 }
286 catch
287 {
288 //try-fault
289 ptr8 = null;
290 throw;
291 }
292 }
293 }
294 }
295 }
296 }
297 finally
298 {
299 if (num2 >= 0)
300 {
301 IDirect3DVertexBuffer9* intPtr2 = pComPtr;
302 num2 = ((delegate* unmanaged[Stdcall, Stdcall]<IntPtr, int>)(int)(*(uint*)(*(int*)intPtr2 + 48)))((nint)intPtr2);
303 }
304 }
305 if (num2 < 0)
306 {
307 throw GraphicsHelpers.GetExceptionFromResult((uint)num2);
308 }
309 if (isSetting && this is IDynamicGraphicsResource dynamicGraphicsResource)
310 {
311 dynamicGraphicsResource.SetContentLost(isContentLost: false);
312 }
313 return;
314 }
315 }
316 throw new ArgumentNullException("data", FrameworkResources.NullNotAllowed);
317 }
unsafe IDirect3DVertexBuffer9 * pComPtr
static unsafe void InitBlock(void *startAddress, byte value, uint byteCount)
Definition Unsafe.cs:117

References Microsoft.Xna.Framework.Graphics.GraphicsResource._parent, Microsoft.Xna.Framework.Graphics.VertexBuffer._pool, Microsoft.Xna.Framework.Graphics.VertexBuffer._size, Microsoft.Xna.Framework.Graphics.VertexBuffer._usage, Microsoft.Xna.Framework.Helpers.CheckDisposed(), Microsoft.Xna.Framework.Graphics.GraphicsDevice.currentVertexBufferCount, Microsoft.Xna.Framework.Graphics.GraphicsDevice.currentVertexBuffers, Microsoft.Xna.Framework.Graphics.GraphicsHelpers.GetExceptionFromResult(), System.Runtime.CompilerServices.Unsafe.InitBlock(), Microsoft.Xna.Framework.Graphics.GraphicsDevice.IsDeviceLost, Microsoft.Xna.Framework.Graphics.VertexBuffer.IsWriteOnly, Microsoft.Xna.Framework.FrameworkResources.NullNotAllowed, System.options, Microsoft.Xna.Framework.Graphics.VertexBuffer.pBufferData, Microsoft.Xna.Framework.Graphics.VertexBuffer.pComPtr, Microsoft.Xna.Framework.FrameworkResources.ResourceDataMustBeCorrectSize, System.startIndex, Microsoft.Xna.Framework.Helpers.ValidateCopyParameters(), Microsoft.Xna.Framework.FrameworkResources.VertexStrideTooSmall, and Microsoft.Xna.Framework.FrameworkResources.WriteOnlyGetNotSupported.