2 * vertex declaration implementation
4 * Copyright 2002-2005 Raphael Junqueira
5 * Copyright 2004 Jason Edmeades
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d_decl
);
30 * DirectX9 SDK download
31 * http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
34 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx07162002.asp
36 * Using Vertex Shaders
37 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp
40 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/whatsnew.asp
43 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/VertexShader2_0.asp
44 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/Instructions/Instructions.asp
45 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexDeclaration/VertexDeclaration.asp
46 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader3_0/VertexShader3_0.asp
49 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/VertexPipe/matrixstack/matrixstack.asp
52 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexFormats/vformats.asp
54 * NVIDIA: DX8 Vertex Shader to NV Vertex Program
55 * http://developer.nvidia.com/view.asp?IO=vstovp
57 * NVIDIA: Memory Management with VAR
58 * http://developer.nvidia.com/view.asp?IO=var_memory_management
61 /** Vertex Shader Declaration 8 data types tokens */
62 #define MAX_VSHADER_DECL_TYPES 8
64 static CONST
char* VertexDecl8_DataTypes
[] = {
76 static CONST
char* VertexDecl8_Registers
[] = {
78 "D3DVSDE_BLENDWEIGHT",
79 "D3DVSDE_BLENDINDICES",
97 typedef enum _D3DVSD_TOKENTYPE
{
99 D3DVSD_TOKEN_STREAM
= 1,
100 D3DVSD_TOKEN_STREAMDATA
= 2,
101 D3DVSD_TOKEN_TESSELLATOR
= 3,
102 D3DVSD_TOKEN_CONSTMEM
= 4,
103 D3DVSD_TOKEN_EXT
= 5,
105 D3DVSD_TOKEN_END
= 7,
106 D3DVSD_FORCE_DWORD
= 0x7FFFFFFF
109 typedef enum _D3DVSDE_REGISTER
{
110 D3DVSDE_POSITION
= 0,
111 D3DVSDE_BLENDWEIGHT
= 1,
112 D3DVSDE_BLENDINDICES
= 2,
116 D3DVSDE_SPECULAR
= 6,
117 D3DVSDE_TEXCOORD0
= 7,
118 D3DVSDE_TEXCOORD1
= 8,
119 D3DVSDE_TEXCOORD2
= 9,
120 D3DVSDE_TEXCOORD3
= 10,
121 D3DVSDE_TEXCOORD4
= 11,
122 D3DVSDE_TEXCOORD5
= 12,
123 D3DVSDE_TEXCOORD6
= 13,
124 D3DVSDE_TEXCOORD7
= 14,
125 D3DVSDE_POSITION2
= 15,
126 D3DVSDE_NORMAL2
= 16,
130 typedef enum _D3DVSDT_TYPE
{
131 D3DVSDT_FLOAT1
= 0x00,
132 D3DVSDT_FLOAT2
= 0x01,
133 D3DVSDT_FLOAT3
= 0x02,
134 D3DVSDT_FLOAT4
= 0x03,
135 D3DVSDT_D3DCOLOR
= 0x04,
136 D3DVSDT_UBYTE4
= 0x05,
137 D3DVSDT_SHORT2
= 0x06,
138 D3DVSDT_SHORT4
= 0x07
142 #define D3DVSD_CONSTADDRESSSHIFT 0
143 #define D3DVSD_EXTINFOSHIFT 0
144 #define D3DVSD_STREAMNUMBERSHIFT 0
145 #define D3DVSD_VERTEXREGSHIFT 0
146 #define D3DVSD_CONSTRSSHIFT 16
147 #define D3DVSD_DATATYPESHIFT 16
148 #define D3DVSD_SKIPCOUNTSHIFT 16
149 #define D3DVSD_VERTEXREGINSHIFT 20
150 #define D3DVSD_EXTCOUNTSHIFT 24
151 #define D3DVSD_CONSTCOUNTSHIFT 25
152 #define D3DVSD_DATALOADTYPESHIFT 28
153 #define D3DVSD_STREAMTESSSHIFT 28
154 #define D3DVSD_TOKENTYPESHIFT 29
156 #define D3DVSD_CONSTADDRESSMASK (0x7F << D3DVSD_CONSTADDRESSSHIFT)
157 #define D3DVSD_EXTINFOMASK (0xFFFFFF << D3DVSD_EXTINFOSHIFT)
158 #define D3DVSD_STREAMNUMBERMASK (0xF << D3DVSD_STREAMNUMBERSHIFT)
159 #define D3DVSD_VERTEXREGMASK (0x1F << D3DVSD_VERTEXREGSHIFT)
160 #define D3DVSD_CONSTRSMASK (0x1FFF << D3DVSD_CONSTRSSHIFT)
161 #define D3DVSD_DATATYPEMASK (0xF << D3DVSD_DATATYPESHIFT)
162 #define D3DVSD_SKIPCOUNTMASK (0xF << D3DVSD_SKIPCOUNTSHIFT)
163 #define D3DVSD_EXTCOUNTMASK (0x1F << D3DVSD_EXTCOUNTSHIFT)
164 #define D3DVSD_VERTEXREGINMASK (0xF << D3DVSD_VERTEXREGINSHIFT)
165 #define D3DVSD_CONSTCOUNTMASK (0xF << D3DVSD_CONSTCOUNTSHIFT)
166 #define D3DVSD_DATALOADTYPEMASK (0x1 << D3DVSD_DATALOADTYPESHIFT)
167 #define D3DVSD_STREAMTESSMASK (0x1 << D3DVSD_STREAMTESSSHIFT)
168 #define D3DVSD_TOKENTYPEMASK (0x7 << D3DVSD_TOKENTYPESHIFT)
170 #define D3DVSD_END() 0xFFFFFFFF
171 #define D3DVSD_NOP() 0x00000000
173 static DWORD
IWineD3DVertexDeclarationImpl_ParseToken8(const DWORD
* pToken
) {
174 const DWORD token
= *pToken
;
177 switch ((token
& D3DVSD_TOKENTYPEMASK
) >> D3DVSD_TOKENTYPESHIFT
) { /* maybe a macro to inverse ... */
178 case D3DVSD_TOKEN_NOP
:
179 TRACE(" 0x%08lx NOP()\n", token
);
181 case D3DVSD_TOKEN_STREAM
:
182 if (token
& D3DVSD_STREAMTESSMASK
) {
183 TRACE(" 0x%08lx STREAM_TESS()\n", token
);
185 TRACE(" 0x%08lx STREAM(%lu)\n", token
, ((token
& D3DVSD_STREAMNUMBERMASK
) >> D3DVSD_STREAMNUMBERSHIFT
));
188 case D3DVSD_TOKEN_STREAMDATA
:
189 if (token
& 0x10000000) {
190 TRACE(" 0x%08lx SKIP(%lu)\n", token
, ((token
& D3DVSD_SKIPCOUNTMASK
) >> D3DVSD_SKIPCOUNTSHIFT
));
192 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
193 DWORD reg
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
194 TRACE(" 0x%08lx REG(%s, %s)\n", token
, VertexDecl8_Registers
[reg
], VertexDecl8_DataTypes
[type
]);
197 case D3DVSD_TOKEN_TESSELLATOR
:
198 if (token
& 0x10000000) {
199 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
200 DWORD reg
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
201 TRACE(" 0x%08lx TESSUV(%s) as %s\n", token
, VertexDecl8_Registers
[reg
], VertexDecl8_DataTypes
[type
]);
203 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
204 DWORD regout
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
205 DWORD regin
= ((token
& D3DVSD_VERTEXREGINMASK
) >> D3DVSD_VERTEXREGINSHIFT
);
206 TRACE(" 0x%08lx TESSNORMAL(%s, %s) as %s\n", token
, VertexDecl8_Registers
[regin
], VertexDecl8_Registers
[regout
], VertexDecl8_DataTypes
[type
]);
209 case D3DVSD_TOKEN_CONSTMEM
:
211 DWORD count
= ((token
& D3DVSD_CONSTCOUNTMASK
) >> D3DVSD_CONSTCOUNTSHIFT
);
212 tokenlen
= (4 * count
) + 1;
215 case D3DVSD_TOKEN_EXT
:
217 DWORD count
= ((token
& D3DVSD_CONSTCOUNTMASK
) >> D3DVSD_CONSTCOUNTSHIFT
);
218 DWORD extinfo
= ((token
& D3DVSD_EXTINFOMASK
) >> D3DVSD_EXTINFOSHIFT
);
219 TRACE(" 0x%08lx EXT(%lu, %lu)\n", token
, count
, extinfo
);
220 /* todo ... print extension */
221 tokenlen
= count
+ 1;
224 case D3DVSD_TOKEN_END
:
225 TRACE(" 0x%08lx END()\n", token
);
228 TRACE(" 0x%08lx UNKNOWN\n", token
);
234 /* structure used by the d3d8 to d3d9 conversion lookup table */
235 typedef struct _Decl8to9Lookup
{
240 static HRESULT
IWineD3DVertexDeclarationImpl_ParseDeclaration8(IWineD3DVertexDeclaration
*iface
, const DWORD
*pDecl
) {
241 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
242 #define MAKE_LOOKUP(_reg,_usage,_usageindex) decl8to9Lookup[_reg].usage = _usage; \
243 decl8to9Lookup[_reg].usageIndex = _usageindex;
244 const DWORD
* pToken
= pDecl
;
253 WINED3DVERTEXELEMENT convToW
[128];
254 /* TODO: find out where rhw (or positionT) is for declaration8 */
255 Decl8to9Lookup decl8to9Lookup
[MAX_D3DVSDE
];
256 MAKE_LOOKUP(D3DVSDE_POSITION
, D3DDECLUSAGE_POSITION
, 0);
257 MAKE_LOOKUP(D3DVSDE_POSITION2
, D3DDECLUSAGE_POSITION
, 1);
258 MAKE_LOOKUP(D3DVSDE_BLENDWEIGHT
, D3DDECLUSAGE_BLENDWEIGHT
, 0);
259 MAKE_LOOKUP(D3DVSDE_BLENDINDICES
, D3DDECLUSAGE_BLENDINDICES
, 0);
260 MAKE_LOOKUP(D3DVSDE_NORMAL
, D3DDECLUSAGE_NORMAL
, 0);
261 MAKE_LOOKUP(D3DVSDE_NORMAL2
, D3DDECLUSAGE_NORMAL
, 1);
262 MAKE_LOOKUP(D3DVSDE_DIFFUSE
, D3DDECLUSAGE_COLOR
, 0);
263 MAKE_LOOKUP(D3DVSDE_SPECULAR
, D3DDECLUSAGE_COLOR
, 1);
264 MAKE_LOOKUP(D3DVSDE_TEXCOORD0
, D3DDECLUSAGE_TEXCOORD
, 0);
265 MAKE_LOOKUP(D3DVSDE_TEXCOORD1
, D3DDECLUSAGE_TEXCOORD
, 1);
266 MAKE_LOOKUP(D3DVSDE_TEXCOORD2
, D3DDECLUSAGE_TEXCOORD
, 2);
267 MAKE_LOOKUP(D3DVSDE_TEXCOORD3
, D3DDECLUSAGE_TEXCOORD
, 3);
268 MAKE_LOOKUP(D3DVSDE_TEXCOORD4
, D3DDECLUSAGE_TEXCOORD
, 4);
269 MAKE_LOOKUP(D3DVSDE_TEXCOORD5
, D3DDECLUSAGE_TEXCOORD
, 5);
270 MAKE_LOOKUP(D3DVSDE_TEXCOORD6
, D3DDECLUSAGE_TEXCOORD
, 6);
271 MAKE_LOOKUP(D3DVSDE_TEXCOORD7
, D3DDECLUSAGE_TEXCOORD
, 7);
274 TRACE("(%p) : pDecl(%p)\n", This
, pDecl
);
275 /* Convert from a directx* declaration into a directx9 one, so we only have to deal with one type of declaration everywhere else */
276 while (D3DVSD_END() != *pToken
) {
278 tokenlen
= IWineD3DVertexDeclarationImpl_ParseToken8(pToken
);
279 tokentype
= ((token
& D3DVSD_TOKENTYPEMASK
) >> D3DVSD_TOKENTYPESHIFT
);
281 if (D3DVSD_TOKEN_STREAM
== tokentype
&& 0 == (D3DVSD_STREAMTESSMASK
& token
)) {
283 * how really works streams,
284 * in DolphinVS dx8 dsk sample they seems to decal reg numbers !!!
286 stream
= ((token
& D3DVSD_STREAMNUMBERMASK
) >> D3DVSD_STREAMNUMBERSHIFT
);
289 } else if (D3DVSD_TOKEN_STREAMDATA
== tokentype
&& 0 == (0x10000000 & tokentype
)) {
290 DWORD type
= ((token
& D3DVSD_DATATYPEMASK
) >> D3DVSD_DATATYPESHIFT
);
291 DWORD reg
= ((token
& D3DVSD_VERTEXREGMASK
) >> D3DVSD_VERTEXREGSHIFT
);
293 convToW
[nTokens
].Stream
= stream
;
294 convToW
[nTokens
].Method
= D3DDECLMETHOD_DEFAULT
;
295 convToW
[nTokens
].Usage
= decl8to9Lookup
[reg
].usage
;
296 convToW
[nTokens
].UsageIndex
= decl8to9Lookup
[reg
].usageIndex
;
297 convToW
[nTokens
].Type
= type
;
298 convToW
[nTokens
].Offset
= offset
;
299 convToW
[nTokens
].Reg
= reg
;
300 offset
+= glTypeLookup
[type
].size
* glTypeLookup
[type
].typesize
;
302 } else if (D3DVSD_TOKEN_STREAMDATA
== tokentype
&& 0x10000000 & tokentype
) {
303 TRACE(" 0x%08lx SKIP(%lu)\n", tokentype
, ((tokentype
& D3DVSD_SKIPCOUNTMASK
) >> D3DVSD_SKIPCOUNTSHIFT
));
304 offset
+= sizeof(DWORD
) * ((tokentype
& D3DVSD_SKIPCOUNTMASK
) >> D3DVSD_SKIPCOUNTSHIFT
);
305 } else if (D3DVSD_TOKEN_CONSTMEM
== tokentype
) {
307 DWORD count
= ((token
& D3DVSD_CONSTCOUNTMASK
) >> D3DVSD_CONSTCOUNTSHIFT
);
308 DWORD constaddress
= ((token
& D3DVSD_CONSTADDRESSMASK
) >> D3DVSD_CONSTADDRESSSHIFT
);
309 if (This
->constants
== NULL
) {
310 This
->constants
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, MAX_VSHADER_CONSTANTS
* 4 * sizeof(float));
312 TRACE(" 0x%08lx CONST(%lu, %lu)\n", token
, constaddress
, count
);
313 for (i
= 0; i
< count
; ++i
) {
314 TRACE(" c[%lu] = (0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx)\n",
321 This
->constants
[constaddress
* 4] = *(const float*) (pToken
+ i
* 4 + 1);
322 This
->constants
[constaddress
* 4 + 1] = *(const float *)(pToken
+ i
* 4 + 2);
323 This
->constants
[constaddress
* 4 + 2] = *(const float *)(pToken
+ i
* 4 + 3);
324 This
->constants
[constaddress
* 4 + 3] = *(const float *)(pToken
+ i
* 4 + 4);
325 FIXME(" c[%lu] = (%8f, %8f, %8f, %8f)\n",
327 *(const float*) (pToken
+ i
* 4 + 1),
328 *(const float*) (pToken
+ i
* 4 + 2),
329 *(const float*) (pToken
+ i
* 4 +3),
330 *(const float*) (pToken
+ i
* 4 + 4));
339 /* here D3DVSD_END() */
340 len
+= IWineD3DVertexDeclarationImpl_ParseToken8(pToken
);
342 convToW
[nTokens
].Stream
= 0xFF;
343 convToW
[nTokens
].Type
= D3DDECLTYPE_UNUSED
;
347 This
->declaration8Length
= len
* sizeof(DWORD
);
348 /* copy the declaration */
349 This
->pDeclaration8
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, This
->declaration8Length
);
350 memcpy(This
->pDeclaration8
, pDecl
, This
->declaration8Length
);
352 /* compute convToW size */
353 This
->declarationWNumElements
= nTokens
;
354 /* copy the convTo9 declaration */
355 This
->pDeclarationWine
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, nTokens
* sizeof(WINED3DVERTEXELEMENT
));
356 memcpy(This
->pDeclarationWine
, convToW
, nTokens
* sizeof(WINED3DVERTEXELEMENT
));
362 static HRESULT
IWineD3DVertexDeclarationImpl_ParseDeclaration9(IWineD3DVertexDeclaration
* iface
, const D3DVERTEXELEMENT9
* pDecl
) {
363 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
364 const D3DVERTEXELEMENT9
* pToken
= pDecl
;
367 TRACE("(%p) : pDecl(%p)\n", This
, pDecl
);
369 This
->declaration9NumElements
= 1;
370 for(pToken
= pDecl
;0xFF != pToken
->Stream
&& This
->declaration9NumElements
< 128 ; pToken
++) This
->declaration9NumElements
++;
372 if (This
->declaration9NumElements
== 128) {
373 FIXME("?(%p) Error parsing vertex declaration\n", This
);
374 return D3DERR_INVALIDCALL
;
378 /* copy the declaration */
379 This
->pDeclaration9
= HeapAlloc(GetProcessHeap(), 0, This
->declaration9NumElements
* sizeof(D3DVERTEXELEMENT9
));
380 memcpy(This
->pDeclaration9
, pDecl
, This
->declaration9NumElements
* sizeof(D3DVERTEXELEMENT9
));
382 /* copy to wine style declaration */
383 This
->pDeclarationWine
= HeapAlloc(GetProcessHeap(), 0, This
->declaration9NumElements
* sizeof(WINED3DVERTEXELEMENT
));
384 for(i
= 0; i
< This
->declaration9NumElements
; ++i
) {
385 memcpy(This
->pDeclarationWine
+ i
, This
->pDeclaration9
+ i
, sizeof(D3DVERTEXELEMENT9
));
386 This
->pDeclarationWine
[i
].Reg
= -1;
389 This
->declarationWNumElements
= This
->declaration9NumElements
;
394 /* *******************************************
395 IWineD3DVertexDeclaration IUnknown parts follow
396 ******************************************* */
397 HRESULT WINAPI
IWineD3DVertexDeclarationImpl_QueryInterface(IWineD3DVertexDeclaration
*iface
, REFIID riid
, LPVOID
*ppobj
)
399 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
400 TRACE("(%p)->(%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
401 if (IsEqualGUID(riid
, &IID_IUnknown
)
402 || IsEqualGUID(riid
, &IID_IWineD3DBase
)
403 || IsEqualGUID(riid
, &IID_IWineD3DVertexDeclaration
)){
404 IUnknown_AddRef(iface
);
408 return E_NOINTERFACE
;
411 ULONG WINAPI
IWineD3DVertexDeclarationImpl_AddRef(IWineD3DVertexDeclaration
*iface
) {
412 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
413 TRACE("(%p) : AddRef increasing from %ld\n", This
, This
->ref
);
414 return InterlockedIncrement(&This
->ref
);
417 ULONG WINAPI
IWineD3DVertexDeclarationImpl_Release(IWineD3DVertexDeclaration
*iface
) {
418 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
420 TRACE("(%p) : Releasing from %ld\n", This
, This
->ref
);
421 ref
= InterlockedDecrement(&This
->ref
);
423 HeapFree(GetProcessHeap(), 0, This
->pDeclaration8
);
424 HeapFree(GetProcessHeap(), 0, This
->pDeclaration9
);
425 HeapFree(GetProcessHeap(), 0, This
->pDeclarationWine
);
426 HeapFree(GetProcessHeap(), 0, This
->constants
);
427 HeapFree(GetProcessHeap(), 0, This
);
432 /* *******************************************
433 IWineD3DVertexDeclaration parts follow
434 ******************************************* */
436 HRESULT WINAPI
IWineD3DVertexDeclarationImpl_GetParent(IWineD3DVertexDeclaration
*iface
, IUnknown
** parent
){
437 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
439 *parent
= This
->parent
;
440 IUnknown_AddRef(*parent
);
441 TRACE("(%p) : returning %p\n", This
, *parent
);
445 HRESULT WINAPI
IWineD3DVertexDeclarationImpl_GetDevice(IWineD3DVertexDeclaration
*iface
, IWineD3DDevice
** ppDevice
) {
446 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
447 TRACE("(%p) : returning %p\n", This
, This
->wineD3DDevice
);
449 *ppDevice
= (IWineD3DDevice
*) This
->wineD3DDevice
;
450 IWineD3DDevice_AddRef(*ppDevice
);
455 static HRESULT WINAPI
IWineD3DVertexDeclarationImpl_GetDeclaration8(IWineD3DVertexDeclaration
* iface
, DWORD
* pData
, DWORD
* pSizeOfData
) {
456 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
458 *pSizeOfData
= This
->declaration8Length
;
462 /* The Incredibles and Teenage Mutant Ninja Turtles require this in d3d9 for NumElements == 0,
463 TODO: this needs to be tested against windows */
464 if(*pSizeOfData
== 0) {
465 TRACE("(%p) : Requested the vertex declaration without specefying the size of the return buffer\n", This
);
466 *pSizeOfData
= This
->declaration8Length
;
467 memcpy(pData
, This
->pDeclaration8
, This
->declaration8Length
);
471 if (*pSizeOfData
< This
->declaration8Length
) {
472 FIXME("(%p) : Returning D3DERR_MOREDATA numElements %ld expected %ld\n", iface
, *pSizeOfData
, This
->declaration8Length
);
473 *pSizeOfData
= This
->declaration8Length
;
474 return D3DERR_MOREDATA
;
476 TRACE("(%p) : GetVertexDeclaration8 copying to %p\n", This
, pData
);
477 memcpy(pData
, This
->pDeclaration8
, This
->declaration8Length
);
481 HRESULT WINAPI
IWineD3DVertexDeclarationImpl_GetDeclaration9(IWineD3DVertexDeclaration
* iface
, D3DVERTEXELEMENT9
* pData
, DWORD
* pNumElements
) {
482 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
484 TRACE("(This %p, pData %p, pNumElements %p)\n", This
, pData
, pNumElements
);
486 TRACE("Setting *pNumElements to %d\n", This
->declaration9NumElements
);
487 *pNumElements
= This
->declaration9NumElements
;
489 /* Passing a NULL pData is used to just retrieve the number of elements */
491 TRACE("NULL pData passed. Returning D3D_OK.\n");
495 TRACE("Copying %p to %p\n", This
->pDeclaration9
, pData
);
496 memcpy(pData
, This
->pDeclaration9
, This
->declaration9NumElements
* sizeof(*pData
));
500 HRESULT WINAPI
IWineD3DVertexDeclarationImpl_GetDeclaration(IWineD3DVertexDeclaration
*iface
, VOID
*pData
, DWORD
*pSize
) {
501 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
504 TRACE("(%p) : d3d version %d r\n", This
, ((IWineD3DImpl
*)This
->wineD3DDevice
->wineD3D
)->dxVersion
);
505 switch (((IWineD3DImpl
*)This
->wineD3DDevice
->wineD3D
)->dxVersion
) {
507 hr
= IWineD3DVertexDeclarationImpl_GetDeclaration8(iface
, (DWORD
*)pData
, pSize
);
510 hr
= IWineD3DVertexDeclarationImpl_GetDeclaration9(iface
, (D3DVERTEXELEMENT9
*)pData
, pSize
);
513 FIXME("(%p) : Unsupport DirectX version %u\n", This
, ((IWineD3DImpl
*)This
->wineD3DDevice
->wineD3D
)->dxVersion
);
519 HRESULT WINAPI
IWineD3DVertexDeclarationImpl_SetDeclaration(IWineD3DVertexDeclaration
*iface
, VOID
*pDecl
) {
520 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
523 TRACE("(%p) : d3d version %d\n", This
, ((IWineD3DImpl
*)This
->wineD3DDevice
->wineD3D
)->dxVersion
);
524 switch (((IWineD3DImpl
*)This
->wineD3DDevice
->wineD3D
)->dxVersion
) {
526 TRACE("Parsing declatation 8\n");
527 hr
= IWineD3DVertexDeclarationImpl_ParseDeclaration8(iface
, (CONST DWORD
*)pDecl
);
530 FIXME("Parsing declatation 9\n");
531 hr
= IWineD3DVertexDeclarationImpl_ParseDeclaration9(iface
, (CONST D3DVERTEXELEMENT9
*)pDecl
);
534 FIXME("(%p) : Unsupport DirectX version %u\n", This
, ((IWineD3DImpl
*)This
->wineD3DDevice
->wineD3D
)->dxVersion
);
537 TRACE("Returning\n");
541 const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl
=
544 IWineD3DVertexDeclarationImpl_QueryInterface
,
545 IWineD3DVertexDeclarationImpl_AddRef
,
546 IWineD3DVertexDeclarationImpl_Release
,
547 /* IWineD3DVertexDeclaration */
548 IWineD3DVertexDeclarationImpl_GetParent
,
549 IWineD3DVertexDeclarationImpl_GetDevice
,
550 IWineD3DVertexDeclarationImpl_GetDeclaration
,
551 IWineD3DVertexDeclarationImpl_SetDeclaration