Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / wined3d / vertexdeclaration.c
blob099129bbb3f5b0416788367216745f6a5aab9fe7
1 /*
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
24 #include "config.h"
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d_decl);
29 /**
30 * DirectX9 SDK download
31 * http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
33 * Exploring D3DX
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
39 * Dx9 New
40 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/whatsnew.asp
42 * Dx9 Shaders
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
48 * Dx9 D3DX
49 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/VertexPipe/matrixstack/matrixstack.asp
51 * FVF
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);
82 *ppobj = This;
83 return S_OK;
85 *ppobj = NULL;
86 return E_NOINTERFACE;
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;
97 ULONG ref;
98 TRACE("(%p) : Releasing from %d\n", This, This->ref);
99 ref = InterlockedDecrement(&This->ref);
100 if (ref == 0) {
101 HeapFree(GetProcessHeap(), 0, This->pDeclarationWine);
102 HeapFree(GetProcessHeap(), 0, This);
104 return ref;
107 /* *******************************************
108 IWineD3DVertexDeclaration parts follow
109 ******************************************* */
111 static HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetParent(IWineD3DVertexDeclaration *iface, IUnknown** parent){
112 IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
114 *parent= This->parent;
115 IUnknown_AddRef(*parent);
116 TRACE("(%p) : returning %p\n", This, *parent);
117 return WINED3D_OK;
120 static HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetDevice(IWineD3DVertexDeclaration *iface, IWineD3DDevice** ppDevice) {
121 IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
122 TRACE("(%p) : returning %p\n", This, This->wineD3DDevice);
124 *ppDevice = (IWineD3DDevice *) This->wineD3DDevice;
125 IWineD3DDevice_AddRef(*ppDevice);
127 return WINED3D_OK;
130 static HRESULT WINAPI IWineD3DVertexDeclarationImpl_GetDeclaration(IWineD3DVertexDeclaration *iface,
131 WINED3DVERTEXELEMENT *elements, size_t *element_count) {
132 IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
133 HRESULT hr = WINED3D_OK;
135 TRACE("(%p) : d3d version %d, elements %p, element_count %p\n",
136 This, ((IWineD3DImpl *)This->wineD3DDevice->wineD3D)->dxVersion, elements, element_count);
138 *element_count = This->declarationWNumElements;
139 if (elements) {
140 CopyMemory(elements, This->pDeclarationWine, This->declarationWNumElements * sizeof(WINED3DVERTEXELEMENT));
143 return hr;
146 static HRESULT WINAPI IWineD3DVertexDeclarationImpl_SetDeclaration(IWineD3DVertexDeclaration *iface,
147 const WINED3DVERTEXELEMENT *elements, size_t element_count) {
148 IWineD3DVertexDeclarationImpl *This = (IWineD3DVertexDeclarationImpl *)iface;
149 HRESULT hr = WINED3D_OK;
151 TRACE("(%p) : d3d version %d\n", This, ((IWineD3DImpl *)This->wineD3DDevice->wineD3D)->dxVersion);
153 if (TRACE_ON(d3d_decl)) {
154 int i;
155 for (i = 0; i < element_count; ++i) {
156 dump_wined3dvertexelement(elements+i);
160 This->declarationWNumElements = element_count;
161 This->pDeclarationWine = HeapAlloc(GetProcessHeap(), 0, sizeof(WINED3DVERTEXELEMENT) * element_count);
162 if (!This->pDeclarationWine) {
163 ERR("Memory allocation failed\n");
164 hr = WINED3DERR_OUTOFVIDEOMEMORY;
165 } else {
166 CopyMemory(This->pDeclarationWine, elements, sizeof(WINED3DVERTEXELEMENT) * element_count);
169 TRACE("Returning\n");
170 return hr;
173 const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl =
175 /* IUnknown */
176 IWineD3DVertexDeclarationImpl_QueryInterface,
177 IWineD3DVertexDeclarationImpl_AddRef,
178 IWineD3DVertexDeclarationImpl_Release,
179 /* IWineD3DVertexDeclaration */
180 IWineD3DVertexDeclarationImpl_GetParent,
181 IWineD3DVertexDeclarationImpl_GetDevice,
182 IWineD3DVertexDeclarationImpl_GetDeclaration,
183 IWineD3DVertexDeclarationImpl_SetDeclaration