句柄 (Direct3D 9)
句柄提供了一种有效的方法,用于通过 ID3DXEffectCompiler 或 ID3DXEffect引用技术、传递、批注和参数。 调用窗体 Get[Parameter| 的函数时,会动态生成它们批注|函数 |技术 |Pass][ByName|BySemantic|Element]。
运行程序时,多次生成同一对象的句柄将每次返回相同的句柄。 但是,当你多次运行程序时,不要依赖于句柄保持不变。 另请注意,ID3DXEffect 的不同实例生成的句柄将有所不同,ID3DXEffectCompiler。
如果查看头文件,你会注意到句柄(D3DXHANDLEs)在技术上是字符串指针。
传递到 GetParameter[ByName| 等函数的句柄元素 |BySemantic] 或 GetAnnotation[ByName] 可以采用三种形式,如下所示:
- GetParameter[ByName| 等函数返回的句柄元素 |BySemantic]。
- MyVariableName、MyTechniqueName 或 MyArray[0] 等字符串。
- Handle = NULL。 有四种情况。
- 如果它是方法返回值,则方法未能找到句柄。
- 如果 NULL 句柄作为 GetParameter[ByName| 的第一个参数传入元素 |BySemantic],函数返回顶级参数。 相反,如果句柄是非NULL,则该函数将返回句柄标识的结构成员或元素。
- 如果 NULL 句柄作为 ValidateTechnique 的第一个参数或 IsParameterUsed 的第二个参数传入,则会验证当前技术。
- 如果将 NULL 句柄作为 FindNextValidTechnique 的第一个参数传入,则搜索有效技术从效果的第一种方法开始。
性能提示在应用程序开始时,执行初始化传递以从字符串生成句柄。 从那一点开始,只使用句柄。 传入字符串而不是生成的句柄的速度较慢。
例子
下面是使用 Get[Parameter| 的一些示例批注|函数 |技术 |Pass][ByName|BySemantic|元素] 用于生成句柄的函数。
// Gets handle of second top-level parameter handle in the effect file
h1 = GetParameter(NULL, 1);
// Gets handle of the third struct member of MyStruct
h2 = GetParameter("MyStruct", 2);
// Gets handle of the third array element handle of MyArray
h3 = GetParameterElement("MyArray", 2);
// Gets handle of first member of h1 (that is, the second top-level param)
h4 = GetParameter(h1, 0);
// Gets handle of MyStruct.Data
h5 = GetParameterByName("MyStruct", "Data");
// or
h6 = GetParameterByName(NULL, "MyStruct.Data");
// Gets handle of MyStruct.Data.SubData
h7 = GetParameterByName("MyStruct.Data", "SubData");
// or
h8 = GetParameterByName(NULL, "MyStruct.Data.SubData");
// Gets handle of fifth annotation of h1 (that is, second top-level param)
h9 = GetAnnotation(h1, 4);
// Gets handle of MyStruct's annotation, called Author
h10 = GetAnnotationByName("MyStruct", "Author");
// or
h11 = GetParameterByName(NULL, "MyStruct@Author");
相关主题