DirectX 8 Developers FAQ

xiaoxiao2021-03-06  112

table of Contents

General Direct3D DirectSound DirectPlay

This article answers the common development issues related to Microsoft DirectX 8.0, including chapters on Direct3D, DirectSound, and DirectPlay.

1, general DirectX development matters

Q: Why do I get so many error messages when trying to compile examples?

A: You may not set the include path to the correct. Many compilers (Microsoft Visual C ) contain an earlier version of the SDK, so if your include path first search the criteria compiler include directory, you get an incorrect version of the header file. To resolve this issue, make sure the include path and library paths are set to search for DirectX include and library paths. See also DXReadme.txt file in SDK. If you install DirectX SDK and you are using Visual C , you can choose to allow the installer to set up each include path to you.

Q: I got a connector error for the global unique identifier (Guid) symbol duplicate or missing.

A: The various GUIDs you use should be a one-time definition and can only be defined once. If you define the InitGuid symbol with #define before inserting the DirectX header, you will insert a definition of the GUID. Therefore, you should ensure that this operation is only available for one compiler. An alternative to this method is to connect with the DXGUID.LIB library, which contains all definitions of DirectX GUID. If you use this method (suggest), you will never define the InitGuid symbol through #define.

Q: Can I point the pointer to a DirectX interface to a lower version number?

A: No. The DirectX interface belongs to the COM interface. This means that it is not required to export higher version numbers from the corresponding low version number. Therefore, the unique security method for obtaining a different interface to the DirectX object is to use the QueryInterface method for the interface. This method is part of a standard IUnknown interface, and all COM interfaces must be exported from them.

Q: Can I mix DirectX 8 components and DirectX 7 or earlier components in the same application?

A: You can mix different versions of "different components" at will, for example, you can use DirectPlay 8 and DirectDraw 7 in the same application. However, you usually do not mix different versions of the "same component" in the same application; for example, you cannot mix DirectDraw 7 and Direct3D 8 (given these actual same components, because DirectDraw has been included in DirectX 8 Direct3D ).

Q: What is the return value of the Release or AddRef method?

A: The return value will be the current reference count of the object. However, COM specification declares, you should not rely on the return value; this value is usually only available for debugging purposes. The value you observed is not expected because various other system objects may maintain a reference to the DirectX object you created. Therefore, you should not write the code that repeatedly calls Release, until the reference count is zero, because the object can be released at this time, even if another component may still be referred to it.

Q: Is the order of I release the DirectX interface?

A: There should be no problem because the COM interface is a reference count. However, in some DirectX versions, the release of the interface has some known defects. Safety, in mayik, it is recommended that you release the interface in the opposite order of creation. Q: What is the smart pointer? I want to use them?

A: The smart pointer is a C template class to encapsulate the pointer function. Especially there are some standard intelligent pointers, which are used to encapsulate COM interface pointers. These pointers automatically perform queryinterface instead of setting, and processes AddRef and Release for you. Do you use these pointers, generally personal preferences. If your code contains a lot of interface pointer replication, you can make your code more simple and easy to make your code with multiple addRefs and Releases. Otherwise, it is not necessary. Visual C contains a standard Microsoft COM smart pointer, is defined in the "Comdef.h" header file (please look up COM_PTR_T in the help).

Q: I encountered problems when debugging DirectX applications, can you prompt?

A: The most common problem when debugging the DirectX application is to try to debug when the DirectDRAW surface is locked. This situation will cause "WIN16 LOCK" on the Windows 9x system, so the debug window cannot be drawn. Specify the D3DLock_nosyslock flag when the surface is locked, usually eliminates. Windows 2000 has no problem. When developing an application, it is best to run debug version of DirectX runtime (select when installing SDK); the version performs some parameters confirmed and outputs some useful messages to the output window of the debugger.

Q: How to check the code correctly?

A: Use succeededed and failed macro. The DirectX method can return multiple success and failure code, so a simple "== D3D_OK" or similar test results are not always enough.

Q: What changes do DirectDRAW?

A: Most of DirectDraw is now included in the new Direct3D8 interface. Developers preparing a simple 2D application may wish to continue using the old DirectX 7 interface. For developers developed with some 2D elements, it is encouraged to use Direct3D alternatives (such as dot objects and bulletin textures), as this improves performance and flexibility.

Q: How do I disable ALT TAB and other task switching functions?

A: Please don't do this.

Q: Is there any book that is recommended to explain COM?

A: "Inside COM", Dale Rogerson is written, Microsoft Press is published, in which COM is well introduced. If you want to invest in detail, "Essential COM", DON Box write, longman published, this book is also worth recommending.

Q: Is there anything about general windows programming?

A: A lot. But the author believes that the recommended book is: "Programming Windows", Charles Petzold Written, Microsoft Press Publishing. "Advanced Windows", Jeffrey Richter is written, and Microsoft Press is published. 2, Direct3D

2.1 General issues

Q: Where can I find information about 3D graphics skills?

A: The standard book about this topic is "Computer Graphics: Principles and Practice", Foley, Van Dam, etc. Writing; for any person who wants to understand geometries, rasterization, and lighting skills, this is a valuable resource. . Comp.graphics.Algorithms News Group common question solution also contains useful information.

Q: Can Direct3D simulate the function of hardware not provided?

A: This should be determined according to the specific situation. Direct3D has a fully equipped vertex processing pipeline (including support for custom vertex shader). However, there is no simulation function for pixel level operations; the application must check the corresponding feature bit and use the ValidatedEvice API to determine if support.

Q: Do Direct3D contains a software rasterizer?

A: No. Direct3D now supports a plug-in software rasterizer. However, any software rasterizer is not provided by default.

Q: Direct3D geometric code uses 3DNOW! Or Pentium III SIMD Directive?

A: Use. Direct3D geometry pipes have multiple different code paths (depending on the processor type) and will use 3DNW! Or the special floating point operation provided by the Pentium III SIMD command (if these instructions are available). These include the processing of custom vertex shaders.

Q: How do I prevent transparent pixels from being written to the Z buffer?

A: You can remove the pixel by means of an alpha value above a given threshold. You control this by depicting state alphatestenable, alphaaref, and alphafunc.

Q: What is the template buffer?

A: The template buffer is an additional buffer that records each pixel information. It is very similar to a Z buffer. In fact, the buffer is still in certain bits of the Z buffer. The common template / z buffer format is 15 bits of Z and 1-bit template, or 24-bit Z and 8-bit templates. When depicting the polygon, you can make a simple arithmetic operation for each pixel. For example, the template buffer can be added or reduced, or the pixel is rejected when the template value cannot pass a simple comparison test. One zone of the frame buffer can be marked, and then only the area marked (or unregulated) is drawn, and the above operation is very useful for this type. Various volume effects is a good example, such as the amount of shadow.

Q: How do I use the template buffer to depict the amount of shadow?

A: This effect and the key to the effect of other volume template buffers are interactions between template buffers and Z buffers. Scene with shaded volume is divided into three stages. First, use the Z buffer to depict the scenes without shadows using the Z buffer. The shadow is then marked in the template buffer, as shown below. Draw the front of the shadow amount using an invisible polygon, where the z test is enabled, and the Z write is disabled, and when each pixel is tested, the template buffer is increased once. In the same way, the back of the shadow is drawn, but the template value is reduced. Now, consider a single pixel situation. Suppose the camera is not in the shadow, there are four possibilities in the scene in the scene. If the light from the camera is not intended with the amount of shadow, no shadow polygon is drawn, and the template buffer is still zero. Otherwise, if you point in front of the amount of shadow, the shadow polygon will be output Z buffer, and the template remains unchanged. If the point is below the shadow, the same multi-faceted shadow is depicted, while the template is zero, that is, the number of times the increase is as much as the number of times the reduction. The last possibility is that the point is in the shadow amount. In this case, the back of the shaded amount will be output in the Z buffer, but the front is not, so the template buffer will be non-zero. As a result, the frame buffer is located in some parts of the shadow with a non-zero template value. Finally, to actually depict the shadow, the entire scene will be charged over again by an Alpha mixed polygon, which is only affected by non-zero pixels. An example of this trick is there in the "Shadow Volume" example provided with DirectX SDK. Q: What is TEXEL (Texel) alignment rules? How can I get one by one map?

A: This is a comprehensive explanation in the DirectX 8 document (Directly Mapping Textels to Pixels). But in short, you should block the screen coordinate to -0.5 in order to correctly align with Texel. Most cards are correctly compliant, but there are some older cards or drivers. To resolve these issues, it is recommended that you prefer to get in touch with relevant hardware vendors, requested to get updated responses or their recommendations.

Q: What is the use of D3DCREATE_PUREDEVICE logo?

A: If the D3DCREATE_PUREDEVICE flag is specified when the device is created, Direct3D will create a "pure" device. This disables the method of Get * family classes, and the vertex processing is limited to hardware. This allows Direct3D to run some optimization to provide the best path to the driver without tracking that many internal states. That is, you can see a certain performance advantage when you use PUREDEVICE, but it sacrifies certain convenient conditions.

Q: How do I use color key?

A: DirectX 8 does not support color keying. You should switch to Alpha Mixing / Test, which is generally a more flexible skill, no problems related to color keying.

Q: How do I enumerate all display devices in a multi-monitor system?

A: That is the same as other enumeration functions, which has been easily repeated from the callback-based call to various methods by the application by means of the iDirect3d8 interface. Call GetAdapterCount to determine the number of display adapters in the system. Call GetAdaptermonitor to determine the physical monitor connected to the adapter (this method returns an HMonitor, you can use this value in Win32 API GetmonitorInfo to determine information about the physical monitor). Determine a specific display adapter's feature, or create a Direct 3D device on the adapter, simply passing the corresponding adapter number by replacing the D3DADAPTER_DEFAULT when calling getDeviceCaps, CreateDefaults. 2.2 Geometry (vertex) processing

Q: What changes are D3DVERTEX and so on?

A: No longer explicitly supports the type of "pre-canned". Multi-top current system allows for more flexible assembly to vertex data. If you want to use one of the "traditional" vertex format, you can create a set of FVF code.

Q: I am not clear about the traffic, how is the working principle?

A: Direct3D is assembled for each vertex from one or more vertex flow feeds. Only one vertical stream is corresponding to the old model before DirectX 8, that is, the vertex comes from a single source. With DirectX 8, different vertex components can come from different sources; for example, a vertex buffer may contain positions and normal, while the other contains color values ​​and texture coordinates.

Q: What is the vertex shader?

A: The vertex shader is a process for processing a single vertex. This is defined by a simple language similar to a compilation, compiling the D3DX utility as a Direct 3D acceptable toxic stream. The vertex shader accepts a single vertex and a set of constant values ​​input, and outputs a vertex position (in scrap space), and it is also possible to output a set of colors and texture coordinates for rasterization. Note that when you have a custom vertex shader, the vertex component will no longer have any semantics applied by Direct3D, and the vertex is just any of the data you created by the vertex shader you created.

Q: Is the vertex shader to divide or cut it?

A: No. The vertex shader outputs a pure coordinate in the scrap space of the transformed vertex position. Perspective segmentation and tailoring are automatically carried out by the coloster.

Q: Can I generate geometric graphics with a vertex shader?

A: The vertex shader cannot be created or eliminated; once it only operates a single vertex, it is used to receive an unprocessed vertex, and output a separately processed vertex. Therefore, it can be used to operate existing geometry (application deformation or appearance conversion operation), but it is actually unable to generate new geometry.

Q: Can I apply a custom vertex shader to a fixed function geometric pipeline (or perform the opposite operation)?

A: No. You must choose one of them. If you are using a custom vertex shader, you are responsible for performing the entire vertex transform operation.

Q: If my hardware does not support customized vertex shaders, can I use it?

A: Yes. The Direct3D software vertex processing engine fully supports customized vertex shaders, and the performance indicators are surprisingly high.

Q: How do I determine if the hardware supports my custom vertex shader?

A: The device that is capable of hardware support the vertex shader is required to populate the D3DCaps8 :: VertexShaderVersion field to indicate the version level of the vertex shader supported. All devices that claim to support a level shader must support all legitimate vertex shaders that meet specifications for this level or lower level. Q: How many constant registers can be used for vertex shaders?

A: The device that requires the DX8 vertex shader supports at least 96 registers. The support capabilities of the device may exceed this minimum and can be reported via the D3DCaps8 :: MaxvertexShaderConst field.

Q: Can I share location data between vertices with different texture coordinates?

A: One usual example of this situation is a cube, which you want to use a different texture for each face. Unfortunately, the answer is not possible; it is still independent independent indexes. Even the multi-top stream is also an index of all the vertices.

Q: When I submit an original language with an index, Direct3D is all the vertices in the buffer or only the vertex I have index?

A: When using the software geometry line, Direct3d first converts all the vertices in the range you submit, not "as required" to convert it according to the index. This is more efficient for intensive data (ie, most of them), especially when the SIMD instruction can be used. If your data is loose (ie, many vertices are not used), you may need to consider rearrange your data to avoid excess conversion. The vertex is often converted as needed when using hardware geometry acceleration.

Q: What is the index buffer?

A: The index buffer is extremely similar to the vertex buffer, but it is included in the index used for DrawIndexedPrimitive calls. It is highly recommended that you use the index buffer as much as possible without using the original memory allocated by the application, the truth is the same as the vertex buffer. I noticed that 32-bit index is now a support type; can I use it on all devices? No. You must check the D3DCaps8 :: MaxvertexIndex field to determine the maximum index value supported by the device. This value must be greater than 216-1 (0xFFFF) to support the D3DFMT_INDEX32 type index buffer. Also note that some devices may support 32-bit indexes, but their maximum index value is less than 232- 1 (0xfffffffff); this, the application must follow the restrictions reported by the device.

Q: What is the restriction of multiple vertices to fixed functional lines?

A: Fixed functional pipeline requires that each vertex pipeline is a strict FVF subset, which is based on a complete FVF declaration. Also note that you must follow the number of pipelines reported by the D3DCaps8 :: MaxStreams field (now many devices and / or drivers only support single-range waterline).

2.3 Performance Tuning

Q: How can I improve my performance of my Direct3D application?

A: When optimizing performance, you need to investigate the following key issues:

· Batch size

Direct3D has been optimized for large quantities. The more polygons that can be sent once, the better it is. With experience, it is recommended that more than 100 polygons are called each time. Lower than this level, you may not get the best performance, but higher than this level, the effect you receive will be reduced, and you may have conflicts with parallel matters (see the discussion below). · Status change

Changing the drawing status This action may be expensive, especially when changing the texture. Therefore, the status changes made by each frame should be as small as possible, this is important. Also, try to reduce the changes to the vertex or index buffer.

Note: Change the buffer in DirectX is not expensive as in previous versions, but it is still recommended to avoid changing the vertex buffer.

·parallel

If you can schedule a drawing and other processing, you can make full use of system performance. This goal may conflict with the target that reducing the depiction status. You need to find a balance point between the batch to reduce status changes and earlier data to the driver to achieve parallel purposes. Using multiple vertex buffers in looping, it will help parallel.

· Texture upload

Uploading the texture to the device will consume bandwidth and lead to a bandwidth with the vertex data. Therefore, it is important to take up too much memory because this will force the cache scheme to upload too much texture for each frame.

· Vertex buffer and index buffer

You should always use a vertex buffer and an index buffer instead of a normal memory block allocated by an application. The lock semantization of the vertex buffer and the index buffer can at least avoid more than the copy operation. For some drivers, the vertex buffer, and index buffers may be more ideal in some areas (probably in a video or AGP memory) for hardware access.

· State macro lock

These are launched in DirectX 7.0, providing a mechanism for a series of status changes, including lighting, material, and matrix changes), which can be reset by a single call. There are two advantages:

You have a call instead of multiple calls, thereby reducing call overhead. A driver that has a sense of ability can pre-analyze and pre-compiled status changes, making the submission speed of graphics hardware. Status changes may still be expensive, but the use of status macros will at least help reduce part of the cost.

· Use only one Direct3D device

If you need to depict multiple targets, use the setrendertarget. Use the CreateAdditionalSwapchain API if you want to create a windowing program with multiple 3D windows. Optimization of single devices at runtime, there are quite a few speed discounts when using multiple devices.

Q: What basic types I should use (strip, sector, list, etc.)?

A: Many grids encountered in real data have the characteristics of multiple polygon shared vertices. To maximize performance, it is best to reduce the repetition rate in the converted vertex, and send it across the bus to the drawing device. This is the least ideal method using a simple triangle list. This is very clear. The choice to be used is to use strips and sector (implied to hint the specific connection between the polygon) or use the index list. These are the most appropriate choices in the case where the data is naturally classified into various strips and segments, because the data sent to the driver is minimized. However, the grid decomposition strip and sector often cause a large number of separation blocks, suggesting a large number of DrawPrimitive calls. Therefore, the most efficient method is usually called a separate DrawIndexedPrimitive call with a triangular list. Another advantage of using the index list is that this is also beneficial when only a single vertex is shared in a continuous triangle. All in all, if your data is naturally classified into a variety of larger strips and segments, the strips and sector are used, otherwise the index list is used. Q: If I want to generate dynamic data, how can I use the vertex buffer?

A: The specific implementation steps.

Use the D3Dusage_Dynamic and D3Dusage_Writeonly using the flag and the D3DPool_Default buffer pool flag to create a vertex buffer. (If you are using the software vertex handling function, you have to specify D3Dusage_softwareProcessing) i = 0 setting status (texture, depiction status, etc.) Check if there is space in the buffer, i.e., iEi m <= n? (Where M is new vertices Number) If true, the VB is LOCK with D3DLOCK_NOOVERWRITE. This informs the Direct3D and drivers, you will add the vertices, and do not modify the vertices you previously batch. Therefore, if the DMA operation is being performed at the time, the operation is not interrupted. Otherwise, turn to 11 Plunate the M top Point Unlock (Unlock) call Draw [Indexed] Primitive. For unconfigured, use I as a StartVertex parameter. For the basic type of the copumed, make sure the indefinite points to the correct part of the vertex buffer (to do this, the basevertexIndex parameter using setindices) can be easier) i = m go to 3 good, space is exhausted, Let's start a new vertex buffer. We don't want to use the same vertex buffer because there is a possibility of DMA operations. Let this case inform Direct3D, and the method is to lock the "same" vertex buffer with the D3DLock_Discard flag. This means, "You can give me a new pointer, because I have used the old pointer, no longer in the expected content." I = 0 go to 4 (or 6)

2.4 Direct3DX Utility Library

Q: What file formats supported by the D3DX image file loader function?

A: The D3DX image file loader function supports BMP, TGA, PNG, JPG, DIB, PPM, and DDS files.

Q: Is there any problem with the text depiction function in D3DX? Is there any problem with my operation?

A: A common error when using the id3dxfont :: DrawText function is to specify a zero alpha component for color parameters, resulting in complete transparent (ie, invisible) text. For completely opaque text, make sure that the alpha composition of the color parameters is completely saturated (255). Q: For font depiction, should I use ID3DXFONT or SDK Framework CD3DFONT class?

A: The ID3DXFont class can handle the word spacing because it uses GDI to draw strings. This may be a bit slow because GDI is called each time. CD3DFont is designed to accelerate and use texture basic types to draw characters. It can only handle simple fonts, do not support the full set of format options available for ID3DxFont, but suitable for simple and fast display, such as frame rate count, and more. For product code, you may need to implement your own glyph drawing capabilities, namely, with texture basic types and / or GDI-based solutions (with avoidance of reanaged cache functions).

3, DirectSound

Q: Why is my application started, why do you send a net noise?

A: I noticed that other applications also have this problem. You may have a debugging DirectX run. The debug version of the runtime fills the buffer with a static noise to help developers capture the defects that are not initialized. You cannot guarantee that the DirectSound buffer is created; especially if you can't clear the buffer.

4, DirectPlay

Q: How do I make sure that my game will be able to set up a variety of network address converters and Internet connection sharing settings?

A: Network Address Translator, NAT and Internet Connection Sharing, ICS are more complex topics, and have more detailed discussion in another article on MSDN. However, the following tips can be used as a well general guidance: nats2-msdn.htm.

• Use a client-server instead of point-to-point network topology through the IDirectPlay8Client and iDirectplay8Server interface.

• Place the server on the clear Internet instead of being behind a NAT.

· Directly enumerate the game port instead of using DPNSVR.

· Do not embed the IP address or port number in your message.

For some point-to-peer games, the server is stationed later, as well as specific recommendations for ICS on a variety of Windows operating systems, please refer to more detailed documents.

Q: What is DPNSVR do?

A: DPNSVR is a forwarding service for enumerating requests, eliminating various problems caused by multiple DirectPlay applications on ports. Using DPNSVR allows DirectPlay to automatically select the port you want to use while allowing the client to enumerate your game. The default is that DirectPlay uses DPNSVR because this usually provides the application with maximum flexibility; however, you can disable it, the method specifies the DPNSession_nodpnsvr flag when you create your session. If the client uses the DPNSVR port to enumerate the host, the host uses its own port to make a response, using DPNSVR may cause the NAT problem on the client side; NAT may refuse to transfer the packet to the client. Because the packet is not from the same port from the request being sent.

Q: Idirectplay8lobbyClient :: Initialize why returns DPNERR_NOTALLOWED? A: DirectPlay does not allow each process to have more than one front-end client or application, thus trying to create multiple clients to cause returning to this error.

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

New Post(0)