API to get the graphics or video memory

后端 未结 3 871
眼角桃花
眼角桃花 2021-01-19 02:51

I want to get the adpater RAM or graphics RAM which you can see in Display settings or Device manager using API. I am in C++ application.

I have tried seraching on n

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 02:59

    There is NO way to directly get graphics RAM on windows, windows prevents you doing this as it maintains control over what is displayed.

    You CAN, however, create a DirectX device. Get the back buffer surface and then lock it. After locking you can fill it with whatever you want and then unlock and call present. This is slow, though, as you have to copy the video memory back across the bus into main memory. Some cards also use "swizzled" formats that it has to un-swizzle as it copies. This adds further time to doing it and some cards will even ban you from doing it.

    In general you want to avoid directly accessing the video card and letting windows/DirectX do the drawing for you. Under D3D1x Im' pretty sure you can do it via an IDXGIOutput though. It really is something to try and avoid though ...

    You can write to a linear array via standard win32 (This example assumes C) but its quite involved.

    First you need the linear array.

        unsigned int* pBits = malloc( width * height );
    

    Then you need to create a bitmap and select it to the DC.

        HBITMAP hBitmap = ::CreateBitmap( width, height, 1, 32, NULL );
        SelectObject( hDC, (HGDIOBJ)hBitmap );
    

    You can then fill the pBits array as you please. When you've finished you can then set the bitmap's bits.

        ::SetBitmapBits( hBitmap, width * height * 4, (void*)pBits )
    

    When you've finished using your bitmap don't forget to delete it (Using DeleteObject) AND free your linear array!

    Edit: There is only one way to reliably get the video ram and that is to go through the DX Diag interfaces. Have a look at IDxDiagProvider and IDxDiagContainer in the DX SDK.

提交回复
热议问题