• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
NineIndexBuffer9_ctor(struct NineIndexBuffer9 * This,struct NineUnknownParams * pParams,D3DINDEXBUFFER_DESC * pDesc)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     switch (pDesc->Format) {
53     case D3DFMT_INDEX16: This->index_size = 2; break;
54     case D3DFMT_INDEX32: This->index_size = 4; break;
55     default:
56         user_assert(!"Invalid index format.", D3DERR_INVALIDCALL);
57         break;
58     }
59 
60     pDesc->Type = D3DRTYPE_INDEXBUFFER;
61     This->desc = *pDesc;
62 
63     return D3D_OK;
64 }
65 
66 void
NineIndexBuffer9_dtor(struct NineIndexBuffer9 * This)67 NineIndexBuffer9_dtor( struct NineIndexBuffer9 *This )
68 {
69     NineBuffer9_dtor(&This->base);
70 }
71 
72 struct pipe_resource *
NineIndexBuffer9_GetBuffer(struct NineIndexBuffer9 * This,unsigned * offset)73 NineIndexBuffer9_GetBuffer( struct NineIndexBuffer9 *This, unsigned *offset )
74 {
75     /* The resource may change */
76     return NineBuffer9_GetResource(&This->base, offset);
77 }
78 
79 HRESULT NINE_WINAPI
NineIndexBuffer9_Lock(struct NineIndexBuffer9 * This,UINT OffsetToLock,UINT SizeToLock,void ** ppbData,DWORD Flags)80 NineIndexBuffer9_Lock( struct NineIndexBuffer9 *This,
81                        UINT OffsetToLock,
82                        UINT SizeToLock,
83                        void **ppbData,
84                        DWORD Flags )
85 {
86     return NineBuffer9_Lock(&This->base, OffsetToLock, SizeToLock, ppbData, Flags);
87 }
88 
89 HRESULT NINE_WINAPI
NineIndexBuffer9_Unlock(struct NineIndexBuffer9 * This)90 NineIndexBuffer9_Unlock( struct NineIndexBuffer9 *This )
91 {
92     return NineBuffer9_Unlock(&This->base);
93 }
94 
95 HRESULT NINE_WINAPI
NineIndexBuffer9_GetDesc(struct NineIndexBuffer9 * This,D3DINDEXBUFFER_DESC * pDesc)96 NineIndexBuffer9_GetDesc( struct NineIndexBuffer9 *This,
97                           D3DINDEXBUFFER_DESC *pDesc )
98 {
99     user_assert(pDesc, E_POINTER);
100     *pDesc = This->desc;
101     return D3D_OK;
102 }
103 
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
119 };
120 
121 static const GUID *NineIndexBuffer9_IIDs[] = {
122     &IID_IDirect3DIndexBuffer9,
123     &IID_IDirect3DResource9,
124     &IID_IUnknown,
125     NULL
126 };
127 
128 HRESULT
NineIndexBuffer9_new(struct NineDevice9 * pDevice,D3DINDEXBUFFER_DESC * pDesc,struct NineIndexBuffer9 ** ppOut)129 NineIndexBuffer9_new( struct NineDevice9 *pDevice,
130                       D3DINDEXBUFFER_DESC *pDesc,
131                       struct NineIndexBuffer9 **ppOut )
132 {
133     NINE_DEVICE_CHILD_NEW(IndexBuffer9, ppOut, /* args */ pDevice, pDesc);
134 }
135