'   0 IDirect3DTexture2_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)  
'   1 IDirect3DTexture2_AddRef(p)             (p)->lpVtbl->AddRef(p)              
'   2 IDirect3DTexture2_Release(p)            (p)->lpVtbl->Release(p)             
'   3 IDirect3DTexture2_GetHandle(p,a,b)      (p)->lpVtbl->GetHandle(p,a,b)       
'   4 IDirect3DTexture2_PaletteChanged(p,a,b) (p)->lpVtbl->PaletteChanged(p,a,b)  
'   5 IDirect3DTexture2_Load(p,a)             (p)->lpVtbl->Load(p,a)              
'                                                                                 

' ****************************************************************************************
function d3dTexture2Prototype() as hresult
  #ifdef DebugFatal
    printf(!"D3D::Texture2.#%i Function not implemented\n",D3DTEXTURE2PROTOID)
    messagebox(null,"D3D::Texture2.#" & D3DTEXTURE2PROTOID & " Function not implemented", _
    "DirectX",MB_SYSTEMMODAL or MB_ICONERROR)
  #endif      
  ExitProcess(1)
  return DDERR_UNSUPPORTED  
  
  asm
    .balign 32
    _d3dTexture2ProtoTable_:  
    #macro ProtoNum(X)
    mov dword ptr [D3DTEXTURE2PROTOID],X
    jmp d3dTexture2Prototype
    .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 d3dTexture2Object ptr
function d3dTexture2_2_Release(P1) as hresult
  #ifdef MyDebugD3D
  Cout("IDirect3D2::Texture2.Release (2)" + chr$(13,10) + _
  " >> THIS: "+hex$(cast(uinteger,pTHIS),8))
  #endif  
  if pTHIS=0 then ddrawError(DDERR_INVALIDPARAMS)
  if pTHIS->Interface <> itd3dTexture2 then ddrawError(DDERR_INVALIDOBJECT)
  #ifdef Render_OpenGL
    if pTHIS->Surface then
      with *(pThis->Surface)
        if .ID > 0 then      
          mt_glDeleteTextures(1, @.ID)
          if .ID = ogl.LastBind then ogl.LastBind=0
          .ID = 0      
        end if
      end with
    end if
  #endif
  Delete pTHIS
  return DD_OK
end function
' ****************************************************************************************
UndefAll()
#define P1 pTHIS    as d3dTexture2Object ptr
#define P2 pOwner   as d3dDevice2Object ptr
#define P3 ppHandle as any ptr ptr
function d3dTexture2_3_GetHandle(P1,P2,P3) as hresult
  #ifdef MyDebugD3D
  Cout("IDirect3D2::Texture2.GetHandle (3)" + 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 <> itd3dTexture2 then ddrawError(DDERR_INVALIDOBJECT)
  *ppHandle = pTHIS->Surface
  return DD_OK
end function

' ****************************************************************************************
' ****************************************************************************************
' ****************************************************************************************
sub d3dTexture2Funcs(VTABLE() as any ptr)
  dim as any ptr PROTOTABLE
  asm mov dword ptr [PROTOTABLE], offset _d3dTexture2ProtoTable_
  for CNT as integer = 0 to 20
    VTABLE(CNT) = PROTOTABLE+CNT*32
  next CNT  
  VTABLE(2) = @d3dTexture2_2_Release
  VTABLE(3) = @d3dTexture2_3_GetHandle 
end sub
