ID3DXInclude Interface

 

 

' ****************************************************************************************
' ID3DXInclude interface
' ****************************************************************************************

' ****************************************************************************************
' ID3DXInclude is a user-implemented interface to provide callbacks for #include
' directives during shader compilation. Each of the methods in this interface must be
' implemented by the user which will then be used as callbacks to the application when one
' of the following occurs:
'    * An high-level shader language (HLSL) shader that contains a #include is compiled by
'      calling one of the D3DXCompileShader*** functions.
'    * An assembly shader #include is assembled by calling any of the D3DXAssembleShader***
'      functions.
'    * An effect that contains a #include is compiled by by calling any of the
'      D3DXCreateEffect*** or D3DXCreateEffectCompiler*** functions.
' Remarks
'    A user creates an ID3DXInclude interface by implementing a class that derives from
'    this interface, and implementing all the interface methods.
' ****************************************************************************************

' ****************************************************************************************
' IUnknown virtual table
' ****************************************************************************************
TYPE ID3DXInclude_IUnknownVtbl
   ' IUnknown interface
   QueryInterface AS DWORD              ' Returns pointers to supported interfaces
   AddRef AS DWORD                      ' Increments reference count
   Release AS DWORD                     ' Decrements reference count
   ' ID3DXInclude interface
   OPEN AS DWORD                        ' Open method
   CLOSE AS DWORD                       ' Close method
   ' Custom data
   pVtblAddr AS DWORD                   ' Address of the virtual table
   cRef AS DWORD                        ' Reference counter
   pthis AS DWORD                       ' IUnknown of the control that fires the events
END TYPE
' ****************************************************************************************

' ****************************************************************************************
' Builds the IUnknown Virtual Table
' ****************************************************************************************
FUNCTION ID3DXInclude_BuildVtbl (BYVAL pthis AS DWORD) AS DWORD

   LOCAL pVtbl AS ID3DXInclude_IUnknownVtbl PTR
   LOCAL pUnk AS ID3DXInclude_IUnknownVtbl PTR

   pVtbl = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, SIZEOF(@pVtbl))
   IF pVtbl = 0 THEN EXIT FUNCTION

   @pVTbl.QueryInterface             = CODEPTR(ID3DXInclude_QueryInterface)
   @pVTbl.AddRef                     = CODEPTR(ID3DXInclude_AddRef)
   @pVTbl.Release                    = CODEPTR(ID3DXInclude_Release)
   @pVTbl.OPEN                       = CODEPTR(ID3DXInclude_Open)
   @pVTbl.CLOSE                      = CODEPTR(ID3DXInclude_Close)
   @pVtbl.pVtblAddr                  = pVtbl
   @pVtbl.pthis                      = pthis

   pUnk = VARPTR(@pVtbl.pVtblAddr)
   FUNCTION = pUnk

END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' UI4 AddRef()
' Increments the reference counter.
' ****************************************************************************************
FUNCTION ID3DXInclude_AddRef (BYVAL pthis AS ID3DXInclude_IUnknownVtbl PTR) AS DWORD
   INCR @@pthis.cRef
   FUNCTION = @@pthis.cRef
END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' HRESULT QueryInterface([in] *GUID riid, [out] **VOID ppvObj)
' Returns the IUnknown of our class and increments the reference counter.
' ****************************************************************************************
FUNCTION ID3DXInclude_QueryInterface (BYVAL pthis AS ID3DXInclude_IUnknownVtbl PTR, BYREF riid AS GUID, BYREF ppvObj AS DWORD) AS DWORD
   ppvObj = pthis
   ID3DXInclude_AddRef pthis
   FUNCTION = %D3D_OK
END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' UI4 Release()
' Releases our class if there is only a reference to him and decrements the reference
' counter.
' ****************************************************************************************
FUNCTION ID3DXInclude_Release (BYVAL pthis AS ID3DXInclude_IUnknownVtbl PTR) AS DWORD
   LOCAL pVtblAddr AS DWORD
   IF @@pCookie.cRef = 1 THEN
      pVtblAddr = @@pCookie.pVtblAddr
      IF ISTRUE HeapFree(GetProcessHeap(), 0, BYVAL pVtblAddr) THEN
         FUNCTION = 0
         EXIT FUNCTION
      ELSE
         FUNCTION = @@pCookie.cRef
         EXIT FUNCTION
      END IF
   END IF
   DECR @@pCookie.cRef
   FUNCTION = @@pCookie.cRef
END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' Open method
' A user-implemented method for opening and reading the contents of a shader #include file.
' Syntax
'   HRESULT Open(
'       D3DXINCLUDE_TYPE IncludeType,
'       LPCSTR pFileName,
'       LPCVOID pParentData,
'       LPCVOID *ppData,
'       UINT *pBytes
'   );
' Parameters
'    IncludeType
'        [in] The location of the #include file. See D3DXINCLUDE_TYPE.
'    pFileName
'        [in] Name of the #include file.
'    pParentData
'        [in] Pointer to the container that includes the #include file.
'    ppData
'        [out] Pointer to the returned buffer that contains the include directives. This
'        pointer remains valid until ID3DXInclude::Close is called.
'    pBytes
'        [out] Number of bytes returned in ppData.
' Return Value
'    The user-implemented method should return S_OK. If the callback fails when reading
'    the #include file, the application programming interface (API) that caused the
'    callback to be called will fail. This is one of the following:
'        * The high-level shader language (HLSL) shader will fail one of the
'          D3DXCompileShader*** functions.
'        * The assembly shader will fail one of the D3DXAssembleShader*** functions.
'        * The effect will fail one of the D3DXCreateEffect*** or
'          D3DXCreateEffectCompiler*** functions.
' Remarks
'    An example implementation of this method is shown in the EffectEdit Sample.
' ****************************************************************************************
FUNCTION ID3DXInclude_Open ( _
    BYVAL pthis AS DWORD PTR, _
    BYVAL IncludeType AS DWORD, _
    BYVAL pFileName AS DWORD, _
    BYVAL pParentData AS DWORD, _
    BYREF ppData AS DWORD, _
    BYVAL pBytes AS DWORD _
    ) AS LONG

    ' *** Put your code here ***

END FUNCTION
' ****************************************************************************************

' ****************************************************************************************
' Close method
' A user-implemented method for closing a shader #include file.
' ****************************************************************************************
FUNCTION ID3DXInclude_Close ( _
    BYVAL pthis AS DWORD PTR, _
    BYVAL pData AS DWORD _
    ) AS LONG

    ' *** Put your code here ***

END FUNCTION
' ****************************************************************************************
 

 

Page last updated on Wednesday, 15 March 2006 02:12:35 +0100