wininet/tests: Add a few more tests.
[wine] / dlls / d3d9 / vertexshader.c
1 /*
2  * IDirect3DVertexShader9 implementation
3  *
4  * Copyright 2002-2003 Jason Edmeades
5  *                     Raphael Junqueira
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DVertexShader9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
33         IUnknown_AddRef(iface);
34         *ppobj = This;
35         return S_OK;
36     }
37
38     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39     *ppobj = NULL;
40     return E_NOINTERFACE;
41 }
42
43 static ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
44     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
45     ULONG ref = InterlockedIncrement(&This->ref);
46
47     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
48
49     return ref;
50 }
51
52 static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
53     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
57
58     if (ref == 0) {
59         IWineD3DVertexShader_Release(This->wineD3DVertexShader);
60         IUnknown_Release(This->parentDevice);
61         HeapFree(GetProcessHeap(), 0, This);
62     }
63     return ref;
64 }
65
66 /* IDirect3DVertexShader9 Interface follow: */
67 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
68     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
69     IWineD3DDevice *myDevice = NULL;
70     HRESULT hr = D3D_OK;
71     TRACE("(%p) : Relay\n", This);
72
73     if (D3D_OK == (hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice) && myDevice != NULL)) {
74         hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
75         IWineD3DDevice_Release(myDevice);
76     } else {
77         *ppDevice = NULL;
78     }
79     TRACE("(%p) returning (%p)\n", This, *ppDevice);
80     return hr;
81 }
82
83 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
84     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
85
86     TRACE("(%p) : Relay\n", This);
87     return IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
88 }
89
90
91 static const IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
92 {
93     /* IUnknown */
94     IDirect3DVertexShader9Impl_QueryInterface,
95     IDirect3DVertexShader9Impl_AddRef,
96     IDirect3DVertexShader9Impl_Release,
97     /* IDirect3DVertexShader9 */
98     IDirect3DVertexShader9Impl_GetDevice,
99     IDirect3DVertexShader9Impl_GetFunction
100 };
101
102
103 /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
104 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
105     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
106     HRESULT hrc = D3D_OK;
107     IDirect3DVertexShader9Impl *object;
108
109     /* Setup a stub object for now */
110     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
111     TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
112     if (NULL == object) {
113         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
114         return D3DERR_OUTOFVIDEOMEMORY;
115     }
116
117     object->ref = 1;
118     object->lpVtbl = &Direct3DVertexShader9_Vtbl;
119     hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, NULL /* declaration */, pFunction, &object->wineD3DVertexShader, (IUnknown *)object);
120
121     if (FAILED(hrc)) {
122
123         /* free up object */
124         FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
125         HeapFree(GetProcessHeap(), 0, object);
126     }else{
127         IUnknown_AddRef(iface);
128         object->parentDevice = iface;
129         *ppShader = (IDirect3DVertexShader9 *)object;
130         TRACE("(%p) : Created vertex shader %p\n", This, object);
131     }
132
133     TRACE("(%p) : returning %p\n", This, *ppShader);
134     return hrc;
135 }
136
137 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9* pShader) {
138     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
139     HRESULT hrc = D3D_OK;
140
141     TRACE("(%p) : Relay\n", This);
142     hrc =  IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
143
144     TRACE("(%p) : returning hr(%u)\n", This, hrc);
145     return hrc;
146 }
147
148 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9** ppShader) {
149     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
150     IWineD3DVertexShader *pShader;
151     HRESULT hrc = D3D_OK;
152
153     TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
154     hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
155     if(hrc == D3D_OK && pShader != NULL){
156        hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
157        IWineD3DVertexShader_Release(pShader);
158     } else {
159         WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
160     }
161     TRACE("(%p) : returning %p\n", This, *ppShader);
162     return hrc;
163 }
164
165 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
166     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
167     TRACE("(%p) : Relay\n", This);
168     return IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
169 }
170
171 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
172     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
173     TRACE("(%p) : Relay\n", This);
174     return IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
175 }
176
177 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
178     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
179     TRACE("(%p) : Relay\n", This);
180     return IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
181 }
182
183 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
184     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
185     TRACE("(%p) : Relay\n", This);
186     return IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
187 }
188
189 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
190     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
191     TRACE("(%p) : Relay\n", This);
192     return IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
193 }
194
195 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
196     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
197     TRACE("(%p) : Relay\n", This);
198     return IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
199 }