2 * vertex shaders declaration implementation
4 * Copyright 2002 Raphael Junqueira
5 * Copyright 2004 Jason Edmeades
6 * Copyright 2004 Christian Costa
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/debug.h"
34 #include "d3d8_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
39 * DirectX9 SDK download
40 * http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
43 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx07162002.asp
45 * Using Vertex Shaders
46 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp
49 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/whatsnew.asp
52 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/VertexShader2_0.asp
53 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/Instructions/Instructions.asp
54 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexDeclaration/VertexDeclaration.asp
55 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader3_0/VertexShader3_0.asp
58 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/VertexPipe/matrixstack/matrixstack.asp
61 * http://msdn.microsoft.com/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexFormats/vformats.asp
63 * NVIDIA: DX8 Vertex Shader to NV Vertex Program
64 * http://developer.nvidia.com/view.asp?IO=vstovp
66 * NVIDIA: Memory Management with VAR
67 * http://developer.nvidia.com/view.asp?IO=var_memory_management
70 /** Vertex Shader Declaration data types tokens */
71 #define MAX_VSHADER_DECL_TYPES 8
72 static CONST char* VertexShaderDeclDataTypes[] = {
84 static CONST char* VertexShaderDeclRegister[] = {
86 "D3DVSDE_BLENDWEIGHT",
87 "D3DVSDE_BLENDINDICES",
105 /** todo check decl validity */
106 /*inline static*/ DWORD Direct3DVextexShaderDeclarationImpl_ParseToken(const DWORD* pToken) {
107 const DWORD token = *pToken;
110 switch ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT) { /* maybe a macro to inverse ... */
111 case D3DVSD_TOKEN_NOP:
112 TRACE(" 0x%08lx NOP()\n", token);
114 case D3DVSD_TOKEN_STREAM:
115 if (token & D3DVSD_STREAMTESSMASK) {
116 TRACE(" 0x%08lx STREAM_TESS()\n", token);
118 TRACE(" 0x%08lx STREAM(%lu)\n", token, ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT));
121 case D3DVSD_TOKEN_STREAMDATA:
122 if (token & 0x10000000) {
123 TRACE(" 0x%08lx SKIP(%lu)\n", token, ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT));
125 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
126 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
127 TRACE(" 0x%08lx REG(%s, %s)\n", token, VertexShaderDeclRegister[reg], VertexShaderDeclDataTypes[type]);
130 case D3DVSD_TOKEN_TESSELLATOR:
131 if (token & 0x10000000) {
132 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
133 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
134 TRACE(" 0x%08lx TESSUV(%s) as %s\n", token, VertexShaderDeclRegister[reg], VertexShaderDeclDataTypes[type]);
136 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
137 DWORD regout = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
138 DWORD regin = ((token & D3DVSD_VERTEXREGINMASK) >> D3DVSD_VERTEXREGINSHIFT);
139 TRACE(" 0x%08lx TESSNORMAL(%s, %s) as %s\n", token, VertexShaderDeclRegister[regin], VertexShaderDeclRegister[regout], VertexShaderDeclDataTypes[type]);
142 case D3DVSD_TOKEN_CONSTMEM:
145 DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
146 DWORD constaddress = ((token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT);
147 TRACE(" 0x%08lx CONST(%lu, %lu)\n", token, constaddress, count);
149 for (i = 0; i < count; ++i) {
151 TRACE(" c[%lu] = (0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n",
158 TRACE(" c[%lu] = (%8f, %8f, %8f, %8f)\n",
161 *(float*) (pToken + 1),
162 *(float*) (pToken + 2),
163 *(float*) (pToken + 3));
167 tokenlen = (4 * count) + 1;
170 case D3DVSD_TOKEN_EXT:
172 DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
173 DWORD extinfo = ((token & D3DVSD_EXTINFOMASK) >> D3DVSD_EXTINFOSHIFT);
174 TRACE(" 0x%08lx EXT(%lu, %lu)\n", token, count, extinfo);
175 /* todo ... print extension */
176 tokenlen = count + 1;
179 case D3DVSD_TOKEN_END:
180 TRACE(" 0x%08lx END()\n", token);
183 TRACE(" 0x%08lx UNKNOWN\n", token);
189 HRESULT WINAPI IDirect3DDeviceImpl_CreateVertexShaderDeclaration8(IDirect3DDevice8Impl* This, CONST DWORD* pDeclaration8, IDirect3DVertexShaderDeclarationImpl** ppVertexShaderDecl) {
191 const DWORD* pToken = pDeclaration8;
198 DWORD tex = D3DFVF_TEX0;
199 /** TRUE if declaration can be matched by a fvf */
200 IDirect3DVertexShaderDeclarationImpl* object;
201 BOOL invalid_fvf = FALSE;
203 TRACE("(%p) : pDeclaration8(%p)\n", This, pDeclaration8);
205 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexShaderDeclarationImpl));
207 /*object->lpVtbl = &Direct3DVextexShaderDeclaration8_Vtbl;*/
208 object->device = This; /* FIXME: AddRef(This) */
212 while (D3DVSD_END() != *pToken) {
214 tokenlen = Direct3DVextexShaderDeclarationImpl_ParseToken(pToken);
215 tokentype = ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
217 /** FVF generation block */
218 if (D3DVSD_TOKEN_STREAM == tokentype && 0 == (D3DVSD_STREAMTESSMASK & token)) {
220 * how really works streams,
221 * in DolphinVS dx8 dsk sample they seems to decal reg numbers !!!
223 DWORD oldStream = stream;
224 stream = ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT);
226 /* copy fvf if valid */
227 if (FALSE == invalid_fvf) {
228 fvf |= tex << D3DFVF_TEXCOUNT_SHIFT;
230 object->fvf[oldStream] = fvf;
231 object->allFVF |= fvf;
233 object->fvf[oldStream] = 0;
237 /* reset valid/invalid fvf */
241 } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 == (0x10000000 & tokentype)) {
242 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
243 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
246 case D3DVSDE_POSITION:
248 case D3DVSDT_FLOAT3: fvf |= D3DFVF_XYZ; break;
249 case D3DVSDT_FLOAT4: fvf |= D3DFVF_XYZRHW; break;
251 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
253 if (type >= MAX_VSHADER_DECL_TYPES) {
254 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_POSITION register: unsupported and unrecognized type %08lx\n", type);
256 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_POSITION register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
261 case D3DVSDE_BLENDWEIGHT:
263 case D3DVSDT_FLOAT1: fvf |= D3DFVF_XYZB1; break;
264 case D3DVSDT_FLOAT2: fvf |= D3DFVF_XYZB2; break;
265 case D3DVSDT_FLOAT3: fvf |= D3DFVF_XYZB3; break;
266 case D3DVSDT_FLOAT4: fvf |= D3DFVF_XYZB4; break;
268 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
270 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDWEIGHT register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
274 case D3DVSDE_BLENDINDICES: /* seem to be B5 as said in MSDN Dx9SDK ?? */
276 case D3DVSDT_UBYTE4: fvf |= D3DFVF_LASTBETA_UBYTE4; break;
278 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
280 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_BLENDINDINCES register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
284 case D3DVSDE_NORMAL: /* TODO: only FLOAT3 supported ... another choice possible ? */
286 case D3DVSDT_FLOAT3: fvf |= D3DFVF_NORMAL; break;
288 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
290 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_NORMAL register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
294 case D3DVSDE_PSIZE: /* TODO: only FLOAT1 supported ... another choice possible ? */
296 case D3DVSDT_FLOAT1: fvf |= D3DFVF_PSIZE; break;
298 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
300 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_PSIZE register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
304 case D3DVSDE_DIFFUSE: /* TODO: only D3DCOLOR supported */
306 case D3DVSDT_D3DCOLOR: fvf |= D3DFVF_DIFFUSE; break;
308 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
310 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_DIFFUSE register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
314 case D3DVSDE_SPECULAR: /* TODO: only D3DCOLOR supported */
316 case D3DVSDT_D3DCOLOR: fvf |= D3DFVF_SPECULAR; break;
318 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
320 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_SPECULAR register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
324 case D3DVSDE_TEXCOORD0:
325 case D3DVSDE_TEXCOORD1:
326 case D3DVSDE_TEXCOORD2:
327 case D3DVSDE_TEXCOORD3:
328 case D3DVSDE_TEXCOORD4:
329 case D3DVSDE_TEXCOORD5:
330 case D3DVSDE_TEXCOORD6:
331 case D3DVSDE_TEXCOORD7:
332 /* Fixme? - assume all tex coords in same stream */
334 int texNo = 1 + (reg - D3DVSDE_TEXCOORD0);
335 tex = max(tex, texNo);
337 case D3DVSDT_FLOAT1: fvf |= D3DFVF_TEXCOORDSIZE1(texNo); break;
338 case D3DVSDT_FLOAT2: fvf |= D3DFVF_TEXCOORDSIZE2(texNo); break;
339 case D3DVSDT_FLOAT3: fvf |= D3DFVF_TEXCOORDSIZE3(texNo); break;
340 case D3DVSDT_FLOAT4: fvf |= D3DFVF_TEXCOORDSIZE4(texNo); break;
342 /** Mismatched use of a register, invalid for fixed function fvf computing (ok for VS) */
344 TRACE("Mismatched use in VertexShader declaration of D3DVSDE_TEXCOORD? register: unsupported type %s\n", VertexShaderDeclDataTypes[type]);
349 case D3DVSDE_POSITION2: /* maybe D3DFVF_XYZRHW instead D3DFVF_XYZ (of D3DVDE_POSITION) ... to see */
350 case D3DVSDE_NORMAL2: /* FIXME i don't know what to do here ;( */
351 FIXME("[%lu] registers in VertexShader declaration not supported yet (token:0x%08lx)\n", reg, token);
354 TRACE("VertexShader declaration define %lx as current FVF\n", fvf);
359 /* here D3DVSD_END() */
360 len += Direct3DVextexShaderDeclarationImpl_ParseToken(pToken);
362 /* copy fvf if valid */
363 if (FALSE == invalid_fvf) {
364 fvf |= tex << D3DFVF_TEXCOUNT_SHIFT;
365 object->fvf[stream] = fvf;
366 object->allFVF |= fvf;
368 object->fvf[stream] = 0;
370 TRACE("Completed, allFVF = %lx\n", object->allFVF);
373 object->declaration8Length = len * sizeof(DWORD);
374 /* copy the declaration */
375 object->pDeclaration8 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->declaration8Length);
376 memcpy(object->pDeclaration8, pDeclaration8, object->declaration8Length);
378 *ppVertexShaderDecl = object;
382 HRESULT WINAPI IDirect3DDeviceImpl_FillVertexShaderInputSW(IDirect3DDevice8Impl* This,
383 IDirect3DVertexShaderImpl* vshader,
384 DWORD SkipnStrides) {
386 const DWORD* pToken = This->UpdateStateBlock->vertexShaderDecl->pDeclaration8;
391 /** for input readers */
392 const char* curPos = NULL;
397 TRACE("(%p) - This:%p, skipstrides=%lu\n", vshader, This, SkipnStrides);
399 while (D3DVSD_END() != *pToken) {
401 tokentype = ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
403 /** FVF generation block */
404 if (D3DVSD_TOKEN_STREAM == tokentype && 0 == (D3DVSD_STREAMTESSMASK & token)) {
405 IDirect3DVertexBuffer8* pVB;
410 * how really works streams,
411 * in DolphinVS dx8 dsk sample use it !!!
413 stream = ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT);
414 skip = This->StateBlock->stream_stride[stream];
415 pVB = This->StateBlock->stream_source[stream];
418 ERR("using unitialised stream[%lu]\n", stream);
419 return D3DERR_INVALIDCALL;
421 if (This->StateBlock->streamIsUP == TRUE) {
422 curPos = ((char *) pVB) + (SkipnStrides * skip); /* Not really a VB */
424 curPos = ((IDirect3DVertexBuffer8Impl*) pVB)->allocatedMemory + (SkipnStrides * skip);
427 TRACE(" using stream[%lu] with %p (%p + (Stride %d * skip %ld))\n", stream, curPos,
428 ((IDirect3DVertexBuffer8Impl*) pVB)->allocatedMemory, skip, SkipnStrides);
430 } else if (D3DVSD_TOKEN_CONSTMEM == tokentype) {
433 DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
434 DWORD constaddress = ((token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT);
436 for (i = 0; i < count; ++i) {
437 vshader->data->C[constaddress + i].x = *(float*)pToken;
438 vshader->data->C[constaddress + i].y = *(float*)(pToken + 1);
439 vshader->data->C[constaddress + i].z = *(float*)(pToken + 2);
440 vshader->data->C[constaddress + i].w = *(float*)(pToken + 3);
444 } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 != (0x10000000 & tokentype)) {
446 DWORD skipCount = ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT);
447 TRACE(" skipping %ld dwords\n", skipCount);
448 curPos = curPos + skipCount * sizeof(DWORD);
451 } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 == (0x10000000 & tokentype)) {
452 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
453 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
456 TRACE(" type : %ld, reg = %ld\n", type, reg);
459 x = *(float*) curPos;
460 curPos = curPos + sizeof(float);
462 vshader->input.V[reg].x = x;
463 vshader->input.V[reg].y = 0.0f;
464 vshader->input.V[reg].z = 0.0f;
465 vshader->input.V[reg].w = 1.0f;
469 x = *(float*) curPos;
470 curPos = curPos + sizeof(float);
471 y = *(float*) curPos;
472 curPos = curPos + sizeof(float);
474 vshader->input.V[reg].x = x;
475 vshader->input.V[reg].y = y;
476 vshader->input.V[reg].z = 0.0f;
477 vshader->input.V[reg].w = 1.0f;
481 x = *(float*) curPos;
482 curPos = curPos + sizeof(float);
483 y = *(float*) curPos;
484 curPos = curPos + sizeof(float);
485 z = *(float*) curPos;
486 curPos = curPos + sizeof(float);
488 vshader->input.V[reg].x = x;
489 vshader->input.V[reg].y = y;
490 vshader->input.V[reg].z = z;
491 vshader->input.V[reg].w = 1.0f;
495 x = *(float*) curPos;
496 curPos = curPos + sizeof(float);
497 y = *(float*) curPos;
498 curPos = curPos + sizeof(float);
499 z = *(float*) curPos;
500 curPos = curPos + sizeof(float);
501 w = *(float*) curPos;
502 curPos = curPos + sizeof(float);
504 vshader->input.V[reg].x = x;
505 vshader->input.V[reg].y = y;
506 vshader->input.V[reg].z = z;
507 vshader->input.V[reg].w = w;
510 case D3DVSDT_D3DCOLOR:
511 dw = *(DWORD*) curPos;
512 curPos = curPos + sizeof(DWORD);
514 vshader->input.V[reg].x = (float) (((dw >> 16) & 0xFF) / 255.0f);
515 vshader->input.V[reg].y = (float) (((dw >> 8) & 0xFF) / 255.0f);
516 vshader->input.V[reg].z = (float) (((dw >> 0) & 0xFF) / 255.0f);
517 vshader->input.V[reg].w = (float) (((dw >> 24) & 0xFF) / 255.0f);
521 u = *(SHORT*) curPos;
522 curPos = curPos + sizeof(SHORT);
523 v = *(SHORT*) curPos;
524 curPos = curPos + sizeof(SHORT);
526 vshader->input.V[reg].x = (float) u;
527 vshader->input.V[reg].y = (float) v;
528 vshader->input.V[reg].z = 0.0f;
529 vshader->input.V[reg].w = 1.0f;
533 u = *(SHORT*) curPos;
534 curPos = curPos + sizeof(SHORT);
535 v = *(SHORT*) curPos;
536 curPos = curPos + sizeof(SHORT);
537 r = *(SHORT*) curPos;
538 curPos = curPos + sizeof(SHORT);
539 t = *(SHORT*) curPos;
540 curPos = curPos + sizeof(SHORT);
542 vshader->input.V[reg].x = (float) u;
543 vshader->input.V[reg].y = (float) v;
544 vshader->input.V[reg].z = (float) r;
545 vshader->input.V[reg].w = (float) t;
549 dw = *(DWORD*) curPos;
550 curPos = curPos + sizeof(DWORD);
552 vshader->input.V[reg].x = (float) ((dw & 0x000F) >> 0);
553 vshader->input.V[reg].y = (float) ((dw & 0x00F0) >> 8);
554 vshader->input.V[reg].z = (float) ((dw & 0x0F00) >> 16);
555 vshader->input.V[reg].w = (float) ((dw & 0xF000) >> 24);
559 default: /** errooooorr what to do ? */
560 ERR("Error in VertexShader declaration of %s register: unsupported type %s\n", VertexShaderDeclRegister[reg], VertexShaderDeclDataTypes[type]);
565 /* here D3DVSD_END() */
569 HRESULT WINAPI IDirect3DDeviceImpl_FillVertexShaderInputArbHW(IDirect3DDevice8Impl* This,
570 IDirect3DVertexShaderImpl* vshader,
571 DWORD SkipnStrides) {
573 const DWORD* pToken = This->UpdateStateBlock->vertexShaderDecl->pDeclaration8;
578 /** for input readers */
579 const char* curPos = NULL;
582 TRACE("(%p) - This:%p, skipstrides=%lu\n", vshader, This, SkipnStrides);
584 while (D3DVSD_END() != *pToken) {
586 tokentype = ((token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
588 /** FVF generation block */
589 if (D3DVSD_TOKEN_STREAM == tokentype && 0 == (D3DVSD_STREAMTESSMASK & token)) {
590 IDirect3DVertexBuffer8* pVB;
594 * how really works streams,
595 * in DolphinVS dx8 dsk sample use it !!!
597 stream = ((token & D3DVSD_STREAMNUMBERMASK) >> D3DVSD_STREAMNUMBERSHIFT);
598 skip = This->StateBlock->stream_stride[stream];
599 pVB = This->StateBlock->stream_source[stream];
602 ERR("using unitialised stream[%lu]\n", stream);
603 return D3DERR_INVALIDCALL;
605 if (This->StateBlock->streamIsUP == TRUE) {
606 curPos = ((char *) pVB) + (SkipnStrides * skip); /* Not really a VB */
608 curPos = ((IDirect3DVertexBuffer8Impl*) pVB)->allocatedMemory + (SkipnStrides * skip);
611 TRACE(" using stream[%lu] with %p (%p + (Stride %d * skip %ld))\n", stream, curPos,
612 ((IDirect3DVertexBuffer8Impl*) pVB)->allocatedMemory, skip, SkipnStrides);
614 } else if (D3DVSD_TOKEN_CONSTMEM == tokentype) {
617 DWORD count = ((token & D3DVSD_CONSTCOUNTMASK) >> D3DVSD_CONSTCOUNTSHIFT);
618 DWORD constaddress = ((token & D3DVSD_CONSTADDRESSMASK) >> D3DVSD_CONSTADDRESSSHIFT);
621 for (i = 0; i < count; ++i) {
622 FIXME("Confirm this is correct handling of consts inside the hw vertex shader\n");
623 GL_EXTCALL(glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, constaddress+i, (GLfloat *)pToken));
624 vshader->data->C[constaddress + i].x = *(float*)pToken;
625 vshader->data->C[constaddress + i].y = *(float*)(pToken + 1);
626 vshader->data->C[constaddress + i].z = *(float*)(pToken + 2);
627 vshader->data->C[constaddress + i].w = *(float*)(pToken + 3);
631 } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 != (0x10000000 & tokentype)) {
633 DWORD skipCount = ((token & D3DVSD_SKIPCOUNTMASK) >> D3DVSD_SKIPCOUNTSHIFT);
634 TRACE(" skipping %ld dwords\n", skipCount);
635 curPos = curPos + skipCount * sizeof(DWORD);
638 } else if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 == (0x10000000 & tokentype)) {
639 DWORD type = ((token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
640 DWORD reg = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
643 TRACE(" type : %ld, reg = %ld\n", type, reg);
646 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg, 1, skip, curPos);
647 GL_EXTCALL(glVertexAttribPointerARB(reg, 1, GL_FLOAT, GL_FALSE, skip, curPos));
648 GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
649 curPos = curPos + sizeof(float);
653 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg, 2, skip, curPos);
654 GL_EXTCALL(glVertexAttribPointerARB(reg, 2, GL_FLOAT, GL_FALSE, skip, curPos));
655 GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
656 curPos = curPos + 2*sizeof(float);
660 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg, 3, skip, curPos);
661 GL_EXTCALL(glVertexAttribPointerARB(reg, 3, GL_FLOAT, GL_FALSE, skip, curPos));
662 GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
663 curPos = curPos + 3*sizeof(float);
667 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg, 4, skip, curPos);
668 GL_EXTCALL(glVertexAttribPointerARB(reg, 4, GL_FLOAT, GL_FALSE, skip, curPos));
669 GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
670 curPos = curPos + 4*sizeof(float);
673 case D3DVSDT_D3DCOLOR:
674 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg, 4, skip, curPos);
675 FIXME("D3DVSDT_D3DCOLOR in hw shader - To confirm\n");
676 GL_EXTCALL(glVertexAttribPointerARB(reg, 4, GL_UNSIGNED_BYTE, GL_TRUE, skip, curPos));
677 GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
678 curPos = curPos + 4*sizeof(BYTE);
682 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg, 2, skip, curPos);
683 GL_EXTCALL(glVertexAttribPointerARB(reg, 2, GL_UNSIGNED_SHORT, GL_FALSE, skip, curPos));
684 GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
685 curPos = curPos + 2*sizeof(short int);
689 TRACE("HW VS glVertexAttribPointerARB(reg=%ld,num=%d,skip=%d,ptr=%p)\n", reg, 1, skip, curPos);
690 GL_EXTCALL(glVertexAttribPointerARB(reg, 4, GL_UNSIGNED_SHORT, GL_FALSE, skip, curPos));
691 GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
692 curPos = curPos + 4*sizeof(short int);
696 FIXME("D3DVSDT_UBYTE4 in hw shader - To confirm\n");
697 GL_EXTCALL(glVertexAttribPointerARB(reg, 4, GL_UNSIGNED_BYTE, GL_TRUE, skip, curPos));
698 GL_EXTCALL(glEnableVertexAttribArrayARB(reg));
699 curPos = curPos + 4*sizeof(BYTE);
702 default: /** errooooorr what to do ? */
703 ERR("Error in VertexShader declaration of %s register: unsupported type %s\n", VertexShaderDeclRegister[reg], VertexShaderDeclDataTypes[type]);
708 /* here D3DVSD_END() */
712 HRESULT WINAPI IDirect3DVertexShaderDeclarationImpl_GetDeclaration8(IDirect3DVertexShaderDeclarationImpl* This, DWORD* pData, UINT* pSizeOfData) {
714 *pSizeOfData = This->declaration8Length;
717 if (*pSizeOfData < This->declaration8Length) {
718 *pSizeOfData = This->declaration8Length;
719 return D3DERR_MOREDATA;
721 TRACE("(%p) : GetVertexShaderDeclaration copying to %p\n", This, pData);
722 memcpy(pData, This->pDeclaration8, This->declaration8Length);