shell32/tests: Fix tests on Vista+.
[wine] / dlls / d3d10core / inputlayout.c
1 /*
2  * Copyright 2009 Henri Verbeet for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  *
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include "d3d10core_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
26
27 static HRESULT isgn_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
28 {
29     struct wined3d_shader_signature *is = ctx;
30     char tag_str[5];
31
32     switch(tag)
33     {
34         case TAG_ISGN:
35             return shader_parse_signature(data, data_size, is);
36
37         default:
38             memcpy(tag_str, &tag, 4);
39             tag_str[4] = '\0';
40             FIXME("Unhandled chunk %s\n", tag_str);
41             return S_OK;
42     }
43 }
44
45 HRESULT d3d10_input_layout_to_wined3d_declaration(const D3D10_INPUT_ELEMENT_DESC *element_descs,
46         UINT element_count, const void *shader_byte_code, SIZE_T shader_byte_code_length,
47         WINED3DVERTEXELEMENT **wined3d_elements, UINT *wined3d_element_count)
48 {
49     struct wined3d_shader_signature is;
50     HRESULT hr;
51     UINT i;
52
53     hr = parse_dxbc(shader_byte_code, shader_byte_code_length, isgn_handler, &is);
54     if (FAILED(hr))
55     {
56         ERR("Failed to parse input signature.\n");
57         return E_FAIL;
58     }
59
60     *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(**wined3d_elements));
61     if (!*wined3d_elements)
62     {
63         ERR("Failed to allocate wined3d vertex element array memory.\n");
64         HeapFree(GetProcessHeap(), 0, is.elements);
65         return E_OUTOFMEMORY;
66     }
67     *wined3d_element_count = 0;
68
69     for (i = 0; i < element_count; ++i)
70     {
71         UINT j;
72
73         for (j = 0; j < is.element_count; ++j)
74         {
75             if (!strcmp(element_descs[i].SemanticName, is.elements[j].semantic_name)
76                     && element_descs[i].SemanticIndex == is.elements[j].semantic_idx)
77             {
78                 WINED3DVERTEXELEMENT *e = &(*wined3d_elements)[(*wined3d_element_count)++];
79                 const D3D10_INPUT_ELEMENT_DESC *f = &element_descs[i];
80
81                 e->format = wined3dformat_from_dxgi_format(f->Format);
82                 e->input_slot = f->InputSlot;
83                 e->offset = f->AlignedByteOffset;
84                 e->output_slot = is.elements[j].register_idx;
85                 e->method = WINED3DDECLMETHOD_DEFAULT;
86                 e->usage = 0;
87                 e->usage_idx = 0;
88
89                 if (f->AlignedByteOffset == D3D10_APPEND_ALIGNED_ELEMENT)
90                     FIXME("D3D10_APPEND_ALIGNED_ELEMENT not supported\n");
91                 if (f->InputSlotClass != D3D10_INPUT_PER_VERTEX_DATA)
92                     FIXME("Ignoring input slot class (%#x)\n", f->InputSlotClass);
93                 if (f->InstanceDataStepRate)
94                     FIXME("Ignoring instace data step rate (%#x)\n", f->InstanceDataStepRate);
95
96                 break;
97             }
98         }
99     }
100
101     shader_free_signature(&is);
102
103     return S_OK;
104 }
105
106 /* IUnknown methods */
107
108 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_QueryInterface(ID3D10InputLayout *iface,
109         REFIID riid, void **object)
110 {
111     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
112
113     if (IsEqualGUID(riid, &IID_ID3D10InputLayout)
114             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
115             || IsEqualGUID(riid, &IID_IUnknown))
116     {
117         IUnknown_AddRef(iface);
118         *object = iface;
119         return S_OK;
120     }
121
122     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
123
124     *object = NULL;
125     return E_NOINTERFACE;
126 }
127
128 static ULONG STDMETHODCALLTYPE d3d10_input_layout_AddRef(ID3D10InputLayout *iface)
129 {
130     struct d3d10_input_layout *This = (struct d3d10_input_layout *)iface;
131     ULONG refcount = InterlockedIncrement(&This->refcount);
132
133     TRACE("%p increasing refcount to %u\n", This, refcount);
134
135     return refcount;
136 }
137
138 static ULONG STDMETHODCALLTYPE d3d10_input_layout_Release(ID3D10InputLayout *iface)
139 {
140     struct d3d10_input_layout *This = (struct d3d10_input_layout *)iface;
141     ULONG refcount = InterlockedDecrement(&This->refcount);
142
143     TRACE("%p decreasing refcount to %u\n", This, refcount);
144
145     if (!refcount)
146     {
147         IWineD3DVertexDeclaration_Release(This->wined3d_decl);
148         HeapFree(GetProcessHeap(), 0, This);
149     }
150
151     return refcount;
152 }
153
154 /* ID3D10DeviceChild methods */
155
156 static void STDMETHODCALLTYPE d3d10_input_layout_GetDevice(ID3D10InputLayout *iface, ID3D10Device **device)
157 {
158     FIXME("iface %p, device %p stub!\n", iface, device);
159 }
160
161 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_GetPrivateData(ID3D10InputLayout *iface,
162         REFGUID guid, UINT *data_size, void *data)
163 {
164     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
165             iface, debugstr_guid(guid), data_size, data);
166
167     return E_NOTIMPL;
168 }
169
170 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateData(ID3D10InputLayout *iface,
171         REFGUID guid, UINT data_size, const void *data)
172 {
173     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
174             iface, debugstr_guid(guid), data_size, data);
175
176     return E_NOTIMPL;
177 }
178
179 static HRESULT STDMETHODCALLTYPE d3d10_input_layout_SetPrivateDataInterface(ID3D10InputLayout *iface,
180         REFGUID guid, const IUnknown *data)
181 {
182     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
183
184     return E_NOTIMPL;
185 }
186
187 const struct ID3D10InputLayoutVtbl d3d10_input_layout_vtbl =
188 {
189     /* IUnknown methods */
190     d3d10_input_layout_QueryInterface,
191     d3d10_input_layout_AddRef,
192     d3d10_input_layout_Release,
193     /* ID3D10DeviceChild methods */
194     d3d10_input_layout_GetDevice,
195     d3d10_input_layout_GetPrivateData,
196     d3d10_input_layout_SetPrivateData,
197     d3d10_input_layout_SetPrivateDataInterface,
198 };