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 This
->buffer
.buffer
= NineIndexBuffer9_GetResource(This
);
53 This
->buffer
.offset
= 0;
55 switch (pDesc
->Format
) {
56 case D3DFMT_INDEX16
: This
->buffer
.index_size
= 2; break;
57 case D3DFMT_INDEX32
: This
->buffer
.index_size
= 4; break;
59 user_assert(!"Invalid index format.", D3DERR_INVALIDCALL
);
62 This
->buffer
.user_buffer
= NULL
;
64 pDesc
->Type
= D3DRTYPE_INDEXBUFFER
;
71 NineIndexBuffer9_dtor( struct NineIndexBuffer9
*This
)
73 NineBuffer9_dtor(&This
->base
);
76 const struct pipe_index_buffer
*
77 NineIndexBuffer9_GetBuffer( struct NineIndexBuffer9
*This
)
82 struct pipe_resource
*
83 NineIndexBuffer9_GetResource( struct NineIndexBuffer9
*This
)
85 return NineBuffer9_GetResource(&This
->base
);
89 NineIndexBuffer9_Lock( struct NineIndexBuffer9
*This
,
95 return NineBuffer9_Lock(&This
->base
, OffsetToLock
, SizeToLock
, ppbData
, Flags
);
99 NineIndexBuffer9_Unlock( struct NineIndexBuffer9
*This
)
101 return NineBuffer9_Unlock(&This
->base
);
105 NineIndexBuffer9_GetDesc( struct NineIndexBuffer9
*This
,
106 D3DINDEXBUFFER_DESC
*pDesc
)
108 user_assert(pDesc
, E_POINTER
);
113 IDirect3DIndexBuffer9Vtbl NineIndexBuffer9_vtable
= {
114 (void *)NineUnknown_QueryInterface
,
115 (void *)NineUnknown_AddRef
,
116 (void *)NineUnknown_Release
,
117 (void *)NineUnknown_GetDevice
, /* actually part of Resource9 iface */
118 (void *)NineUnknown_SetPrivateData
,
119 (void *)NineUnknown_GetPrivateData
,
120 (void *)NineUnknown_FreePrivateData
,
121 (void *)NineResource9_SetPriority
,
122 (void *)NineResource9_GetPriority
,
123 (void *)NineResource9_PreLoad
,
124 (void *)NineResource9_GetType
,
125 (void *)NineIndexBuffer9_Lock
,
126 (void *)NineIndexBuffer9_Unlock
,
127 (void *)NineIndexBuffer9_GetDesc
130 static const GUID
*NineIndexBuffer9_IIDs
[] = {
131 &IID_IDirect3DIndexBuffer9
,
132 &IID_IDirect3DResource9
,
138 NineIndexBuffer9_new( struct NineDevice9
*pDevice
,
139 D3DINDEXBUFFER_DESC
*pDesc
,
140 struct NineIndexBuffer9
**ppOut
)
142 NINE_DEVICE_CHILD_NEW(IndexBuffer9
, ppOut
, /* args */ pDevice
, pDesc
);