Basic graphics concepts

interactive relationship

Direct3D is a set of low-level graphics APIs. With this API, we can use hardware acceleration to draw 3D scenes. Direct3D can be regarded as an intermediary for applications to interact with graphics devices.

 HAL : Hardware abstraction layer, a set of device-related codes that instructs the device to complete certain operations. Device manufacturers implement all functions supported by their products into HAL. Calling a Direct3D function that is not implemented in HAL will cause the call to fail. , unless it is a vertex processing operation and the user has specified that it be simulated using a software operation.

REF : Sometimes some functions provided by Direct3D cannot be supported by existing graphics devices, but you still want to use them. Direct provides a reference raster device, the REF device, which can fully support Direct3DAPI in software. The REF device is only used in the development stage. , this is very important, it is bundled with the DirectX SDK and cannot be released to end users. In addition, REF is very slow and is not practical for other occasions except testing.

D3DDEVTYPE : In the code, the HAL device is specified with the value D3DDEVTYPE_HAL, and the REF device is specified with the value D3DDEVTYPE_REF. When creating a device, you must specify which device type to use.

COM (Component Object Model) : For example, IDirect3DDevice9. COM is a technology that makes DirectX independent of programming languages ​​and has backward compatibility. COM objects are often called interfaces and can be used as a C++ class to create a COM interface. New cannot be used when using an interface. After using an interface, the corresponding Release method of the interface should be called (all COM interface functions are inherited from the COM interface IUnknown , which provides the Release method). Instead of using delete, the COM object can The memory used enforces autonomy

surface

The surface is a pixel matrix mainly used by Direct3D to store 2D image data. Although the data stored on the surface is regarded as a matrix, the pixel data is actually stored in a linear array.

 Surfaces are described using the interface IDirect3DSurface9, which provides several methods for reading and writing data directly from the surface.

LockRect: used to obtain the pointer to the surface storage area. Through pointer operations, each pixel in the surface can be read and written. UnlockRect:
If the LockRect method is called and the operation of accessing the storage area has been completed, this method needs to be called to unlock.
GetDesc: This method can obtain the description information of the surface by filling the structure D3DSURFACE_DESC

multisampling

Blocky effects often occur when representing images using a pixel matrix. Multisampling is a technology used to smooth blocky images. Multisampling the surface is often used for full-screen anti-aliasing.

 The D3DMULTISAMPLE_TYPE enumeration type contains a series of enumeration constant values ​​that are used to represent the level of multi-sampling on the surface. This technology will significantly reduce the running speed of the program. If you want to use this technology, please use IDirect3D9::CheckDeviceMultiSampleType to check Whether the graphics device supports the desired multisampling type

Pixel format

When creating surfaces or textures, it is often necessary to specify the pixel format of these Direct3D resources. The pixel format can be defined using the constants of the D3DFORMAT enumeration type
D3DFMT_R8G8B8
D3DFMT_A8B8G8R8
.....

memory pool

Surfaces and other Direct3D resources can be placed in many types of memory pools. The type of memory pool can be represented by the D3DPOOL enumeration type.

Swap chain and page replacement

Direct3D maintains a surface collection, which is usually composed of two or three surfaces and becomes a swap chain. This collection is represented by the interface IDirect3DSwapChain9. The swap chain and page replacement technology are mainly used to generate smoother animations.

 The surface located in the front buffer slot corresponds to the image currently displayed on the monitor . The content in the front buffer will not be updated to the next frame until the current frame is displayed on the monitor. During the period when the monitor displays the content of the front buffer, we will next One frame of content is drawn to an off-screen surface (background cache), so that when the monitor finishes displaying the content in the front cache, we replace it to the end of the swap chain and promote the next back cache in the swap chain to the front cache. This process is called submission .

Complete the drawing function program structure:
1. Draw in the background cache
2. Submit the background cache content
3. Return to step 1

Depth cache

The depth buffer is a surface that only contains depth information for specific pixels, but does not contain image data. The depth buffer retains a depth item for each pixel in the final drawn image. Direct3D determines which pixels of an object are located on another surface. Before an object, a technology called depth cache is used . The depth cache is used to calculate the depth value of each pixel and perform depth testing. The basic content of the depth test is to let different pixels at the same position compete based on the depth value. The pixel that should be written to this location is selected, the pixel closest to the camera wins and is written to the corresponding location in the depth buffer .
D3DFMT_D32
D3DFMT_D24S8
.........

Vertex operations

There are two different ways to perform vertex operations in Direct3D, namely software vertex operations or hardware vertex operations . No matter what configuration of hardware is used, software vertex operations are always supported, so they can always be used. Hardware vertex operations can only be obtained It can only be used with the support of the graphics card . We should always give priority to hardware vertex calculations, because using its proprietary acceleration function will be much faster than software calculations, and performing vertex calculations in hardware does not occupy CPU resources, and the CPU can be liberated. To perform other operations , another equivalent way of saying that the graphics card supports hardware vertex operations is that the graphics card supports hardware calculations of transformations and lighting.

Equipment performance

Each performance provided by Direct3D corresponds to a data member or a certain bit in the structure D3DCAP9 . We first initialize an example of the D3DCAP9 type based on a specific hardware , and then check the corresponding instance in the program. Data members or bits to determine whether a device has a certain feature.

Guess you like

Origin blog.csdn.net/SwordArcher/article/details/126873611