General DirectX development matters

zhaozj2021-02-11  182

General DirectX development matters

Why did I get so much error message when I try to compile examples?

You may not set the include path to the correct. Many compilers (including Microsoft® Visual C ®) contain an earlier version of the SDK, so if your include path first search for a standard 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.

I have to get an error in the global unique identifier (GUID) symbol repetitive or missing connector error.

The various GUIDs you use should get 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.

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

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.

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

You can mix with 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 ).

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

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.

Do I release the order of the DirectX interface?

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.

What is the smart pointer, do I use them?

The smart pointer is a C template class to encapsulate pointer functions. 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). I have problems when I debug DirectX app, can you prompt?

The most common problem when debugging DirectX applications is to try to debug when the DirectDraw surface is locked. This situation will cause "WIN16 LOCK" on the Microsoft Windows® 9x system, so the debug window cannot be drawn. Specify the D3DLock_nosyslock flag when locking the surface, 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.

How to check the return code correctly?

Use succeeded 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.

What changes do DirectDRAW?

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.

How do I disable Alt Tab and other task switching functions?

Please don't do this.

Is there anything worth recommending to explain COM?

Inside COM ("COM Insider"), Dale Rogerson, Microsoft Press, which is a good introduction to COM. To examine COM, Essential COM ("COM Delicization"), DON BOX, Longman published, this book is also recommended.

Is there any book about general windows programming?

a lot of. But the author believes that the recommended book is:

Programming Windows ("Windows Programming"), Charles Petzold (Microsoft Press) Advanced Windows ("Windows Advanced"), Jeffrey Richter (Microsoft Press)

Direct3D

General problem

Where can I find information about 3D graphic skills?

The standard book about this subject is Computer Graphics: Principles and Practice ("Computer Graphics: Principle and Practice"), Foley, Van Dam is waiting; for anyone who wants to understand geometries, rasterization, and lighting skills, this It is a valuable resource. Comp.Graphics.Algorithms News Group FAQ ("Frequently Asked Questions") also contains useful information. Can Direct3D simulate hardware not provided?

This is dependent on 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 cap position and use the ValidateDevice API to determine if support.

Direct3D contains a software rasterizer?

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

DIRECT3D Geometry code uses a 3DNOW! And / or PENTIUM III SIMD instruction?

use. Direct3D geometry has multiple different code paths (depending on the processor type) and will use the special floating point operations provided by the 3DNOW! Or Pentium III SIMD instruction (if these instructions are available). These include the processing of custom vertex shaders.

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

You can use Alpha values ​​that are above or below a given threshold to remove pixels. You control this by depicting state alphatestenable, alphaaref, and alphafunc.

What is the template buffer?

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.

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

This effect and the key to other volume template buffers are the interaction between the template buffer and the z buffer. 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. What is TEXEL (Texel) alignment rules? How can I get one by one map?

This is a comprehensive explanation in the DirectX 8 document (in the article title 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.

What is the use of D3DCREATE_PUREDEVICE?

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.

How do I use color key?

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.

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

Similarly to other enumeration functions, this function has been easily repeated from the callback based on the application by means of the application of the IDirect 3D8 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.

Geometric (vertex) processing

What changes do D3DVERTEX and so on?

No longer explicitly supports the "pre-canned" vertex type. 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.

I don't know much about the vertices. What is the working principle?

Direct3D assembles 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.

What is the vertex shader?

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. Is the vertex shader to divide or cut?

Do not. 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.

Can I generate geometric graphics with a vertex shader?

The vertex shader cannot be created or eliminated at a single operation, that is, an unprocessed vertex is received as an input, and outputs 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.

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

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.

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

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

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

The device capable of hardware supporting vertex shaders is required to populate the D3DCaps8 :: VertexShaderversion field to indicate the version level of the vertex shader that it supports. All devices that claim to support a level shader must support all legitimate vertex shaders that meet specifications for this level or lower level.

How many constant registers can be used for vertex shaders?

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

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

One of the usual examples 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.

When I submit an original language with an index, Direct3D is to process all the vertices in the buffer or only the vertices I have indexed?

When using the software geometry pipeline, Direct3d first converts all the apections 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.

What is the index buffer?

The index buffer is extremely similar to the vertex buffer, but it contains an index 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 the maximum index value supported is less than 232-1 (0xfffffffff); so that the application must follow the restrictions reported by the device. What are the restrictions on the multi-top stream for fixed functional pipeline?

The 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).

Performance tuning

How can I improve my performance of my Direct3D application?

When optimizing performance, you need to examine 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: Change 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 8 is not as expensive as in previous versions, but it is still recommended to avoid changing the vertex buffer. Parallel: If you can arrange the 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 consumes bandwidth and leads to the bandwidth of 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. The vertex buffer and index buffer: You should always use the vertex buffer and index buffer instead of the common memory block allocated by the 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. Status Macro Lock: These are launched in DX 7.0, which provides a mechanism to record a series of state changes (including lighting, material and matrix changes) into a macro, the macro can then play back 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 a single 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.

What basic types I should use (strip, sector, list, etc.)? 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.

If I want to generate dynamic data, how can I use the vertex buffer?

Use D3Dusage_Dynamic and D3Dusage_Writeonly to create a vertex buffer using the flag and the D3DPool_Default buffer pool flag. (If you are using the software vertex handling function, you have to specify D3Dusage_softwareProcessing.) I = 0. Set status (texture, depiction status, etc.). Check if there is space in the buffer, ie I.E.I m <= n? (Where m is the number of new vertices). If true, the VB is lock to the VB 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. Fill the M top points at i. UNLOCK. Call DRAW [Indexed] Primitive. For unconfigured, use I as a StartVertex parameter. For a copumed basic type, make sure the index refers to the correct part of the vertex buffer (to do this, the basevertexIndex parameter that uses setIndices) may be easier). I = M. Go to 3. Ok, the space is exhausted, let us start a new vertex buffer. We don't want to use the same vertex buffer because there is a possibility of DMA operations. We inform Direct3D this case, and the method is locked with 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 meaning of the content." I = 0. Go to 4 (or 6).

Direct3DX Utility Library

What file formats supported by D3DX image file loader functions?

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

The text drawing function in D3DX seems to be invalid, is there any problem with my operation?

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). For font depiction, should I use ID3DXFONT or SDK Framework CD3DFONT class?

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).

DirectSound

Why is my app started when I started a net noise? 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.

DirectPlay

How do I make sure my game will be able to set up normal work with a variety of NetWork Address Translator (Network Address Converter, NAT), and Internet Connection Sharing (ICS)?

NAT and ICS are more complex topics that have more detailed discussion in another article on MSDN. However, the following tips can be used as a good general guidance:

With the IDirectplay8Client and iDirectplay8 Server interface, use a client-server instead of point-to-peer network topology. Place the server on the clear Internet instead of being behind a NAT. Enumerate the game port directly, not using DPNSVR. Don't 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.

What is the DPNSVR use?

DPNSVR is a forwarding service for enumerating requests, eliminating various issues caused by multiple DirectPlay applications on conflicts in port use. 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 maximum flexibility for the application; however, you can disable it, the method specifies the DPNSession_nodpnsvr flag when creating 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.

IdirectPlay8lobbyClient :: Initialize why returns DPNERR_NOTALLOWED?

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-5472.html

New Post(0)