indexbuffer.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * IDirect3DIndexBuffer9 implementation
  3. *
  4. * Copyright 2002-2004 Jason Edmeades
  5. * Raphael Junqueira
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include "config.h"
  22. #include "d3d9_private.h"
  23. WINE_DEFAULT_DEBUG_CHANNEL(d3d);
  24. /* IDirect3DIndexBuffer9 IUnknown parts follow: */
  25. HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
  26. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  27. if (IsEqualGUID(riid, &IID_IUnknown)
  28. || IsEqualGUID(riid, &IID_IDirect3DResource9)
  29. || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
  30. IDirect3DIndexBuffer9Impl_AddRef(iface);
  31. *ppobj = This;
  32. return D3D_OK;
  33. }
  34. WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
  35. return E_NOINTERFACE;
  36. }
  37. ULONG WINAPI IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
  38. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  39. ULONG ref = InterlockedIncrement(&This->ref);
  40. TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
  41. return ref;
  42. }
  43. ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
  44. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  45. ULONG ref = InterlockedDecrement(&This->ref);
  46. TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
  47. if (ref == 0) {
  48. IWineD3DIndexBuffer_Release(This->wineD3DIndexBuffer);
  49. HeapFree(GetProcessHeap(), 0, This);
  50. }
  51. return ref;
  52. }
  53. /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
  54. HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
  55. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  56. return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
  57. }
  58. HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
  59. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  60. return IWineD3DIndexBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
  61. }
  62. HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
  63. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  64. return IWineD3DIndexBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
  65. }
  66. HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
  67. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  68. return IWineD3DIndexBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
  69. }
  70. DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
  71. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  72. return IWineD3DIndexBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
  73. }
  74. DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
  75. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  76. return IWineD3DIndexBuffer_GetPriority(This->wineD3DIndexBuffer);
  77. }
  78. void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
  79. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  80. IWineD3DIndexBuffer_PreLoad(This->wineD3DIndexBuffer);
  81. return ;
  82. }
  83. D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
  84. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  85. return IWineD3DIndexBuffer_GetType(This->wineD3DIndexBuffer);
  86. }
  87. /* IDirect3DIndexBuffer9 Interface follow: */
  88. HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
  89. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  90. return IWineD3DIndexBuffer_Lock(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
  91. }
  92. HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
  93. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  94. return IWineD3DIndexBuffer_Unlock(This->wineD3DIndexBuffer);
  95. }
  96. HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
  97. IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
  98. return IWineD3DIndexBuffer_GetDesc(This->wineD3DIndexBuffer, pDesc);
  99. }
  100. IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
  101. {
  102. IDirect3DIndexBuffer9Impl_QueryInterface,
  103. IDirect3DIndexBuffer9Impl_AddRef,
  104. IDirect3DIndexBuffer9Impl_Release,
  105. IDirect3DIndexBuffer9Impl_GetDevice,
  106. IDirect3DIndexBuffer9Impl_SetPrivateData,
  107. IDirect3DIndexBuffer9Impl_GetPrivateData,
  108. IDirect3DIndexBuffer9Impl_FreePrivateData,
  109. IDirect3DIndexBuffer9Impl_SetPriority,
  110. IDirect3DIndexBuffer9Impl_GetPriority,
  111. IDirect3DIndexBuffer9Impl_PreLoad,
  112. IDirect3DIndexBuffer9Impl_GetType,
  113. IDirect3DIndexBuffer9Impl_Lock,
  114. IDirect3DIndexBuffer9Impl_Unlock,
  115. IDirect3DIndexBuffer9Impl_GetDesc
  116. };
  117. /* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
  118. HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9 iface,
  119. UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
  120. IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) {
  121. IDirect3DIndexBuffer9Impl *object;
  122. IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
  123. HRESULT hrc = D3D_OK;
  124. /* Allocate the storage for the device */
  125. object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DIndexBuffer9Impl));
  126. if (NULL == object) {
  127. FIXME("Allocation of memory failed\n");
  128. *ppIndexBuffer = NULL;
  129. return D3DERR_OUTOFVIDEOMEMORY;
  130. }
  131. object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
  132. object->ref = 1;
  133. hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage, Format, Pool, &(object->wineD3DIndexBuffer), pSharedHandle, (IUnknown *)object);
  134. if (hrc != D3D_OK) {
  135. /* free up object */
  136. FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
  137. HeapFree(GetProcessHeap(), 0, object);
  138. *ppIndexBuffer = NULL;
  139. } else {
  140. *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
  141. }
  142. return hrc;
  143. }