ASSEMBLING VERTEX AND PIXEL SHADERS

Assembling the shader simply means taking the ASCII string and converting it to binary tokens. There's nothing magical about this step. If you're a masochist, you can write the shader in binary yourself, but it is easier to use the D3DXAssembleShader() helper function, which will assemble a pixel or vertex shader. This function will take the input ASCII buffer and its length and, if it succeeds, return a pointer to the tokenized buffer. If it fails and you haven't set the flags so that the shader isn't validated, the error messages (in somewhat readable ASCII) will tell you where you went wrong.

 // DirectX 9! // Assume we have a valid D3D pointer DWORD dwFlags = 0; LPD3DBUFFER* pShaderTokens, ppErrMsgs; HRESULT hRet = g_pD3DDevice->D3DXAssembleShader(        pSrcBuff,             // pointer to the ASCII buffer        ::strlen(pSrcBuff),   // length of buffer        dwFlags,              // assemble flags        &pShaderTokens,   // pointer to the shader        ppErrMsgs             // where error messages go ); 

If the shader was assembled successfully, the return value will be D3D_OK, and you can then use the handle/interface to the assembled shader to load the shader into the device. At this point, you just have a valid token array; nothing is actually loaded into the device. There are various flavors of the helper function that can load from a resource handle or from a file instead of from a memory buffer.

The next step is to take the assembled tokens and create the shader. This will store the shader in the device and give you a handle or interface so that you can select it later on. The DirectX 9 interface is a little cleaner than the DirectX 8 one so I've shown it here, but the basics are the same.

 // DirectX 9! // Assume we have a valid D3D pointer // and a token array IDirect3DVShader9 * pShader; HRESULT hRet = g_pD3DDevice->CreateVertexShader(       pShaderTokens,  // pointer to token array       &pShader    // shader interface       ); 



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net