Handle (Direct3D 9)
Gli handle forniscono un mezzo efficiente per fare riferimento a tecniche, passaggi, annotazioni e parametri con ID3DXEffectCompiler o ID3DXEffect. Vengono generati in modo dinamico quando si chiamano le funzioni del modulo Get[Parameter|Annotazione |Funzione |Tecnica |Pass][ByName|BySemantic |Elemento].
Durante l'esecuzione di un programma, la generazione di un handle per lo stesso oggetto più volte restituirà lo stesso handle ogni volta. Ma non basarsi sull'handle che rimane costante quando si esegue il programma più volte. Tenere inoltre presente che gli handle generati da istanze diverse di ID3DXEffect e ID3DXEffectCompiler saranno diversi.
Se si visualizzano i file di intestazione, si noterà che gli handle (D3DXHANDLEs) sono puntatori tecnicamente stringa.
Handle passati in funzioni come GetParameter[ByName|Elemento |BySemantic] o GetAnnotation[ByName] può essere in tre forme come indicato di seguito:
- Handle restituiti da funzioni come GetParameter[ByName|Elemento |BySemantic].
- Stringhe come MyVariableName, MyTechniqueName o MyArray[0].
- Handle = NULL. Ci sono quattro casi.
- Se si tratta di un valore restituito dal metodo, il metodo non è riuscito a trovare l'handle.
- Se un handle NULL viene passato come primo parametro di GetParameter[ByName|Elemento |BySemantic], la funzione restituisce un parametro di primo livello. Viceversa, se l'handle non èNULL, la funzione restituisce un membro o un elemento della struttura identificato dall'handle.
- Se un handle NULL viene passato come primo argomento di ValidateTechnique o il secondo argomento di IsParameterUsed, la tecnica corrente viene convalidata.
- Se un handle NULL viene passato come primo argomento di FindNextValidTechnique, la ricerca di una tecnica valida inizia alla prima tecnica dell'effetto.
Suggerimento per le prestazioni All'inizio dell'applicazione eseguire un passaggio di inizializzazione per generare handle dalle stringhe. Da quel punto in poi, usare solo handle. Il passaggio di stringhe anziché handle generati è più lento.
Esempi
Ecco alcuni esempi che usano Get[Parameter|Annotazione |Funzione |Tecnica |Pass][ByName|BySemantic |Element] funzioni per generare handle.
// 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");
Argomenti correlati