Path: blob/21.2-virgl/src/gallium/frontends/nine/indexbuffer9.c
4561 views
/*1* Copyright 2011 Joakim Sindholt <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122#include "indexbuffer9.h"23#include "device9.h"24#include "nine_helpers.h"25#include "nine_pipe.h"26#include "nine_dump.h"2728#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"3435#define DBG_CHANNEL DBG_INDEXBUFFER3637HRESULT38NineIndexBuffer9_ctor( struct NineIndexBuffer9 *This,39struct NineUnknownParams *pParams,40D3DINDEXBUFFER_DESC *pDesc )41{42HRESULT hr;43DBG("This=%p pParams=%p pDesc=%p Usage=%s\n",44This, pParams, pDesc, nine_D3DUSAGE_to_str(pDesc->Usage));4546hr = NineBuffer9_ctor(&This->base, pParams, D3DRTYPE_INDEXBUFFER,47pDesc->Usage, pDesc->Size, pDesc->Pool);48if (FAILED(hr))49return hr;5051switch (pDesc->Format) {52case D3DFMT_INDEX16: This->index_size = 2; break;53case D3DFMT_INDEX32: This->index_size = 4; break;54default:55user_assert(!"Invalid index format.", D3DERR_INVALIDCALL);56break;57}5859pDesc->Type = D3DRTYPE_INDEXBUFFER;60This->desc = *pDesc;6162return D3D_OK;63}6465void66NineIndexBuffer9_dtor( struct NineIndexBuffer9 *This )67{68NineBuffer9_dtor(&This->base);69}7071struct pipe_resource *72NineIndexBuffer9_GetBuffer( struct NineIndexBuffer9 *This, unsigned *offset )73{74/* The resource may change */75return NineBuffer9_GetResource(&This->base, offset);76}7778HRESULT NINE_WINAPI79NineIndexBuffer9_Lock( struct NineIndexBuffer9 *This,80UINT OffsetToLock,81UINT SizeToLock,82void **ppbData,83DWORD Flags )84{85return NineBuffer9_Lock(&This->base, OffsetToLock, SizeToLock, ppbData, Flags);86}8788HRESULT NINE_WINAPI89NineIndexBuffer9_Unlock( struct NineIndexBuffer9 *This )90{91return NineBuffer9_Unlock(&This->base);92}9394HRESULT NINE_WINAPI95NineIndexBuffer9_GetDesc( struct NineIndexBuffer9 *This,96D3DINDEXBUFFER_DESC *pDesc )97{98user_assert(pDesc, E_POINTER);99*pDesc = This->desc;100return D3D_OK;101}102103IDirect3DIndexBuffer9Vtbl NineIndexBuffer9_vtable = {104(void *)NineUnknown_QueryInterface,105(void *)NineUnknown_AddRef,106(void *)NineUnknown_Release,107(void *)NineUnknown_GetDevice, /* actually part of Resource9 iface */108(void *)NineUnknown_SetPrivateData,109(void *)NineUnknown_GetPrivateData,110(void *)NineUnknown_FreePrivateData,111(void *)NineResource9_SetPriority,112(void *)NineResource9_GetPriority,113(void *)NineResource9_PreLoad,114(void *)NineResource9_GetType,115(void *)NineIndexBuffer9_Lock,116(void *)NineIndexBuffer9_Unlock,117(void *)NineIndexBuffer9_GetDesc118};119120static const GUID *NineIndexBuffer9_IIDs[] = {121&IID_IDirect3DIndexBuffer9,122&IID_IDirect3DResource9,123&IID_IUnknown,124NULL125};126127HRESULT128NineIndexBuffer9_new( struct NineDevice9 *pDevice,129D3DINDEXBUFFER_DESC *pDesc,130struct NineIndexBuffer9 **ppOut )131{132NINE_DEVICE_CHILD_NEW(IndexBuffer9, ppOut, /* args */ pDevice, pDesc);133}134135136