[C++-Direct3D]D3DPRESENT_PARAMETERS

prototype

typedef struct _D3DPRESENT_PARAMETERS_
{
    UINT                BackBufferWidth;
    UINT                BackBufferHeight;
    D3DFORMAT           BackBufferFormat;
    UINT                BackBufferCount;

    D3DMULTISAMPLE_TYPE MultiSampleType;
    DWORD               MultiSampleQuality;

    D3DSWAPEFFECT       SwapEffect;
    HWND                hDeviceWindow;
    BOOL                Windowed;
    BOOL                EnableAutoDepthStencil;
    D3DFORMAT           AutoDepthStencilFormat;
    DWORD               Flags;

    /* FullScreen_RefreshRateInHz must be zero for Windowed mode */
    UINT                FullScreen_RefreshRateInHz;
    UINT                PresentationInterval;
} D3DPRESENT_PARAMETERS;

Explanation

BackBufferWidth and BackBufferHeight

The width and height of the back buffer in pixels

1. In window mode, 0 can be used by default, or other sizes can be specified.

2. In full-screen mode, the values ​​of these two must match the resolution supported by the graphics card, such as 800600, 640480, etc., you can use DisplayModeCollection EnumAdapterModes to obtain the resolutions supported by the display. (I still have questions about these two functions)

BackBufferFormat

The pixel format of the back buffer, i.e. color depth and format

1. This value must be one of the pixel formats confirmed by Manager's CheckDeviceType. Use Device's DisplayMode to obtain the currently used pixel format.

2. In window mode, the color mode used by the current window must be specified. You can use D3DFMT_UNKOWN to notify the runtime library to use the pixel format of the current display mode, or you can call the Device's DisplayMode to obtain it.

3. In full screen mode, any color mode supported by the device can be used. Checking can be done using the CheckDeviceType method. (For windowed applications, since color conversion can be done by hardware (provided the hardware supports color conversion), the back buffer format does not need to match the display mode format. However, color conversion cannot be performed in full screen mode, so it should not Get the current display mode directly, but specify a display format supported by the device.

BackBufferCount

Number of back buffers

1.可以为0,1,2,3。指定为0时会被视为1。通常该参数设置为1,表示只使用一个后台缓冲区。

2. (I don’t know if it makes sense) Generally speaking, for games in window mode, we set it to 1, and for games in full-screen mode, we set it to 0. The reason is that in window mode games, our game window may be used by other players. The window is blocked. At this time, we need to set up an extra back buffer to store the previous image. When the blocked window is removed, we will not have to redraw the back buffer. We only need to put the buffer in memory into the foreground. Our game window has been restored. In full-screen mode, we don’t need to consider this. Setting it to 0 does not mean that there is no background buffer. The system will give us one by default. Setting it to 1 is what the system gives us. In addition to the background buffer, set up a new background buffer.

MultiSampleType and MultiSampleQuality

Multisampling type and quality, i.e. type and level of full-screen anti-aliasing

1. These two parameters may make your rendering scene look better, but they consume a lot of memory resources. Moreover, not all graphics cards support the functions set by these two. Therefore, you must first check whether the hardware supports it before using it.

2. Multi-sampling is only supported when the value of SwapEffect is D3DSWAPEFFECT_DISCARD, that is, when the swap effect is Discard. So if the value of SwapEffect is not D3DSWAPEFFECT_DISCARD, this value should be set to NONE.

3.MultiSampleType一般设为D3DMULTISAMPLE_NONE:不进行多重采样(不使用抗锯齿),也可使用D3DMULTISAMPLE_1_SAMPLE ~ D3DMULTISAMPLE_16_SAMPLE参数,指定16个不同的重采样级别,每个级别都对应不同的效果(1X – 16X)。

4. The value of MultiSampleQuality is between 0 and 1. This component is only valid when MultiSampleType is set.

SwapEffect

Used to specify how the buffers in the swap chain are exchanged (that is, the buffer exchange method. After the current back buffer is exchanged, what should be done with the data in the replaced buffer? It can be copied or discarded. Different value effects also different

1. If Windowed is set to true and SwapEffect is set to Flip, no matter which buffer becomes the front buffer when rendering, the runtime will create an additional back buffer and make a copy. The Copy setting requires BackBufferCount to be set to 1. This setting is enforced in the debug runtime, which fills in noise in any buffer after it is rendered.

(It’s called DISCARD because since you don’t control the exchange method yourself, obviously you don’t care about or need the content of the back buffer, so after each effect change, the content of the back buffer is “discarded”, that is, it is no longer managed. . Therefore, when you need to achieve some special effects, you may need multiple buffers, and then process the graphics in the buffers. At this time, you cannot use the automatic discard method.)

2.D3DSWAPEFFECT type enumeration value:

D3DSWAPEEFECT_COPY: When swapping, the contents of the back buffer are copied to the front buffer, and the contents of the back buffer remain unchanged.

D3DSWAPEEFECT_FLIP: When swapping, exchange the front and rear buffer pointers to complete page turning. After that, the content of the back buffer is the content of the front buffer.

D3DSWAPEEFECT_DISCARD: It may be COPY or FLIP. It is up to the device to determine the method that is most suitable for the current situation.

D3DSWAPEFFECT_DISCARD:Clear the contents of the background cache

D3DSWAPEEFECT_FLIP: Preserve the contents of the background cache. When buffer area >1.

D3DSWAPEFFECT_COPY: Keep the contents of the background cache, when buffer=1.

(Generally use D3DSWAPEFFECT_DISCARD)

hDeviceWindow

Specifies the handle of the rendered window. If it is NULL, it means using the current window.

Windowed

Specify window/full screen mode. When true, the program will run in window mode. When false, the program will run in full screen mode.

EnableAutoDepthStencil

Whether to enable depth caching and template caching. true means to enable and create depth and stencil buffers and automatically manage them by DirectX. When false, it means it is not enabled. Should be turned on in 3D scenes.

AutoDepthStencilFormat

Specify the format of the depth buffer and stencil buffer. If the depth stencil buffer is not used, this parameter will be useless and can be set to NULL. The D3DFMT_D16 format is usually used, that is, the depth value is represented in 16-bit binary. The more bits, the more accurately the scene is drawn, and the corresponding memory consumption will be more.

D3DFMT_D32: Specify a 32-bit depth buffer

D3DFMT_D24S8:指定一个32位的深度/模板缓冲区,其中24位用于深度缓冲区,8位用于模板缓冲区

D3DFMT_D24X8:指定一个32位的深度/模板缓冲区,其中24位用于的度缓冲区,8位空闲

D3DFMT_D24X4S4:指定一个32位的深度/模板缓冲区,其中24位用于深度缓冲区,4位用于模板缓冲区,4位空闲

D3DFMT_D16: Specify a 16-bit depth buffer

D3DFMT_D15S1:指定一个16位的深度/模板缓冲区,其中15位用于深度缓冲区,1位用于模板缓冲区

Flags

Other additional feature flags (usually specified as 0 or NULL)

D3DPRESENTFLAG_LOCKABLE_BACKBUFFER: Indicates that the back buffer can be locked. It should be noted that this buffer will reduce the running efficiency of the program.

D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL: Specifies that the depth buffer and stencil buffer will be abandoned when the latter buffer is rendered (that is, after the Present method is called). "Abandon" here means that the depth buffer and template buffer are released or become invalid, thereby speeding up the program and improving performance.

FullScreen_RefreshRateInHz

Specify the refresh frequency of the screen (in full-screen mode, you can specify any refresh rate supported by the screen (obtained using EnumAdapterModes)

However, if an unsupported refresh rate is used, the device will not be created or a warning message will be issued. In window mode, must be specified as 0 or D3DPRESENT_RATE_DEFAULT (that is, the default), which means using the same refresh rate as the current screen)

D3DPRESENT_RATE_DEFAULT: Indicates using the default refresh rate, which is the same as the screen refresh rate.

D3DPRESENT_RATE_UNLIMITED: Indicates that the content will be copied to the front buffer immediately after the graphics drawing is completed.

PresentationInterval

A member of the D3DPRESENT flags set. Used to specify the flip mode of the screen, that is, the frequency of exchange of front and back buffers. In window mode, its value is 0, and only D3DPRESENT_INTERVAL_DEFAULT can be selected.

(The SDK recommends that D3DPRESENT_INTERVAL_DEFAULT should be used under normal circumstances to avoid vertical synchronization. This option must be used in window mode. But we will find that when the game freezes, the screen jumps one by one, and the frame skipping phenomenon is due to our The background buffer has not been rendered yet, and the system does not allow it to be placed in the foreground. As a result, the front buffer cannot be replaced for a long time. By the time it is replaced, we may have already performed a lot of operations.)

D3DPRESENT_INTERVAL_DEFAULT: D3D selects the swap frequency, usually equivalent to the screen refresh rate

D3DPRESENT_INTERVAL_IMMEDIATE: Show updates immediately (or swap immediately), not recommended

D3DPRESENT_INTERVAL_ONE: Wait for a vertical scan cycle before updating, which helps to reduce shearing and tearing effects (in fact, there is no difference between DEFAULT and ONE)

D3DPRESENT_INTERVAL_TWO~FOUR: respectively wait for the corresponding number of cycles before updating.

Original link:https://blog.csdn.net/setflvet/article/details/6987532

Post Reply