crtdll: Fixed copy/paste error in definition of _baseminor_dll and _baseversion_dll.
[wine] / dlls / d3d9 / pixelshader.c
1 /*
2  * IDirect3DPixelShader9 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 /* IDirect3DPixelShader9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DPixelShader9Impl_QueryInterface(LPDIRECT3DPIXELSHADER9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DPixelShader9)) {
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 IDirect3DPixelShader9Impl_AddRef(LPDIRECT3DPIXELSHADER9 iface) {
44     IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
45     ULONG ref = InterlockedIncrement(&This->ref);
46
47     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
48
49     return ref;
50 }
51
52 static ULONG WINAPI IDirect3DPixelShader9Impl_Release(LPDIRECT3DPIXELSHADER9 iface) {
53     IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
57
58     if (ref == 0) {
59         IWineD3DPixelShader_Release(This->wineD3DPixelShader);
60         IUnknown_Release(This->parentDevice);
61         HeapFree(GetProcessHeap(), 0, This);
62     }
63     return ref;
64 }
65
66 /* IDirect3DPixelShader9 Interface follow: */
67 static HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(LPDIRECT3DPIXELSHADER9 iface, IDirect3DDevice9** ppDevice) {
68     IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
69     IWineD3DDevice *myDevice = NULL;
70
71     TRACE("(%p) : Relay\n", This);
72
73     IWineD3DPixelShader_GetDevice(This->wineD3DPixelShader, &myDevice);
74     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
75     IWineD3DDevice_Release(myDevice);
76     TRACE("(%p) returing (%p)", This, *ppDevice);
77     return D3D_OK;
78 }
79
80 static HRESULT WINAPI IDirect3DPixelShader9Impl_GetFunction(LPDIRECT3DPIXELSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
81     IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
82     TRACE("(%p) Relay\n", This);
83     return IWineD3DPixelShader_GetFunction(This->wineD3DPixelShader, pData, pSizeOfData);
84 }
85
86
87 static const IDirect3DPixelShader9Vtbl Direct3DPixelShader9_Vtbl =
88 {
89     /* IUnknown */
90     IDirect3DPixelShader9Impl_QueryInterface,
91     IDirect3DPixelShader9Impl_AddRef,
92     IDirect3DPixelShader9Impl_Release,
93     /* IDirect3DPixelShader9 */
94     IDirect3DPixelShader9Impl_GetDevice,
95     IDirect3DPixelShader9Impl_GetFunction
96 };
97
98
99 /* IDirect3DDevice9 IDirect3DPixelShader9 Methods follow:  */
100 HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) {
101     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
102     IDirect3DPixelShader9Impl *object;
103     HRESULT hrc = D3D_OK;
104
105     TRACE("(%p) Relay\n", This);
106
107     if (ppShader == NULL) {
108         TRACE("(%p) Invalid call\n", This);
109         return D3DERR_INVALIDCALL;
110     }
111
112     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
113
114     if (NULL == object) {
115         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
116         return E_OUTOFMEMORY;
117     }
118
119     object->ref    = 1;
120     object->lpVtbl = &Direct3DPixelShader9_Vtbl;
121     hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, &object->wineD3DPixelShader , (IUnknown *)object);
122     if (hrc != D3D_OK) {
123
124         /* free up object */
125         FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
126         HeapFree(GetProcessHeap(), 0 , object);
127     } else {
128         IUnknown_AddRef(iface);
129         object->parentDevice = iface;
130         *ppShader = (IDirect3DPixelShader9*) object;
131         TRACE("(%p) : Created pixel shader %p\n", This, object);
132     }
133
134     TRACE("(%p) : returning %p\n", This, *ppShader);
135     return hrc;
136 }
137
138 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9 iface, IDirect3DPixelShader9* pShader) {
139     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
140     IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)pShader;
141     TRACE("(%p) Relay\n", This);
142     IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
143     return D3D_OK;
144 }
145
146 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9 iface, IDirect3DPixelShader9** ppShader) {
147     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
148     IWineD3DPixelShader *object;
149
150     HRESULT hrc = D3D_OK;
151     TRACE("(%p) Relay\n", This);
152     if (ppShader == NULL) {
153         TRACE("(%p) Invalid call\n", This);
154         return D3DERR_INVALIDCALL;
155     }
156
157     hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
158     if (hrc == D3D_OK && object != NULL) {
159        hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)ppShader);
160        IWineD3DPixelShader_Release(object);
161     } else {
162         *ppShader = NULL;
163     }
164
165     TRACE("(%p) : returning %p\n", This, *ppShader);
166     return hrc;
167 }
168
169 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
170    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
171     TRACE("(%p) Relay\n", This);   
172     return IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
173 }
174
175 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
176     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
177     TRACE("(%p) Relay\n", This);
178     return IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
179 }
180
181 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
182     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
183     TRACE("(%p) Relay\n", This);
184     return IWineD3DDevice_SetPixelShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
185 }
186
187 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
188     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
189     TRACE("(%p) Relay\n", This);
190     return IWineD3DDevice_GetPixelShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
191 }
192
193 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
194     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
195     TRACE("(%p) Relay\n", This);
196     return  IWineD3DDevice_SetPixelShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
197 }
198
199 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
200     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
201     TRACE("(%p) Relay\n", This);
202     return IWineD3DDevice_GetPixelShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
203 }