1 /* 2 * Copyright 2011 Joakim Sindholt <opensource (at) zhasha.com> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 22 23 #include "vertexbuffer9.h" 24 #include "device9.h" 25 #include "nine_helpers.h" 26 #include "nine_pipe.h" 27 28 #include "pipe/p_screen.h" 29 #include "pipe/p_context.h" 30 #include "pipe/p_state.h" 31 #include "pipe/p_defines.h" 32 #include "pipe/p_format.h" 33 #include "util/u_box.h" 34 35 #define DBG_CHANNEL DBG_VERTEXBUFFER 36 37 HRESULT 38 NineVertexBuffer9_ctor( struct NineVertexBuffer9 *This, 39 struct NineUnknownParams *pParams, 40 D3DVERTEXBUFFER_DESC *pDesc ) 41 { 42 HRESULT hr; 43 44 DBG("This=%p Size=0x%x Usage=%x Pool=%u\n", This, 45 pDesc->Size, pDesc->Usage, pDesc->Pool); 46 47 hr = NineBuffer9_ctor(&This->base, pParams, D3DRTYPE_VERTEXBUFFER, 48 pDesc->Usage, pDesc->Size, pDesc->Pool); 49 if (FAILED(hr)) 50 return hr; 51 52 pDesc->Type = D3DRTYPE_VERTEXBUFFER; 53 pDesc->Format = D3DFMT_VERTEXDATA; 54 This->desc = *pDesc; 55 56 return D3D_OK; 57 } 58 59 void 60 NineVertexBuffer9_dtor( struct NineVertexBuffer9 *This ) 61 { 62 NineBuffer9_dtor(&This->base); 63 } 64 65 struct pipe_resource * 66 NineVertexBuffer9_GetResource( struct NineVertexBuffer9 *This, unsigned *offset ) 67 { 68 return NineBuffer9_GetResource(&This->base, offset); 69 } 70 71 HRESULT NINE_WINAPI 72 NineVertexBuffer9_Lock( struct NineVertexBuffer9 *This, 73 UINT OffsetToLock, 74 UINT SizeToLock, 75 void **ppbData, 76 DWORD Flags ) 77 { 78 return NineBuffer9_Lock(&This->base, OffsetToLock, SizeToLock, ppbData, Flags); 79 } 80 81 HRESULT NINE_WINAPI 82 NineVertexBuffer9_Unlock( struct NineVertexBuffer9 *This ) 83 { 84 return NineBuffer9_Unlock(&This->base); 85 } 86 87 HRESULT NINE_WINAPI 88 NineVertexBuffer9_GetDesc( struct NineVertexBuffer9 *This, 89 D3DVERTEXBUFFER_DESC *pDesc ) 90 { 91 user_assert(pDesc, E_POINTER); 92 *pDesc = This->desc; 93 return D3D_OK; 94 } 95 96 IDirect3DVertexBuffer9Vtbl NineVertexBuffer9_vtable = { 97 (void *)NineUnknown_QueryInterface, 98 (void *)NineUnknown_AddRef, 99 (void *)NineUnknown_Release, 100 (void *)NineUnknown_GetDevice, /* actually part of Resource9 iface */ 101 (void *)NineUnknown_SetPrivateData, 102 (void *)NineUnknown_GetPrivateData, 103 (void *)NineUnknown_FreePrivateData, 104 (void *)NineResource9_SetPriority, 105 (void *)NineResource9_GetPriority, 106 (void *)NineResource9_PreLoad, 107 (void *)NineResource9_GetType, 108 (void *)NineVertexBuffer9_Lock, 109 (void *)NineVertexBuffer9_Unlock, 110 (void *)NineVertexBuffer9_GetDesc 111 }; 112 113 static const GUID *NineVertexBuffer9_IIDs[] = { 114 &IID_IDirect3DVertexBuffer9, 115 &IID_IDirect3DResource9, 116 &IID_IUnknown, 117 NULL 118 }; 119 120 HRESULT 121 NineVertexBuffer9_new( struct NineDevice9 *pDevice, 122 D3DVERTEXBUFFER_DESC *pDesc, 123 struct NineVertexBuffer9 **ppOut ) 124 { 125 NINE_DEVICE_CHILD_NEW(VertexBuffer9, ppOut, /* args */ pDevice, pDesc); 126 } 127