2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
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:
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
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. */
23 #include "indexbuffer9.h"
25 #include "nine_helpers.h"
26 #include "nine_pipe.h"
27 #include "nine_dump.h"
29 #include "pipe/p_screen.h"
30 #include "pipe/p_context.h"
31 #include "pipe/p_state.h"
32 #include "pipe/p_defines.h"
33 #include "pipe/p_format.h"
34 #include "util/u_box.h"
36 #define DBG_CHANNEL DBG_INDEXBUFFER
39 NineIndexBuffer9_ctor( struct NineIndexBuffer9
*This
,
40 struct NineUnknownParams
*pParams
,
41 D3DINDEXBUFFER_DESC
*pDesc
)
44 DBG("This=%p pParams=%p pDesc=%p Usage=%s\n",
45 This
, pParams
, pDesc
, nine_D3DUSAGE_to_str(pDesc
->Usage
));
47 hr
= NineBuffer9_ctor(&This
->base
, pParams
, D3DRTYPE_INDEXBUFFER
,
48 pDesc
->Usage
, pDesc
->Size
, pDesc
->Pool
);
52 switch (pDesc
->Format
) {
53 case D3DFMT_INDEX16
: This
->index_size
= 2; break;
54 case D3DFMT_INDEX32
: This
->index_size
= 4; break;
56 user_assert(!"Invalid index format.", D3DERR_INVALIDCALL
);
60 pDesc
->Type
= D3DRTYPE_INDEXBUFFER
;
67 NineIndexBuffer9_dtor( struct NineIndexBuffer9
*This
)
69 NineBuffer9_dtor(&This
->base
);
72 struct pipe_resource
*
73 NineIndexBuffer9_GetBuffer( struct NineIndexBuffer9
*This
, unsigned *offset
)
75 /* The resource may change */
76 return NineBuffer9_GetResource(&This
->base
, offset
);
80 NineIndexBuffer9_Lock( struct NineIndexBuffer9
*This
,
86 return NineBuffer9_Lock(&This
->base
, OffsetToLock
, SizeToLock
, ppbData
, Flags
);
90 NineIndexBuffer9_Unlock( struct NineIndexBuffer9
*This
)
92 return NineBuffer9_Unlock(&This
->base
);
96 NineIndexBuffer9_GetDesc( struct NineIndexBuffer9
*This
,
97 D3DINDEXBUFFER_DESC
*pDesc
)
99 user_assert(pDesc
, E_POINTER
);
104 IDirect3DIndexBuffer9Vtbl NineIndexBuffer9_vtable
= {
105 (void *)NineUnknown_QueryInterface
,
106 (void *)NineUnknown_AddRef
,
107 (void *)NineUnknown_Release
,
108 (void *)NineUnknown_GetDevice
, /* actually part of Resource9 iface */
109 (void *)NineUnknown_SetPrivateData
,
110 (void *)NineUnknown_GetPrivateData
,
111 (void *)NineUnknown_FreePrivateData
,
112 (void *)NineResource9_SetPriority
,
113 (void *)NineResource9_GetPriority
,
114 (void *)NineResource9_PreLoad
,
115 (void *)NineResource9_GetType
,
116 (void *)NineIndexBuffer9_Lock
,
117 (void *)NineIndexBuffer9_Unlock
,
118 (void *)NineIndexBuffer9_GetDesc
121 static const GUID
*NineIndexBuffer9_IIDs
[] = {
122 &IID_IDirect3DIndexBuffer9
,
123 &IID_IDirect3DResource9
,
129 NineIndexBuffer9_new( struct NineDevice9
*pDevice
,
130 D3DINDEXBUFFER_DESC
*pDesc
,
131 struct NineIndexBuffer9
**ppOut
)
133 NINE_DEVICE_CHILD_NEW(IndexBuffer9
, ppOut
, /* args */ pDevice
, pDesc
);