DirectX FAQ 翻译(Graphics 部分)

巡山小妖精
904次浏览
2020年07月30日 17:11
最佳经验
本文由作者推荐

捐赠英文-将什么求

s Windows 98 drivers.
对当前硬件更好的支持-大多数比Windows98驱动用的更久
Improved memory management - which results in better stability and security.
改进内存管理-提供更高的稳定性和安全性
Improved NTFS file system - which is more resistant to failure, and has better performance with security features.
改进NTFS文件系统-提供更好的容错性,保证安全的同时提供更高的性能
Should game developers still be publishing games for Windows 2000?游戏开发者仍然需要在Windows 2000上编程吗?

Not anymore. In addition to the reasons listed in Should game developers still be publishing games for Windows 95, Windows 98 or Windows ME?, Windows 2000 does not have these features:

不需要。作为对上个问题的补充,Windows 2000不支持这些特性:

Windows XP supports advanced processor features such as Hyper-Threading, Multi-Core and x64.
XP支持高级处理器特性比如超线程,多内核和64位程序
Windows XP supports side-by-side components which significantly reduces application versioning conflicts.
XP支持并行组件技术,能够有效减少程序版本冲突
Windows XP supports no-execute memory protection which helps prevent malicious programs and can aid debugging.
XP支持未执行程序保护,这能够阻止恶意程序访问和辅助调试
Windows XP has improved support for advanced AGP and PCI Express based video cards.
XP改进了对使用高级AGP和PCIE显卡的支持
Windows XP supports fast user switching, remote desktop and remote assistance which can help lower product support costs.
XP支持快速用户切换,远程桌面和远程帮助,这能够帮助降低产品支持消耗
Performance tools like Reference (in the DirectX Developer SDK) no longer support Windows 2000.
2000不再支持类似于PIX,PIXWIN之类的性能工具
In short, Windows 2000 was never designed or marketed as a consumer operating system.

简而言之,Windows 2000不再作为个人用户操作系统而设计和销售。

I think I have found a driver bug, what do I do?我想我找到了一个驱动Bug,应该怎么办?

First, ensure you have checked the results with the Reference Rasterizer. Then check the results with the latest WHQL certified version of the IHVs driver. You can programmatically check the WHQL status using the GetAdapterIdentifier() method on the IDirect3D9 interface passing the D3DENUM_WHQL_LEVEL flag. With a WHQL certified driver issue, send a description of the bug, the output from dxdiag and a repro case to directx@ with a note in the subject line "WHQL Driver Bug".

首先,使用参考光栅化程序检查你的结果,然后检查最后一次由WHQL(Windows Hardware Quality Labs,视窗硬件质量实验室)认证的IHVs(Independent Hardware Vendors,独立硬件开发商)驱动运行结果。你可以在程序中使用DX9的GetAdapterIdentifier()函
数并传入D3DENUM_WHQL_LEVEL 标记检查WHQL状态。发送WHQL认证的驱动,bug的描述、dx窗口的输出和重现bug的例子到 directx@,题目标为"WHQL Driver Bug"。

Why do I get so many error messages when I try to compile the samples?为什么我在编译sample的时候有这么多的错误信息?

You probably don't have your include path set correctly. Many compilers, including Microsoft Visual C++, include an earlier version of the SDK, so if your include path searches the standard compiler include directories first, you'll get incorrect versions of the header files. To remedy this issue, make sure the include path and library paths are set to search the Microsoft DirectX include and library paths first. See also the file in the SDK. If you install the DirectX SDK and you are using Visual C++, the installer can optionally set up the include paths for you.

你可能没有正确设定你的include路径。许多编译器,包括MS VC++在内,设定了早期版本的SDK路径,所以如果你的include路径在标准编译器从前设定的路径下搜寻,你会得到版本不正确的头文件。为了解决这个问题,必须首先保证include路径和lib路径设置到当前的DX SDK include 目录和lib目录。你可以参考SDK中的文件。如果你安装了DX SDK并在使用VC++,安装程序会可选择的为你设定include路径。

I get linker errors about multiple or missing symbols for globally unique identifiers (GUIDs), what do I do?我(在编译过程中)产生一个找不到全局一致标记符(GUIDs)定义的错误,应该怎么办?

The various GUIDs you use should be defined once and only once. The definition for the GUID will be inserted if you #define the INITGUID symbol before including the DirectX header files. Therefore, you should make sure that this only occurs for one compilation unit. An alternative to this method is to link with the library, which contains definitions for all of the DirectX GUIDs. If you use this method (which is recommended), then you should never #define the INITGUID symbol.

你使用的大量的GUIDs必须并且只能定义一次。如果你在include DX头文件之前使用#define定义了宏INITGUID,对GUID的定义会被插入到你的程序中。但是你必须保证在一次编译中这个定义只出现一次。另一个办法是在程序中链接 库文件,这个文件包含所有的DX GUIDs的定义。如果你使用这个(我们推荐的)方法,你就不需要使用 #define INITGUID了。

Can I cast a pointer to a DirectX interface to a lower version number?我能够使用低版本号的DX接口指针吗?

No. DirectX interfaces are COM interfaces. This means that there is no requirement for higher numbered interfaces to be derived from corresponding lower numbered ones. Therefore, the only safe way to obtain a different interface to a DirectX object is
to use the QueryInterface method of the interface. This method is part of the standard IUnknown interface, from which all COM interfaces must derive.

不行。DX接口是COM接口,这意味着高版本的接口不是从低版本接口上派生得到。使用不同版本接口唯一安全的办法是使用该接口QueryInterface函数。这个函数是标准IUnknown接口的一部分,所有的COM接口都从IUnknown派生。

Can I mix the use of DirectX 9 components and DirectX 8 or earlier components within the same application?我能够在相同的程序中混合使用DX9组件和DX8(或者更早版本的)组件吗?

You can freely mix different components of differing version; for example, you could use DirectInput 8 with Direct3D 9 in the same application. However, you generally cannot mix different versions of the same component within the same application; for example, you cannot mix DirectDraw 7 with Direct3D 9 (since these are effectively the same component as DirectDraw has been subsumed into Direct3D as of DirectX 8). There are exceptions, however, such as the use of Direct3D 9 and Direct3D 10 together in the same application, which is allowed.

你能够自由混合使用不同版本的DX组件。举个例子说,你能够在同一个程序中使用DirectInput8和D3D9。当然,你不能在同一程序中使用不同版本的相同组件。比如你不能混合使用DirectDraw7和Direct3D9(因为DirectDraw从DirectX8起成为Direct3D的一部分)。当然也有例外,比如在程序中允许同时使用Direct3D9和Direct3D10。

Can I mix the use of Direct3D 9 and Direct3D 10 within the same application?我能够在同一程序中混合使用Direct3D9和Direct3D10吗?

Yes, you may use these versions of Direct3D together in the same application.

是的,猪头,我刚才说过了。

What do the return values from the Release or AddRef methods mean?Release函数和AddRef函数的返回值是什么意思?

The return value will be the current reference count of the object. However, the COM specification states that you should not rely on this and the value is generally only available for debugging purposes. The values you observe may be unexpected since various other system objects may be holding references to the DirectX objects you create. For this reason, you should not write code that repeatedly calls Release until the reference count is zero, as the object may then be freed even though another component may still be referencing it.

返回值是当前对象的reference数量。当然,COM组件定义中说你不需要用到它,这个值通常用作调试。你看到的值可能不是你所期望的,因为大量的其他系统对象会保存你创建的DirectX对象的reference。因为如此,你不能在程序中重复调用Release()知道它的返回值为0,否则这个对象会被真正释放,而同时还有其他组件保存有它的reference(要使用它)。

Does
it matter in which order I release DirectX interfaces?我释放DirectX接口的顺序重要吗?

It shouldn't matter because COM interfaces are reference counted. However, there are some known bugs with the release order of interfaces in some versions of DirectX. For safety, you are advised to release interfaces in reverse creation order when possible.

没关系,因为COM接口有reference的计数。当然,在一些版本的DirectX中有一些和释放顺序相关的已知的Bug,为了安全,你最好尽可能的使用和创建接口相反的顺序来释放。

What is a smart pointer and should I use it?什么是smart pointer(智能指针),我必须用它吗?

A smart pointer is a C++ template class designed to encapsulate pointer functionality. In particular, there are standard smart pointer classes designed to encapsulate COM interface pointers. These pointers automatically perform QueryInterface instead of a cast and they handle AddRef and Release for you. Whether you should use them is largely a matter of taste. If your code contains lots of copying of interface pointers, with multiple AddRefs and Releases, then smart pointers can probably make your code neater and less error prone. Otherwise, you can do without them. Visual C++ includes a standard Microsoft COM smart pointer, defined in the "comdef.h" header file (look up com_ptr_t in the help).

智能指针是一个C++模板类,设计为封装指针的功能。通常情况下,我们有专门封装COM接口指针的的标准智能指针类。这些指针自动执行QueryInterface函数,不需要做类型转换。它们也会为为你执行AddRef和Release函数。你是否使用只能只能完全看你个人喜好。如果你的代码里包含大量的接口指针拷贝,同时还有多种AddRef和Release操作,使用智能指针能够使你的代码更简洁和减少出错。当然你也可以不用它们。VC++包含一个标准MS COM只能指针类,在文件”comdef.h”中定义(在help中查找com_ptr_t)

I have trouble debugging my DirectX application, any tips?我在调试DirectX程序时有问题,有什么建议吗?

The most common problem with debugging DirectX applications is attempting to debug while a DirectDraw surface is locked. This situation can cause a "Win16 Lock" on Microsoft Windows 9x systems, which prevents the debugger window from painting. Specifying the D3DLOCK_NOSYSLOCK flag when locking the surface can usually eliminate this. Windows 2000 does not suffer from this problem. When developing an application, it is useful to be running with the debugging version of the DirectX runtime (selected when you install the SDK), which performs some parameter validation and outputs useful messages to the debugger output.

调试DX程序时最常见的问题就是在DirectDraw surface被锁定的时候尝试调试。这种情况会导致MS Win 9x系统产生一个“Win16 Lock”的错误,阻止调试器窗口绘制。
caching symbol files.

c:cache代表cache文件的本地路径。

Direct3D Questions
D3D问题

General Direct3D Questions
Geometry (Vertex) Processing
Performance Tuning
D3DX Utility Library
General Direct3D Questions一般D3D问题

Where can I find information about 3D graphics techniques?
我怎么样才能找到3D图形技术的信息?

The standard book on the subject is Computer Graphics: Principles and Practice by Foley, Van Dam et al. It is a valuable resource for anyone wanting to understand the mathematical foundations of geometry, rasterization and lighting techniques. The FAQ for the thms Usenet group also contains useful material.

这个方面的标准参考书是:《计算机图形学:原理与实践》作者Foley,Van Dam等。对于希望理解图形学几何,光栅化和光照技术的数学基础的人来说,这是本有价值的书。thms Usenet组的FAQ也有很多有用的信息。

Does Direct3D emulate functionality not provided by hardware?
硬件不提供D3D的模拟功能?

It depends. Direct3D has a fully featured software vertex-processing pipeline (including support for custom vertex shaders). However, no emulation is provided for pixel level operations; applications must check the appropriate caps bits and use the ValidateDevice API to determine support.

D3D模拟功能依赖于硬件。D3D有着完整的软件顶点处理流水线(包括处理用户的VS)。当然,像素操作没有提供模拟功能;应用程序必须使用ValidateDevice检查合适的Caps位,判断是不是支持像素操作。

Is there a software rasterizer included with Direct3D?
D3D中做软件光栅化吗?

Not for performance applications. A reference rasterizer is supplied for driver validation but the implementation is designed for accuracy and not performance. Direct3D does support plug-in software rasterizers.

对性能要求高的程序不做软件光栅化。D3D提供参考光栅化作为驱动的参照,但它的设计是为了精确性而不是为了性能。D3D支持软件光栅化插件。

How can I perform color keying with DirectX graphics?
在DX中怎么做颜色索引?

Color keying is not directly supported, instead you will have to use alpha blending to emulate color keying. The D3DXCreateTextureFromFileEx() function can be used to facilitate this. This function accepts a key color parameter and will replace all pixels from the source image containing the specified color with transparent black pixels in the created texture.

颜色索引并没有直接被支持,但是你可以使用alpha混合来模拟颜色索引。D3DXCreateTextureFromFileEx()函数也可以协助实现这个功能。这个函数接受一个颜色索引参数并在创建的纹理中把所有源图像中和颜色索引相同的像素替换程黑色。

Does the Direct3D geometry code utilize 3DNow! and/or Pentium III SIMD instructions?
D
3D几何代码使用了3DNow!或者奔三SIMD指令吗?

Yes. The Direct3D geometry pipeline has several different code paths, depending on the processor type, and it will utilize the special floating-point operations provided by the 3DNow! or Pentium III SIMD instructions where these are available. This includes processing of custom vertex shaders.

是的。D3D几何流水线有依赖于处理器类型的几个不同的代码路径,如果可以的话,它会使用3D Now!或者奔三提供的特殊的SIMD浮点处理指令,包括执行用户的VS在内。

How do I prevent transparent pixels being written to the z-buffer?
我怎么样阻止透明像素写到z缓存中?

You can filter out pixels with an alpha value above or below a given threshold. You control this behavior by using the renderstates ALPHATESTENABLE, ALPHAREF and ALPHAFUNC.

你可以通过设置一个超过阀值的Alpha值滤除像素,这需要设置绘制状态ALPHATESTENABLE, ALPHAREF和ALPHAFUNC来控制。

What is a stencil buffer?
什么是模板缓存?

A stencil buffer is an additional buffer of per-pixel information, much like a z-buffer. In fact, it resides in some of the bits of a z-buffer. Common stencil/z-buffer formats are 15-bit z and 1-bit stencil, or 24-bit z and 8-bit stencil. It is possible to perform simple arithmetic operations on the contents of the stencil buffer on a per-pixel basis as polygons are rendered. For example, the stencil buffer can be incremented or decremented, or the pixel can be rejected if the stencil value fails a simple comparison test. This is useful for effects that involve marking out a region of the frame buffer and then performing rendering only the marked (or unmarked) region. Good examples are volumetric effects like shadow volumes.

模板缓存是一个保存逐像素信息的附加缓存,和Z缓存非常类似。实际上,它使用Z缓存的一些比特位来实现。普通的S/Z缓存格式是15位Z值和1位S值,或者24位Z值和8位S值。在绘制多边形时可以对模板缓存中的数组做逐像素的简单算术操作。比如说模板缓存可以递增或者递减,或者在模板测试失败的时候剔除像素。这样操作可以标记屏幕上一块区域然后值绘制标记好的区域。使用模板缓存最好的例子是Shadow Volumes算法。

How do I use a stencil buffer to render shadow volumes?
我怎么样使用模板缓存来绘制Shadow Volume?

The key to this and other volumetric stencil buffer effects, is the interaction between the stencil buffer and the z-buffer. A scene with a shadow volume is rendered in three stages. First, the scene without the shadow is rendered as usual, using the z-buffer. Next, the shadow is marked out in the stencil buffer as follows. The front faces of the shadow volume are drawn using invisible polygons, with z-testing enabled but z-writes disabled and the stencil buffer incremented at every pixel passing the z-test.
The back faces of the shadow volume are rendered similarly, but decrementing the stencil value instead.

这个问题和其他体素模板缓存效果的关键是如何让模板缓存和Z缓存做交互。使用Shadow Volume绘制场景分三步。首先,打开Z缓存使用无阴影方式绘制一次。接下来使用这样的手段标记阴影:绘制不可见的Shadow Volume的正面,打开Z测试关闭Z写入,模板缓存在每个像素通过z测试时加1。Shadow Volume的背面使用同样方法绘制,只是在通过z测试时减1。

Now, consider a single pixel. Assuming the camera is not in the shadow volume there are four possibilities for the corresponding point in the scene. If the ray from the camera to the point does not intersect the shadow volume, then no shadow polygons will have been drawn there and the stencil buffer is still zero. Otherwise, if the point lies in front of the shadow volume the shadow polygons will be z-buffered out and the stencil again remains unchanged. If the points lies behind the shadow volume then the same number of front shadow faces as back faces will have been rendered and the stencil will be zero, having been incremented as many times as decremented.

现在考虑单个像素。假设相机不在Shadow Volume中,对于场景中的点有四种可能。如果相机发出的光线没有和Shadow Volume相交,那么没有多边形被画到这个像素上,模板缓存值位0。如果点在Shadow Volume之前,那么在绘制Shadow Volume时它不会通过z测试,因此模板缓存保持为0。如果点在Shadow Volume之后,那么模板缓存递增的次数和递减的次数相同,因此模板缓存值还是0。

The final possibility is that the point lies inside the shadow volume. In this case the back face of the shadow volume will be z-buffered out, but not the front face, so the stencil buffer will be a non-zero value. The result is portions of the frame buffer lying in shadow have non-zero stencil value. Finally, to actually render the shadow, the whole scene is washed over with an alpha-blended polygon set to only affect pixels with non-zero stencil value. An example of this technique can been seen in the "Shadow Volume" sample that comes with the DirectX SDK.

最后一种可能是在Shadow Volume中的像素点。在这种情况下背面Shadow Volume不通过z测试而正面通过,所以模板缓存是一个非0的值。这样的结果就是模板缓存不为0的像素处于阴影中。最后,实际绘制阴影,整个场景用Alpha混合只对阴影中的区域绘制多边形。这种技术的一个例子参见DX SDK中的Shadow Volume sample程序。

What are the texel alignment rules? How do I get a one-to-one mapping?
什么是纹理对齐规则?我们怎么得到1比1采样?

This is explained fully in the Direct3D 9 documentation. However, the executive summary is that you should bias your screen coordinates by -0.5 of a pixel in order to alig
n properly with texels. Most cards now conform properly to the texel alignment rules, however there are some older cards or drivers that do not. To handle these cases, the best advice is to contact the hardware vendor in question and request updated drivers or their suggested workaround. Note that in Direct3D 10, this rule no longer holds.

这在D3D9的文档中已经完全解释过了。在执行的细节上,你需要注意把你的屏幕坐标向左偏移0.5以完成像素的对齐。大部分显卡现在都支持纹元对齐规则,但是一些老的卡没有支持。对于这种情况,你最好和硬件制造商联系,要求更新驱动或者按照他们的建议设置工作环境。注意在D3D10中,这种规则已经不存在了。

What is the purpose of the D3DCREATE_PUREDEVICE flag?
D3DCREATE_PUREDEVICE标记的作用是什么?

Use the D3DCREATE_PUREDEVICE flag during device creation to create a pure device. A pure device does not save the current state (during state changes), which often improves performance; this device also requires hardware vertex processing. A pure device is typically used when development and debugging are completed, and you want to achieve the best performance.

在创建设备过程中使用D3DCREATE_PUREDEVICE标记来创建纯设备。纯设备并(在状态切换时)不保存当前状态,这样能提高性能。这种设备同时也需求硬件顶点处理。纯设备在调试和开发结束后使用,用作或者最好性能。

One drawback of a pure device is that it does not support all Get* API calls; this means you can not use a pure device to query the pipeline state. This makes it more difficult to debug while running an application. Below is a list of all the methods that are disabled by a pure device.

纯设备的缺点是它不支持Get*API() 调用,这意味着你不能够使用纯设备来查询设备状态。在运行调试程序时,这会比一般设备更困难。下面是在使用纯设备是不能调用的函数:

ID3D10Device9::GetClipPlane
ID3D10Device9::GetClipStatus
ID3D10Device9::GetLight
ID3D10Device9::GetLightEnable
ID3D10Device9::GetMaterial
ID3D10Device9::GetPixelShaderConstantF
ID3D10Device9::GetPixelShaderConstantI
ID3D10Device9::GetPixelShaderConstantB
ID3D10Device9::GetRenderState
ID3D10Device9::GetSamplerState
ID3D10Device9::GetTextureStageState
ID3D10Device9::GetTransform
ID3D10Device9::GetVertexShaderConstantF
ID3D10Device9::GetVertexShaderConstantI
ID3D10Device9::GetVertexShaderConstantB
A second drawback of a pure device is that it does not filter any redundant state changes. When using a pure device, your application should reduce the number of state changes in the render loop to a minimum; this may include filtering state changes to make sure that states do not get set more than once. This trade-off is application dependent; if you use more than a 1000 Set calls per frame, you should consider taking adv

What happened to Fixed Function Bumpmapping in D3D9?
D3D9中固定管线的Bumpmapping做了什么?

As of Direct3D 9 we tightened the validation on cards that could only support > 2 simultaneous textures. Certain older cards only have 3 texture stages available when you use a specific alpha modulate operation. The most common usage that people use the 3 stages for is emboss bumpmapping, and you can still do this with D3D9,

在D3D9中我们严格定义了一块显卡必须能够支持同时采样2张以上纹理。一般老的卡当你打开Alpha乘操作时最多只有3个纹理阶段。最普通的使用3个纹理阶段的操作就是凹凸贴图,在D3D9中你仍然能够这样做。

The height field has to be stored in the alpha channel and is used to modulate the lights contribution i.e.:

高度场被保存在Alpha通道中,被用作和光照效果叠加,如下:

// Stage 0 is the base texture, with the height map in the alpha channel
m_pd3dDevice->SetTexture(0, m_pEmbossTexture );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0 );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
if( m_bShowEmbossMethod )
{
// Stage 1 passes through the RGB channels (SELECTARG2 = CURRENT), and
// does a signed add with the inverted alpha channel.
// The texture coords associated with Stage 1 are the shifted ones, so
// the result is:
// (height - shifted_height) * *
m_pd3dDevice->SetTexture( 1, m_pEmbossTexture );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG2 );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_ADDSIGNED );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE|D3DTA_COMPLEMENT );
m_pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );

// Set up the alpha blender to multiply the alpha channel
// (monochrome emboss) with the src color (lighted texture)
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );
}
This sample, along with other older samples, are no longer shipped in the current SDK release, and will not be shipped in future SDK releases.

这个sample和其他更老的一些sample一样不会出现在当前的SDK中,也不会在将来发布的SDK中出现


Geometry (Vertex) Processing几何(顶点)处理问题
Vertex streams confuse me how do they work?
顶点流数据让我觉得有些糊涂,它们是怎么工作的?

Direct3D assembles each vertex that is fed into the processing portion of the pipeline from one or more vertex streams. Having only one vertex stream corresponds to the old pre-DirectX 8 model, in which vertices come from a single source. With DirectX 8, different vertex components can come from different sources; for example, one vertex buffer could hold positions and normals, while a second held color values and texture coordinates.

D3D把管线中同时操作的多个数据流中的不同数据集中到一起放在同一个数据流中。只使用一个数据流和老的DX8之前的模型相对应,这样顶点就只源自同一个数据流。举个例子,一个顶点缓存可能保存位置和法向而另一个保存颜色和纹理坐标。

What is a vertex shader?
什么是顶点渲染器?

A vertex shader is a procedure for processing a single vertex. It is defined using a simple assembly-like language that is assembled by the D3DX utility library into a token stream that Direct3D accepts. The vertex shader takes as input a single vertex and a set of constant values; it outputs a vertex position (in clip-space) and optionally a set of colors and texture coordinates, which are used in rasterization. Notice that when you have a custom vertex shader, the vertex components no longer have any semantics applied to them by Direct3D and vertices are simply arbitrary data that is interpreted by the vertex shader you create.

顶点渲染器(VS)是处理单个顶点的过程。它使用类汇编的语言定义,可以被D3DX使用库编译为D3D接受的符号流数据。VS把单个顶点和一系列常数作为输入,输出顶点位置(在裁减空间中的)和可选的一系列颜色和纹理坐标,在光栅化时被使用。注意当你使用自己定义的VS时,顶点数据就不再具备D3D定义的语法属性,只是作为你创建的VS的单纯数据来解析。

Does a vertex shader perform perspective division or clipping?
VS做透视除法和裁减吗?

No. The vertex shader outputs a homogenous coordinate in clip-space for the transformed vertex position. Perspective division and clipping is performed automatically post-shader.

不。VS输出裁减空间中变换后齐次坐标。透视除法和裁减在VS之后被自动执行。(嘿嘿,现在未必这样了^_^)

Can I generate geometry with a vertex shader?
我能用VS创建几何吗?

A vertex shader cannot create or destroy vertices; it operates on a single vertex at a time, taking one unprocessed vertex as input and outputting a single processed vertex. It can therefore be used to manipulate existing geometry (applying deformations, or performing skinning operations) but cannot actually generate new geometry per se.

VS不能够创建或者删除
it an indexed list of primitives, does Direct3D process all of the vertices in the buffer, or just the ones I indexed?
当我提交了图元的索引列表后,D3D会处理缓存中所有顶点吗,还是只处理我的索引列表里的?

When using the software geometry pipeline, Direct3D first transforms all of the vertices in the range you submitted, rather than transforming them "on demand" as they are indexed. For densely packed data (that is, where most of the vertices are used) this is more efficient, particularly when SIMD instructions are available. If your data is sparsely packed (that is, many vertices are not used) then you may want to consider rearranging your data to avoid too many redundant transformations. When using the hardware geometry acceleration, vertices are typically transformed on demand as they are required.

当你使用软件几何处理流水线时,D3D首先处理你提交的所有顶点,而不是按照它们在索引列表里的顺序操作。对于密集打包的数据(就是大部分顶点被使用的缓存)这会更高效,部分因为SIMD指令在处理它们。如果你的数据被分散打包(许多数据没有被使用),你可以考虑重新安排数据以避免太多的冗余变换。当使用够硬件几何加速时,硬件只会处理你要求变换的数据。

What is an index buffer?
什么是索引缓存?

An index buffer is exactly analogous to a vertex buffer, but instead it contains indices for use in DrawIndexedPrimitive calls. It is highly recommended that you use index buffers rather than raw application-allocated memory when possible, for the same reasons as vertex buffers.

索引缓存和顶点缓存类似,但是它保存的是DrawIndexedPrimitive调用需要的索引数据。我们强烈推荐你尽可能使用使用索引缓存而不是直接程序分配内存,同样也推荐使用顶点缓存。

I notice that 32-bit indices are a supported type; can I use them on all devices?
我注意到32位索引是D3D支持的类型,我能够用吗?

No. You must check the D3DCAPS9::MaxVertexIndex field to determine the maximum index value that is supported by the device. This value must be greater than 2 to the 16th power -1 (0xffff) in order for index buffers of type D3DFMT_INDEX32 to be supported. In addition, note that some devices may support 32-bit indices but support a maximum index value less than 2 to the 32nd power -1 (0xffffffff); in this case the application must respect the limit reported by the device.

不,你必须首先检查D3DCAPS9::MaxVertexIndex域确定设备支持的最大的索引值。这个值必须大于2^16-1才能真正支持D3DFMT_INDEX32。同时还要注意有些设备支持32位索引但是它的最大索引不是 2^32 -1。在这种情况下程序必须遵循设备的限制。

Does S/W vertex processing support 64 bit?
软件顶点处理支持64位操作吗?

There is an optimized s/w vertex pipeline for x6
多顶点缓存轮流操作能够促进并行性。

Texture uploads
纹理上传

Uploading textures to the device consumes bandwidth and causes a bandwidth competition with vertex data. Therefore, it is important to not to over commit texture memory, which would force your caching scheme to upload excessive quantities of textures each frame.

上传纹理到设备上会消耗带宽并引起和顶点数据的带宽冲突。同时还要注意纹理不要超过纹理内存大小,否则你的高速缓存机制会被强迫每帧上传大量的纹理数据。

Vertex and index buffers
顶点缓存和索引缓存

You should always use vertex and index buffers, rather than plain blocks of application allocated memory. At a minimum, the locking semantics for vertex and index buffers can avoid a redundant copy operation. With some drivers, the vertex or index buffer may be placed in more optimal memory (perhaps in video or AGP memory) for access by the hardware.

你应该尽量使用顶点和索引缓存而不是完全由程序分配内存,因为至少顶点(索引)缓存的锁定机制能够避免冗余的拷贝操作。在一些驱动中,顶点(索引)缓存会被放到更优化的内存中(可能是在显存或者AGP内存中)被硬件读取。

State macro blocks
状态宏模块

These were introduced in DirectX 7.0. They provide a mechanism for recording a series of state changes (including lighting, material and matrix changes) into a macro, which can then be replayed by a single call. This has two advantages:

这是在DX7中引入的概念。它提供了一个机制记录一系列状态改动(包括光照,材质和矩阵改变)到宏中,并且能用一个函数调用重现。它由两个优点:

You reduce the call overhead by making one call instead of many.
减少了函数调用次数
An aware driver can pre-parse and pre-compile the state changes, making it much faster to submit to the graphics hardware.
驱动能够预解析和编译状态改动,使之对硬件效率更高
State changes can still be expensive, but using state macros can help reduce at least some of the cost. Use only a single Direct3D device. If you need to render to multiple targets, use SetRenderTarget. If you are creating a windowed application with multiple 3D windows, use the CreateAdditionalSwapChain API. The runtime is optimized for a single device and there is a considerable speed penalty for using multiple devices.

状态改动仍然是耗时的,但是使用状态宏能够帮助你降低一些代价。尽量使用一个D3D设备,如果你需要绘制到多个对象上就使用SetRenderTarget函数来切换对象。如果你要创建一个拥有多个3D窗口的Windows窗口程序,使用CreateAdditionalSwapChain函数即可完成。对单个设备运行时间会有优化,而使用多个设备还会降低单个运行速度。

Which primitive types (strips, fans, lists and so on) should I use?
多少显存来分配资源并不是一个好主意。举个例子说,如果你的卡使用统一内存架构(UMA)或者能够压缩纹理,它的显存是多少?它会比你想像的多的多。你应该创建资源并判断它有没有返回“超出内存”错误,然后减少纹理大小,比如移除最高层的Mipmap。

What's a good usage pattern for vertex buffers if I'm generating dynamic data?
创建动态数据时,应该按怎么样的模式操作?

Create a vertex buffer using the D3DUSAGE_DYNAMIC and D3DUSAGE_WRITEONLY usage flags and the D3DPOOL_DEFAULT pool flag. (Also specify D3DUSAGE_SOFTWAREPROCESSING if you are using software vertex processing.)
使用D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY和D3DPOOL_DEFAULT创建顶点缓存(如果使用软件顶点缓存的话使用D3DUSAGE_SOFTWAREPROCESSING)

I = 0.
Set state (textures, renderstates and so on).
检查状态(纹理状态,绘制状态等等)

Check if there is space in the buffer, that is, for example, I + M <= N? (Where M is the number of new vertices).
检查缓存中是否有多余空间,比如I+M<=N?(M代表新顶点数据)

If yes, then Lock the VB with D3DLOCK_NOOVERWRITE. This tells Direct3D and the driver that you will be adding vertices and won't be modifying the ones that you previously batched. Therefore, if a DMA operation was in progress, it isn't interrupted. If no, goto 11.
如果有,使用D3DLOCK_NOOVERWRITE锁定顶点缓存。这告诉D3D和设备你要添加新的顶点到缓存中,但是不改变原有顶点数据。并且如果使用DMA操作的话,它不会被打断。如果没有,跳转到11

Fill in the M vertices at I.
在I处填充M个顶点

Unlock.
解除锁定

Call Draw[Indexed]Primitive. For non-indexed primitives use I as the StartVertex parameter. For indexed primitives, ensure the indices point to the correct portion of the vertex buffer (it may be easiest to use the BaseVertexIndex parameter of the SetIndices call to achieve this).
调用Draw[Indexed]Primitive。对于没有索引的图元,使用I作为开始顶点参数。对于索引数据,保证索引指向VB中正确的位置(最简单的,使用BaseVertexIndex作为SetIndeces调用的参数)。

I += M.
Goto 3.
Ok, so we are out of space, so let us start with a new VB. We don't want to use the same one because there might be a DMA operation in progress. We communicate to this to Direct3D and the driver by locking the same VB with the D3DLOCK_DISCARD flag. What this means is "you can give me a new pointer because I am done with the old one and don't really care about the old contents any more."
如果超出范围,就创建一个新的VB。我们不想用相同的数据因为当前可能有一个DMA操作。我们使用D3DLOCK_DISCARD标记通知D3D和设备锁定相同的VB。这告诉它们“你们能够给我一个新的指针因为我已经用过了旧的数据并不再需要它们了。”

I = 0.
Go
ted (255).

使用ID3DXFont::DrawText函数常犯的错误就是给颜色参数定义了一个alpha通道为0的颜色值,导致文本完全透明(也就是不可见)。对于不透明文本,保证颜色参数alpha通道为最大值(255)。

How can I save the contents of a surface or texture to a file?
我怎么样才能保存一个surface或者纹理到文件中?

The DirectX 8.1 SDK added two functions to the D3DX library specifically for this purpose: D3DXSaveSurfaceToFile() and D3DXSaveTextureToFile(). These functions support saving an image to file in either BMP or DDS format. In previous versions you will have to lock the surface and read the image data, then write it to a bitmap file. An article on writing a function to store bitmaps can be found at Windows GDI: Storing an Image.

DX8.1SDK为D3DX库增加两个库函数来完整这个操作:D3DXSaveSurfaceToFile()和D3DXSaveTextureToFile()。这两个函数支持保存图像到BMP或者DDS格式中。在过去的版本中,你不得不锁定surface然后读取图像数据,然后写入bmp文件中。编写保存bmp文件的文章可以在GDI: Storing an Image一节中找到。

Alternatively, GDI+ could be used to save the image in a wide variety of formats, though this requires additional support files to be distributed with your application.

同样的,GDI+能够用做保存图像到大量的格式中,虽然这需要你的程序支持文件分发。

How can I make use of the High Level Shader Language (HLSL) in my game?
在我的游戏中怎么使用HLSL?

There are three ways that the High Level Shading Language can be incorporated into your game engine:

有三种方法支持HLSL在游戏中插入:

Compile your shader source into vertex or pixel shading assembly (using the command line utility ) and use D3DXAssembleShader() at run time. This way even a DirectX 8 game can even take advantage of the power of the HLSL.
编译Shader源代码成VS或者PS汇编(使用)并在运行时调用D3DXAssembleShader()。这种方法可以使DX8以上的游戏都能使用HLSL
Use D3DXCompileShader() to compile your shader source into token stream and constant table form. At run time load the token stream and constant table and call CreateVertexShader() or CreatePixelShader() on the device to create your shaders.
使用D3DXCompileShader()编译Shader为符号流和常数表,在运行时符号流和常数表被CreateVertexShader()或者CreatePixelShader()导入到设备中。
The easiest way to get up and running is to take advantage of the D3DX Effects system by calling D3DXCreateEffectFromFile() or D3DXCreateEffectFromResource() with your effect file.
最简单的方法是使用D3DX Effect系统,调用D3DXCreateEffectFromFile()或者D3DXCreateEffectFromResource()打开效果文件。
What is the correct way to get shaders from an Effect?
从Effect中得到shader的正确方法是什么?

Use D3DXCreateEffect t
o create an ID3DXEffect and then use GetPassDesc to retrieve a D3DXPASS_DESC. This structure contains pointers to vertex and pixel shaders.

使用D3DXCreateEffect创建ID3DXEffect对象然后使用GetPassDesc获得D3DXPASS_DESC结构,这个结构包含VS和PS指针

Do not use ID3DXEffectCompiler::GetPassDesc. Vertex and pixel shader handles returned from this method are NULL.

不要使用ID3DXEffectCompiler::GetPassDesc,这个函数返回的VS和PS指针为NULL

What is the HLSL noise() intrinsic for?
HLSL的noise()函数是做什么的?

The noise intrinsic function generates perlin noise as defined by Ken Perlin. The HLSL function can currently only be used to fill textures in texture shaders as current h/w does not support the method natively. Texture shaders are used in conjuction with the D3DXFill*Texture() functions which are useful helper functions to generate procedurally defined textures during load time.

噪音内置函数产生perlin噪音。这个HLSL函数目前只能在纹理shader中用作填充纹理,因为当前的硬件还没有直接支持这个函数。纹理shader在D3DXFill*Texture()中使用。这个函数在载入时创建过程纹理非常有用。

How do I detect whether to use pixel shader model 2.0 or 2.a?
我怎么确定是否使用PS2.0还是PS2.a

You can use the D3DXGetPixelShaderProfile() and D3DXGetPixelShaderProfile() functions which return a string determining what HLSL profile is best suited to the device being ran.

你能够使用D3DXGetPixelShaderProfile()和D3DXGetPixelShaderProfile()函数,它们会返回一个字符串,确定哪个HLSL profile是最适合在设备上运行的。

How do I access the Parameters in my Precompiled Effects Shaders?
在我预编译好的Effect Shader中怎么操作参数值?

Through the ID3DXConstantTable interface which is used to access the constant table. This table contains the variables that are used by high-level language shaders and effects.

通过ID3DXConstantTable操作常数表。这个表保存了HLSL shader和effect的变量内容。

Is there a way to add user data to an effect or other resource?
有办法添加用户数据到effect或者其他数据上吗?

Yes, to set private data you call SetPrivateData (pReal is the D3D texture object, pSpoof is the wrapped texture object).

是的,你可以通过调用SetPrivateData设置个人数据(pReal是D3D纹理对象,pSpoof是包含用户数据的纹理对象)

hr = pReal->SetPrivateData(IID_Spoof, &pSpoof,
sizeof(IDirect3DResource9*), 0)));
To look up the wrapped pointer:

查找用户数据纹理对象指针:

IDirect3DResource9* pSpoof;
DWORD dwSize = sizeof(pSpoof);
hr = pReal->GetPrivateData(IID_Spoof, (void*) &pSpoof, &dwSize);
Why does rendering of an ID3DXMesh object slow down significantly after I define subsets?
在我定义了mesh子集之后,为什么绘制ID3DXMesh对象会明显慢下来呢?

You
et。在把场景绘制到这个RenderTarget后,用StretchRet把它拷到一个Rendertarget纹理上。如果你对屏幕外的纹理作合任何操作(比如模糊或者扩散),在你调用persent() 显示之前把它拷回到back buffer上。

posted on 2006-09-25 17:09 王大牛的幸福生活 阅读(2535) 评论(6) 编辑 收藏 引用 网摘 所属分类: Computer Graphic


FeedBack:
# re: DirectX FAQ 翻译(Graphics 部分) 2006-09-27 02:15 shamy
什么时候写点心得,哈哈,我可以少看点资料:)
看来工作还蛮happy的 回复 更多评论

# re: DirectX FAQ 翻译(Graphics 部分) 2006-09-27 09:07 wangdaniu
向shamy学厚积薄发,心得不能想写就写,哈哈。 回复 更多评论

# re: DirectX FAQ 翻译(Graphics 部分) 2006-10-08 14:33 Weapon
Should game developers still be publishing games for Windows 95, Windows 98 or Windows ME?

翻译成“游戏开发者仍然还要为Windows 95、 Windows 98 或者 Windows ME发行游戏么”更妥当些吧,原文没有什么“只能在……”的意思。

Not anymore for two reasons: performance and feature set.
基于两个原因,不再会了:

呵呵,开篇刚看到,觉得别扭,我帮你挑点小刺,继续拜读,呵呵 回复 更多评论

# re: DirectX FAQ 翻译(Graphics 部分) 2006-10-08 15:03 wangdaniu
多谢,本来就是贴出来大家讨论的:) 回复 更多评论

# re: DirectX FAQ 翻译(Graphics 部分) 2007-02-13 23:35 Tony Qu
翻的不错,请把这篇文章加到翻译团队首页,谢谢! 回复 更多评论

# re: DirectX FAQ 翻译(Graphics 部分) 2007-05-24 16:28 zdl
Not anymore for two reasons: performance and feature set.
不再为了这两个原因。。。

我也感觉怪怪的。。。 回复 更多评论x00

payed-安歇


比例比例吧-奔走呼号


囫囵怎么读-销售近义词


处众人之所恶-蜕化变质


天的英文-帀


长方形的面积公式-蛮横意思


自觉的意思-肩负


家的近义词-叟怎么读