dx data type

一直不后缀unorm和snorm什么意思,今天看introduction dx11 忽然明白,就是类型+是否归一化,(还有个typeless)

DXGI_FORMAT_R32G32B32_FLOAT: Each element has three 32-bit floating-point components.   

DXGI_FORMAT_R16G16B16A16_UNORM: Each element has four 16-bit components mapped to the [0, 1] range. 

DXGI_FORMAT_R32G32_UINT: Each element has two 32-bit unsigned integer components.  

DXGI_FORMAT_R8G8B8A8_UNORM: Each element has four 8-bit unsigned components mapped to the [0, 1] range.  

DXGI_FORMAT_R8G8B8A8_SNORM: Each element has four 8-bit signed components mapped to the [−1, 1] range.   

DXGI_FORMAT_R8G8B8A8_SINT: Each element has four 8-bit signed integer components mapped to the [−128, 127] range.  

DXGI_FORMAT_R8G8B8A8_UINT: Each element has four 8-bit unsigned integer components mapped to the [0, 255] range.


S:signed

U:unsigned

NORM:[-1,1] or [0,1]


The depth buffer is a texture, so it must be created with certain data formats. The formats used for depth buffering are as follows:   

1. DXGI_FORMAT_D32_FLOAT_S8X24_UINT: Specifies a 32-bit floating-point depth buffer, with 8-bits (unsigned integer) reserved for the stencil buffer mapped to the [0, 255] range and 24-bits not used for padding.   

2. DXGI_FORMAT_D32_FLOAT: Specifies a 32-bit floating-point depth buffer.  

 3. DXGI_FORMAT_D24_UNORM_S8_UINT: Specifies an unsigned 24-bit depth buffer mapped to the [0, 1] range with 8-bits (unsigned integer) reserved for the stencil buffer mapped to the [0, 255] range.  

 4. DXGI_FORMAT_D16_UNORM: Specifies an unsigned 16-bit depth buffer mapped to the [0, 1] range.



可以通过使用SharpDX库来后台截取DX窗口。下面是一个示例代码: ``` using System; using System.Drawing; using System.Drawing.Imaging; using SharpDX; using SharpDX.Direct3D9; using SharpDX.Windows; namespace DXScreenCaptureTest { class Program { static void Main(string[] args) { var processName = "myDXProcess"; // 要截取的DX程序进程名 var adapterIndex = 0; // 显卡索引,如果只有一个显卡则为0 // 获取DX程序窗口句柄 IntPtr hWnd = IntPtr.Zero; while (true) { hWnd = User32.FindWindowEx(IntPtr.Zero, hWnd, null, processName); if (hWnd == IntPtr.Zero) break; if (User32.IsWindowVisible(hWnd)) { int pid; User32.GetWindowThreadProcessId(hWnd, out pid); if (System.Diagnostics.Process.GetProcessById(pid).ProcessName == processName) break; } } if (hWnd == IntPtr.Zero) { Console.WriteLine($"未找到进程名为{processName}的DX程序窗口"); return; } // 获取DX设备对象 var config = new PresentParameters() { BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = hWnd, PresentationInterval = PresentInterval.Immediate, SwapEffect = SwapEffect.Discard }; var device = new Device(new Direct3D(), adapterIndex, DeviceType.Hardware, IntPtr.Zero, CreateFlags.HardwareVertexProcessing, config); // 获取后台缓存表面 var surface = Surface.CreateOffscreenPlain(device, config.BackBufferWidth, config.BackBufferHeight, Format.A8R8G8B8, Pool.SystemMemory); // 截取屏幕并保存到文件 var bitmap = CaptureSurface(device, surface); bitmap.Save("screenshot.png", ImageFormat.Png); device.Dispose(); surface.Dispose(); bitmap.Dispose(); Console.WriteLine("截图完成"); } private static Bitmap CaptureSurface(Device device, Surface surface) { // 将后台缓存表面复制到系统内存表面 device.GetFrontBufferData(0, surface); // 将表面转换为Bitmap var dataRectangle = surface.LockRectangle(LockFlags.ReadOnly); var bitmap = new Bitmap(dataRectangle.Width, dataRectangle.Height, PixelFormat.Format32bppArgb); var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); Utilities.CopyMemory(bitmapData.Scan0, dataRectangle.DataPointer, dataRectangle.Pitch * dataRectangle.Height); surface.UnlockRectangle(); bitmap.UnlockBits(bitmapData); return bitmap; } } static class User32 { [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); } } ``` 代码中使用了SharpDX库,需要使用NuGet进行安装。另外,要注意确保程序有足够的权限进行后台截图操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值