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 | #include "config.h"
|
---|
25 | #include "d3d8_private.h"
|
---|
26 |
|
---|
27 | WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
|
---|
28 |
|
---|
29 | #ifdef VBOX_WINE_WITHOUT_LIBWINE
|
---|
30 | typedef DWORD D3DVSDT_TYPE;
|
---|
31 | typedef DWORD D3DVSDE_REGISTER;
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | static const char *debug_d3dvsdt_type(D3DVSDT_TYPE d3dvsdt_type)
|
---|
35 | {
|
---|
36 | switch (d3dvsdt_type)
|
---|
37 | {
|
---|
38 | #define D3DVSDT_TYPE_TO_STR(u) case u: return #u
|
---|
39 | D3DVSDT_TYPE_TO_STR(D3DVSDT_FLOAT1);
|
---|
40 | D3DVSDT_TYPE_TO_STR(D3DVSDT_FLOAT2);
|
---|
41 | D3DVSDT_TYPE_TO_STR(D3DVSDT_FLOAT3);
|
---|
42 | D3DVSDT_TYPE_TO_STR(D3DVSDT_FLOAT4);
|
---|
43 | D3DVSDT_TYPE_TO_STR(D3DVSDT_D3DCOLOR);
|
---|
44 | D3DVSDT_TYPE_TO_STR(D3DVSDT_UBYTE4);
|
---|
45 | D3DVSDT_TYPE_TO_STR(D3DVSDT_SHORT2);
|
---|
46 | D3DVSDT_TYPE_TO_STR(D3DVSDT_SHORT4);
|
---|
47 | #undef D3DVSDT_TYPE_TO_STR
|
---|
48 | default:
|
---|
49 | FIXME("Unrecognized D3DVSDT_TYPE %#x\n", d3dvsdt_type);
|
---|
50 | return "unrecognized";
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | static const char *debug_d3dvsde_register(D3DVSDE_REGISTER d3dvsde_register)
|
---|
55 | {
|
---|
56 | switch (d3dvsde_register)
|
---|
57 | {
|
---|
58 | #define D3DVSDE_REGISTER_TO_STR(u) case u: return #u
|
---|
59 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_POSITION);
|
---|
60 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_BLENDWEIGHT);
|
---|
61 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_BLENDINDICES);
|
---|
62 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_NORMAL);
|
---|
63 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_PSIZE);
|
---|
64 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_DIFFUSE);
|
---|
65 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_SPECULAR);
|
---|
66 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD0);
|
---|
67 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD1);
|
---|
68 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD2);
|
---|
69 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD3);
|
---|
70 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD4);
|
---|
71 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD5);
|
---|
72 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD6);
|
---|
73 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_TEXCOORD7);
|
---|
74 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_POSITION2);
|
---|
75 | D3DVSDE_REGISTER_TO_STR(D3DVSDE_NORMAL2);
|
---|
76 | #undef D3DVSDE_REGISTER_TO_STR
|
---|
77 | default:
|
---|
78 | FIXME("Unrecognized D3DVSDE_REGISTER %#x\n", d3dvsde_register);
|
---|
79 | return "unrecognized";
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | size_t parse_token(const DWORD* pToken)
|
---|
84 | {
|
---|
85 | const DWORD token = *pToken;
|
---|
86 | size_t tokenlen = 1;
|
---|
87 |
|
---|
88 | switch ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT) { /* maybe a macro to inverse ... */
|
---|
89 | case D3DVSD_TOKEN_NOP:
|
---|
90 | TRACE(" 0x%08x NOP()\n", token);
|
---|
91 | break;
|
---|
92 |
|
---|
93 | case D3DVSD_TOKEN_STREAM:
|
---|
94 | if (token & D3DVSD_STREAMTESSMASK)
|
---|
95 | {
|
---|
96 | TRACE(" 0x%08x STREAM_TESS()\n", token);
|
---|
97 | } else {
|
---|
98 | TRACE(" 0x%08x STREAM(%u)\n", token, ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT));
|
---|
99 | }
|
---|
100 | break;
|
---|
101 |
|
---|
102 | case D3DVSD_TOKEN_STREAMDATA:
|
---|
103 | if (token & 0x10000000)
|
---|
104 | {
|
---|
105 | TRACE(" 0x%08x SKIP(%u)\n", token, ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT));
|
---|
106 | } else {
|
---|
107 | DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
108 | DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
109 | TRACE(" 0x%08x REG(%s, %s)\n", token, debug_d3dvsde_register(reg), debug_d3dvsdt_type(type));
|
---|
110 | }
|
---|
111 | break;
|
---|
112 |
|
---|
113 | case D3DVSD_TOKEN_TESSELLATOR:
|
---|
114 | if (token & 0x10000000)
|
---|
115 | {
|
---|
116 | DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
117 | DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
118 | TRACE(" 0x%08x TESSUV(%s) as %s\n", token, debug_d3dvsde_register(reg), debug_d3dvsdt_type(type));
|
---|
119 | } else {
|
---|
120 | DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
121 | DWORD regout = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
122 | DWORD regin = ((token & D3DVSD_VERTEXREGINMASK) >> D3DVSD_VERTEXREGINSHIFT);
|
---|
123 | TRACE(" 0x%08x TESSNORMAL(%s, %s) as %s\n", token, debug_d3dvsde_register(regin),
|
---|
124 | debug_d3dvsde_register(regout), debug_d3dvsdt_type(type));
|
---|
125 | }
|
---|
126 | break;
|
---|
127 |
|
---|
128 | case D3DVSD_TOKEN_CONSTMEM:
|
---|
129 | {
|
---|
130 | DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
|
---|
131 | tokenlen = (4 * count) + 1;
|
---|
132 | }
|
---|
133 | break;
|
---|
134 |
|
---|
135 | case D3DVSD_TOKEN_EXT:
|
---|
136 | {
|
---|
137 | DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
|
---|
138 | DWORD extinfo = ((token & D3DVSD_EXTINFOMASK) >> D3DVSD_EXTINFOSHIFT);
|
---|
139 | TRACE(" 0x%08x EXT(%u, %u)\n", token, count, extinfo);
|
---|
140 | /* todo ... print extension */
|
---|
141 | tokenlen = count + 1;
|
---|
142 | }
|
---|
143 | break;
|
---|
144 |
|
---|
145 | case D3DVSD_TOKEN_END:
|
---|
146 | TRACE(" 0x%08x END()\n", token);
|
---|
147 | break;
|
---|
148 |
|
---|
149 | default:
|
---|
150 | TRACE(" 0x%08x UNKNOWN\n", token);
|
---|
151 | /* arg error */
|
---|
152 | }
|
---|
153 |
|
---|
154 | return tokenlen;
|
---|
155 | }
|
---|
156 |
|
---|
157 | void load_local_constants(const DWORD *d3d8_elements, struct wined3d_shader *wined3d_vertex_shader)
|
---|
158 | {
|
---|
159 | const DWORD *token = d3d8_elements;
|
---|
160 |
|
---|
161 | while (*token != D3DVSD_END())
|
---|
162 | {
|
---|
163 | if (((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT) == D3DVSD_TOKEN_CONSTMEM)
|
---|
164 | {
|
---|
165 | DWORD count = ((*token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
|
---|
166 | DWORD constant_idx = ((*token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT);
|
---|
167 | HRESULT hr;
|
---|
168 |
|
---|
169 | if (TRACE_ON(d3d8))
|
---|
170 | {
|
---|
171 | DWORD i;
|
---|
172 | for (i = 0; i < count; ++i)
|
---|
173 | {
|
---|
174 | TRACE("c[%u] = (%8f, %8f, %8f, %8f)\n",
|
---|
175 | constant_idx,
|
---|
176 | *(const float *)(token + i * 4 + 1),
|
---|
177 | *(const float *)(token + i * 4 + 2),
|
---|
178 | *(const float *)(token + i * 4 + 3),
|
---|
179 | *(const float *)(token + i * 4 + 4));
|
---|
180 | }
|
---|
181 | }
|
---|
182 | hr = wined3d_shader_set_local_constants_float(wined3d_vertex_shader,
|
---|
183 | constant_idx, (const float *)token + 1, count);
|
---|
184 | if (FAILED(hr)) ERR("Failed setting shader constants\n");
|
---|
185 | }
|
---|
186 |
|
---|
187 | token += parse_token(token);
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | /* NOTE: Make sure these are in the correct numerical order. (see /include/wined3d_types.h) */
|
---|
192 | static const size_t wined3d_type_sizes[] =
|
---|
193 | {
|
---|
194 | /*WINED3DDECLTYPE_FLOAT1*/ 1 * sizeof(float),
|
---|
195 | /*WINED3DDECLTYPE_FLOAT2*/ 2 * sizeof(float),
|
---|
196 | /*WINED3DDECLTYPE_FLOAT3*/ 3 * sizeof(float),
|
---|
197 | /*WINED3DDECLTYPE_FLOAT4*/ 4 * sizeof(float),
|
---|
198 | /*WINED3DDECLTYPE_D3DCOLOR*/ 4 * sizeof(BYTE),
|
---|
199 | /*WINED3DDECLTYPE_UBYTE4*/ 4 * sizeof(BYTE),
|
---|
200 | /*WINED3DDECLTYPE_SHORT2*/ 2 * sizeof(short int),
|
---|
201 | /*WINED3DDECLTYPE_SHORT4*/ 4 * sizeof(short int),
|
---|
202 | /*WINED3DDECLTYPE_UBYTE4N*/ 4 * sizeof(BYTE),
|
---|
203 | /*WINED3DDECLTYPE_SHORT2N*/ 2 * sizeof(short int),
|
---|
204 | /*WINED3DDECLTYPE_SHORT4N*/ 4 * sizeof(short int),
|
---|
205 | /*WINED3DDECLTYPE_USHORT2N*/ 2 * sizeof(short int),
|
---|
206 | /*WINED3DDECLTYPE_USHORT4N*/ 4 * sizeof(short int),
|
---|
207 | /*WINED3DDECLTYPE_UDEC3*/ 3 * sizeof(short int),
|
---|
208 | /*WINED3DDECLTYPE_DEC3N*/ 3 * sizeof(short int),
|
---|
209 | /*WINED3DDECLTYPE_FLOAT16_2*/ 2 * sizeof(short int),
|
---|
210 | /*WINED3DDECLTYPE_FLOAT16_4*/ 4 * sizeof(short int)
|
---|
211 | };
|
---|
212 |
|
---|
213 | static const enum wined3d_format_id wined3d_format_lookup[] =
|
---|
214 | {
|
---|
215 | /*WINED3DDECLTYPE_FLOAT1*/ WINED3DFMT_R32_FLOAT,
|
---|
216 | /*WINED3DDECLTYPE_FLOAT2*/ WINED3DFMT_R32G32_FLOAT,
|
---|
217 | /*WINED3DDECLTYPE_FLOAT3*/ WINED3DFMT_R32G32B32_FLOAT,
|
---|
218 | /*WINED3DDECLTYPE_FLOAT4*/ WINED3DFMT_R32G32B32A32_FLOAT,
|
---|
219 | /*WINED3DDECLTYPE_D3DCOLOR*/ WINED3DFMT_B8G8R8A8_UNORM,
|
---|
220 | /*WINED3DDECLTYPE_UBYTE4*/ WINED3DFMT_R8G8B8A8_UINT,
|
---|
221 | /*WINED3DDECLTYPE_SHORT2*/ WINED3DFMT_R16G16_SINT,
|
---|
222 | /*WINED3DDECLTYPE_SHORT4*/ WINED3DFMT_R16G16B16A16_SINT,
|
---|
223 | /*WINED3DDECLTYPE_UBYTE4N*/ WINED3DFMT_R8G8B8A8_UNORM,
|
---|
224 | /*WINED3DDECLTYPE_SHORT2N*/ WINED3DFMT_R16G16_SNORM,
|
---|
225 | /*WINED3DDECLTYPE_SHORT4N*/ WINED3DFMT_R16G16B16A16_SNORM,
|
---|
226 | /*WINED3DDECLTYPE_USHORT2N*/ WINED3DFMT_R16G16_UNORM,
|
---|
227 | /*WINED3DDECLTYPE_USHORT4N*/ WINED3DFMT_R16G16B16A16_UNORM,
|
---|
228 | /*WINED3DDECLTYPE_UDEC3*/ WINED3DFMT_R10G10B10A2_UINT,
|
---|
229 | /*WINED3DDECLTYPE_DEC3N*/ WINED3DFMT_R10G10B10A2_SNORM,
|
---|
230 | /*WINED3DDECLTYPE_FLOAT16_2*/ WINED3DFMT_R16G16_FLOAT,
|
---|
231 | /*WINED3DDECLTYPE_FLOAT16_4*/ WINED3DFMT_R16G16B16A16_FLOAT,
|
---|
232 | };
|
---|
233 |
|
---|
234 | static const struct
|
---|
235 | {
|
---|
236 | BYTE usage;
|
---|
237 | BYTE usage_idx;
|
---|
238 | }
|
---|
239 | wined3d_usage_lookup[] =
|
---|
240 | {
|
---|
241 | /* D3DVSDE_POSITION */ {WINED3D_DECL_USAGE_POSITION, 0},
|
---|
242 | /* D3DVSDE_BLENDWEIGHT */ {WINED3D_DECL_USAGE_BLEND_WEIGHT, 0},
|
---|
243 | /* D3DVSDE_BLENDINDICES */ {WINED3D_DECL_USAGE_BLEND_INDICES, 0},
|
---|
244 | /* D3DVSDE_NORMAL */ {WINED3D_DECL_USAGE_NORMAL, 0},
|
---|
245 | /* D3DVSDE_PSIZE */ {WINED3D_DECL_USAGE_PSIZE, 0},
|
---|
246 | /* D3DVSDE_DIFFUSE */ {WINED3D_DECL_USAGE_COLOR, 0},
|
---|
247 | /* D3DVSDE_SPECULAR */ {WINED3D_DECL_USAGE_COLOR, 1},
|
---|
248 | /* D3DVSDE_TEXCOORD0 */ {WINED3D_DECL_USAGE_TEXCOORD, 0},
|
---|
249 | /* D3DVSDE_TEXCOORD1 */ {WINED3D_DECL_USAGE_TEXCOORD, 1},
|
---|
250 | /* D3DVSDE_TEXCOORD2 */ {WINED3D_DECL_USAGE_TEXCOORD, 2},
|
---|
251 | /* D3DVSDE_TEXCOORD3 */ {WINED3D_DECL_USAGE_TEXCOORD, 3},
|
---|
252 | /* D3DVSDE_TEXCOORD4 */ {WINED3D_DECL_USAGE_TEXCOORD, 4},
|
---|
253 | /* D3DVSDE_TEXCOORD5 */ {WINED3D_DECL_USAGE_TEXCOORD, 5},
|
---|
254 | /* D3DVSDE_TEXCOORD6 */ {WINED3D_DECL_USAGE_TEXCOORD, 6},
|
---|
255 | /* D3DVSDE_TEXCOORD7 */ {WINED3D_DECL_USAGE_TEXCOORD, 7},
|
---|
256 | /* D3DVSDE_POSITION2 */ {WINED3D_DECL_USAGE_POSITION, 1},
|
---|
257 | /* D3DVSDE_NORMAL2 */ {WINED3D_DECL_USAGE_NORMAL, 1},
|
---|
258 | };
|
---|
259 |
|
---|
260 | /* TODO: find out where rhw (or positionT) is for declaration8 */
|
---|
261 | static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size,
|
---|
262 | struct wined3d_vertex_element **wined3d_elements)
|
---|
263 | {
|
---|
264 | struct wined3d_vertex_element *element;
|
---|
265 | const DWORD *token = d3d8_elements;
|
---|
266 | D3DVSD_TOKENTYPE token_type;
|
---|
267 | unsigned int element_count = 0;
|
---|
268 | WORD stream = 0;
|
---|
269 | int offset = 0;
|
---|
270 |
|
---|
271 | TRACE("d3d8_elements %p, wined3d_elements %p\n", d3d8_elements, wined3d_elements);
|
---|
272 |
|
---|
273 | /* 128 should be enough for anyone... */
|
---|
274 | *wined3d_elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 128 * sizeof(**wined3d_elements));
|
---|
275 | while (D3DVSD_END() != *token)
|
---|
276 | {
|
---|
277 | token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
|
---|
278 |
|
---|
279 | if (token_type == D3DVSD_TOKEN_STREAM && !(*token & D3DVSD_STREAMTESSMASK))
|
---|
280 | {
|
---|
281 | stream = ((*token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT);
|
---|
282 | offset = 0;
|
---|
283 | } else if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
|
---|
284 | DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
|
---|
285 | DWORD reg = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
|
---|
286 |
|
---|
287 | TRACE("Adding element %d:\n", element_count);
|
---|
288 |
|
---|
289 | element = *wined3d_elements + element_count++;
|
---|
290 | element->format = wined3d_format_lookup[type];
|
---|
291 | element->input_slot = stream;
|
---|
292 | element->offset = offset;
|
---|
293 | element->output_slot = reg;
|
---|
294 | element->method = WINED3D_DECL_METHOD_DEFAULT;
|
---|
295 | element->usage = wined3d_usage_lookup[reg].usage;
|
---|
296 | element->usage_idx = wined3d_usage_lookup[reg].usage_idx;
|
---|
297 |
|
---|
298 | offset += wined3d_type_sizes[type];
|
---|
299 | } else if (token_type == D3DVSD_TOKEN_STREAMDATA && (token_type & 0x10000000)) {
|
---|
300 | TRACE(" 0x%08x SKIP(%u)\n", token_type, ((token_type & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT));
|
---|
301 | offset += sizeof(DWORD) * ((token_type & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT);
|
---|
302 | }
|
---|
303 |
|
---|
304 | if (element_count >= 127) {
|
---|
305 | ERR("More than 127 elements?\n");
|
---|
306 | break;
|
---|
307 | }
|
---|
308 |
|
---|
309 | token += parse_token(token);
|
---|
310 | }
|
---|
311 |
|
---|
312 | *d3d8_elements_size = (++token - d3d8_elements) * sizeof(DWORD);
|
---|
313 |
|
---|
314 | return element_count;
|
---|
315 | }
|
---|
316 |
|
---|
317 | static void STDMETHODCALLTYPE d3d8_vertexdeclaration_wined3d_object_destroyed(void *parent)
|
---|
318 | {
|
---|
319 | struct d3d8_vertex_declaration *declaration = parent;
|
---|
320 | HeapFree(GetProcessHeap(), 0, declaration->elements);
|
---|
321 | HeapFree(GetProcessHeap(), 0, declaration);
|
---|
322 | }
|
---|
323 |
|
---|
324 | void d3d8_vertex_declaration_destroy(struct d3d8_vertex_declaration *declaration)
|
---|
325 | {
|
---|
326 | TRACE("declaration %p.\n", declaration);
|
---|
327 |
|
---|
328 | wined3d_mutex_lock();
|
---|
329 | wined3d_vertex_declaration_decref(declaration->wined3d_vertex_declaration);
|
---|
330 | wined3d_mutex_unlock();
|
---|
331 | }
|
---|
332 |
|
---|
333 | static const struct wined3d_parent_ops d3d8_vertexdeclaration_wined3d_parent_ops =
|
---|
334 | {
|
---|
335 | d3d8_vertexdeclaration_wined3d_object_destroyed,
|
---|
336 | };
|
---|
337 |
|
---|
338 | HRESULT d3d8_vertex_declaration_init(struct d3d8_vertex_declaration *declaration,
|
---|
339 | struct d3d8_device *device, const DWORD *elements, DWORD shader_handle)
|
---|
340 | {
|
---|
341 | struct wined3d_vertex_element *wined3d_elements;
|
---|
342 | UINT wined3d_element_count;
|
---|
343 | HRESULT hr;
|
---|
344 |
|
---|
345 | declaration->shader_handle = shader_handle;
|
---|
346 |
|
---|
347 | wined3d_element_count = convert_to_wined3d_declaration(elements, &declaration->elements_size, &wined3d_elements);
|
---|
348 | declaration->elements = HeapAlloc(GetProcessHeap(), 0, declaration->elements_size);
|
---|
349 | if (!declaration->elements)
|
---|
350 | {
|
---|
351 | ERR("Failed to allocate vertex declaration elements memory.\n");
|
---|
352 | HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
---|
353 | return E_OUTOFMEMORY;
|
---|
354 | }
|
---|
355 |
|
---|
356 | memcpy(declaration->elements, elements, declaration->elements_size);
|
---|
357 |
|
---|
358 | wined3d_mutex_lock();
|
---|
359 | hr = wined3d_vertex_declaration_create(device->wined3d_device, wined3d_elements, wined3d_element_count,
|
---|
360 | declaration, &d3d8_vertexdeclaration_wined3d_parent_ops, &declaration->wined3d_vertex_declaration);
|
---|
361 | wined3d_mutex_unlock();
|
---|
362 | HeapFree(GetProcessHeap(), 0, wined3d_elements);
|
---|
363 | if (FAILED(hr))
|
---|
364 | {
|
---|
365 | WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
|
---|
366 | HeapFree(GetProcessHeap(), 0, declaration->elements);
|
---|
367 | return hr;
|
---|
368 | }
|
---|
369 |
|
---|
370 | return D3D_OK;
|
---|
371 | }
|
---|
372 |
|
---|
373 | HRESULT d3d8_vertex_declaration_init_fvf(struct d3d8_vertex_declaration *declaration,
|
---|
374 | struct d3d8_device *device, DWORD fvf)
|
---|
375 | {
|
---|
376 | HRESULT hr;
|
---|
377 |
|
---|
378 | declaration->elements = NULL;
|
---|
379 | declaration->elements_size = 0;
|
---|
380 | declaration->shader_handle = fvf;
|
---|
381 |
|
---|
382 | hr = wined3d_vertex_declaration_create_from_fvf(device->wined3d_device, fvf, declaration,
|
---|
383 | &d3d8_vertexdeclaration_wined3d_parent_ops, &declaration->wined3d_vertex_declaration);
|
---|
384 | if (FAILED(hr))
|
---|
385 | {
|
---|
386 | WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
|
---|
387 | return hr;
|
---|
388 | }
|
---|
389 |
|
---|
390 | return D3D_OK;
|
---|
391 | }
|
---|