kernel32: Test GetPrivateProfileString with empty string as key and section.
[wine.git] / dlls / d3d9 / vertexshader.c
blobd7b680e80116cf079f64096fc1338a1f9c99e896
1 /*
2 * IDirect3DVertexShader9 implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
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.
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.
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
22 #include "config.h"
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DVertexShader9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
33 IDirect3DVertexShader9_AddRef(iface);
34 *ppobj = This;
35 return S_OK;
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39 *ppobj = NULL;
40 return E_NOINTERFACE;
43 static ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
44 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
45 ULONG ref = InterlockedIncrement(&This->ref);
47 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
49 return ref;
52 static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
53 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
54 ULONG ref = InterlockedDecrement(&This->ref);
56 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
58 if (ref == 0) {
59 EnterCriticalSection(&d3d9_cs);
60 IWineD3DVertexShader_Release(This->wineD3DVertexShader);
61 LeaveCriticalSection(&d3d9_cs);
62 IDirect3DDevice9Ex_Release(This->parentDevice);
63 HeapFree(GetProcessHeap(), 0, This);
65 return ref;
68 /* IDirect3DVertexShader9 Interface follow: */
69 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
70 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
71 IWineD3DDevice *myDevice = NULL;
72 HRESULT hr;
73 TRACE("(%p) : Relay\n", This);
75 EnterCriticalSection(&d3d9_cs);
76 hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
77 if (WINED3D_OK == hr && myDevice != NULL) {
78 hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
79 IWineD3DDevice_Release(myDevice);
80 } else {
81 *ppDevice = NULL;
83 LeaveCriticalSection(&d3d9_cs);
84 TRACE("(%p) returning (%p)\n", This, *ppDevice);
85 return hr;
88 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
89 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
90 HRESULT hr;
91 TRACE("(%p) : Relay\n", This);
93 EnterCriticalSection(&d3d9_cs);
94 hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
95 LeaveCriticalSection(&d3d9_cs);
96 return hr;
100 static const IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
102 /* IUnknown */
103 IDirect3DVertexShader9Impl_QueryInterface,
104 IDirect3DVertexShader9Impl_AddRef,
105 IDirect3DVertexShader9Impl_Release,
106 /* IDirect3DVertexShader9 */
107 IDirect3DVertexShader9Impl_GetDevice,
108 IDirect3DVertexShader9Impl_GetFunction
112 /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
113 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
114 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
115 HRESULT hrc = D3D_OK;
116 IDirect3DVertexShader9Impl *object;
118 /* Setup a stub object for now */
119 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
120 TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
121 if (NULL == object) {
122 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
123 return D3DERR_OUTOFVIDEOMEMORY;
126 object->ref = 1;
127 object->lpVtbl = &Direct3DVertexShader9_Vtbl;
128 EnterCriticalSection(&d3d9_cs);
129 hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
130 NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
131 LeaveCriticalSection(&d3d9_cs);
133 if (FAILED(hrc)) {
135 /* free up object */
136 FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
137 HeapFree(GetProcessHeap(), 0, object);
138 }else{
139 IDirect3DDevice9Ex_AddRef(iface);
140 object->parentDevice = iface;
141 *ppShader = (IDirect3DVertexShader9 *)object;
142 TRACE("(%p) : Created vertex shader %p\n", This, object);
145 TRACE("(%p) : returning %p\n", This, *ppShader);
146 return hrc;
149 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
150 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
151 HRESULT hrc = D3D_OK;
153 TRACE("(%p) : Relay\n", This);
154 EnterCriticalSection(&d3d9_cs);
155 hrc = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
156 LeaveCriticalSection(&d3d9_cs);
158 TRACE("(%p) : returning hr(%u)\n", This, hrc);
159 return hrc;
162 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9** ppShader) {
163 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
164 IWineD3DVertexShader *pShader;
165 HRESULT hrc = D3D_OK;
167 TRACE("(%p) : Relay device@%p\n", This, This->WineD3DDevice);
168 EnterCriticalSection(&d3d9_cs);
169 hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
170 if (SUCCEEDED(hrc))
172 if (pShader)
174 hrc = IWineD3DVertexShader_GetParent(pShader, (IUnknown **)ppShader);
175 IWineD3DVertexShader_Release(pShader);
177 else
179 *ppShader = NULL;
182 else
184 WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
186 LeaveCriticalSection(&d3d9_cs);
187 TRACE("(%p) : returning %p\n", This, *ppShader);
188 return hrc;
191 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
192 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
193 HRESULT hr;
194 TRACE("(%p) : Relay\n", This);
196 if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
197 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
198 Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
199 return D3DERR_INVALIDCALL;
202 EnterCriticalSection(&d3d9_cs);
203 hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
204 LeaveCriticalSection(&d3d9_cs);
205 return hr;
208 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
209 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
210 HRESULT hr;
212 if(Register + Vector4fCount > D3D9_MAX_VERTEX_SHADER_CONSTANTF) {
213 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
214 Register + Vector4fCount, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
215 return D3DERR_INVALIDCALL;
218 TRACE("(%p) : Relay\n", This);
219 EnterCriticalSection(&d3d9_cs);
220 hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
221 LeaveCriticalSection(&d3d9_cs);
222 return hr;
225 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
226 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
227 HRESULT hr;
228 TRACE("(%p) : Relay\n", This);
230 EnterCriticalSection(&d3d9_cs);
231 hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
232 LeaveCriticalSection(&d3d9_cs);
233 return hr;
236 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
237 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
238 HRESULT hr;
239 TRACE("(%p) : Relay\n", This);
241 EnterCriticalSection(&d3d9_cs);
242 hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
243 LeaveCriticalSection(&d3d9_cs);
244 return hr;
247 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
248 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
249 HRESULT hr;
250 TRACE("(%p) : Relay\n", This);
252 EnterCriticalSection(&d3d9_cs);
253 hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
254 LeaveCriticalSection(&d3d9_cs);
255 return hr;
258 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
259 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
260 HRESULT hr;
261 TRACE("(%p) : Relay\n", This);
263 EnterCriticalSection(&d3d9_cs);
264 hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
265 LeaveCriticalSection(&d3d9_cs);
266 return hr;