'   0 IDirect3DMaterial2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) 
'   1 IDirect3DMaterial2_AddRef(p)             (p)->lpVtbl->AddRef(p)             
'   2 IDirect3DMaterial2_Release(p)            (p)->lpVtbl->Release(p)            
'   3 IDirect3DMaterial2_SetMaterial(p,a)      (p)->lpVtbl->SetMaterial(p,a)      
'   4 IDirect3DMaterial2_GetMaterial(p,a)      (p)->lpVtbl->GetMaterial(p,a)      
'   5 IDirect3DMaterial2_GetHandle(p,a,b)      (p)->lpVtbl->GetHandle(p,a,b)      
'                                                                                 

' ****************************************************************************************
function d3dMaterial2Prototype() as hresult
  FatalError("D3D::Material2.#%i Function not implemented",D3DMATERIAL2PROTOID)
  return DDERR_UNSUPPORTED  
  
  asm
    .balign 32
    _d3dMaterial2ProtoTable_:  
    #macro ProtoNum(X)
    mov dword ptr [D3DMATERIAL2PROTOID],X
    jmp d3dMaterial2Prototype
    .balign 32
    #endmacro
    ProtoNum(0)
    ProtoNum(1)
    ProtoNum(2)
    ProtoNum(3)
    ProtoNum(4)
    ProtoNum(5)
    ProtoNum(6)
    ProtoNum(7)
    ProtoNum(8)
    ProtoNum(9)
    ProtoNum(10)
    ProtoNum(11)
    ProtoNum(12)
    ProtoNum(13)
    ProtoNum(14)
    ProtoNum(15)
    ProtoNum(16)
    ProtoNum(17)
    ProtoNum(18)
    ProtoNum(19)
    ProtoNum(20)    
  end asm  
  
end function
' ****************************************************************************************
UndefAll()
#define P1 pTHIS as d3dMaterial2Object ptr
function d3dMaterial2_2_Release(P1) as hresult
  #ifdef MyDebugD3D
  Cout("IDirect3D2::Material2.Release (2)" + chr$(13,10) + _
  " >> THIS: "+hex$(cast(uinteger,pTHIS),8))
  #endif  
  if pTHIS=0 then ddrawError(DDERR_INVALIDPARAMS)
  if pTHIS->Interface <> itd3dMaterial2 then ddrawError(DDERR_INVALIDOBJECT)
  Delete pTHIS
  return DD_OK
end function
' ****************************************************************************************
UndefAll()
#define P1 pTHIS    as d3dMaterial2Object ptr
#define P2 pMat     as D3DMATERIAL ptr
function d3dMaterial2_3_SetMaterial(P1,P2) as hresult
  #ifdef MyDebugD3D
  Cout("IDirect3D2::Material2.SetMaterial (3)" + chr$(13,10) + _
  " >> THIS: "+hexptr(pTHIS)+"  pMat: "+hexptr(pMat))
  #endif  
  if pTHIS=0 or pMat=0 then ddrawError(DDERR_INVALIDPARAMS)  
  if pTHIS->Interface <> itd3dMaterial2 then ddrawError(DDERR_INVALIDOBJECT)
  pTHIS->Props = *pMat
  return DD_OK
end function
' ****************************************************************************************
UndefAll()
#define P1 pTHIS    as d3dMaterial2Object ptr
#define P2 pMat     as D3DMATERIAL ptr
function d3dMaterial2_4_GetMaterial(P1,P2) as hresult
  #ifdef MyDebugD3D
  Cout("IDirect3D2::Material2.GetMaterial (4)" + chr$(13,10) + _
  " >> THIS: "+hexptr(pTHIS)+"  pMat: "+hexptr(pMat))
  #endif  
  if pTHIS=0 or pMat=0 then ddrawError(DDERR_INVALIDPARAMS)  
  if pTHIS->Interface <> itd3dMaterial2 then ddrawError(DDERR_INVALIDOBJECT)
  *pMat = pTHIS->Props
  return DD_OK
end function
' ****************************************************************************************
UndefAll()
#define P1 pTHIS    as d3dMaterial2Object ptr
#define P2 pOwner   as d3dDevice2Object ptr
#define P3 ppHandle as any ptr ptr
function d3dMaterial2_5_GetHandle(P1,P2,P3) as hresult
  #ifdef MyDebugD3D
  Cout("IDirect3D2::Material2.GetHandle (5)" + chr$(13,10) + _
  " >> THIS: "+hexptr(pTHIS)+"  pOwner: "+hexptr(pOwner)+"  OUT: "+hexptr(ppHandle))
  #endif  
  if pTHIS=0 or ppHandle=0 then ddrawError(DDERR_INVALIDPARAMS)  
  if pTHIS->Interface <> itd3dMaterial2 then ddrawError(DDERR_INVALIDOBJECT)
  *ppHandle = pTHIS
  return DD_OK
end function

' ****************************************************************************************
' ****************************************************************************************
' ****************************************************************************************
sub d3dMaterial2Funcs(VTABLE() as any ptr)
  dim as any ptr PROTOTABLE
  asm mov dword ptr [PROTOTABLE], offset _d3dMaterial2ProtoTable_
  for CNT as integer = 0 to 20
    VTABLE(CNT) = PROTOTABLE+CNT*32
  next CNT  
  VTABLE(2) = @d3dMaterial2_2_Release
  VTABLE(3) = @d3dMaterial2_3_SetMaterial
  VTABLE(4) = @d3dMaterial2_4_GetMaterial
  VTABLE(5) = @d3dMaterial2_5_GetHandle 
end sub