17ec681f3Smrg/* 27ec681f3Smrg * Copyright 2011 Joakim Sindholt <opensource@zhasha.com> 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 87ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom 97ec681f3Smrg * the Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 217ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 227ec681f3Smrg 237ec681f3Smrg#include "indexbuffer9.h" 247ec681f3Smrg#include "device9.h" 257ec681f3Smrg#include "nine_helpers.h" 267ec681f3Smrg#include "nine_pipe.h" 277ec681f3Smrg#include "nine_dump.h" 287ec681f3Smrg 297ec681f3Smrg#include "pipe/p_screen.h" 307ec681f3Smrg#include "pipe/p_context.h" 317ec681f3Smrg#include "pipe/p_state.h" 327ec681f3Smrg#include "pipe/p_defines.h" 337ec681f3Smrg#include "pipe/p_format.h" 347ec681f3Smrg#include "util/u_box.h" 357ec681f3Smrg 367ec681f3Smrg#define DBG_CHANNEL DBG_INDEXBUFFER 377ec681f3Smrg 387ec681f3SmrgHRESULT 397ec681f3SmrgNineIndexBuffer9_ctor( struct NineIndexBuffer9 *This, 407ec681f3Smrg struct NineUnknownParams *pParams, 417ec681f3Smrg D3DINDEXBUFFER_DESC *pDesc ) 427ec681f3Smrg{ 437ec681f3Smrg HRESULT hr; 447ec681f3Smrg DBG("This=%p pParams=%p pDesc=%p Usage=%s\n", 457ec681f3Smrg This, pParams, pDesc, nine_D3DUSAGE_to_str(pDesc->Usage)); 467ec681f3Smrg 477ec681f3Smrg hr = NineBuffer9_ctor(&This->base, pParams, D3DRTYPE_INDEXBUFFER, 487ec681f3Smrg pDesc->Usage, pDesc->Size, pDesc->Pool); 497ec681f3Smrg if (FAILED(hr)) 507ec681f3Smrg return hr; 517ec681f3Smrg 527ec681f3Smrg switch (pDesc->Format) { 537ec681f3Smrg case D3DFMT_INDEX16: This->index_size = 2; break; 547ec681f3Smrg case D3DFMT_INDEX32: This->index_size = 4; break; 557ec681f3Smrg default: 567ec681f3Smrg user_assert(!"Invalid index format.", D3DERR_INVALIDCALL); 577ec681f3Smrg break; 587ec681f3Smrg } 597ec681f3Smrg 607ec681f3Smrg pDesc->Type = D3DRTYPE_INDEXBUFFER; 617ec681f3Smrg This->desc = *pDesc; 627ec681f3Smrg 637ec681f3Smrg return D3D_OK; 647ec681f3Smrg} 657ec681f3Smrg 667ec681f3Smrgvoid 677ec681f3SmrgNineIndexBuffer9_dtor( struct NineIndexBuffer9 *This ) 687ec681f3Smrg{ 697ec681f3Smrg NineBuffer9_dtor(&This->base); 707ec681f3Smrg} 717ec681f3Smrg 727ec681f3Smrgstruct pipe_resource * 737ec681f3SmrgNineIndexBuffer9_GetBuffer( struct NineIndexBuffer9 *This, unsigned *offset ) 747ec681f3Smrg{ 757ec681f3Smrg /* The resource may change */ 767ec681f3Smrg return NineBuffer9_GetResource(&This->base, offset); 777ec681f3Smrg} 787ec681f3Smrg 797ec681f3SmrgHRESULT NINE_WINAPI 807ec681f3SmrgNineIndexBuffer9_Lock( struct NineIndexBuffer9 *This, 817ec681f3Smrg UINT OffsetToLock, 827ec681f3Smrg UINT SizeToLock, 837ec681f3Smrg void **ppbData, 847ec681f3Smrg DWORD Flags ) 857ec681f3Smrg{ 867ec681f3Smrg return NineBuffer9_Lock(&This->base, OffsetToLock, SizeToLock, ppbData, Flags); 877ec681f3Smrg} 887ec681f3Smrg 897ec681f3SmrgHRESULT NINE_WINAPI 907ec681f3SmrgNineIndexBuffer9_Unlock( struct NineIndexBuffer9 *This ) 917ec681f3Smrg{ 927ec681f3Smrg return NineBuffer9_Unlock(&This->base); 937ec681f3Smrg} 947ec681f3Smrg 957ec681f3SmrgHRESULT NINE_WINAPI 967ec681f3SmrgNineIndexBuffer9_GetDesc( struct NineIndexBuffer9 *This, 977ec681f3Smrg D3DINDEXBUFFER_DESC *pDesc ) 987ec681f3Smrg{ 997ec681f3Smrg user_assert(pDesc, E_POINTER); 1007ec681f3Smrg *pDesc = This->desc; 1017ec681f3Smrg return D3D_OK; 1027ec681f3Smrg} 1037ec681f3Smrg 1047ec681f3SmrgIDirect3DIndexBuffer9Vtbl NineIndexBuffer9_vtable = { 1057ec681f3Smrg (void *)NineUnknown_QueryInterface, 1067ec681f3Smrg (void *)NineUnknown_AddRef, 1077ec681f3Smrg (void *)NineUnknown_Release, 1087ec681f3Smrg (void *)NineUnknown_GetDevice, /* actually part of Resource9 iface */ 1097ec681f3Smrg (void *)NineUnknown_SetPrivateData, 1107ec681f3Smrg (void *)NineUnknown_GetPrivateData, 1117ec681f3Smrg (void *)NineUnknown_FreePrivateData, 1127ec681f3Smrg (void *)NineResource9_SetPriority, 1137ec681f3Smrg (void *)NineResource9_GetPriority, 1147ec681f3Smrg (void *)NineResource9_PreLoad, 1157ec681f3Smrg (void *)NineResource9_GetType, 1167ec681f3Smrg (void *)NineIndexBuffer9_Lock, 1177ec681f3Smrg (void *)NineIndexBuffer9_Unlock, 1187ec681f3Smrg (void *)NineIndexBuffer9_GetDesc 1197ec681f3Smrg}; 1207ec681f3Smrg 1217ec681f3Smrgstatic const GUID *NineIndexBuffer9_IIDs[] = { 1227ec681f3Smrg &IID_IDirect3DIndexBuffer9, 1237ec681f3Smrg &IID_IDirect3DResource9, 1247ec681f3Smrg &IID_IUnknown, 1257ec681f3Smrg NULL 1267ec681f3Smrg}; 1277ec681f3Smrg 1287ec681f3SmrgHRESULT 1297ec681f3SmrgNineIndexBuffer9_new( struct NineDevice9 *pDevice, 1307ec681f3Smrg D3DINDEXBUFFER_DESC *pDesc, 1317ec681f3Smrg struct NineIndexBuffer9 **ppOut ) 1327ec681f3Smrg{ 1337ec681f3Smrg NINE_DEVICE_CHILD_NEW(IndexBuffer9, ppOut, /* args */ pDevice, pDesc); 1347ec681f3Smrg} 135