- some cleanups and fixes on d3d8 and d3d9 headers
[wine/hacks.git] / dlls / d3d9 / vertexshader.c
blob38bedef8260ca6e6a473c0ca15ab96430ab14184
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wingdi.h"
30 #include "wine/debug.h"
32 #include "d3d9_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
36 /* IDirect3DVertexShader9 IUnknown parts follow: */
37 HRESULT WINAPI IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEXSHADER9 iface, REFIID riid, LPVOID* ppobj) {
38 ICOM_THIS(IDirect3DVertexShader9Impl,iface);
40 if (IsEqualGUID(riid, &IID_IUnknown)
41 || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
42 IDirect3DVertexShader9Impl_AddRef(iface);
43 *ppobj = This;
44 return D3D_OK;
47 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
48 return E_NOINTERFACE;
51 ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
52 ICOM_THIS(IDirect3DVertexShader9Impl,iface);
53 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
54 return ++(This->ref);
57 ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
58 ICOM_THIS(IDirect3DVertexShader9Impl,iface);
59 ULONG ref = --This->ref;
61 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
62 if (ref == 0) {
63 HeapFree(GetProcessHeap(), 0, This);
65 return ref;
68 /* IDirect3DVertexShader9 Interface follow: */
69 HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
70 ICOM_THIS(IDirect3DVertexShader9Impl,iface);
71 TRACE("(%p) : returning %p\n", This, This->Device);
72 *ppDevice = (LPDIRECT3DDEVICE9) This->Device;
73 IDirect3DDevice9Impl_AddRef(*ppDevice);
74 return D3D_OK;
77 HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
78 ICOM_THIS(IDirect3DVertexShader9Impl,iface);
79 FIXME("(%p) : stub\n", This);
80 return D3D_OK;
84 ICOM_VTABLE(IDirect3DVertexShader9) Direct3DVertexShader9_Vtbl =
86 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
87 IDirect3DVertexShader9Impl_QueryInterface,
88 IDirect3DVertexShader9Impl_AddRef,
89 IDirect3DVertexShader9Impl_Release,
90 IDirect3DVertexShader9Impl_GetDevice,
91 IDirect3DVertexShader9Impl_GetFunction
95 /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
96 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
97 ICOM_THIS(IDirect3DDevice9Impl,iface);
98 FIXME("(%p) : stub\n", This);
99 return D3D_OK;
102 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9* pShader) {
103 ICOM_THIS(IDirect3DDevice9Impl,iface);
105 This->UpdateStateBlock->VertexShader = pShader;
106 This->UpdateStateBlock->Changed.vertexShader = TRUE;
107 This->UpdateStateBlock->Set.vertexShader = TRUE;
109 /* Handle recording of state blocks */
110 if (This->isRecordingState) {
111 TRACE("Recording... not performing anything\n");
112 return D3D_OK;
115 * TODO: merge HAL shaders context switching from prototype
117 return D3D_OK;
120 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9** ppShader) {
121 ICOM_THIS(IDirect3DDevice9Impl,iface);
122 TRACE("(%p) : GetVertexShader returning %p\n", This, This->StateBlock->VertexShader);
123 *ppShader = This->StateBlock->VertexShader;
124 IDirect3DVertexShader9Impl_AddRef(*ppShader);
125 return D3D_OK;
128 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
129 ICOM_THIS(IDirect3DDevice9Impl,iface);
131 if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
132 ERR("(%p) : SetVertexShaderConstant C[%u] invalid\n", This, Register);
133 return D3DERR_INVALIDCALL;
135 if (NULL == pConstantData) {
136 return D3DERR_INVALIDCALL;
138 if (Vector4fCount > 1) {
139 CONST FLOAT* f = pConstantData;
140 UINT i;
141 TRACE("(%p) : SetVertexShaderConstant C[%u..%u]=\n", This, Register, Register + Vector4fCount - 1);
142 for (i = 0; i < Vector4fCount; ++i) {
143 TRACE("{%f, %f, %f, %f}\n", f[0], f[1], f[2], f[3]);
144 f += 4;
146 } else {
147 FLOAT* f = (FLOAT*) pConstantData;
148 TRACE("(%p) : SetVertexShaderConstant, C[%u]={%f, %f, %f, %f}\n", This, Register, f[0], f[1], f[2], f[3]);
150 This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
151 memcpy(&This->UpdateStateBlock->vertexShaderConstantF[Register], pConstantData, Vector4fCount * 4 * sizeof(FLOAT));
152 return D3D_OK;
155 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
156 ICOM_THIS(IDirect3DDevice9Impl,iface);
158 TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4fCount);
159 if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
160 return D3DERR_INVALIDCALL;
162 if (NULL == pConstantData) {
163 return D3DERR_INVALIDCALL;
165 memcpy(pConstantData, &This->UpdateStateBlock->vertexShaderConstantF[Register], Vector4fCount * 4 * sizeof(FLOAT));
166 return D3D_OK;
169 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
170 ICOM_THIS(IDirect3DDevice9Impl,iface);
172 if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
173 ERR("(%p) : SetVertexShaderConstantI C[%u] invalid\n", This, Register);
174 return D3DERR_INVALIDCALL;
176 if (NULL == pConstantData) {
177 return D3DERR_INVALIDCALL;
179 if (Vector4iCount > 1) {
180 CONST int* f = pConstantData;
181 UINT i;
182 TRACE("(%p) : SetVertexShaderConstantI C[%u..%u]=\n", This, Register, Register + Vector4iCount - 1);
183 for (i = 0; i < Vector4iCount; ++i) {
184 TRACE("{%d, %d, %d, %d}\n", f[0], f[1], f[2], f[3]);
185 f += 4;
187 } else {
188 CONST int* f = pConstantData;
189 TRACE("(%p) : SetVertexShaderConstantI, C[%u]={%i, %i, %i, %i}\n", This, Register, f[0], f[1], f[2], f[3]);
191 This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
192 memcpy(&This->UpdateStateBlock->vertexShaderConstantI[Register], pConstantData, Vector4iCount * 4 * sizeof(int));
193 return D3D_OK;
196 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
197 ICOM_THIS(IDirect3DDevice9Impl,iface);
199 TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4iCount);
200 if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
201 return D3DERR_INVALIDCALL;
203 if (NULL == pConstantData) {
204 return D3DERR_INVALIDCALL;
206 memcpy(pConstantData, &This->UpdateStateBlock->vertexShaderConstantI[Register], Vector4iCount * 4 * sizeof(FLOAT));
207 return D3D_OK;
210 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
211 ICOM_THIS(IDirect3DDevice9Impl,iface);
212 UINT i;
214 if (Register + BoolCount > D3D_VSHADER_MAX_CONSTANTS) {
215 ERR("(%p) : SetVertexShaderConstantB C[%u] invalid\n", This, Register);
216 return D3DERR_INVALIDCALL;
218 if (NULL == pConstantData) {
219 return D3DERR_INVALIDCALL;
221 if (BoolCount > 1) {
222 CONST BOOL* f = pConstantData;
223 TRACE("(%p) : SetVertexShaderConstantB C[%u..%u]=\n", This, Register, Register + BoolCount - 1);
224 for (i = 0; i < BoolCount; ++i) {
225 TRACE("{%u}\n", f[i]);
227 } else {
228 CONST BOOL* f = pConstantData;
229 TRACE("(%p) : SetVertexShaderConstantB, C[%u]={%u}\n", This, Register, f[0]);
231 This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
232 for (i = 0; i < BoolCount; ++i) {
233 This->UpdateStateBlock->vertexShaderConstantB[Register] = pConstantData[i];
235 return D3D_OK;
238 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
239 ICOM_THIS(IDirect3DDevice9Impl,iface);
240 FIXME("(%p) : stub\n", This);
241 return D3D_OK;