Get rid of HEAP_strdupWtoA calls.
[wine/multimedia.git] / dlls / d3d9 / vertexshader.c
blobade9c54d40fc396d75270390b4e9eaa042840dd4
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"
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
27 /* IDirect3DVertexShader9 IUnknown parts follow: */
28 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 IDirect3DVertexShader9Impl_AddRef(iface);
34 *ppobj = This;
35 return D3D_OK;
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39 return E_NOINTERFACE;
42 ULONG WINAPI IDirect3DVertexShader9Impl_AddRef(LPDIRECT3DVERTEXSHADER9 iface) {
43 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
44 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
45 return ++(This->ref);
48 ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 iface) {
49 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
50 ULONG ref = --This->ref;
52 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
53 if (ref == 0) {
54 HeapFree(GetProcessHeap(), 0, This);
56 return ref;
59 /* IDirect3DVertexShader9 Interface follow: */
60 HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
61 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
62 TRACE("(%p) : returning %p\n", This, This->Device);
63 *ppDevice = (LPDIRECT3DDEVICE9) This->Device;
64 IDirect3DDevice9Impl_AddRef(*ppDevice);
65 return D3D_OK;
68 HRESULT WINAPI IDirect3DVertexShader9Impl_GetFunction(LPDIRECT3DVERTEXSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
69 IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
70 FIXME("(%p) : stub\n", This);
71 return D3D_OK;
75 IDirect3DVertexShader9Vtbl Direct3DVertexShader9_Vtbl =
77 IDirect3DVertexShader9Impl_QueryInterface,
78 IDirect3DVertexShader9Impl_AddRef,
79 IDirect3DVertexShader9Impl_Release,
80 IDirect3DVertexShader9Impl_GetDevice,
81 IDirect3DVertexShader9Impl_GetFunction
85 /* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
86 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
87 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
88 FIXME("(%p) : stub\n", This);
89 return D3D_OK;
92 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9* pShader) {
93 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
95 This->UpdateStateBlock->VertexShader = pShader;
96 This->UpdateStateBlock->Changed.vertexShader = TRUE;
97 This->UpdateStateBlock->Set.vertexShader = TRUE;
99 /* Handle recording of state blocks */
100 if (This->isRecordingState) {
101 TRACE("Recording... not performing anything\n");
102 return D3D_OK;
105 * TODO: merge HAL shaders context switching from prototype
107 return D3D_OK;
110 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9 iface, IDirect3DVertexShader9** ppShader) {
111 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
112 TRACE("(%p) : GetVertexShader returning %p\n", This, This->StateBlock->VertexShader);
113 *ppShader = This->StateBlock->VertexShader;
114 IDirect3DVertexShader9Impl_AddRef(*ppShader);
115 return D3D_OK;
118 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
119 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
121 if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
122 ERR("(%p) : SetVertexShaderConstant C[%u] invalid\n", This, Register);
123 return D3DERR_INVALIDCALL;
125 if (NULL == pConstantData) {
126 return D3DERR_INVALIDCALL;
128 if (Vector4fCount > 1) {
129 CONST FLOAT* f = pConstantData;
130 UINT i;
131 TRACE("(%p) : SetVertexShaderConstant C[%u..%u]=\n", This, Register, Register + Vector4fCount - 1);
132 for (i = 0; i < Vector4fCount; ++i) {
133 TRACE("{%f, %f, %f, %f}\n", f[0], f[1], f[2], f[3]);
134 f += 4;
136 } else {
137 const FLOAT* f = (const FLOAT*) pConstantData;
138 TRACE("(%p) : SetVertexShaderConstant, C[%u]={%f, %f, %f, %f}\n", This, Register, f[0], f[1], f[2], f[3]);
140 This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
141 memcpy(&This->UpdateStateBlock->vertexShaderConstantF[Register], pConstantData, Vector4fCount * 4 * sizeof(FLOAT));
142 return D3D_OK;
145 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
146 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
148 TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4fCount);
149 if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
150 return D3DERR_INVALIDCALL;
152 if (NULL == pConstantData) {
153 return D3DERR_INVALIDCALL;
155 memcpy(pConstantData, &This->UpdateStateBlock->vertexShaderConstantF[Register], Vector4fCount * 4 * sizeof(FLOAT));
156 return D3D_OK;
159 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
160 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
162 if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
163 ERR("(%p) : SetVertexShaderConstantI C[%u] invalid\n", This, Register);
164 return D3DERR_INVALIDCALL;
166 if (NULL == pConstantData) {
167 return D3DERR_INVALIDCALL;
169 if (Vector4iCount > 1) {
170 CONST int* f = pConstantData;
171 UINT i;
172 TRACE("(%p) : SetVertexShaderConstantI C[%u..%u]=\n", This, Register, Register + Vector4iCount - 1);
173 for (i = 0; i < Vector4iCount; ++i) {
174 TRACE("{%d, %d, %d, %d}\n", f[0], f[1], f[2], f[3]);
175 f += 4;
177 } else {
178 CONST int* f = pConstantData;
179 TRACE("(%p) : SetVertexShaderConstantI, C[%u]={%i, %i, %i, %i}\n", This, Register, f[0], f[1], f[2], f[3]);
181 This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
182 memcpy(&This->UpdateStateBlock->vertexShaderConstantI[Register], pConstantData, Vector4iCount * 4 * sizeof(int));
183 return D3D_OK;
186 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
187 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
189 TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4iCount);
190 if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
191 return D3DERR_INVALIDCALL;
193 if (NULL == pConstantData) {
194 return D3DERR_INVALIDCALL;
196 memcpy(pConstantData, &This->UpdateStateBlock->vertexShaderConstantI[Register], Vector4iCount * 4 * sizeof(FLOAT));
197 return D3D_OK;
200 HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
201 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
202 UINT i;
204 if (Register + BoolCount > D3D_VSHADER_MAX_CONSTANTS) {
205 ERR("(%p) : SetVertexShaderConstantB C[%u] invalid\n", This, Register);
206 return D3DERR_INVALIDCALL;
208 if (NULL == pConstantData) {
209 return D3DERR_INVALIDCALL;
211 if (BoolCount > 1) {
212 CONST BOOL* f = pConstantData;
213 TRACE("(%p) : SetVertexShaderConstantB C[%u..%u]=\n", This, Register, Register + BoolCount - 1);
214 for (i = 0; i < BoolCount; ++i) {
215 TRACE("{%u}\n", f[i]);
217 } else {
218 CONST BOOL* f = pConstantData;
219 TRACE("(%p) : SetVertexShaderConstantB, C[%u]={%u}\n", This, Register, f[0]);
221 This->UpdateStateBlock->Changed.vertexShaderConstant = TRUE;
222 for (i = 0; i < BoolCount; ++i) {
223 This->UpdateStateBlock->vertexShaderConstantB[Register] = pConstantData[i];
225 return D3D_OK;
228 HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
229 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
230 FIXME("(%p) : stub\n", This);
231 return D3D_OK;