控點 (Direct3D 9)
句柄提供有效率的方法,以 ID3DXEffectCompiler 或 ID3DXEffect來參考技術、傳遞、批注和參數。 當您呼叫 Get[Parameter] 表單的函式時,會以動態方式產生它們註釋|函式|技術|Pass][ByName|BySemantic|Element]。
執行程式時,產生相同物件的句柄多次,每次都會傳回相同的句柄。 但是,當您多次執行程式時,請勿依賴句柄保持常數。 另請注意,ID3DXEffect 的不同實例所產生的句柄,ID3DXEffectCompiler 將會不同。
如果您檢視頭檔,您會發現句柄 (D3DXHANDLEs) 在技術上是字串指標。
您傳入 GetParameter[ByName] 等函式的句柄|Element|BySemantic] 或 GetAnnotation[ByName] 可以有三種形式,如下所示:
- Handles that were returned by functions such as GetParameter[ByName|Element|BySemantic]。
- MyVariableName、MyTechniqueName 或 MyArray[0] 等字串。
- Handle = NULL。 有四種情況。
- 如果它是方法傳回值,則方法找不到句柄。
- 如果 NULL 句柄以 GetParameter[ByName| 的第一個參數傳入Element|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");
相關主題