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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 static void dump_wined3dvertexelement(const WINED3DVERTEXELEMENT
*element
) {
62 TRACE(" Stream: %d\n", element
->Stream
);
63 TRACE(" Offset: %d\n", element
->Offset
);
64 TRACE(" Type: %s (%#x)\n", debug_d3ddecltype(element
->Type
), element
->Type
);
65 TRACE(" Method: %s (%#x)\n", debug_d3ddeclmethod(element
->Method
), element
->Method
);
66 TRACE(" Usage: %s (%#x)\n", debug_d3ddeclusage(element
->Usage
), element
->Usage
);
67 TRACE("Usage index: %d\n", element
->UsageIndex
);
68 TRACE(" Register: %d\n", element
->Reg
);
71 /* *******************************************
72 IWineD3DVertexDeclaration IUnknown parts follow
73 ******************************************* */
74 static HRESULT WINAPI
IWineD3DVertexDeclarationImpl_QueryInterface(IWineD3DVertexDeclaration
*iface
, REFIID riid
, LPVOID
*ppobj
)
76 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
77 TRACE("(%p)->(%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
78 if (IsEqualGUID(riid
, &IID_IUnknown
)
79 || IsEqualGUID(riid
, &IID_IWineD3DBase
)
80 || IsEqualGUID(riid
, &IID_IWineD3DVertexDeclaration
)){
81 IUnknown_AddRef(iface
);
89 static ULONG WINAPI
IWineD3DVertexDeclarationImpl_AddRef(IWineD3DVertexDeclaration
*iface
) {
90 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
91 TRACE("(%p) : AddRef increasing from %d\n", This
, This
->ref
);
92 return InterlockedIncrement(&This
->ref
);
95 static ULONG WINAPI
IWineD3DVertexDeclarationImpl_Release(IWineD3DVertexDeclaration
*iface
) {
96 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
98 TRACE("(%p) : Releasing from %d\n", This
, This
->ref
);
99 ref
= InterlockedDecrement(&This
->ref
);
101 if(iface
== This
->wineD3DDevice
->stateBlock
->vertexDecl
) {
102 /* See comment in PixelShader::Release */
103 IWineD3DDeviceImpl_MarkStateDirty(This
->wineD3DDevice
, STATE_VDECL
);
106 HeapFree(GetProcessHeap(), 0, This
->pDeclarationWine
);
107 HeapFree(GetProcessHeap(), 0, This
);
112 /* *******************************************
113 IWineD3DVertexDeclaration parts follow
114 ******************************************* */
116 static HRESULT WINAPI
IWineD3DVertexDeclarationImpl_GetParent(IWineD3DVertexDeclaration
*iface
, IUnknown
** parent
){
117 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
119 *parent
= This
->parent
;
120 IUnknown_AddRef(*parent
);
121 TRACE("(%p) : returning %p\n", This
, *parent
);
125 static HRESULT WINAPI
IWineD3DVertexDeclarationImpl_GetDevice(IWineD3DVertexDeclaration
*iface
, IWineD3DDevice
** ppDevice
) {
126 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
127 TRACE("(%p) : returning %p\n", This
, This
->wineD3DDevice
);
129 *ppDevice
= (IWineD3DDevice
*) This
->wineD3DDevice
;
130 IWineD3DDevice_AddRef(*ppDevice
);
135 static HRESULT WINAPI
IWineD3DVertexDeclarationImpl_GetDeclaration(IWineD3DVertexDeclaration
*iface
,
136 WINED3DVERTEXELEMENT
*elements
, size_t *element_count
) {
137 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
138 HRESULT hr
= WINED3D_OK
;
140 TRACE("(%p) : d3d version %d, elements %p, element_count %p\n",
141 This
, ((IWineD3DImpl
*)This
->wineD3DDevice
->wineD3D
)->dxVersion
, elements
, element_count
);
143 *element_count
= This
->declarationWNumElements
;
145 CopyMemory(elements
, This
->pDeclarationWine
, This
->declarationWNumElements
* sizeof(WINED3DVERTEXELEMENT
));
151 static HRESULT WINAPI
IWineD3DVertexDeclarationImpl_SetDeclaration(IWineD3DVertexDeclaration
*iface
,
152 const WINED3DVERTEXELEMENT
*elements
, size_t element_count
) {
153 IWineD3DVertexDeclarationImpl
*This
= (IWineD3DVertexDeclarationImpl
*)iface
;
154 HRESULT hr
= WINED3D_OK
;
156 TRACE("(%p) : d3d version %d\n", This
, ((IWineD3DImpl
*)This
->wineD3DDevice
->wineD3D
)->dxVersion
);
158 if (TRACE_ON(d3d_decl
)) {
160 for (i
= 0; i
< element_count
; ++i
) {
161 dump_wined3dvertexelement(elements
+i
);
165 This
->declarationWNumElements
= element_count
;
166 This
->pDeclarationWine
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINED3DVERTEXELEMENT
) * element_count
);
167 if (!This
->pDeclarationWine
) {
168 ERR("Memory allocation failed\n");
169 hr
= WINED3DERR_OUTOFVIDEOMEMORY
;
171 CopyMemory(This
->pDeclarationWine
, elements
, sizeof(WINED3DVERTEXELEMENT
) * element_count
);
174 TRACE("Returning\n");
178 const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl
=
181 IWineD3DVertexDeclarationImpl_QueryInterface
,
182 IWineD3DVertexDeclarationImpl_AddRef
,
183 IWineD3DVertexDeclarationImpl_Release
,
184 /* IWineD3DVertexDeclaration */
185 IWineD3DVertexDeclarationImpl_GetParent
,
186 IWineD3DVertexDeclarationImpl_GetDevice
,
187 IWineD3DVertexDeclarationImpl_GetDeclaration
,
188 IWineD3DVertexDeclarationImpl_SetDeclaration