예제 #1
0
 public int Map([NativeTypeName("ID3D11Resource *")] ID3D11Resource *pResource, [NativeTypeName("UINT")] uint Subresource, D3D11_MAP MapType, [NativeTypeName("UINT")] uint MapFlags, [NativeTypeName("D3D11_MAPPED_SUBRESOURCE *")] D3D11_MAPPED_SUBRESOURCE *pMappedResource)
 {
     return(((delegate * stdcall <ID3D11DeviceContext *, ID3D11Resource *, uint, D3D11_MAP, uint, D3D11_MAPPED_SUBRESOURCE *, int>)(lpVtbl[14]))((ID3D11DeviceContext *)Unsafe.AsPointer(ref this), pResource, Subresource, MapType, MapFlags, pMappedResource));
 }
        public static D3D11_MAPPED_SUBRESOURCE Map(this ID3D11DeviceContext context, ID3D11Resource resource, int subResource, D3D11_MAP mapType, D3D11_MAP_FLAG mapFlag = 0)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            using (var ptr = new ComMemory(Marshal.SizeOf <D3D11_MAPPED_SUBRESOURCE>()))
            {
                context.Map(resource, (uint)subResource, mapType, (uint)mapFlag, ptr.Pointer).ThrowOnError();
                return(ptr.ToStructure <D3D11_MAPPED_SUBRESOURCE>());
            }
        }
        public static void WithMap <T>(this IComObject <ID3D11DeviceContext> context, IComObject <ID3D11Resource> resource, int subResource, D3D11_MAP mapType, MapAction <T> action, D3D11_MAP_FLAG mapFlag = 0)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var map = Map(context, resource, subResource, mapType, mapFlag);

            try
            {
                var structure = Marshal.PtrToStructure <T>(map.pData);
                action(ref map, ref structure);
                Marshal.StructureToPtr(structure, map.pData, false);
            }
            finally
            {
                Unmap(context, resource, subResource);
            }
        }
 public static D3D11_MAPPED_SUBRESOURCE Map(this IComObject <ID3D11DeviceContext> context, IComObject <ID3D11Resource> resource, int subResource, D3D11_MAP mapType, D3D11_MAP_FLAG mapFlag = 0) => Map(context?.Object, resource?.Object, subResource, mapType, mapFlag);