Store a bitmap of active hooks on the client side to try to avoid
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
26
27 /* IDirect3DVertexShader9 IUnknown parts follow: */
28 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         IDirect3DVertexShader9Impl_AddRef(iface);
34         *ppobj = This;
35         return D3D_OK;
36     }
37
38     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39     return E_NOINTERFACE;
40 }
41
42 ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
43     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
44     ULONG ref = InterlockedIncrement(&This->ref);
45
46     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
47
48     return ref;
49 }
50
51 ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
52     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
53     ULONG ref = InterlockedDecrement(&This->ref);
54
55     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
56
57     if (ref == 0) {
58         HeapFree(GetProcessHeap(), 0, This);
59     }
60     return ref;
61 }
62
63 /* IDirect3DVertexShader9 Interface follow: */
64 HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
65     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
66     TRACE("(%p) : returning %p\n", This, This->Device);
67     *ppDevice = (LPDIRECT3DDEVICE9) This->Device;
68     IDirect3DDevice9Impl_AddRef(*ppDevice);
69     return D3D_OK;
70 }
71
72 HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
73     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
74     FIXME("(%p) : stub\n", This);
75     return D3D_OK;
76 }
77
78
79 IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
80 {
81     IDirect3DVertexShader9Impl_QueryInterface,
82     IDirect3DVertexShader9Impl_AddRef,
83     IDirect3DVertexShader9Impl_Release,
84     IDirect3DVertexShader9Impl_GetDevice,
85     IDirect3DVertexShader9Impl_GetFunction
86 };
87
88
89 /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
90 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
91     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
92     FIXME("(%p) : stub\n", This);
93     return D3D_OK;
94 }
95
96 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9* pShader) {
97     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
98
99     This->UpdateStateBlock->VertexShader = pShader;
100     This->UpdateStateBlock->Changed.vertexShader = TRUE;
101     This->UpdateStateBlock->Set.vertexShader = TRUE;
102     
103     /* Handle recording of state blocks */
104     if (This->isRecordingState) {
105       TRACE("Recording... not performing anything\n");
106       return D3D_OK;
107     }
108     /**
109      * TODO: merge HAL shaders context switching from prototype
110      */
111     return D3D_OK;
112 }
113
114 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9** ppShader) {
115     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
116     TRACE("(%p) : GetVertexShader returning %p\n", This, This->StateBlock->VertexShader);
117     *ppShader = This->StateBlock->VertexShader;
118     IDirect3DVertexShader9Impl_AddRef(*ppShader);
119     return D3D_OK;
120 }
121
122 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
123   IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
124
125   if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
126     ERR("(%p) : SetVertexShaderConstant C[%u] invalid\n", This, Register);
127     return D3DERR_INVALIDCALL;
128   }
129   if (NULL == pConstantData) {
130     return D3DERR_INVALIDCALL;
131   }
132   if (Vector4fCount > 1) {
133     CONST FLOAT* f = pConstantData;
134     UINT i;
135     TRACE("(%p) : SetVertexShaderConstant C[%u..%u]=\n", This, Register, Register + Vector4fCount - 1);
136     for (i = 0; i < Vector4fCount; ++i) {
137       TRACE("{%f, %f, %f, %f}\n", f[0], f[1], f[2], f[3]);
138       f += 4;
139     }
140   } else { 
141     const FLOAT* f = (const FLOAT*) pConstantData;
142     TRACE("(%p) : SetVertexShaderConstant, C[%u]={%f, %f, %f, %f}\n", This, Register, f[0], f[1], f[2], f[3]);
143   }
144   This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
145   memcpy(&This->UpdateStateBlock->vertexShaderConstantF[Register], pConstantData, Vector4fCount * 4 * sizeof(FLOAT));
146   return D3D_OK;
147 }
148
149 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
150   IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
151
152   TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4fCount);
153   if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
154     return D3DERR_INVALIDCALL;
155   }
156   if (NULL == pConstantData) {
157     return D3DERR_INVALIDCALL;
158   }
159   memcpy(pConstantData, &This->UpdateStateBlock->vertexShaderConstantF[Register], Vector4fCount * 4 * sizeof(FLOAT));
160   return D3D_OK;
161 }
162
163 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
164   IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
165
166   if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
167     ERR("(%p) : SetVertexShaderConstantI C[%u] invalid\n", This, Register);
168     return D3DERR_INVALIDCALL;
169   }
170   if (NULL == pConstantData) {
171     return D3DERR_INVALIDCALL;
172   }
173   if (Vector4iCount > 1) {
174     CONST int* f = pConstantData;
175     UINT i;
176     TRACE("(%p) : SetVertexShaderConstantI C[%u..%u]=\n", This, Register, Register + Vector4iCount - 1);
177     for (i = 0; i < Vector4iCount; ++i) {
178       TRACE("{%d, %d, %d, %d}\n", f[0], f[1], f[2], f[3]);
179       f += 4;
180     }
181   } else { 
182     CONST int* f = pConstantData;
183     TRACE("(%p) : SetVertexShaderConstantI, C[%u]={%i, %i, %i, %i}\n", This, Register, f[0], f[1], f[2], f[3]);
184   }
185   This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
186   memcpy(&This->UpdateStateBlock->vertexShaderConstantI[Register], pConstantData, Vector4iCount * 4 * sizeof(int));
187   return D3D_OK;
188 }
189
190 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
191   IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
192
193   TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4iCount);
194   if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
195     return D3DERR_INVALIDCALL;
196   }
197   if (NULL == pConstantData) {
198     return D3DERR_INVALIDCALL;
199   }
200   memcpy(pConstantData, &This->UpdateStateBlock->vertexShaderConstantI[Register], Vector4iCount * 4 * sizeof(FLOAT));
201   return D3D_OK;
202 }
203
204 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
205   IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
206   UINT i;
207
208   if (Register + BoolCount > D3D_VSHADER_MAX_CONSTANTS) {
209     ERR("(%p) : SetVertexShaderConstantB C[%u] invalid\n", This, Register);
210     return D3DERR_INVALIDCALL;
211   }
212   if (NULL == pConstantData) {
213     return D3DERR_INVALIDCALL;
214   }
215   if (BoolCount > 1) {
216     CONST BOOL* f = pConstantData;
217     TRACE("(%p) : SetVertexShaderConstantB C[%u..%u]=\n", This, Register, Register + BoolCount - 1);
218     for (i = 0; i < BoolCount; ++i) {
219       TRACE("{%u}\n", f[i]);
220     }
221   } else { 
222     CONST BOOL* f = pConstantData;
223     TRACE("(%p) : SetVertexShaderConstantB, C[%u]={%u}\n", This, Register, f[0]);
224   }
225   This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
226   for (i = 0; i < BoolCount; ++i) {
227     This->UpdateStateBlock->vertexShaderConstantB[Register] = pConstantData[i];
228   }
229   return D3D_OK;
230 }
231
232 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
233     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
234     FIXME("(%p) : stub\n", This);
235     return D3D_OK;
236 }