DirectX5.0 Latest Game Programming Guide DirectDraw Article Third, DirectDraw Elements (3)

zhaozj2021-02-11  172

4.4, Creating a surface DirectDrawSurface object characterizes a surface that resides in the display memory. If the memory is displayed or explicitly created, the surface can also exist in system memory. You can create one or more surfaces using the iDirectdraw2 :: CreateSurface method. When calling createSurface, you must specify the size of the surface, the surface type (is a single surface or complex surface), the pixel format (if the surface does not use the palette of the index). All of these features are included in the DDSurfaceDesc structure, and the address of the structure will be transmitted in the past. If the hardware does not support request, the call will fail if those resources have been assigned to another DirectDrawSurface object. Creating a single surface or multi-surface requires only a few lines of simple code. There are four main steps to create a surface. Every step is more ready than the previous step, but it is not too difficult, they are: (1). Create a main surface (2). Create a screen (3). Create a complex surface and flip chain (4). Creating a wide surface In the default, DirectDraw creates a surface in the local video memory. If enough local video memory saves the surface, DirectDraw tries to use non-local video memory (only in some AGP device systems) . You can explicitly specify the surface in which type memory is explicitly indicated to the DDSCAPS structure with the appropriate flag when calling createSurface. 4.4.1, Creating the main surface main surface is visible on the display and indicated by the DDSCAPS_PRIMARYSURFACE flag, each DirectDRAW object can only have a main surface. When you create a home surface, its size should match the current display mode. Therefore, in this case you don't need to indicate the size of the surface. In fact, if you indicate the size of the surface, even if you match the current display mode, it will also result in failure of the creation process. The following example shows how to set the relevant members of the structure to create a master DDSURFACEDESC surface:. DDSURFACEDESC ddsd; ddsd.dwSize = sizeof (ddsd); // Tell DirectDraw which members are valid ddsd.dwFlags = DDSD_CAPS; // Request a primary surface DDSD.DDSCAPS.DWCAPS = DDSCAPS_PRIMARYSURFACE; 4.4.2, Creating a screen Out of Surface Screen The outer surface is usually used for the cache of bitmaps, which will be transferred by the bit block to the main surface or in the background buffer. You must set the DDSC_WIDTH and DDSD_HEIGHT flags and set DWWIDTH and DWHEIGHT members to explain the size of the outer surface of the screen. In addition, you must also include DDSCAPS_OFFSCREENPLAIN flags in the DDSCAPS structure. DirectDraw uses system memory to create a surface when there is not enough display memory usage. You can display DDSCAPS_SYSTEMEMORY or DDSCAPS_VIDEMEMORY flags in the DDSCAPS structure to explicitly indicate that the memory is displayed in the system memory.

The following example shows the previous screen to create an outer surface preparation: DDSURFACEDESC ddsd; ddsd.dwSize = sizeof (ddsd); // Tell DirectDraw which members are valid ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; // Request a. Simple Off-Screen Surface, SIZED / / 100 BY 100 Pixels. Ddsd.ddscaps.dwcaps = DDSCAPS_OffScreenPlain; dwheight = 100; dwWidth = 100; In previous versions of DirectX, the maximum width of the exterior surface cannot exceed the width of the main surface. In DirectX 5, you can create an exterior surface of any width, as long as the display device is pointed out. It should be noted that when the width of the exterior surface is declared, if the width of the surface of the requested surface is displayed, the surface will be created in the system memory. If the video memory is explicitly declared, the work of creating a surface will fail when the video memory is not enough. 4.4.3, Creating a complex surface (FLIPPING) A complex surface is a set of single surfaces created with the idirectdraw2 :: createSurface method. If the DDSCAPS_COMPLEX flag is set when CreateSurface is called. In addition to the explicit specified surface, DirectDRAW will also implicate one or more surfaces. You can manage complex surfaces like manageing a single surface. Call iDirectDraw :: Release method Releases all surfaces, call IDirectdrawSurface3 :: Restore to recover these surfaces. The most commonly used complex surface is a flip chain. Typically, a flip chain is from one main surface and one or more background buffer groups. The DDSCAPS_FLIP flag shows that a surface is part of a flip chain. Creating a flip chain with this way also requires the DDSCAPS_COMPLEX flag. The following example creates a chain of flip main surface preparation needed: DDSURFACEDESC ddsd; ddsd.dwSize = sizeof (ddsd); // Tell DirectDraw which members are valid ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; // Request a primary surface. WITH A SINGLE / / BACK Buffer DDSD.DDSCAPS.DWCAPS = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE; DDSD.DWBACKBUFFERCOUNT = 1; this example constructs a double buffer overwhelming environment. Call the IDirectdrawSurface3 :: Flip method to swap the surface memory of the main surface and the background buffer. If the DwBackBufferCount in the DDSurfaceDesc structure is 2, two back buffers will be created, and the surface will be turned around each time the flip is looped and the three buffer overwhelming environments are provided. 4.4.4, Creating a wide surface (Wide Surface) DirectDRAW allows you to create an exterior surface that is wide than the main surface, of course this needs to display hardware support. To determine if the display device supports the wide surface, you need to call the IDirectDraw2 :: getCaps method to see if DWCaps2 members in the first DDCAPS structure include DDCaps2_WIDesurfaces flags.

If the flag exists, it indicates that the outer surface of the exterior surface that is wider than the main surface can be created in the video memory. If the flag does not exist, create a wide surface in the video memory will fail and return a DDERR_INVALIDPARAMS error. The system memory surface, the video port surface, and the buffer are supported by the wide surface. 4.4.5 Flipping Surface DirectDraw can be constructed as a flip surface. A flip surface is any of the memory that can exchange each other between the Front Buffer and the Back Buffer. Typically, the front buffer is the main surface, but this is not required. When using the IDirectDrawSurface3 :: FLIP method to perform surface flip operation, pointing to the surface memory of the main surface and a pointer to the surface memory of the background buffer interchange. Therefore, the flip of the surface is the exchange of the display device to point to the pointer of the memory, not a copy of the surface memory. The only exception is that it is just simply copy the surface when DirectDraw is flipped. DirectDraw uses software simulation to flip operations with software simulation when a background buffer cannot be loaded into memory or hardware is not supported. When a flip chain contains a major surface and a plurality of background buffers, the switching of the pointer uses a loop mode, as shown below: The other additional surface of the DirectDRAW object is not part of the flip chain, not affected by the FLIP method. influences. Remember that the DirectDRAW flip surface is implemented by swapping a pointer to the surface memory of the DirectDrawSurface object instead of exchanging these objects. This means that when the bit block is transmitted to the background buffer, the same DirectDrawSurface object must always be used, which is the background buffer you created a flip chain. The pointing operation is always done by calling the FLIP method of the front desk buffer. 4.4.6 Losing Surface When the DirectDrawSurface object characterizing the surface memory is unnecessary, the surface memory associated with the surface is released. This is to lose the surface. When the DirectDrawSurface object is in its surface memory, many methods do not perform other operations and returns Dderr_SurfaceLost. Since the display mode or another application has released all surface memory that is currently allocated, the surface may be lost. The iDirectdrawsurface3 :: RESTORE method Recreate these lost surfaces and re-connects with the DirectDrawSurface object. The recovery surface does not place the bitmap before the surface is lost. Therefore, if the lost surface must be completely reloaded into the previously loaded graphics. 4.4.7, the release surface is like all COM interfaces, when there is no need, the Release method must be called to release the surface. Each individually created surface must be explicitly released. If it is called IDirectdraw2 :: createSurface or iDirectdraw :: CreateSurface method Explicitly created multiple surfaces (such as flip chains, etc.), you only need to release the front bobbure. In this case, any pointer to the surface of the background buffer will be explicitly released, and it is not reused. 4.4.8, Updating Surface Characteristics You can use the iDirectdrawsurface3 :: setSurfaceDesc method to update features of existing surfaces. With this method, you can change the pixel format, or you can change the location of the system memory in the surface of the DirectDrawSurface object, which is explicitly assigned by the application.

It allows a surface directly using data in the previously assigned buffer without copying, this new surface memory is allocated by the customer application, and is also released by the customer application. When calling the idirectdrawsurface3 :: setSurfaceDesc method, the LPDDSD parameter must be the address of the structure DDSurfaceDesc describing the new surface memory, that is, pointing to the memory address. In the DDSurfaceDesc structure, only DWFLAGS members can be set to reflect the location, size, and pixel format of the surface memory. Therefore, DWFLAGS can only contain a combination of DDSD_WIDTH, DDSD_HEIGHT, DDSD_PITCH, DDSD_LPSURFACE, and DDSD_PIXELFORMAT, etc., with these combinations to set effective structural members. Before setting the value of the structure, you must allocate the memory to load the surface. The size of the assigned memory is very important. You need not only to assign enough memory to accommodate the width and high surface, but also leave enough memory space for surface spacing (PITCH), the surface spacing is a Qword (8 bytes), the spacing is high instead of using pixels Measurement. When setting the value of the surface in the structure, the LPSURFACE member is a pointer you assigned, DwHeight and DWWIDTH members describe the size of the surface in pixel units. If the size of the surface is specified, you also need to populate the iPitch member to reflect the surface spacing. DDPFPixelformat members describe the pixel format of the surface. In addition to the LPSurface member, if you don't set a value for these members, the IDirectdrawSurface3 :: setSurfaceDesc method uses the default value from the current surface. Pay attention to some problems when calling the IDirectDrawsurface3 :: setSurfaceDesc method. For example, LPSurface must be a valid pointer for system memory (this method does not currently support video memory pointers); DWWIDTH and DWHEIGHT must be non-zero; the main surface or other surface cannot be reassigned in the main flip chain. You can assign the same memory for multiple DirectDrawSurface objects, but you must notice that the memory is allocated to the memory when the memory is assigned to any surface object. The use of incorrect use of the setsurfacedesc method can result in an unpredictable reaction. Therefore, when you no longer need surface memory, you must remember to release it. However, when the method is called, DirectDRAW will release the explicitly allocated surface memory when the surface is created. 4.4.9, Direct Accessing The Frame-Buffer Directly You can use the iDirectdrawSurface3 :: Lock method to access surface memory in the frame buffer or system memory. When this method is called, the LPDESTRECT parameter is a pointer for a RECT structure. This structure describes a rectangle on the surface to be directly accessed. To lock the entire surface, you can set the LPDESTRECT to NULL. You can also specify a RECT that contains only a part of the surface. If there is no two rectangles overlap, two processes can lock multiple rectangles in a surface. The LOCK method fills the DDSurfaceDesc structure with all the information that needs to properly access the surface memory. This structure contains information about surface spacing and pixel format (the pixel format of the same host surface is not at the same time). After completing access to the surface, call the iDirectdrawsurface3 :: UNLOCK method to unlock it. 4.4.10, using non-local video memory surface (use non-local video memory "DirectDraw supports advanced graphics port AGP (Advanced Graphics Port) feature, can be created in non-local video memory.

In the AGP system, if the local video memory has been used or the application explicitly requires non-local memory, DirectDRAW will create a surface using a non-local video memory. Currently, there are two AGP systems. One is "Execute Model), one is Direct Memory Access Model. In the execution model, the display device supports the same characteristics of non-local video memory and local video memory. Therefore, when you use the IDirectDraw2 :: getCaps method to get your hardware performance, the same bit block transfers related flags DWNLVBCAPS, DWNLVBCAPS2, DWNLVBCAPS, DWNLVBFXCAPS, and DWNLVBROPS will indicate that the local video memory is used. In execution mode, if the local video memory is run, DirectDRAW will automatically use non-local video memory. In the DMA model, support for texture map transmitted from non-local video memory is limited. When the display device uses the DMA model, you want to obtain the performance of the hardware, and the DWCAPS member will be set to the DDCAPS2_NONLOCALVIDMEMCAPS flag. The same bit block transmission-related logo is included in members of DWNLVBCAPS, DWNLVBCAPS, DWNLVBCKEYCAPS, DWNLVBFXCAPS, and DWNLVBROPS. DirectDraw will not use non-local video memory to create surfaces unless explicitly indicated. The implementation of the DMA model is different in support for non-local video memory surfaces. If the driver supports the texture map from a non-local video memory surface, the D3DDEVCAPS_TEXTURENONONLOCALVIDMEM flag will be set when the 3D device is obtained with the iDirect3ddevice2 :: getcaps method. 4.4.11 Conversion Color and Format Non-RGB Surface Format is represented by four characters. If the application calls the iDirectdrawsurface3 :: getpixelformat method to require the use of the pixel format, and the surface is a non-RGB surface, the DDPF_FOURCC flag will be set, and the members dwfourcc in the DDPixElFormat will become effective. If the Fourcc code is represented by a YUV format, the DDPF_YUV flag will be set, dwyuvbitcount, dwybits, dwubits, dwvbits, and dwyuvalphabits members will be a valid mask, which can be used to extract information from the pixels. If the current RGB format is current, the DDPF_RGB flag will be set, dwrgbbitcount, dwrbits, dwgbits, dwbits, and dwrgbalphabits members will be a valid mask that can be used for advance information from pixels. During the colors and formats, there are two groups of FOURCC code for the application. A set of capabilities identified the power of hardware block transmission, and the other group identified hardware coverage. 4.4.12, overlay surface (Overlay Surfaces) coverage surface is a surface with special hardware support capabilities, typically used to display active video, recording video, or still bitmaps without providing bit blocks to the main surface or changing the main surface. This is entirely provided by the word coverage surface, and DirectDraw supports the features supported by the display device driver, and DirectDRAW does not simulate the surface. The cover surface can be imagined as a plastic paper, and we can draw on this plastic and placed it in front of the display. When plastic paper is covered in front of the display, you can see the overlay and main surface, after removing plastic paper, the main surface has not changed. The working principle of covering the surface is similar to the principle of transparent plastic paper.

When a cover surface is displayed, it is to tell the device driver how to make the coverage surface visible. When the display device scan line is swatched to the display, it checks each pixel on the main surface to see if it is overwritten. If so, the display device is replaced from the data of the associated pixel from the overlay surface. Using this method, display the adapter card generates the main surface and the synthetic surface of the cover surface, generating transparent and stretching effects without changing the content of each surface. Synthetic surface is sent to the display directly to the display. Because this processing and pixel replacement is the hardware level operation, there is no significant performance loss. In addition, this method also enables seamlessly synthesizing the main surface and covers the surface with different pixel formats. Creating an overlay surface You need to specify a DDSCAPS_OVERLAY flag in the DDSCAPS structure, then call the iDirectDraw2 :: CreateSurface method The overlay surface can only be created in the dominant memory, so you must also include the DDSCAPS_VIDEMEMORY flag. As with other types of surfaces, by containing a suitable logo, a single coverage surface can be created, or a flip chain consisting of multiple overrides. You can call the iDirectdraw2 :: getCaps method to get information about supported overlay features. This method fills a DDCAPS structure with the description of all feature information. In reporting hardware features, the device driver sets the flag of the DWCAPS member to indicate when to enforce some type of constraint provided by the hardware. After the ability to obtain the driver, you can know the information provided by checking the DWCAPS member. The DDCAPS structure contains nine members, which describes the constraints of coverage of the surface. The subscript is listed in the same coverage. Membership Sign dwMaxVisibleOverlays the member is always active member of the dwCurrVisibleOverlays always effective dwAlignBoundarySrcDDCAPS_ALIGNBOUNDARYSRCdwAlignSizeSrcDDCAPS_ALIGNSIZESRCdwAlignBoundaryDestDDCAPS_ALIGNBOUNDARYDESTdwAlignSizeDestDDCAPS_ALIGNSIZEDESTdwMinOverlayStretchDDCAPS_OVERLAYSTRETCHdwMaxOverlayStretchDDCAPS_OVERLAYSTRETCH

DwMaxvisibleOverlays and dwcurrvisibleoverlays members indicate the maximum number of overrides that the hardware can be displayed, as well as how many visible. DwalignBoundarySRC, DwalignSizesrc, DwalignBoundaryDest, DwalignSizeDest, and DwalIgnstridealign members are constraints of the rectangle and size of the hardware report. The values ​​of these members refer to how to determine the size and position of the source rectangle and the destination rectangle when the cover is displayed. DWMINOVERLAYSTRETCH and DWMAXOverLaystretch are information about tensile factors. A, source rectangular and destination rectangle To display an overlay surface, you need to call the idirectdrawsurface3 :: updateoverLay method, specify the DDOVER_SHOW flag in the dwflags parameter. This method requires you to specify a source rectangle and destination rectangle in the LPSRCRECT and LPDESTRECT parameters. If the entire surface is used, the LPSRCRECT parameter is set to NULL. The destination rectangle is a position where the cover surface is generated on the main surface. Source, the destination rectangle does not have to be the same. Generally, the destination rectangle must be large or small, and the hardware is automatically compressed or stretched when the hardware is displayed. To successfully display a coverage surface, you may need to adjust the source, the size of the destination rectangle, whether this process is necessary to deserve the limitations of the device driver. B, Boundary and Size Alignment Due to different hardware restrictions, some device drivers are constrained for the size and location of the source rectangle and the destination rectangle of the cover surface. To find out the constraints of the device application, call the IDirectDraw2 :: getCaps method, then check the flag of the DDCaps structure that covered the related DWCaps. The subscript lists the members and signs of the specified boundary and size adjustment constraints. Category Sign Member Boundary Constrained DDCAPS_ALIGNBOUNDARYSRCDWALIGNBOUNDARYSRC

DDCAPS_ALIGNBOUNDARYDESTDWALIGNBOUNDARYDEST Size Constrained DDCAPS_ALIGNSIZESRCDWALIGNSIZESRC

DDCAPS_ALIGNSIZEDESTDWALIGNSIZEDEST

There are two, boundary constraints, and size constraints. Both constraints are represented by pixels, and can be used for source rectles and destination rectangles. Of course, these constraints can be different due to the different surface and the pixel format of the main surface. The boundary constraint affects the position of the source rectangle and the rectangular rectangle. The value of DwalignBoundarySRC and DwalignBoundaryDest members tells you how to adjust the upper left corner of the relevant rectangle. The X coordinate in the upper left corner of the rectangle (the LEFT member in the RECT structure) must be an integer multiple of the reported values. The size constraint affects the effective width of the source rectangle and the rectangular rectangle. The value of DwalignSizesRC and DwalIgnsizedest members indicate how to adjust the width of the correlation rectangle in pixel format. If the rectangular tensile rectangle is drawn according to a minimum tensile factor, it should be ensured that the rectangle after the stretch is still adjusted. After the tensile rectangle, the width can be maintained by adjusting the width upwards, and the minimum tensile factor can be maintained. C, MINIMUM AND MAXIMUM Stretch Factors, due to hardware limitations, some devices limits the comparison of destination rectangular rectangular widths. DirectDraw uses these constraints as tensile factors. A tensile fact is the ratio between the source rectangular rectangles. If the driver provides information about the stretch factor, it will set the DDCaps_Overlaystretch flag in the DDCAPS structure when calling the IDirectDraw2 :: getCaps method. Note that all tensile factors have been multiplied by 1000, so the tensile factor having a value of 1300 is actually 1.3. The maximum minimum tensile factor reported by non-compression and stretching covered rectangular devices is usually 0. The minimum tensile factor indicates how much or narrower in the rectangular rectangular rectangle. If the minimum tensile factor is greater than 1000, the width of the objective rectangle must be increased. For example, if the stretching factor is 1300, the width of the destination rectangle should be at least 1.3 times that of the source rectangular width. If the tensile factor is less than 1000, the destination rectangle is smaller than the width of the source rectangle. The maximum tensile factor is the maximum multiple of the destination rectangle to stretch. For example, if the maximum tensile factor is 2000, the width of the destination rectangle can be 2 times the source rectangular width. If the maximum tensile factor is less than 1000, the destination rectangle needs to be compressed. After stretching, the destination rectangle must comply with any size adjustment constraints required by the device. Therefore, it is finally stretched with the rectangle before the size is adjusted. Hardware does not require adjustment of the height of the destination rectangle. You can increase the height of the rectangle to keep the direction ratio. D, the COLOR Key is covered like other types of surfaces, and the cover surface also uses the source, the destination color key to control the transparent bit block transmission operation between the surface. Because the display of the cover is not completed by the bit block, you need to take different ways to display different methods when calling the IDIRECTDRAWSURFACE3 :: UpdateOverlay method. The answer is to override the Color Key. Symphoto block Transmission Related Color Key Similarly, override the Color Key also has the source color key and the purpose of the purpose, can set the source Color Key and the destination color key with the DDCKEY_DESTOVERLAY flag by calling method iDirectdrawsurface3 :: setColorKey. The overlay surface can combine bit block transmission and override Color Key to control bit block transmission operations and override display operations, and two different types of Color Key do not conflict with each other. IdirectDrawSurface3 :: Updateoverlay method Source Color Key Check which pixel in the overlay surface should be transparent, allowing the main surface to be displayed through the overlay surface. Similarly, the method uses the purpose to override the Color Key to determine which part allows which part allows the overlay surface to be overwritten, and its display effect is the same as the same bit block.

转载请注明原文地址:https://www.9cbs.com/read-4911.html

New Post(0)