Game development basis (4)
Chapter IV DIECTXDARW Basic Articles Section 1 DirectDraw Profile Grubers One View is DirectDraw "just a Bltting Engine". This is quite accurate, but it is too simplified. More accurately, DirectDraw is a BLTTING engine that can provide software simulation tests. The main purpose of DirectDraw is as fast as possible, as reliably as possible and continuously connect graphics to video display devices. Another way to define DirectDraw is to use a video memory manager. Like a regular memory manager, the DirectDRAW issues a memory packet to track the status of each packet. The packet can be created, copied, modified, or destroyed, and the details of these operations are imposed by the programmer, which is too simple. In addition, DireCTDRAW is capable of using system RAM and video RAM. The memory manager is often designed to be as strong as the main goal, not just pursuit of performance. For DirectDraw, performance is only one of the design goals. From a technical point of view, DirectDraw is a portable API set with the device driver. DirectDraw is designed to completely avoid the traditional Windows graphics mechanism (GDI, or graphic device interface). The GDI is not well represented by the low performance, so DirectDraw's equipment independence is critical to provide optimum performance. 2 DirectDraw Basic Concept 1. The display mode display mode is a visual configuration that allows the display hardware supported by the displayed graphic output to be displayed. The most commonly used display mode properties are resolution. The default value of the display mode used by Windows is the resolution of 640 × 480. This means that there are 640 pixels in the horizontal direction, 480 pixels in the vertical direction. Other common display mode resolutions have 800 × 600, 1024 × 768. Some display cards support Mode X display mode. A typical MODE X display mode has a resolution of 320 × 200. The display mode also varies with the variation of pixel depth. The pixel depth determines how many different values accommodated for each pixel, and thus how many colors can be displayed. For example, for a display mode of an 8-bit pixel depth, each pixel can reproduce the 256 colors. The display mode of the pixel depth is 16 bits support 65,536 colors (ie 2 N times), typical pixel depth of 8, 16, 24, and 32. The display mode is supported by a display device or video card installed in the machine. The display device has its own RAM, separating from the RAM of the computer. We refer to the memory in the display device is called the display RAM, and the conventional memory is called the system RAM. The capacity of RAM supporting a given display mode depends on the resolution and pixel depth of the display mode. For example, the display mode of 640 × 480 × 8 (640 × 480 pixels, depth is 8 bits) requires 307200 bytes. 1024 × 768 × 16 display mode requires 1572864 bytes. The memory that supports the display mode must be a display RAM. A display mode supported by a given display device is therefore also limited by the display of RAMs that can be utilized. For example, the display mode of 1024 × 768 × 16 is required because of memory or more than one megabyte, so it cannot be supported by a display device with only one megabyte RAM. One of DirectDraw is a main feature of display mode switching. This allows a DirectDRAW application to detect and activate any display modes supported by the installed display devices. We will discuss the details of display mode switching in Chapter 4. 2. The most important reason for hardware acceleration DirectDraw has the best performance is that it uses hardware acceleration as much as possible. Hardware Acceleration occurs when the display device can perform operations with processing features built in the display device. Hardware acceleration has two advantages. First, when the hardware accelerates, the hardware is designed to support graphics operations, which provides the fastest way to perform a given task: Second, hardware acceleration makes the main processor from execution Operation is liberated, which allows the master processor to perform other tasks. 3. The surface surface is a DirectDRAW term of a rectangular portion of the memory, typically including image data.
This memory is usually used to represent an surface existing in the display RAM or system RAM. Residing on the surface of the RAM enjoys ultra-high performance because most of the display hardware cannot access the system RAM. The surface is divided into a large class, the simplest type is the surface of the screen. The surface of the disengaged screen can reside in the display RAM or in the system RAM, but it cannot be displayed. This type of surface is generally used in storage subfamous screens and backgrounds. On the other hand, a major surface is part of a video RAM that can be seen on the screen. All DirectDraw programs (available videos) have the main surface. The main surface must reside in the display RAM. The main surface is usually complicated or flipped. The flipped surface allows the page to flip, this is a technique that can be instantaneously visible through a hardware operation. Page flip is used in many DirectDraw or other graphics applications because it produces an animation that is quite smoothed and does not flash. A fluttable main surface is actually two surfaces, a visible, and the other is invisible. The unacceptable surface is called a backup buffer. When the page flip occurs, the surface of the backup buffer is visible, while the previously visible surface is a backup buffer. There are two categories: palette and non-tone panels from the panel surface and main surface. In DirectDraw, only 8-bit surfaces are palette surfaces. The palette surface does not contain color data, but it is introduced into a color table. This table is called a palette. The surface of the pixel depth of 16, 24 or 32 is the surface of the pavement. The actual color value is stored without the palette surface without introducing a palette. Because each pixel in the surface of the wireless palette is stored in color data, it is important to know the pixel format of the surface. The pixel format describes the manner of red, green, and blue (RGB) components stored in the pixel. The pixel format varies from the pixel depth, the display mode, and the hardware design, and all pixel formats can be found in Chapter 5. 4. BLTTINGBLTTING is a graphical language for copying. A typical BLT operation is to copy the contents of the screen surface into a backbound buffer. When BLTTING is completed by hardware, the execution speed is quite fast. If the hardware acceleration cannot be obtained, DirectDRAW will use a software operation to simulate the BLT. This simulation operation can also complete the task, but it is much more slower than the hardware. Generally only the surface that resides in the display RAM can be completed by using the display hardware to complete the BLT. The BLT operation calls a source surface and a target surface, and the content of the source surface is copied to the target surface. The content in the source surface will not change in the operation, only the target surface is affected by the BLT. BLT operations do not need to use all source surfaces or target surfaces. Any rectangular area in the source surface can be placed anywhere in the target surface. BLTTING (eg, typical sub-picture) of an irregular shape surface is completed in a transparent manner. Transparency is obtained by specifying a pixel that is not copied by the BLT operation. Pixel values are given by using color keycase. The color key code can be attached to the source surface or target surface. The source color key is very common. Source color key code allows transparency, because the pixel values in the source surface are not treated. As for the target color, only the pixel values specified in the target surface can be covered by the contents of the source surface. DirectDraw also supports some specific operations, including stretching, compression, mirrored mapping, and mixing. The implementation of these functions is often depends on the display hardware. DirectDraw can simulate some of these operations, but prices are often expensive compared to performance. DirectDraw also has functions that cannot simulate (eg, target color keying). Using these functions is adventurous unless this feature is supported by the installed display hardware support, the operation of this feature will fail. This brings two basic choices to the developers of DirectDraw: either abandoned these features: either add custom software to your application. 5. The palette uses the 8-bit display mode application to provide a palette. The palette is the color table that can be used at any time. If the 8-bit display mode does not require a palette, the application will be forced to use a fixed setting of 256 colors. The palette allows the user to define one of the 256 colors that will be used. When you use the palette display mode, you must ensure that the same palette is also used in the application in the application.
If this is not done, there will be an error color in some or all of the images displayed. The palette also brings trouble, especially when using a palette to display a lot of images. There are also some advantages in palette. As mentioned earlier, the palette allows the most colors to be used in a limited color. The palette also allows the palette animation. The palette animation is an animation to perform techniques performed by changing the palette item, rather than changing the pixel value, making many pixels on one screen can instantose color. For some limited applications, such as allocation, repetitive animations, palette animations are useful. 6. Target the ideal state, a BLT operation is that the entire surface is also another surface that is BLT. Usually the source surface is bound by the BLT as the target surface, or the target surface is shaped by another surface or window. Tarring is required like this. Tailoring only part of a part or a portion of a surface is blocked by the BLT. Targes often use when writing window DirectDRAW applications because these applications must follow the rules of the Windows desktop. We will discuss window applications later in this chapter. DirectDraw provides full rectangular tailoring support. There is also this situation that is the payment of customized tailoring routines, we will study custom tailoring solutions in Chapter 3. 7. Other surface proof surfaces and main surfaces (with optional backup buffers) are the most DirectDRAW applications. However, some other surfaces have different, including overlapping surfaces, Alpha channel surfaces, Z-buffers, and 3D equipment surfaces. The overlapping surface is a hardware monochrome picture, which is therefore only available on display hardware that supports overlapping. Unlike the software monochrome screen, it can be moved without the need to be recovered. The Alpha channel surface is used to perform Alpha deployment. Alpha deployment is a transparent advanced form. Allow the surface to be copied in transparency or translucent. The Alpha channel surface can be used to control the transparency setting of each pixel. The depth of the Alpha channel surface is 1,2,4,8. The 1-bit depth Alpha channel surface supports only two transparent settings, opaque (non-transparent) or invisible (full transparency). On the other hand, the 8-bit Alpha channel surface allows 256 different transparency settings. Alpha deployment is an example of the function of DirectDraw simulation. In order to use Alpha to be prepared, there is a need to support its display hardware or a custom-forming scheme established in the application. The Z-buffer and 3D device surface are used in the 3D application. These types of surfaces have been specially added to DirectDraw to support Direct3D. The Z-buffer is used for the scene to track the most recent objects in the viewer in the scene, so that the object can appear in front of other objects. The 3D device surface can be used as a surface of the Direct3D to draw the target. This book does not include a Z-buffer or 3D device. The third element object model (COM) 1. Microsoft COM specification DirectDraw is achieved according to Microsoft's COM (Component Object Model) specification. COM is designed to provide complete portable, safe, upgraded software structure, COM is a big project, but it is not an object discussed in this software. We discuss COM just to facilitate programming using DirectDraw. COM uses an object-oriented model, which is more stringent than the model used in languages such as C . For example, COM objects are often accessed through member functions, and there is no public data member. COM supports the support of inheritance and C is also limited. 2. Comparison of objects and interfaces COM has a big difference between objects and interfaces. The COM object provides actual functionality, and the COM interface provides a method of accessing a functionality. The COM object cannot be accessed directly. In contrast, all accessors are done through the interface. This rule is so powerful, so that we cannot give any COM objects in name. We can only give the interface name for accessing objects. Because we can't access COM objects, there are most time this time is based on the interface. A COM object can support multiple interfaces.
This sounds like a special case, but it often appears because, once a COM interface is defined once, it is no longer changed or increased. This is to ensure that the old program will not be stopped when a COM object is upgraded. This initial interface always exists, a new, replacement interface is provided when providing new functions of access objects. 3. All COM interfaces of the iUnknown interface are derived from the iUnknown interface. The "I" logo is often used to name the COM interface (which represents interface). The DirectDRAW interface is always started with "I". But this logo often doesn't see in the literature. The "i" flag will be omitted when the interface is mentioned later. The IunkNown interface will provide 3 member functions, and all COM interfaces are thus inherit of these functions: ● addRef () ● Release () ● queryinterface () addRef () and release () member functions are COM called life encapsulation (LifeTime Encapsulation) Function provides support. Life packaging is a protocol that places every object according to its own structure. Life packages are implemented by reference. Each object has a pointer that can track the object, or the internal value referenced. This value is 1 after the object is created. If the attached interface or interface of the interface is created, the value is incremented. Similarly, if the pointer of the interface is destroyed, the value is decremented. When its reference number is 0, the object is destroyed. The addRef () function is used to increase the internal reference value of the object. Most of the time, the function is called by the DirectDraw API. For example, when you create a new interface using the DirectDrawAW API, create the function automatically call AddRef (). Release () function is used to deliver the internal reference value of the object. Users should use this function when the pointer of the interface will be out of the range or to use this function when using the interface pointer. The addRef () and release () functions returns a value to indicate a new reference value of the object. QueryInterface () function allows COM objects to query specific interfaces. For example, an upgraded COM object provides an additional interface, not a modified version of the interface. The queryinterface () function can be used to determine the old interface to determine if the new interface is supported. If the object being queried does not support a problematic interface, the pointer to the interface is returned. 4. GUID is secretly identified an issue with a problem with the specified interface that uses the queryinterface () function. This is implemented by the GUID (GlobalLoBally Identifier) of the interface. A GUID is a 128-bit value, that is, for all intentions and purposes are unique. All directDRAW interfaces of GUIDs are included in the DirectX header file. The above brief introduction to COM is to effectively use the DirectDraw API needs. In the future, when we discuss the DirectDraw API, you will find that these contents are related. Section IV DirectDRAW Interface Function 1. A method for measuring the DirectDraw API measures API is to see its size. A huge complex API may be the result of the plan for no circumference. On the other hand, a huge API sometimes means that every situation may appear. A small API is a new, lack of functional package evidence. It also means that an API can only do what it needs, but can't do more. The DirectDraw API is relatively small, so every function discussed in this chapter does not look like a reference manual like this chapter. DirectDraw offers very little convenience and few restrictions. DirectDraw is composed of a COM object, each object can be accessed by one or more interfaces.
These interfaces include: ● DirectDraw ● DirectDraw2 ● DirectDrawSurface ● DirectDrawSurface3 ● DirectDrawPalette ● DirectDrawPalette ● DirectDrawPalette ● DirectDrawPalette ● DirectDrawPalette ● DirectDrawPalette We will discuss each interface and then discuss their member functions. But we don't discuss details of each function, because we don't provide you with a reference manual. Instead, we will discuss what is dry, why use this, and how you may use it. When DirectX is first launched (earlier it is called Games SDK), the DirectDraw core functionality is represented by the DirectDraw interface. DirectDraw has also been upgraded when DirectX2 is launched. DirectDraw abides by the COM specification without changing. The new functionality may be accessed through the DirectDraw2 interface. It is important to note that the DirectDraw2 interface is a super setting of the DirectDraw interface. The DirectDraw2 interface provides all functions of the DirectDraw interface, and some new functions have also increased. If you are using DirectX or higher, you can use the DirectDRAW interface or DirectDraw2 interface at will. However, because the DirectDraw2 interface is stronger than the DirectDRAW interface, it is not necessary to use the DirectDRAW interface. Similarly, Microsoft does not advocate use these unoccupied, network variable interfaces. Therefore, in the program after this book we only use the DirectDraw2 interface. DirectDraw and member functions DirectDraw2 interface provided below (in alphabetical order): ● Compact () ● CreateClipper () ● CreatePalette () ● CreateSurface () ● DuplicateSurface () ● EnumDisplayModes () ● EnumSurfaces () ● FlipToGDISurface () ● GetAvailableVidMem () ● GetCaps () ● getDisplayMode () ● GetFourCCCodes () ● GetGDISurface () ● GetMonitorFrequency () ● GetScanline () ● GetVerticalBlankStatus () ● RestoreDisplayMode () ● SetCooperativeLevel () ● SetDisplayMode () ● WaitForVerticalBlank () Next we discuss DirectDRAW interface function. Note that in this chapter, the DirectDRAW interface represents both the DirectDraw interface, also represents the DirectDraw2 interface. Different by distinguishing between DirectDRAW interfaces and DirectDraw2 interfaces. 1. Interface Create a DirectDraw interface represents DirectDraw itself. This interface is a primary interface when it is used to create another DirectDRAW interface instance. The DirectDRAW interface provides three such interface instances creation functions: ● createclipper () ● createPalette () ● createSurface () createclipper () function is used to create a DirectDrawClipper interface instance. Not all DirectDRAW applications are used to use the ceramer, so the function is not in all programs. We will discuss the details of DirectDrawClipper soon. The createPalette () function is used to create a DirectDrawPalette interface instance. Like DirectDrawClipper, not all DirectDRAW applications are used in palettes. For example, when the application uses 16-bit display mode, it is not a palette.
However, when the application uses 8-bit display mode, at least one DirectDrawPalette instance must be created. The CreateSurface () function is used to create a DirectDrawSurface interface instance. Any DirectDRAW application must use a surface to generate image data, so this function is often used. The DirectDraw interface is created by the DirectDrawCreate () function. DirectDrawCreate () is one of several regular functions in the DirectDraw function, but is not a COM interface member function. 2. The getCaps () function DirectDRAW interface allows you to accurately determine the features supported by the hardware and software. The getCaps () function can initialize two DDCAP structural instances. A structure indicates which features are directly supported by display hardware, and another structure indicates which features are supported by software simulation. It is best to use the getCaps () function to determine if the features you will use are supported. Tip: DirectX Browser DirectX SKD is also launched at the same time as the DXVIEW program. DXView illustrates the functionality of the DirectX component, including DirectDraw. In most systems, there are two DirectDraw projects: the main display driver and hardware simulation layer. The first item illustrates the function of displaying the hardware. The second item illustrates some of the features that DirectDraw will simulate in the absence of hardware support. In a computer with a display card supported by more than two DirectDraw, DXVIEW displays the functionality of the card. 3. SetCoopeRATIVELEVEL () Function setCoopeRATIVEVEL () function is used to specify the degree of control of the display hardware required by the application. For example, a normal cooperation means that the application does not change both the current display mode, and cannot specify the content of the entire system palette. And a proprietary partnership allows display mode to switch and fully controls the palette. No matter which partnership you decide, you must call the setCooPERATIVELEVEL () function. 4. The display mode function DirectDRAW interface provides four display mode operation functions. They are: ● EnumdisplayModes () ● getDisplayMode () ● restDisplayMode () ● setDisplayMode () enumdisplayModes () function can be used to query the display mode of DirectDRAW. All display modes can be obtained by setting the enumdisplayModes () function default value, and those that are not interested in eliminating the modes of interest. It is best to use the EnumDisplayModes () function during the display mode switch. There are now a variety of display devices on the market, each of which has its own characteristics and limitations. In addition to the default 640 × 480 × 8 window display mode, it is best not to rely on any given display mode support. The getDisplayMode () function can retrieve information about the current display mode and display information such as width, height, pixel depth, and pixel format of the current display mode in the DDSurfaceDesc structure instance. There is also another way to retrieve the same information (such as retrieving the main surface description), so the function does not appear in all programs. The setDisplayMode () function is used to activate the supported display mode. The DirectDraw2 version of the setDisplayMode () function also allows the display mode refresh rate. The DirectDraw interface version of the setDisplayMode () function can only be set in display mode width, height, and pixel depth. Any program to display mode switches is used to use the setDisplayMode () function. The restiSplayMode () function is used to store the display mode before calling the setDisplayMode () function. SetDISPLAYMODE () and restiSplayMode () functions require priority to use the SETCOOPERATIVELEVEL () function to have proprietary cooperation access.
The surface of the support functions in addition to the CreateSurface () function, DirectDraw interface also provides the following functions related to the surfaces: ● DuplicateSurface () ● EnumSurfaces () ● FlipToGDISurface () ● GetGDISurface () ● GetAvailableVidMem () ● Compact () DuplicateSurface () The function is used to the current surface of the test. This function only copies the surface interface and does not replicate memory. The replicated surface shares memory with the source surface, thus changing the content of the memory changes the image of the two surfaces. Enumsurfaces () functions can be used to iterate all surfaces that meet the specified standard. If there is no specified standard, then all current surfaces are enumerated. The function of the FlipTogDisurface () function is to ensure that the main surface is properly stored before terminating the page flip application. There are two surfaces alternately displayed when the page is flipped. That is to say, there is no preservation of the original visible surface before terminating the application. In this case, Windows recovers by drawing an invisible surface. This is easily avoided using the fliptogdisurface () function. The getGDisurface () function can return a pin to the surface approved by the GDI. The GDI surface is the surface for Windows for output. This function is very useful when performing screen capture, and DirectDRAW can capture any part of the Windows desktop. The getavailablevidmem () function is used to retrieve the number of video memory (display RAM) in use. This function is provided by the DirectDraw2 interface instead of being provided by the DirectDRAW interface. This function is used to determine the application using the display RAM to create the number of surfaces. The Compact () function is not implemented via DirectX5, but it can provide fragmentation skills for video memory. A large amount of memory can be released when the surface of the display RAM is constantly created or destroyed. 6. The monitor refresh function DirectDraw interface provides four functions suitable for computer display devices or monitors, but these functions are not suitable for display cards, they are: ● getMonitorfrequency () ● getscanline () ● getVerticalBlankstatus () WaitforVerticalBlank () These functions are especially close to the monitor's refresh mechanism. This is critical when ensuring that the animation is generated as much as possible without flickering and image tearing phenomenon. But care must be noted that these functions are not supported by all display card / monitor combinations. The getMonitorfrequency () function is used to retrieve the current refresh rate of the monitor. The refresh rate is usually expressed by Hz, abbreviated as Hz. For example, 60 Hz refresh rate indicates that the screen is updated 60 times per second. The getScanLine () function is used to return to the monitor that is currently being refreshed with a scan line (horizontal pixel row). This function is supported by all display devices / monitor combinations. If this feature is not supported, the function will return Dderr-unsupported. For high-performance graphics applications, you usually update the screen with a vertical refresh synchronization. In particular, it is best to update the main surface when the display just completes the screen refresh. Otherwise, a part of the screen displays the new image data, and the other portion still shows the old image data, which is the so-called image tear. DirectDraw defaults to synchronize the screen with a vertical refresh. If you don't do this, you can use the getVerticalBLankStatus () and WaitforVerticalBLANK () functions to achieve synchronous refresh. 7. The last function provided by the getFourcccodes () function DirectDRAW interface is a getfourcccodes () function. This function is used to return the FourCC code supported by the display card. The Fourcc code is used to describe the surface of the non-RGB or YUV. We don't discuss the surface of the YOV here, they have exceeded the scope of this book.
The DirectDrawSurface interface function is the same as the DirectDraw interface. The DirectDrawSurface interface also follows the COM specification. Initially, surface support is provided by the DirectDrawSurface interface. DirectX2 introduces new functionality of the DirectDrawSurface2 interface, DirectX5 describes the DirectDrawSurface3 interface. Although this software discusses the DirectDraw2 interface instead of the DirectDraw interface, we are still loyal to the original DirectDrawSurface interface, because the new functions of DirectDrawSurface2 and DirectDrawSurface3 interfaces are not very important. In the later content, we will use the DirectDrawSurface interface to indicate these three interfaces unless otherwise specified. DirectDrawSurface is the largest DirectDRAW interface that allows copy, clearing, and direct access to the calling program. DirectDrawSurawSurface Interface total of 36 members functions, in alphabetical order the following: ● AddAttachedSurface () ● AddOverlayDirtyRect () ● Blt () ● BltBatch () ● BltFast () ● DeleteAttachedSurface () ● EnumAttachedSurfaces () ● EnumOverlayZOrders () ● Flip ( ) ● GetAttachedSurface () ● GetBltstatus () ● GetCaps () ● GetClipper () ● GetColorKey () ● GetDC () ● GetDDInterface () ● GetFlipStatus () ● GetOverlayPosition () ● GetPalette () ● GetPixelFormat () ● GetSurfaceDesc () ● IsLost () ● Lock () ● PageLock () ● PageUnlock () ● ReleaseDC () ● Restore () ● SetClipper () ● SetColorKey () ● SetOverlayPosition () ● SetPalette () ● SetSurfaceDesc () ● Unlock () ● UpdateOverlay ( ● UpdateoverlayDisplay () ● UpdateoverlayZorder () 1. Surface Description Function We first discussed a function that can be used to retrieve the surface itself, they are: ● getcaps () ● getSurfaceDesc () ● setsurfaceDesc () with DirectDRAW interface Like the supplied getCaps () function, the DirectDrawSurFace interface provides the getCaps () function to output which features that characterize which features can be supported. This information includes: The surface is the main surface or the slave surface; the surface used by the surface is positioned to display the RAM or the system RAM. The getpixelformat () function is very important when used for high color and true color, because the pixel format is different from the display card. This function returns a symbolic code that indicates how each color component is stored. The getSurfaceDesc () function returns a surface description. This information includes the width, height, and depth of the surface. Surface pixel format (also retrieved by getpixelformat () function) is also included. SetsurfaceDesc () function (for DirectX5) is new, only by the DirectDrawSurface3 interface) allows you to set some surface properties. This function can be used to specify the memory used by the surface. This is very useful when designing custom surface memory manager policies. 2. Surface BLT function DirectDrawSurface interface provides 3 functions that support BLT operations: ● BLT () ● BLTBATCH () ● BLTFast () blt () function is a major function.
The BLT () function enables conventional Blting (there is no specially affected simple surface to the surface of the BLT) while supporting an operation of extending, rotating, mirroring, and color filling. When used in the surface associated with the ceramer, BLT () can make a clipping BLT operation. The BLTBATCH () function is not implemented under DirectX3 (you can call the function, but nothing will happen). When executing a bLTBATCH () function, if possible, it can simultaneously perform multiple BLT operations. The BLTFast () function is an optimized version of the BLT () function. The efficiency of the BLTFast () function is improved, but performance has fallen. The BLTFast () function cannot perform some special BLT operations, and the blt () function can. Moreover, the BLTFast () function cannot be used to cut. But the Bltfast () function supports the operation of the source and target color keystream BLT. In the case of clarifying the custom tailor, the BLTFast () function can perform the fastest and flexible BLT operations that DirectDRAW can provide. In the next chapter we will perform a custom tailoring routine. The above three BLT functions use the source surface and the target surface as a variable. Other data, such as the ideal positioning of the BLT on the target surface, is provided by specifying the exact attribute of the ideal BLT operation. Once possible, these three functions will perform hardware acceleration BLT. 3. FLIP () function flip () function is used for page flip operation. Call the flip () function hides the previously visible surface on the screen and makes a backup buffer appear. Only the call should be called with the surface that is explicitly created as the flip surface. It must be kept in mind that the real flip operation cannot always be successful. The page flip requires enough display RAM to accommodate two full screen valid data. If this requirement is not met, a backup buffer will be created in the system RAM. At this time, call the flip () function is a BLT operation instead of the page flip. The content in the backup buffer based on the system RAM is copied to the main surface. This will seriously affect performance, but if there is not enough display RAM in the true page, it is only like this. If your application requires optimal performance, you have to try to avoid display modes that cannot be reversed in real pages. 4. Surface Status Functions Discuss two functions that can retrieve operational and flip operation information, which are: ● getBltstatus () ● getFlipStatus () getBltstatus () function is used to determine if BLT operation is performed. This is important because other operations are not available on the surface of the BLT. This function indicates whether a given surface is a source surface or target surface that performs a BLT operation. Similarly, the getBltStatus () function indicates whether the flipping operation is being performed. Even if DirectDRAW is flipped through the BLT operation emulation page, the function is not getBltstatus () must also be used to flip in the monitor page initialized by the FLIP () function. 5. Color key code function DirectDrawSurface interface provides the following two functions to set and check the scope of the surface color key code or color key code, which is: ● getColorKey () ● setColoKey () By default, the surface does not have a color key code . A color key code only corresponds to a color, but some hardware supports color keying range. The color key code and color keying range are defined by the DDCOLORKEY structure. GetColorKey () and setColoKey () functions use pointers of this structure as variables. These two functions can be used when a part of the required surface is transparent or when the target color key code is required. 6. Lock and UNLOCK () Function DirectDraw's main features are to provide direct access to image data. Direct access can provide optimal performance and better flexibility, because there is no intermediate API affects running speed, and developers use image data. The intermediate access of the surface memory is implemented by the following function: ● UNLOCK () ● Lock () Lock () function returns a pointer to the memory constituting surface, regardless of whether the surface memory is located in the display RAM or the system RAM.
The memory is generally arranged in linear style to simply perform image data access. The unolock () function is specified to DirectDraw after the access of the surface memory is completed. Direct access to image data must pay at a price. In order to support this approach, DirectDraw must turn off the basic Windows institution when locking on the surface. In Windows95, if you forget to unlock the surface, you will definitely damage the machine. Therefore, the time of surface locking should be shortened as low as possible. The program call between the Lock () and UNLOCK () functions should be carefully checked before testing. Because this program cannot debug with a traditional debugger. The locking surface cannot be converted to the BLT and flip, so trying to keep the surface in the locked state without any benefit. Moreover, once the surface is unlocked, the pointer retrieved by the LOCK () function is invalid. It cannot be locked again after the surface is locked. The LOCK () function cannot be called when the surface is locked. 7. Getdc () ReleaseDC () Function The direct access to the surface is very large, sometimes it is better to put the surface as a regular Windows device. Here, the DirectDrawSurface interface provides the following two functions: ● getDC () ● ReleaseDC () getdc () function provides a DC (device environment) that can be written on the surface with a regular Win32 function. For example, DC can draw text on the surface with a textOut () function of Win32. You must immediately call the ReleaseDC () function immediately after DC. Like the LOCK () and UNLOCK () functions, the ReleaseDC () function must be called immediately after calling the getDc () function. This is because the Lock function is called inside the getDC () function, and the unlock () function is called inside the ReleaseDC () function. 8. Pagelock () and pageunlock () functions Next, we discuss the other two functions that look very similar to the Lock () function and unlock () function: ● PageLock () ● Pageunlock () Although these two functions look It is very similar to the Lock () and UNLOCK () functions, but they have a completely different role. The PageLock () and PageunLock () functions are used to control Windows how to process system-based surfaces. These two functions are provided by the DirectDrawSurface2 interface instead of being provided by the DirectDrawSurface interface. When Windows thinks that other applications or processes currently running are more suitable for using memory, Windows releases partial memory to the hard drive. This buffer works for the entire system memory, so the surface of the DirectDRAW residing in the system's memory may be saved on the hard disk. If you want to use such a surface, Windows needs to take a certain time to read surface data from the hard disk. PageLock () function prompts which given surfaces of Windows should not be released on the hard disk. This way, do not take time to access the hard disk if you use the surface. Conversely, the PageunLock () function is used to inform Windows which surface memory can be released. Procedure Calling the PageLock () function reduces the total amount of buffer memory, resulting in a great reduction in Windows. As for this happening, it takes depends on the amount of system memory provided by the page locking system memory and the amount of system provided. The PageLock () and pageunlock () functions are mainly provided by DirectDraw instead of the DirectDRAW application. For example, DirectDRAW automatically uses the PageLock () function to ensure that the system RAM-based surface is not released to the hard disk when running the BLT operation. The PageLock () function can be called multiple times in the same surface. DirectDRAW Record the number of times the PageLock () function is called by the reference count, so the PageLock () function must be called multiple times. The PageLock () and PageunLock () functions do not work for the surface that resides in the display RAM.
9. Islost () RESTORE () function now discusses two functions related to the surface that resides in the display RAM: ● Islost () ● restore () Let's take a look at this situation. When the application is running, try to assign the surface to the display RAM, and the rest is created into the system RAM. After running a period of time, the user performs or switches to another application. The app is arbitrary, can be a regular Windows program such as a Windows development program or notepad. It can also be another DirectDraw application that also tries to allocate as much as possible to display RAM. If DirectDraw does not accept the display RAM, then new applications can not run at all. Conversely, the application means that the application does not allow allocation to any display RAM. Therefore, DirectDRAW can freely remove any one or all of the display RAM-based surface from an inactive application. This is the so-called surface loss. Technically, the program still has a surface, but they no longer be associated with any memory. The Dderr-Surfacelost error is caused to use the lost surface. The islost () function can be used to determine if a surface has lost memory. After the surface memory is lost, you can recover through the restore () function, but you can only recover after the application is reactivated. This will cause the application to restore all surfaces that minimize the state. The restore () function can restore any memory attached to the surface, but does not resume the contents of memory. After the surface is restored, the application can restore the surface content. Note that this usage is not suitable for the surface created by the system RAM. If you need to use the memory based on the system RAM, Windows will immediately release these surfaces into your hard drive. Windows automatically processes storage and recovery, including the contents of the recovery surface. 10. GetDDinterface () Function getDDinterface () function can retrieve pointers for creating a DirectDRAW interface for a given surface. Since only one DirectDRAW interface instance is mostly in most cases, the getDDinterface () function is not commonly used. However, it is possible to use multiple DirectDRAW interfaces in an application. In this case, the getDDinterface () function plays an important role. 11. The surface connection function DirectDrawSurface interface provides the following four functions to maintain the connection between the surface: ● addattachedsurface () ● deletettachedSurface () ● EnumattachedSurface () ● GetAttachedSurface () DirectDRAW supports a large number of connection between the surface. The most common situation is that the page flips. When the page is flipped, two or more surfaces are connected into cyclic, and each time the FLIP () function is called each time, the next surface in the annular surface is displayed. The surface connection function is used to create, check, or eliminate the connection between the surface, but these functions are not essential. DirectDraw is often automatically created connection surface. For example, when creating a main flip surface, you can specify the number of backup buffers for the connection surface. DirectDraw creates these surfaces and connects them. 12. DirectDrawSurface overlapping functions to support interface for the overlapping functions as follows: ● AddOverlayDirtyRect () ● EnumOverlayZOrders () ● GetOverlayPosition () ● SetOverlayPosition () ● UpdateOverlay () ● UpdateOverlayDisplay () ● UpdateOverlayZOrder () GetOverlayPosition () and SetOverlayPosition () function Used to control the position of overlapping.
The UpdateOverlay () function is used to update a large amount of overlapping settings, including whether overlap can be visible, and overlap is mixed with alpha or alpha to mix on the background surface. The UpdateoverlayDisplay () function is used to update the display settings. This function is used to update the entire overlapping display, or only the rectangular overlap portion specified by the addoverlayDirtyRect () function. The enumoverlayzorders () function can repeat overlap overlap according to the overlapping z value (which overlap is at the top). Overlapping can be enumerated in order from before or later. 13. Tariators DirectDraw supported by cutting the DirectDrawClipper interface (this interface we have not discussed) one instance to the surface. Once the connection is completed, the tailor object will have regular BLT to the surface. The connection of the tailor / surface is controlled by the following two DirectDrawSurface function: ● getClipper () ● setClipper () setClipper () function is used to connect the tailor object to the surface. The getClipper () function is used to returns a pointer to the front of a connection. The setClipper () function can also be used to release the connection of the surface with a ceramer, and the specific approach is to replace the DirctDrawClipper interface pointer by specifying null. 14. The palette function is like a tailor, and the palette can also be connected to the surface. The DirctDrawSurface interface provides the following two functions for this: ● getPalette () ● setPalette () setpalette () function is used to connect an instance of the DirctDrawPalette interface (which we will discuss) to the surface. The getPalette () function is used to retrieve a pointer to the previous connection palette. The palette can be connected to any surface, but only when connecting to the main surface, the palette works. When connected to the main surface, the palette determines the setting of the display of the hardware palette. Section 6 DirectDrawplette Interface Functions DirctDraw provides a DirctDrawPaletTE interface for palette display mode and surface. Although Windows supports several display modes below 8-bit pixel depth, the unique palette display mode supported by DirctDraw is 8-bit mode. The DirctDrawPalette interface instance is created by the DirctDraw CreatePalette () function. The createPalette () function uses a lot of logo to define the palette properties. The DirctDrawPaletTE interface only provides the following three functions: ● getCaps () ● getNtries () ● setEntries () getCaps () function is used to retrieve information about the palette, including the number of palette items, whether the palette supports synchronous vertical refresh And 256 palette items in the 8-bit palette are all set. The setEntries () function allows the color value of the palette to be set in the program. This data is read from the file. These items can be calculated and set during operation. The getNtries () function is used to retrieve previously set palette items. DirctDrawPalette () Interface instances can be connected to the surface using the DirctDrawSurface setpalette () function. Connect different palettes to the main surface or use the setEntries () function to change the palette project. Section 7 The DirectDrawClipper interface function DirctDrawClipper interface supports tailoring. Connect the crop object to the surface and take it as a target surface in the BLT operation. The DirectDrawClipper instance is created by the DirectDraw CreateClipper () function. The DirectDrawClipper interface supports the following five functions: ● sethwnd () ● gethWnd () ● iscliplistChanged () ● setCliplist () ● getCliplist () Triaser object is generally used to appear on the window DirctDRAW application. Ask the tailor to ensure that other windows on the desktop are taken into account during the BLT operation.
For example, when the entire or part of the application is obscured by another window, tailoring must ensure that the shaded window is not destroyed by the DirctDraw application. Desktop clipping is done by the setWnd () function. The sethwnd () function connects the tailor object to a window handle. This initializes communication between Windows and Tariors. When any window on the desktop changes, the tailor object will be notified and respond. The gethwnd () function is used to determine which window handle is connected to the garrison. The iScliplistChanged () function is used to determine if the internal tailor list is updated due to changes in the desktop. SetCliplist () and getCliplist () functions provide convenient custom use for DirectDrawClipper interfaces. The setCliplist () function is used to define some rectangular areas that are used to define the legitimate area of the BLT operation. The getCliplist () function is used to retrieve the internal tailor data of the ceramer. Once connected to the surface, BLT (), bLTBATCH (), and UpdateoverLay () functions The BLT operations performed according to the data contained in the DirctDrawCliper interface is automatically cut. Note that the BLT FAST () function is ignored here. The BLTFast () function does not support tailoring. Section 8 Additional DirectDRAW Interface DirctDraw also provides an additional interface we have not discussed, which is: ● DDVIDEOPORTCONTAINER ● DirectDrawColorControl ● DirectDrawVideoPort These interfaces are introduced by DirectX5, which provides low level video port control. These interfaces also provide a way to stream activity video to the DirctDRAW surface. Despite the use of these interfaces to increase video support for the DirctDRAW application, it is best not to make this method unless high level video APIs cannot meet the needs. Article 9 DirectDRAW Structure We have discussed the DirctDraw interface and its member functions, then look at the structure defined by DirctDraw. DirctDraw a total of 8 full-defined structure: ● DDBLTFX ● DDCAPS ● DDOVERLAYFX ● DDPIXELFORMAT ● DDSURFACEDESC ● DDSCAPS ● DDBLTBATCH ● DDCOLORKEY We have already seen some of the structure in which, for example, when discussing DirctDrawSurface SetColorKey () function we contact DDCOLORKEY structure. Here, we don't discuss details of each structure in detail, but it must be pointed out that Dirctdraw Quirk will cause failure when it is forgotten. The top 5 in the above structure has a field called DWSize. This field is used to store the size of the structure, and the task of setting this field is made by you. In addition, if this field is not set correctly, then any one of the five structures as a variable is invalid. Taking the DDSurfaceDesc structure as an example, the code using the structure is as follows: ddsurfacedesc surfDesc; surfDesc.dwsize = sizeof (surfDesc); Surf-> GetSurfaceDesc (& SurfDesc); first declare structure, then set the DWSIZE field with the sizeof () keyword. The final structure is passed to the DirctDrawSurface getSurfaceDesc () function. Forgetting to set the dwsize field will result in this code to fail. Why is DirCtDraw insisting on requesting the size of the structure it defined? The reason is that these five structures containing the DWSize field will change in the future. DirctDraw checks the size of the structure to determine the version being used. DirctDraw insists on giving an effective size value to allow developers to provide effective structural size. This is good because the new version of DirCtDraw can properly use the old version of the DirctDraw program.
Before using the structure, it is best to initialize the structure to zero. Thus, the previous code becomes: DDSURFACEDESC surfdesc; ZeroMemory (& surfdesc, sizeof (surfdesc)); surfdesc.dwSize = sizeof (surfdesc); surf-> GetSurfaceDesc (& surfdesc); ZeroMemory () function is a Win32 function, it The memory as the first parameter is set to zero. The second parameter of the zeromeMory () function indicates how many memory should be initialized. The advantage of this approach is that the text of the structure can be found by getSurfaceDesc () function to be updated. If there is no initialization of the structure, it is possible to use the unpredictable value in the structure field as the set value of DirectDRAW. Section 10 Window Application DirctDRAW application mainly has two types: window and full screen. Window DirctDRAW applications look like a regular Windows program. We will soon discuss full screen applications. Window applications include window boundaries, title boxes, and menus, which are all common in traditional Windows applications. Since the window application appears on the desktop with other windows, they are underway using the resolution and bit depth of Windows. The window program has a home surface, but only appears when the real page is flipped. Moreover, the main surface does not represent the customer area of the window (this area is in the window boundary). The main surface also represents the entire desktop. That is to say, your program must track the location and size of the window so that the visible output is displayed correctly within the window. In other words, the drawing can be performed on the entire desktop using window-wide applications. If the page is not allowed to flip, the image must be from the slave BLT to the main surface. This increases the possibility of image tearing, because BLT is slow than the page flip speed. In order to avoid image tear, the BLT operation can be synchronized with the monitoring refresh rate. If the off-screen buffer with the same size as the window customer area is created to the display RAM, the window application can run well. Thus, the content of the window can be synthesized from the surface surface. The slave surface can be quickly accelerated quickly to the main surface by hardware acceleration. Due to the lack of the display of the memory, the performance will be severely influenced when the off-screen buffer is created into the system RAM. Unfortunately, this situation often occurs, especially when only 2MB display cards, this is because people always want to set high-resolution display modes for their Windows desktop. For example, the main surface of the 1024 × 768 × 16 display mode will take up 2MB of RAM. On a 2MB display card, there is almost no RAM to leave the panel surface. Another problem with the window app is tailored. A good performance application must have a tailoring object connected to the main surface. This is damaged performance because the BLT operation can only be performed within a small rectangular portion in order to check the tailor list of the ceramer. Moreover, an optimized BLTFast () function cannot be used. BLTTING must be slow, (and more cumbers) BLT () functions. The last thing to say is that the window application does not allow full-tuning panel control. Since Windows retains 20 palette items, only 236 colors of 256 colors can be set. Colors reserved by Windows only use the top 10 items and 10 items of the system palette. Therefore, only 236 palette items can be used in the middle of the color. Section 11 The full screen application contains a Dirctdraw application that performs proprietary access to the display device is a full screen application. Such an application can arbitrarily select the display mode supported by the display card and enjoy a full-pace control. In addition, full-screen applications can also be flipped. Therefore, compared with window applications, full screen applications are faster and flexible. Typical full-screen applications first check the supported display mode and activate one of them.