处理 (Direct3D 9)

句柄提供了一种有效的方法来引用 ID3DXEffectCompilerID3DXEffect 的技术、传递、批注和参数。 它们是在调用 Get[Parameter| 表单的函数时动态生成的批注|函数|技术 |Pass][ByName|BySemantic |元素]。

运行程序时,多次生成同一对象的句柄将每次返回相同的句柄。 但是,在多次运行程序时,不要依赖于句柄保持恒定。 另请注意, ID3DXEffectID3DXEffectCompiler 的不同实例生成的句柄将不同。

如果查看头文件,你会注意到句柄 (D3DXHANDLEs) 技术上是字符串指针。

传递到 GetParameter[ByName| 等函数中的句柄元素|BySemantic] 或 GetAnnotation[ByName] 可以采用三种形式,如下所示:

  1. GetParameter 等函数返回的句柄[ByName|元素|BySemantic]。
  2. 字符串,如 MyVariableName、MyTechniqueName 或 MyArray[0]。
  3. 句柄 = 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"); 

效果格式