Fixed header dependencies to be fully compatible with the Windows
[wine/multimedia.git] / dlls / d3d8 / vshaderdeclaration.c
blobc15cd9feaaeaae136eeca38905dbe77316c6ca25
1 /*
2 * vertex shaders declaration implementation
4 * Copyright 2002 Raphael Junqueira
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <math.h>
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wingdi.h"
30 #include "wine/debug.h"
32 #include "d3d8_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
36 /**
37 * DirectX9 SDK download
38 * http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
40 * Exploring D3DX
41 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx07162002.asp
43 * Using Vertex Shaders
44 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp
46 * Dx9 New
47 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/whatsnew.asp
49 * Dx9 Shaders
50 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/VertexShader2_0.asp
51 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/Instructions/Instructions.asp
52 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexDeclaration/VertexDeclaration.asp
53 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader3_0/VertexShader3_0.asp
55 * Dx9 D3DX
56 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/VertexPipe/matrixstack/matrixstack.asp
58 * FVF
59 * http://msdn.microsoft.com/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexFormats/vformats.asp
61 * NVIDIA: DX8 Vertex Shader to NV Vertex Program
62 * http://developer.nvidia.com/view.asp?IO=vstovp
64 * NVIDIA: Memory Management with VAR
65 * http://developer.nvidia.com/view.asp?IO=var_memory_management
68 /** Vertex Shader Declaration data types tokens */
69 #define MAX_VSHADER_DECL_TYPES 8
70 static CONST char* VertexShaderDeclDataTypes[] = {
71 "D3DVSDT_FLOAT1",
72 "D3DVSDT_FLOAT2",
73 "D3DVSDT_FLOAT3",
74 "D3DVSDT_FLOAT4",
75 "D3DVSDT_D3DCOLOR",
76 "D3DVSDT_UBYTE4",
77 "D3DVSDT_SHORT2",
78 "D3DVSDT_SHORT4",
79 NULL
82 static CONST char* VertexShaderDeclRegister[] = {
83 "D3DVSDE_POSITION",
84 "D3DVSDE_BLENDWEIGHT",
85 "D3DVSDE_BLENDINDICES",
86 "D3DVSDE_NORMAL",
87 "D3DVSDE_PSIZE",
88 "D3DVSDE_DIFFUSE",
89 "D3DVSDE_SPECULAR",
90 "D3DVSDE_TEXCOORD0",
91 "D3DVSDE_TEXCOORD1",
92 "D3DVSDE_TEXCOORD2",
93 "D3DVSDE_TEXCOORD3",
94 "D3DVSDE_TEXCOORD4",
95 "D3DVSDE_TEXCOORD5",
96 "D3DVSDE_TEXCOORD6",
97 "D3DVSDE_TEXCOORD7",
98 "D3DVSDE_POSITION2",
99 "D3DVSDE_NORMAL2",
100 NULL
103 /** todo check decl validity */
104 /*inline static*/ DWORD Direct3DVextexShaderDeclarationImpl_ParseToken(const DWORD* pToken) {
105 const DWORD token = *pToken;
106 DWORD tokenlen = 1;
108 switch ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT) { /* maybe a macro to inverse ... */
109 case D3DVSD_TOKEN_NOP:
110 TRACE(" 0x%08lx NOP()\n", token);
111 break;
112 case D3DVSD_TOKEN_STREAM:
113 if (token & D3DVSD_STREAMTESSMASK) {
114 TRACE(" 0x%08lx STREAM_TESS()\n", token);
115 } else {
116 TRACE(" 0x%08lx STREAM(%lu)\n", token, ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT));
118 break;
119 case D3DVSD_TOKEN_STREAMDATA:
120 if (token & 0x10000000) {
121 TRACE(" 0x%08lx SKIP(%lu)\n", token, ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT));
122 } else {
123 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
124 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
125 TRACE(" 0x%08lx REG(%s, %s)\n", token, VertexShaderDeclRegister[reg], VertexShaderDeclDataTypes[type]);
127 break;
128 case D3DVSD_TOKEN_TESSELLATOR:
129 if (token & 0x10000000) {
130 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
131 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
132 TRACE(" 0x%08lx TESSUV(%s) as %s\n", token, VertexShaderDeclRegister[reg], VertexShaderDeclDataTypes[type]);
133 } else {
134 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
135 DWORD regout = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
136 DWORD regin = ((token & D3DVSD_VERTEXREGINMASK) >> D3DVSD_VERTEXREGINSHIFT);
137 TRACE(" 0x%08lx TESSNORMAL(%s, %s) as %s\n", token, VertexShaderDeclRegister[regin], VertexShaderDeclRegister[regout], VertexShaderDeclDataTypes[type]);
139 break;
140 case D3DVSD_TOKEN_CONSTMEM:
142 DWORD i;
143 DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
144 DWORD constaddress = ((token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT);
145 TRACE(" 0x%08lx CONST(%lu, %lu)\n", token, constaddress, count);
146 ++pToken;
147 for (i = 0; i < count; ++i) {
148 #if 0
149 TRACE(" c[%lu] = (0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n",
150 constaddress,
151 *pToken,
152 *(pToken + 1),
153 *(pToken + 2),
154 *(pToken + 3));
155 #endif
156 TRACE(" c[%lu] = (%8f, %8f, %8f, %8f)\n",
157 constaddress,
158 *(float*) pToken,
159 *(float*) (pToken + 1),
160 *(float*) (pToken + 2),
161 *(float*) (pToken + 3));
162 pToken += 4;
163 ++constaddress;
165 tokenlen = (4 * count) + 1;
167 break;
168 case D3DVSD_TOKEN_EXT:
170 DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
171 DWORD extinfo = ((token & D3DVSD_EXTINFOMASK) >> D3DVSD_EXTINFOSHIFT);
172 TRACE(" 0x%08lx EXT(%lu, %lu)\n", token, count, extinfo);
173 /* todo ... print extension */
174 tokenlen = count + 1;
176 break;
177 case D3DVSD_TOKEN_END:
178 TRACE(" 0x%08lx END()\n", token);
179 break;
180 default:
181 TRACE(" 0x%08lx UNKNOWN\n", token);
182 /* argg error */
184 return tokenlen;
187 HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevice8Impl* This, CONST DWORD* pDeclaration8, IDirect3DVertexShaderDeclarationImpl** ppVertexShaderDecl) {
188 /** parser data */
189 const DWORD* pToken = pDeclaration8;
190 DWORD fvf = 0;
191 DWORD len = 0;
192 DWORD stream = 0;
193 DWORD token;
194 DWORD tokenlen;
195 DWORD tokentype;
196 DWORD tex = D3DFVF_TEX0;
197 /** TRUE if declaration can be matched by a fvf */
198 IDirect3DVertexShaderDeclarationImpl* object;
199 BOOL invalid_fvf = FALSE;
201 TRACE("(%p) : pDeclaration8(%p)\n", This, pDeclaration8);
203 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexShaderDeclarationImpl));
204 /*object->lpVtbl = &Direct3DVextexShaderDeclaration8_Vtbl;*/
205 object->device = This; /* FIXME: AddRef(This) */
206 object->ref = 1;
207 object->allFVF = 0;
209 while (D3DVSD_END() != *pToken) {
210 token = *pToken;
211 tokenlen = Direct3DVextexShaderDeclarationImpl_ParseToken(pToken);
212 tokentype = ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
214 /** FVF generation block */
215 if (D3DVSD_TOKEN_STREAM == tokentype && 0 == (D3DVSD_STREAMTESSMASK & token)) {
216 /**
217 * how really works streams,
218 * in DolphinVS dx8 dsk sample they seems to decal reg numbers !!!
220 DWORD oldStream = stream;
221 stream = ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT);
223 /* copy fvf if valid */
224 if (FALSE == invalid_fvf) {
225 fvf |= tex << D3DFVF_TEXCOUNT_SHIFT;
226 tex = 0;
227 object->fvf[oldStream] = fvf;
228 object->allFVF |= fvf;
229 } else {
230 object->fvf[oldStream] = 0;
231 tex = 0;
234 /* reset valid/invalid fvf */
235 fvf = 0;
236 invalid_fvf = FALSE;
238 } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 == (0x10000000 & tokentype)) {
239 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
240 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
242 switch (reg) {
243 case D3DVSDE_POSITION:
244 switch (type) {
245 case D3DVSDT_FLOAT3: fvf |= D3DFVF_XYZ; break;
246 case D3DVSDT_FLOAT4: fvf |= D3DFVF_XYZRHW; break;
247 default:
248 /** errooooorr mismatched use of a register, invalid fvf computing */
249 invalid_fvf = TRUE;
250 if (type >= MAX_VSHADER_DECL_TYPES) {
251 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_POSITION register: unsupported and unrecognized type %08lx\n", type);
252 } else {
253 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_POSITION register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
256 break;
258 case D3DVSDE_BLENDWEIGHT:
259 switch (type) {
260 case D3DVSDT_FLOAT1: fvf |= D3DFVF_XYZB1; break;
261 case D3DVSDT_FLOAT2: fvf |= D3DFVF_XYZB2; break;
262 case D3DVSDT_FLOAT3: fvf |= D3DFVF_XYZB3; break;
263 case D3DVSDT_FLOAT4: fvf |= D3DFVF_XYZB4; break;
264 default:
265 /** errooooorr mismatched use of a register, invalid fvf computing */
266 invalid_fvf = TRUE;
267 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDWEIGHT register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
269 break;
271 case D3DVSDE_BLENDINDICES: /* seem to be B5 as said in MSDN Dx9SDK ?? */
272 switch (type) {
273 case D3DVSDT_UBYTE4: fvf |= D3DFVF_LASTBETA_UBYTE4; break;
274 default:
275 /** errooooorr mismatched use of a register, invalid fvf computing */
276 invalid_fvf = TRUE;
277 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDINDINCES register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
279 break;
281 case D3DVSDE_NORMAL: /* TODO: only FLOAT3 supported ... another choice possible ? */
282 switch (type) {
283 case D3DVSDT_FLOAT3: fvf |= D3DFVF_NORMAL; break;
284 default:
285 /** errooooorr mismatched use of a register, invalid fvf computing */
286 invalid_fvf = TRUE;
287 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_NORMAL register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
289 break;
291 case D3DVSDE_PSIZE: /* TODO: only FLOAT1 supported ... another choice possible ? */
292 switch (type) {
293 case D3DVSDT_FLOAT1: fvf |= D3DFVF_PSIZE; break;
294 default:
295 /** errooooorr mismatched use of a register, invalid fvf computing */
296 invalid_fvf = TRUE;
297 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_PSIZE register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
299 break;
301 case D3DVSDE_DIFFUSE: /* TODO: only D3DCOLOR supported */
302 switch (type) {
303 case D3DVSDT_D3DCOLOR: fvf |= D3DFVF_DIFFUSE; break;
304 default:
305 /** errooooorr mismatched use of a register, invalid fvf computing */
306 invalid_fvf = TRUE;
307 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_DIFFUSE register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
309 break;
311 case D3DVSDE_SPECULAR: /* TODO: only D3DCOLOR supported */
312 switch (type) {
313 case D3DVSDT_D3DCOLOR: fvf |= D3DFVF_SPECULAR; break;
314 default:
315 /** errooooorr mismatched use of a register, invalid fvf computing */
316 invalid_fvf = TRUE;
317 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_SPECULAR register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
319 break;
321 case D3DVSDE_TEXCOORD0:
322 case D3DVSDE_TEXCOORD1:
323 case D3DVSDE_TEXCOORD2:
324 case D3DVSDE_TEXCOORD3:
325 case D3DVSDE_TEXCOORD4:
326 case D3DVSDE_TEXCOORD5:
327 case D3DVSDE_TEXCOORD6:
328 case D3DVSDE_TEXCOORD7:
329 /* Fixme? - assume all tex coords in same stream */
331 int texNo = 1 + (reg - D3DVSDE_TEXCOORD0);
332 tex = max(tex, texNo);
333 switch (type) {
334 case D3DVSDT_FLOAT1: fvf |= D3DFVF_TEXCOORDSIZE1(texNo); break;
335 case D3DVSDT_FLOAT2: fvf |= D3DFVF_TEXCOORDSIZE2(texNo); break;
336 case D3DVSDT_FLOAT3: fvf |= D3DFVF_TEXCOORDSIZE3(texNo); break;
337 case D3DVSDT_FLOAT4: fvf |= D3DFVF_TEXCOORDSIZE4(texNo); break;
338 default:
339 /** errooooorr mismatched use of a register, invalid fvf computing */
340 invalid_fvf = TRUE;
341 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_TEXCOORD? register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
344 break;
346 case D3DVSDE_POSITION2: /* maybe D3DFVF_XYZRHW instead D3DFVF_XYZ (of D3DVDE_POSITION) ... to see */
347 case D3DVSDE_NORMAL2: /* FIXME i don't know what to do here ;( */
348 TRACE("[%lu] registers in VertexShader declaration not supported yet (token:0x%08lx)\n", reg, token);
349 break;
351 TRACE("VertexShader declaration define %lx as current FVF\n", fvf);
353 len += tokenlen;
354 pToken += tokenlen;
356 /* here D3DVSD_END() */
357 len += Direct3DVextexShaderDeclarationImpl_ParseToken(pToken);
359 /* copy fvf if valid */
360 if (FALSE == invalid_fvf) {
361 fvf |= tex << D3DFVF_TEXCOUNT_SHIFT;
362 object->fvf[stream] = fvf;
363 object->allFVF |= fvf;
364 } else {
365 object->fvf[stream] = 0;
367 TRACE("Completed, allFVF = %lx\n", object->allFVF);
369 /* compute size */
370 object->declaration8Length = len * sizeof(DWORD);
371 /* copy the declaration */
372 object->pDeclaration8 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->declaration8Length);
373 memcpy(object->pDeclaration8, pDeclaration8, object->declaration8Length);
374 /* returns */
375 *ppVertexShaderDecl = object;
376 return D3D_OK;
380 HRESULT WINAPI IDirect3DDeviceImpl_FillVertexShaderInput(IDirect3DDevice8Impl* This,
381 IDirect3DVertexShaderImpl* vshader,
382 DWORD SkipnStrides) {
383 /** parser data */
384 const DWORD* pToken = This->UpdateStateBlock->vertexShaderDecl->pDeclaration8;
385 DWORD stream = 0;
386 DWORD token;
387 /*DWORD tokenlen;*/
388 DWORD tokentype;
389 /** for input readers */
390 const char* curPos = NULL;
391 FLOAT x, y, z, w;
392 SHORT u, v, r, t;
393 DWORD dw;
395 TRACE("(%p) - This:%p, skipstrides=%lu\n", vshader, This, SkipnStrides);
397 while (D3DVSD_END() != *pToken) {
398 token = *pToken;
399 tokentype = ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
401 /** FVF generation block */
402 if (D3DVSD_TOKEN_STREAM == tokentype && 0 == (D3DVSD_STREAMTESSMASK & token)) {
403 IDirect3DVertexBuffer8* pVB;
404 int skip = 0;
406 ++pToken;
407 /**
408 * how really works streams,
409 * in DolphinVS dx8 dsk sample use it !!!
411 stream = ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT);
412 skip = This->StateBlock->stream_stride[stream];
413 pVB = This->StateBlock->stream_source[stream];
415 if (NULL == pVB) {
416 ERR("using unitialised stream[%lu]\n", stream);
417 return D3DERR_INVALIDCALL;
418 } else {
419 if (This->StateBlock->streamIsUP == TRUE) {
420 curPos = ((char *) pVB) + (SkipnStrides * skip); /* Not really a VB */
421 } else {
422 curPos = ((IDirect3DVertexBuffer8Impl*) pVB)->allocatedMemory + (SkipnStrides * skip);
425 TRACE(" using stream[%lu] with %p (%p + (Stride %d * skip %ld))\n", stream, curPos,
426 ((IDirect3DVertexBuffer8Impl*) pVB)->allocatedMemory, skip, SkipnStrides);
428 } else if (D3DVSD_TOKEN_CONSTMEM == tokentype) {
429 /** Const decl */
430 DWORD i;
431 DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
432 DWORD constaddress = ((token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT);
433 ++pToken;
434 for (i = 0; i < count; ++i) {
435 vshader->data->C[constaddress + i].x = *(float*)pToken;
436 vshader->data->C[constaddress + i].y = *(float*)(pToken + 1);
437 vshader->data->C[constaddress + i].z = *(float*)(pToken + 2);
438 vshader->data->C[constaddress + i].w = *(float*)(pToken + 3);
439 pToken += 4;
442 } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 != (0x10000000 & tokentype)) {
443 /** skip datas */
444 DWORD skipCount = ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT);
445 curPos = curPos + skipCount * sizeof(DWORD);
446 ++pToken;
448 } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 == (0x10000000 & tokentype)) {
449 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
450 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
451 ++pToken;
453 switch (type) {
454 case D3DVSDT_FLOAT1:
455 x = *(float*) curPos;
456 curPos = curPos + sizeof(float);
457 /**/
458 vshader->input.V[reg].x = x;
459 vshader->input.V[reg].y = 0.0f;
460 vshader->input.V[reg].z = 0.0f;
461 vshader->input.V[reg].w = 1.0f;
462 break;
464 case D3DVSDT_FLOAT2:
465 x = *(float*) curPos;
466 curPos = curPos + sizeof(float);
467 y = *(float*) curPos;
468 curPos = curPos + sizeof(float);
469 /**/
470 vshader->input.V[reg].x = x;
471 vshader->input.V[reg].y = y;
472 vshader->input.V[reg].z = 0.0f;
473 vshader->input.V[reg].w = 1.0f;
474 break;
476 case D3DVSDT_FLOAT3:
477 x = *(float*) curPos;
478 curPos = curPos + sizeof(float);
479 y = *(float*) curPos;
480 curPos = curPos + sizeof(float);
481 z = *(float*) curPos;
482 curPos = curPos + sizeof(float);
483 /**/
484 vshader->input.V[reg].x = x;
485 vshader->input.V[reg].y = y;
486 vshader->input.V[reg].z = z;
487 vshader->input.V[reg].w = 1.0f;
488 break;
490 case D3DVSDT_FLOAT4:
491 x = *(float*) curPos;
492 curPos = curPos + sizeof(float);
493 y = *(float*) curPos;
494 curPos = curPos + sizeof(float);
495 z = *(float*) curPos;
496 curPos = curPos + sizeof(float);
497 w = *(float*) curPos;
498 curPos = curPos + sizeof(float);
499 /**/
500 vshader->input.V[reg].x = x;
501 vshader->input.V[reg].y = y;
502 vshader->input.V[reg].z = z;
503 vshader->input.V[reg].w = w;
504 break;
506 case D3DVSDT_D3DCOLOR:
507 dw = *(DWORD*) curPos;
508 curPos = curPos + sizeof(DWORD);
509 /**/
510 vshader->input.V[reg].x = (float) (((dw >> 16) & 0xFF) / 255.0f);
511 vshader->input.V[reg].y = (float) (((dw >> 8) & 0xFF) / 255.0f);
512 vshader->input.V[reg].z = (float) (((dw >> 0) & 0xFF) / 255.0f);
513 vshader->input.V[reg].w = (float) (((dw >> 24) & 0xFF) / 255.0f);
514 break;
516 case D3DVSDT_SHORT2:
517 u = *(SHORT*) curPos;
518 curPos = curPos + sizeof(SHORT);
519 v = *(SHORT*) curPos;
520 curPos = curPos + sizeof(SHORT);
521 /**/
522 vshader->input.V[reg].x = (float) u;
523 vshader->input.V[reg].y = (float) v;
524 vshader->input.V[reg].z = 0.0f;
525 vshader->input.V[reg].w = 1.0f;
526 break;
528 case D3DVSDT_SHORT4:
529 u = *(SHORT*) curPos;
530 curPos = curPos + sizeof(SHORT);
531 v = *(SHORT*) curPos;
532 curPos = curPos + sizeof(SHORT);
533 r = *(SHORT*) curPos;
534 curPos = curPos + sizeof(SHORT);
535 t = *(SHORT*) curPos;
536 curPos = curPos + sizeof(SHORT);
537 /**/
538 vshader->input.V[reg].x = (float) u;
539 vshader->input.V[reg].y = (float) v;
540 vshader->input.V[reg].z = (float) r;
541 vshader->input.V[reg].w = (float) t;
542 break;
544 case D3DVSDT_UBYTE4:
545 dw = *(DWORD*) curPos;
546 curPos = curPos + sizeof(DWORD);
547 /**/
548 vshader->input.V[reg].x = (float) ((dw & 0x000F) >> 0);
549 vshader->input.V[reg].y = (float) ((dw & 0x00F0) >> 8);
550 vshader->input.V[reg].z = (float) ((dw & 0x0F00) >> 16);
551 vshader->input.V[reg].w = (float) ((dw & 0xF000) >> 24);
553 break;
555 default: /** errooooorr what to do ? */
556 ERR("Error in VertexShader declaration of %s register: unsupported type %s\n", VertexShaderDeclRegister[reg], VertexShaderDeclDataTypes[type]);
561 /* here D3DVSD_END() */
562 return D3D_OK;
565 HRESULT WINAPI IDirect3DVertexShaderDeclarationImpl_GetDeclaration8(IDirect3DVertexShaderDeclarationImpl* This, DWORD* pData, UINT* pSizeOfData) {
566 if (NULL == pData) {
567 *pSizeOfData = This->declaration8Length;
568 return D3D_OK;
570 if (*pSizeOfData < This->declaration8Length) {
571 *pSizeOfData = This->declaration8Length;
572 return D3DERR_MOREDATA;
574 TRACE("(%p) : GetVertexShaderDeclaration copying to %p\n", This, pData);
575 memcpy(pData, This->pDeclaration8, This->declaration8Length);
576 return D3D_OK;