Handle (Direct3D 9)

Gli handle forniscono un mezzo efficiente per fare riferimento alle tecniche, ai passaggi, alle annotazioni e ai parametri con ID3DXEffectCompiler o ID3DXEffect. Vengono generati dinamicamente quando si chiamano funzioni del modulo Get[Parameter| Annotazione| Funzione | Tecnica | Pass][ByName| BySemantic | Elemento].

Durante l'esecuzione di un programma, la generazione di un handle nello stesso oggetto più volte restituirà lo stesso handle ogni volta. Ma non si basa sull'handle rimanere costante quando si esegue il programma più volte. Tenere presente anche che gli handle generati da istanze diverse di ID3DXEffect e ID3DXEffectCompiler saranno diversi.

Se si visualizzano i file di intestazione, si noterà che handle (D3DXHANDLEs) sono puntatori di stringa tecnicamente.

Handle passati a funzioni come GetParameter[ByName| Elemento | BySemantic] o GetAnnotation[ByName] può essere in tre forme come indicato di seguito:

  1. Handle restituiti da funzioni, ad esempio GetParameter[ByName| Elemento | BySemantic].
  2. Stringhe come MyVariableName, MyTechniqueName o MyArray[0].
  3. 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. Al contrario, se l'handle non è NULL, la funzione restituisce un membro della struttura o un elemento 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 sulle prestazioni All'inizio dell'applicazione eseguire un passaggio di inizializzazione per generare handle dalle stringhe. A partire da questo punto, usare solo handle. Il passaggio di stringhe anziché handle generati è più lento.

Esempio

Ecco alcuni esempi che usano Get[Parameter| Annotazione| Funzione | Tecnica | Pass][ByName| BySemantic | Funzioni elemento] 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"); 

Formato effetto