1 | /*
|
---|
2 | * IDirect3DVertexDeclaration8 implementation
|
---|
3 | *
|
---|
4 | * Copyright 2007 Henri Verbeet
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | /* IDirect3DVertexDeclaration8 is internal to our implementation.
|
---|
22 | * It's not visible in the API. */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
26 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
27 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
28 | * a choice of LGPL license versions is made available with the language indicating
|
---|
29 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
30 | * of the LGPL is applied is otherwise unspecified.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include "config.h"
|
---|
34 | #include "d3d8_private.h"
|
---|
35 |
|
---|
36 | WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
|
---|
37 |
|
---|
38 | /* IUnknown */
|
---|
39 | static HRESULT WINAPI IDirect3DVertexDeclaration8Impl_QueryInterface(IDirect3DVertexDeclaration8 *iface, REFIID riid, void **obj_ptr)
|
---|
40 | {
|
---|
41 | TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj_ptr);
|
---|
42 |
|
---|
43 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
44 | || IsEqualGUID(riid, &IID_IDirect3DVertexDeclaration8))
|
---|
45 | {
|
---|
46 | IUnknown_AddRef(iface);
|
---|
47 | *obj_ptr = iface;
|
---|
48 | return S_OK;
|
---|
49 | }
|
---|
50 |
|
---|
51 | *obj_ptr = NULL;
|
---|
52 | return E_NOINTERFACE;
|
---|
53 | }
|
---|
54 |
|
---|
55 | static ULONG WINAPI IDirect3DVertexDeclaration8Impl_AddRef(IDirect3DVertexDeclaration8 *iface)
|
---|
56 | {
|
---|
57 | IDirect3DVertexDeclaration8Impl *This = (IDirect3DVertexDeclaration8Impl *)iface;
|
---|
58 | ULONG ref_count = InterlockedIncrement(&This->ref_count);
|
---|
59 |
|
---|
60 | TRACE("%p increasing refcount to %u.\n", iface, ref_count);
|
---|
61 |
|
---|
62 | if (ref_count == 1)
|
---|
63 | {
|
---|
64 | wined3d_mutex_lock();
|
---|
65 | IWineD3DVertexDeclaration_AddRef(This->wined3d_vertex_declaration);
|
---|
66 | wined3d_mutex_unlock();
|
---|
67 | }
|
---|
68 |
|
---|
69 | return ref_count;
|
---|
70 | }
|
---|
71 |
|
---|
72 | static ULONG WINAPI IDirect3DVertexDeclaration8Impl_Release(IDirect3DVertexDeclaration8 *iface)
|
---|
73 | {
|
---|
74 | IDirect3DVertexDeclaration8Impl *This = (IDirect3DVertexDeclaration8Impl *)iface;
|
---|
75 | ULONG ref_count = InterlockedDecrement(&This->ref_count);
|
---|
76 |
|
---|
77 | TRACE("%p decreasing refcount to %u.\n", iface, ref_count);
|
---|
78 |
|
---|
79 | if (!ref_count) {
|
---|
80 | wined3d_mutex_lock();
|
---|
81 | IWineD3DVertexDeclaration_Release(This->wined3d_vertex_declaration);
|
---|
82 | wined3d_mutex_unlock();
|
---|
83 | }
|
---|
84 |
|
---|
85 | return ref_count;
|
---|
86 | }
|
---|
87 |
|
---|
88 | static const char *debug_d3dvsdt_type(D3DVSDT_TYPE d3dvsdt_type)
|
---|
89 | {
|
---|
90 | switch (d3dvsdt_type)
|
---|
91 | {
|
---|
92 | #define D3DVSDT_TYPE_TO_STR(u) case u: return #u
|
---|
93 | D3DVSDT_TYPE_TO_STR(D3DVSDT_FLOAT1);
|
---|
94 | D3DVSDT_TYPE_TO_STR(D3DVSDT_FLOAT2);
|
---|
95 | D3DVSDT_TYPE_TO_STR(D3DVSDT_FLOAT3);
|
---|
96 | D3DVSDT_TYPE_TO_STR(D3DVSDT_FLOAT4);
|
---|
97 | D3DVSDT_TYPE_TO_STR(D3DVSDT_D3DCOLOR);
|
---|
98 | D3DVSDT_TYPE_TO_STR(D3DVSDT_UBYTE4);
|
---|
99 | D3DVSDT_TYPE_TO_STR(D3DVSDT_SHORT2);
|
---|
100 | D3DVSDT_TYPE_TO_STR(D3DVSDT_SHORT4);
|
---|
101 | #undef D3DVSDT_TYPE_TO_STR
|
---|
102 | default:
|
---|
103 | FIXME("Unrecognized D3DVSDT_TYPE %#x\n", d3dvsdt_type);
|
---|
104 | return "unrecognized";
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | static const char *debug_d3dvsde_register(D3DVSDE_REGISTER d3dvsde_register)
|
---|
109 | {
|
---|
110 | switch (d3dvsde_register)
|
---|
111 | {
|
---|
112 | #define D3DVSDE_REGISTER_TO_STR(u) case u: return #u
|
---|
113 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_POSITION);
|
---|
114 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_BLENDWEIGHT);
|
---|
115 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_BLENDINDICES);
|
---|
116 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_NORMAL);
|
---|
117 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_PSIZE);
|
---|
118 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_DIFFUSE);
|
---|
119 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_SPECULAR);
|
---|
120 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD0);
|
---|
121 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD1);
|
---|
122 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD2);
|
---|
123 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD3);
|
---|
124 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD4);
|
---|
125 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD5);
|
---|
126 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD6);
|
---|
127 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD7);
|
---|
128 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_POSITION2);
|
---|
129 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_NORMAL2);
|
---|
130 | #undef D3DVSDE_REGISTER_TO_STR
|
---|
131 | default:
|
---|
132 | FIXME("Unrecognized D3DVSDE_REGISTER %#x\n", d3dvsde_register);
|
---|
133 | return "unrecognized";
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | size_t parse_token(const DWORD* pToken)
|
---|
138 | {
|
---|
139 | const DWORD token = *pToken;
|
---|
140 | size_t tokenlen = 1;
|
---|
141 |
|
---|
142 | switch ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT) { /* maybe a macro to inverse ... */
|
---|
143 | case D3DVSD_TOKEN_NOP:
|
---|
144 | TRACE(" 0x%08x NOP()\n", token);
|
---|
145 | break;
|
---|
146 |
|
---|
147 | case D3DVSD_TOKEN_STREAM:
|
---|
148 | if (token & D3DVSD_STREAMTESSMASK)
|
---|
149 | {
|
---|
150 | TRACE(" 0x%08x STREAM_TESS()\n", token);
|
---|
151 | } else {
|
---|
152 | TRACE(" 0x%08x STREAM(%u)\n", token, ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT));
|
---|
153 | }
|
---|
154 | break;
|
---|
155 |
|
---|
156 | case D3DVSD_TOKEN_STREAMDATA:
|
---|
157 | if (token & 0x10000000)
|
---|
158 | {
|
---|
159 | TRACE(" 0x%08x SKIP(%u)\n", token, ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT));
|
---|
160 | } else {
|
---|
161 | DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
162 | DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
163 | TRACE(" 0x%08x REG(%s, %s)\n", token, debug_d3dvsde_register(reg), debug_d3dvsdt_type(type));
|
---|
164 | }
|
---|
165 | break;
|
---|
166 |
|
---|
167 | case D3DVSD_TOKEN_TESSELLATOR:
|
---|
168 | if (token & 0x10000000)
|
---|
169 | {
|
---|
170 | DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
171 | DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
172 | TRACE(" 0x%08x TESSUV(%s) as %s\n", token, debug_d3dvsde_register(reg), debug_d3dvsdt_type(type));
|
---|
173 | } else {
|
---|
174 | DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
175 | DWORD regout = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
176 | DWORD regin = ((token & D3DVSD_VERTEXREGINMASK) >> D3DVSD_VERTEXREGINSHIFT);
|
---|
177 | TRACE(" 0x%08x TESSNORMAL(%s, %s) as %s\n", token, debug_d3dvsde_register(regin),
|
---|
178 | debug_d3dvsde_register(regout), debug_d3dvsdt_type(type));
|
---|
179 | }
|
---|
180 | break;
|
---|
181 |
|
---|
182 | case D3DVSD_TOKEN_CONSTMEM:
|
---|
183 | {
|
---|
184 | DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
|
---|
185 | tokenlen = (4 * count) + 1;
|
---|
186 | }
|
---|
187 | break;
|
---|
188 |
|
---|
189 | case D3DVSD_TOKEN_EXT:
|
---|
190 | {
|
---|
191 | DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
|
---|
192 | DWORD extinfo = ((token & D3DVSD_EXTINFOMASK) >> D3DVSD_EXTINFOSHIFT);
|
---|
193 | TRACE(" 0x%08x EXT(%u, %u)\n", token, count, extinfo);
|
---|
194 | /* todo ... print extension */
|
---|
195 | tokenlen = count + 1;
|
---|
196 | }
|
---|
197 | break;
|
---|
198 |
|
---|
199 | case D3DVSD_TOKEN_END:
|
---|
200 | TRACE(" 0x%08x END()\n", token);
|
---|
201 | break;
|
---|
202 |
|
---|
203 | default:
|
---|
204 | TRACE(" 0x%08x UNKNOWN\n", token);
|
---|
205 | /* argg error */
|
---|
206 | }
|
---|
207 |
|
---|
208 | return tokenlen;
|
---|
209 | }
|
---|
210 |
|
---|
211 | void load_local_constants(const DWORD *d3d8_elements, IWineD3DVertexShader *wined3d_vertex_shader)
|
---|
212 | {
|
---|
213 | const DWORD *token = d3d8_elements;
|
---|
214 |
|
---|
215 | while (*token != D3DVSD_END())
|
---|
216 | {
|
---|
217 | if (((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT) == D3DVSD_TOKEN_CONSTMEM)
|
---|
218 | {
|
---|
219 | DWORD count = ((*token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
|
---|
220 | DWORD constant_idx = ((*token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT);
|
---|
221 | HRESULT hr;
|
---|
222 |
|
---|
223 | if (TRACE_ON(d3d8))
|
---|
224 | {
|
---|
225 | DWORD i;
|
---|
226 | for (i = 0; i < count; ++i)
|
---|
227 | {
|
---|
228 | TRACE("c[%u] = (%8f, %8f, %8f, %8f)\n",
|
---|
229 | constant_idx,
|
---|
230 | *(const float *)(token + i * 4 + 1),
|
---|
231 | *(const float *)(token + i * 4 + 2),
|
---|
232 | *(const float *)(token + i * 4 + 3),
|
---|
233 | *(const float *)(token + i * 4 + 4));
|
---|
234 | }
|
---|
235 | }
|
---|
236 | hr = IWineD3DVertexShader_SetLocalConstantsF(wined3d_vertex_shader, constant_idx, (const float *)token+1, count);
|
---|
237 | if (FAILED(hr)) ERR("Failed setting shader constants\n");
|
---|
238 | }
|
---|
239 |
|
---|
240 | token += parse_token(token);
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | /* NOTE: Make sure these are in the correct numerical order. (see /include/wined3d_types.h) */
|
---|
245 | static const size_t wined3d_type_sizes[] =
|
---|
246 | {
|
---|
247 | /*WINED3DDECLTYPE_FLOAT1*/ 1 * sizeof(float),
|
---|
248 | /*WINED3DDECLTYPE_FLOAT2*/ 2 * sizeof(float),
|
---|
249 | /*WINED3DDECLTYPE_FLOAT3*/ 3 * sizeof(float),
|
---|
250 | /*WINED3DDECLTYPE_FLOAT4*/ 4 * sizeof(float),
|
---|
251 | /*WINED3DDECLTYPE_D3DCOLOR*/ 4 * sizeof(BYTE),
|
---|
252 | /*WINED3DDECLTYPE_UBYTE4*/ 4 * sizeof(BYTE),
|
---|
253 | /*WINED3DDECLTYPE_SHORT2*/ 2 * sizeof(short int),
|
---|
254 | /*WINED3DDECLTYPE_SHORT4*/ 4 * sizeof(short int),
|
---|
255 | /*WINED3DDECLTYPE_UBYTE4N*/ 4 * sizeof(BYTE),
|
---|
256 | /*WINED3DDECLTYPE_SHORT2N*/ 2 * sizeof(short int),
|
---|
257 | /*WINED3DDECLTYPE_SHORT4N*/ 4 * sizeof(short int),
|
---|
258 | /*WINED3DDECLTYPE_USHORT2N*/ 2 * sizeof(short int),
|
---|
259 | /*WINED3DDECLTYPE_USHORT4N*/ 4 * sizeof(short int),
|
---|
260 | /*WINED3DDECLTYPE_UDEC3*/ 3 * sizeof(short int),
|
---|
261 | /*WINED3DDECLTYPE_DEC3N*/ 3 * sizeof(short int),
|
---|
262 | /*WINED3DDECLTYPE_FLOAT16_2*/ 2 * sizeof(short int),
|
---|
263 | /*WINED3DDECLTYPE_FLOAT16_4*/ 4 * sizeof(short int)
|
---|
264 | };
|
---|
265 |
|
---|
266 | static const WINED3DFORMAT wined3d_format_lookup[] =
|
---|
267 | {
|
---|
268 | /*WINED3DDECLTYPE_FLOAT1*/ WINED3DFMT_R32_FLOAT,
|
---|
269 | /*WINED3DDECLTYPE_FLOAT2*/ WINED3DFMT_R32G32_FLOAT,
|
---|
270 | /*WINED3DDECLTYPE_FLOAT3*/ WINED3DFMT_R32G32B32_FLOAT,
|
---|
271 | /*WINED3DDECLTYPE_FLOAT4*/ WINED3DFMT_R32G32B32A32_FLOAT,
|
---|
272 | /*WINED3DDECLTYPE_D3DCOLOR*/ WINED3DFMT_B8G8R8A8_UNORM,
|
---|
273 | /*WINED3DDECLTYPE_UBYTE4*/ WINED3DFMT_R8G8B8A8_UINT,
|
---|
274 | /*WINED3DDECLTYPE_SHORT2*/ WINED3DFMT_R16G16_SINT,
|
---|
275 | /*WINED3DDECLTYPE_SHORT4*/ WINED3DFMT_R16G16B16A16_SINT,
|
---|
276 | /*WINED3DDECLTYPE_UBYTE4N*/ WINED3DFMT_R8G8B8A8_UNORM,
|
---|
277 | /*WINED3DDECLTYPE_SHORT2N*/ WINED3DFMT_R16G16_SNORM,
|
---|
278 | /*WINED3DDECLTYPE_SHORT4N*/ WINED3DFMT_R16G16B16A16_SNORM,
|
---|
279 | /*WINED3DDECLTYPE_USHORT2N*/ WINED3DFMT_R16G16_UNORM,
|
---|
280 | /*WINED3DDECLTYPE_USHORT4N*/ WINED3DFMT_R16G16B16A16_UNORM,
|
---|
281 | /*WINED3DDECLTYPE_UDEC3*/ WINED3DFMT_R10G10B10A2_UINT,
|
---|
282 | /*WINED3DDECLTYPE_DEC3N*/ WINED3DFMT_R10G10B10A2_SNORM,
|
---|
283 | /*WINED3DDECLTYPE_FLOAT16_2*/ WINED3DFMT_R16G16_FLOAT,
|
---|
284 | /*WINED3DDECLTYPE_FLOAT16_4*/ WINED3DFMT_R16G16B16A16_FLOAT,
|
---|
285 | };
|
---|
286 |
|
---|
287 | typedef struct {
|
---|
288 | BYTE usage;
|
---|
289 | BYTE usage_idx;
|
---|
290 | } wined3d_usage_t;
|
---|
291 |
|
---|
292 | static const wined3d_usage_t wined3d_usage_lookup[] = {
|
---|
293 | /*D3DVSDE_POSITION*/ {WINED3DDECLUSAGE_POSITION, 0},
|
---|
294 | /*D3DVSDE_BLENDWEIGHT*/ {WINED3DDECLUSAGE_BLENDWEIGHT, 0},
|
---|
295 | /*D3DVSDE_BLENDINDICES*/ {WINED3DDECLUSAGE_BLENDINDICES, 0},
|
---|
296 | /*D3DVSDE_NORMAL*/ {WINED3DDECLUSAGE_NORMAL, 0},
|
---|
297 | /*D3DVSDE_PSIZE*/ {WINED3DDECLUSAGE_PSIZE, 0},
|
---|
298 | /*D3DVSDE_DIFFUSE*/ {WINED3DDECLUSAGE_COLOR, 0},
|
---|
299 | /*D3DVSDE_SPECULAR*/ {WINED3DDECLUSAGE_COLOR, 1},
|
---|
300 | /*D3DVSDE_TEXCOORD0*/ {WINED3DDECLUSAGE_TEXCOORD, 0},
|
---|
301 | /*D3DVSDE_TEXCOORD1*/ {WINED3DDECLUSAGE_TEXCOORD, 1},
|
---|
302 | /*D3DVSDE_TEXCOORD2*/ {WINED3DDECLUSAGE_TEXCOORD, 2},
|
---|
303 | /*D3DVSDE_TEXCOORD3*/ {WINED3DDECLUSAGE_TEXCOORD, 3},
|
---|
304 | /*D3DVSDE_TEXCOORD4*/ {WINED3DDECLUSAGE_TEXCOORD, 4},
|
---|
305 | /*D3DVSDE_TEXCOORD5*/ {WINED3DDECLUSAGE_TEXCOORD, 5},
|
---|
306 | /*D3DVSDE_TEXCOORD6*/ {WINED3DDECLUSAGE_TEXCOORD, 6},
|
---|
307 | /*D3DVSDE_TEXCOORD7*/ {WINED3DDECLUSAGE_TEXCOORD, 7},
|
---|
308 | /*D3DVSDE_POSITION2*/ {WINED3DDECLUSAGE_POSITION, 1},
|
---|
309 | /*D3DVSDE_NORMAL2*/ {WINED3DDECLUSAGE_NORMAL, 1},
|
---|
310 | };
|
---|
311 |
|
---|
312 | /* TODO: find out where rhw (or positionT) is for declaration8 */
|
---|
313 | static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size,
|
---|
314 | WINED3DVERTEXELEMENT **wined3d_elements)
|
---|
315 | {
|
---|
316 | const DWORD *token = d3d8_elements;
|
---|
317 | WINED3DVERTEXELEMENT *element;
|
---|
318 | D3DVSD_TOKENTYPE token_type;
|
---|
319 | unsigned int element_count = 0;
|
---|
320 | DWORD stream = 0;
|
---|
321 | int offset = 0;
|
---|
322 |
|
---|
323 | TRACE("d3d8_elements %p, wined3d_elements %p\n", d3d8_elements, wined3d_elements);
|
---|
324 |
|
---|
325 | /* 128 should be enough for anyone... */
|
---|
326 | *wined3d_elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 128 * sizeof(WINED3DVERTEXELEMENT));
|
---|
327 | while (D3DVSD_END() != *token)
|
---|
328 | {
|
---|
329 | token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
|
---|
330 |
|
---|
331 | if (token_type == D3DVSD_TOKEN_STREAM && !(*token & D3DVSD_STREAMTESSMASK))
|
---|
332 | {
|
---|
333 | stream = ((*token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT);
|
---|
334 | offset = 0;
|
---|
335 | } else if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
|
---|
336 | DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
337 | DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
338 |
|
---|
339 | TRACE("Adding element %d:\n", element_count);
|
---|
340 |
|
---|
341 | element = *wined3d_elements + element_count++;
|
---|
342 | element->format = wined3d_format_lookup[type];
|
---|
343 | element->input_slot = stream;
|
---|
344 | element->offset = offset;
|
---|
345 | element->output_slot = reg;
|
---|
346 | element->method = WINED3DDECLMETHOD_DEFAULT;
|
---|
347 | element->usage = wined3d_usage_lookup[reg].usage;
|
---|
348 | element->usage_idx = wined3d_usage_lookup[reg].usage_idx;
|
---|
349 |
|
---|
350 | offset += wined3d_type_sizes[type];
|
---|
351 | } else if (token_type == D3DVSD_TOKEN_STREAMDATA && (token_type & 0x10000000)) {
|
---|
352 | TRACE(" 0x%08x SKIP(%u)\n", token_type, ((token_type & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT));
|
---|
353 | offset += sizeof(DWORD) * ((token_type & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT);
|
---|
354 | }
|
---|
355 |
|
---|
356 | if (element_count >= 127) {
|
---|
357 | ERR("More than 127 elements?\n");
|
---|
358 | break;
|
---|
359 | }
|
---|
360 |
|
---|
361 | token += parse_token(token);
|
---|
362 | }
|
---|
363 |
|
---|
364 | *d3d8_elements_size = (++token - d3d8_elements) * sizeof(DWORD);
|
---|
365 |
|
---|
366 | return element_count;
|
---|
367 | }
|
---|
368 |
|
---|
369 | static const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl =
|
---|
370 | {
|
---|
371 | IDirect3DVertexDeclaration8Impl_QueryInterface,
|
---|
372 | IDirect3DVertexDeclaration8Impl_AddRef,
|
---|
373 | IDirect3DVertexDeclaration8Impl_Release
|
---|
374 | };
|
---|
375 |
|
---|
376 | static void STDMETHODCALLTYPE d3d8_vertexdeclaration_wined3d_object_destroyed(void *parent)
|
---|
377 | {
|
---|
378 | IDirect3DVertexDeclaration8Impl *declaration = parent;
|
---|
379 | HeapFree(GetProcessHeap(), 0, declaration->elements);
|
---|
380 | HeapFree(GetProcessHeap(), 0, declaration);
|
---|
381 | }
|
---|
382 |
|
---|
383 | static const struct wined3d_parent_ops d3d8_vertexdeclaration_wined3d_parent_ops =
|
---|
384 | {
|
---|
385 | d3d8_vertexdeclaration_wined3d_object_destroyed,
|
---|
386 | };
|
---|
387 |
|
---|
388 | HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
|
---|
389 | IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle)
|
---|
390 | {
|
---|
391 | WINED3DVERTEXELEMENT *wined3d_elements;
|
---|
392 | UINT wined3d_element_count;
|
---|
393 | HRESULT hr;
|
---|
394 |
|
---|
395 | declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
|
---|
396 | declaration->ref_count = 1;
|
---|
397 | declaration->shader_handle = shader_handle;
|
---|
398 |
|
---|
399 | wined3d_element_count = convert_to_wined3d_declaration(elements, &declaration->elements_size, &wined3d_elements);
|
---|
400 | declaration->elements = HeapAlloc(GetProcessHeap(), 0, declaration->elements_size);
|
---|
401 | if (!declaration->elements)
|
---|
402 | {
|
---|
403 | ERR("Failed to allocate vertex declaration elements memory.\n");
|
---|
404 | HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
---|
405 | return E_OUTOFMEMORY;
|
---|
406 | }
|
---|
407 |
|
---|
408 | memcpy(declaration->elements, elements, declaration->elements_size);
|
---|
409 |
|
---|
410 | wined3d_mutex_lock();
|
---|
411 | hr = IWineD3DDevice_CreateVertexDeclaration(device->WineD3DDevice, &declaration->wined3d_vertex_declaration,
|
---|
412 | (IUnknown *)declaration, &d3d8_vertexdeclaration_wined3d_parent_ops,
|
---|
413 | wined3d_elements, wined3d_element_count);
|
---|
414 | wined3d_mutex_unlock();
|
---|
415 | HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
---|
416 | if (FAILED(hr))
|
---|
417 | {
|
---|
418 | WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
|
---|
419 | HeapFree(GetProcessHeap(), 0, declaration->elements);
|
---|
420 | return hr;
|
---|
421 | }
|
---|
422 |
|
---|
423 | return D3D_OK;
|
---|
424 | }
|
---|
425 |
|
---|
426 | HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
|
---|
427 | IDirect3DDevice8Impl *device, DWORD fvf)
|
---|
428 | {
|
---|
429 | HRESULT hr;
|
---|
430 |
|
---|
431 | declaration->ref_count = 1;
|
---|
432 | declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
|
---|
433 | declaration->elements = NULL;
|
---|
434 | declaration->elements_size = 0;
|
---|
435 | declaration->shader_handle = fvf;
|
---|
436 |
|
---|
437 | hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(device->WineD3DDevice,
|
---|
438 | &declaration->wined3d_vertex_declaration, (IUnknown *)declaration,
|
---|
439 | &d3d8_vertexdeclaration_wined3d_parent_ops, fvf);
|
---|
440 | if (FAILED(hr))
|
---|
441 | {
|
---|
442 | WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
|
---|
443 | return hr;
|
---|
444 | }
|
---|
445 |
|
---|
446 | return D3D_OK;
|
---|
447 | }
|
---|