st/nine: Rename pipe to pipe_data in nine_context
[mesa.git] / src / gallium / state_trackers / nine / indexbuffer9.c
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@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 "indexbuffer9.h"
24 #include "device9.h"
25 #include "nine_helpers.h"
26 #include "nine_pipe.h"
27 #include "nine_dump.h"
28
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"
35
36 #define DBG_CHANNEL DBG_INDEXBUFFER
37
38 HRESULT
39 NineIndexBuffer9_ctor( struct NineIndexBuffer9 *This,
40 struct NineUnknownParams *pParams,
41 D3DINDEXBUFFER_DESC *pDesc )
42 {
43 HRESULT hr;
44 DBG("This=%p pParams=%p pDesc=%p Usage=%s\n",
45 This, pParams, pDesc, nine_D3DUSAGE_to_str(pDesc->Usage));
46
47 hr = NineBuffer9_ctor(&This->base, pParams, D3DRTYPE_INDEXBUFFER,
48 pDesc->Usage, pDesc->Size, pDesc->Pool);
49 if (FAILED(hr))
50 return hr;
51
52 This->buffer.buffer = NineIndexBuffer9_GetResource(This);
53 This->buffer.offset = 0;
54
55 switch (pDesc->Format) {
56 case D3DFMT_INDEX16: This->buffer.index_size = 2; break;
57 case D3DFMT_INDEX32: This->buffer.index_size = 4; break;
58 default:
59 user_assert(!"Invalid index format.", D3DERR_INVALIDCALL);
60 break;
61 }
62 This->buffer.user_buffer = NULL;
63
64 pDesc->Type = D3DRTYPE_INDEXBUFFER;
65 This->desc = *pDesc;
66
67 return D3D_OK;
68 }
69
70 void
71 NineIndexBuffer9_dtor( struct NineIndexBuffer9 *This )
72 {
73 NineBuffer9_dtor(&This->base);
74 }
75
76 const struct pipe_index_buffer *
77 NineIndexBuffer9_GetBuffer( struct NineIndexBuffer9 *This )
78 {
79 return &This->buffer;
80 }
81
82 struct pipe_resource *
83 NineIndexBuffer9_GetResource( struct NineIndexBuffer9 *This )
84 {
85 return NineBuffer9_GetResource(&This->base);
86 }
87
88 HRESULT NINE_WINAPI
89 NineIndexBuffer9_Lock( struct NineIndexBuffer9 *This,
90 UINT OffsetToLock,
91 UINT SizeToLock,
92 void **ppbData,
93 DWORD Flags )
94 {
95 return NineBuffer9_Lock(&This->base, OffsetToLock, SizeToLock, ppbData, Flags);
96 }
97
98 HRESULT NINE_WINAPI
99 NineIndexBuffer9_Unlock( struct NineIndexBuffer9 *This )
100 {
101 return NineBuffer9_Unlock(&This->base);
102 }
103
104 HRESULT NINE_WINAPI
105 NineIndexBuffer9_GetDesc( struct NineIndexBuffer9 *This,
106 D3DINDEXBUFFER_DESC *pDesc )
107 {
108 user_assert(pDesc, E_POINTER);
109 *pDesc = This->desc;
110 return D3D_OK;
111 }
112
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
128 };
129
130 static const GUID *NineIndexBuffer9_IIDs[] = {
131 &IID_IDirect3DIndexBuffer9,
132 &IID_IDirect3DResource9,
133 &IID_IUnknown,
134 NULL
135 };
136
137 HRESULT
138 NineIndexBuffer9_new( struct NineDevice9 *pDevice,
139 D3DINDEXBUFFER_DESC *pDesc,
140 struct NineIndexBuffer9 **ppOut )
141 {
142 NINE_DEVICE_CHILD_NEW(IndexBuffer9, ppOut, /* args */ pDevice, pDesc);
143 }