2 * IDirect3DPixelShader9 implementation
4 * Copyright 2002-2003 Jason Edmeades
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
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
27 /* IDirect3DPixelShader9 IUnknown parts follow: */
28 HRESULT WINAPI IDirect3DPixelShader9Impl_QueryInterface(LPDIRECT3DPIXELSHADER9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DPixelShader9)) {
33 IDirect3DPixelShader9Impl_AddRef(iface);
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42 ULONG WINAPI IDirect3DPixelShader9Impl_AddRef(LPDIRECT3DPIXELSHADER9 iface) {
43 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
44 ULONG ref = InterlockedIncrement(&This->ref);
46 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
51 ULONG WINAPI IDirect3DPixelShader9Impl_Release(LPDIRECT3DPIXELSHADER9 iface) {
52 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
53 ULONG ref = InterlockedDecrement(&This->ref);
55 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
58 HeapFree(GetProcessHeap(), 0, This);
63 /* IDirect3DPixelShader9 Interface follow: */
64 HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(LPDIRECT3DPIXELSHADER9 iface, IDirect3DDevice9** ppDevice) {
65 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
66 TRACE("(%p) : returning %p\n", This, This->Device);
67 *ppDevice = (LPDIRECT3DDEVICE9) This->Device;
68 IDirect3DDevice9Impl_AddRef(*ppDevice);
72 HRESULT WINAPI IDirect3DPixelShader9Impl_GetFunction(LPDIRECT3DPIXELSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
73 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
74 FIXME("(%p): stub\n", This);
79 IDirect3DPixelShader9Vtbl Direct3DPixelShader9_Vtbl =
81 IDirect3DPixelShader9Impl_QueryInterface,
82 IDirect3DPixelShader9Impl_AddRef,
83 IDirect3DPixelShader9Impl_Release,
84 IDirect3DPixelShader9Impl_GetDevice,
85 IDirect3DPixelShader9Impl_GetFunction
89 /* IDirect3DDevice9 IDirect3DPixelShader9 Methods follow: */
90 HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) {
91 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
92 FIXME("(%p) : stub\n", This);
96 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9 iface, IDirect3DPixelShader9* pShader) {
97 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
99 This->UpdateStateBlock->PixelShader = pShader;
100 This->UpdateStateBlock->Changed.pixelShader = TRUE;
101 This->UpdateStateBlock->Set.pixelShader = TRUE;
103 /* Handle recording of state blocks */
104 if (This->isRecordingState) {
105 TRACE("Recording... not performing anything\n");
109 * TODO: merge HAL shaders context switching from prototype
114 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9 iface, IDirect3DPixelShader9** ppShader) {
115 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
116 TRACE("(%p) : GetPixelShader returning %p\n", This, This->StateBlock->PixelShader);
117 *ppShader = This->StateBlock->PixelShader;
118 IDirect3DPixelShader9Impl_AddRef(*ppShader);
122 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, CONST float* pConstantData, UINT Vector4fCount) {
123 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
125 if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
126 ERR("(%p) : SetPixelShaderConstant C[%u] invalid\n", This, Register);
127 return D3DERR_INVALIDCALL;
129 if (NULL == pConstantData) {
130 return D3DERR_INVALIDCALL;
132 if (Vector4fCount > 1) {
133 CONST FLOAT* f = pConstantData;
135 TRACE("(%p) : SetPixelShaderConstant 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]);
141 const FLOAT* f = (const FLOAT*) pConstantData;
142 TRACE("(%p) : SetPixelShaderConstant, C[%u]={%f, %f, %f, %f}\n", This, Register, f[0], f[1], f[2], f[3]);
144 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
145 memcpy(&This->UpdateStateBlock->pixelShaderConstantF[Register], pConstantData, Vector4fCount * 4 * sizeof(FLOAT));
149 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(LPDIRECT3DDEVICE9 iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
150 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
152 TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4fCount);
153 if (Register + Vector4fCount > D3D_VSHADER_MAX_CONSTANTS) {
154 return D3DERR_INVALIDCALL;
156 if (NULL == pConstantData) {
157 return D3DERR_INVALIDCALL;
159 memcpy(pConstantData, &This->UpdateStateBlock->pixelShaderConstantF[Register], Vector4fCount * 4 * sizeof(FLOAT));
163 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
164 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
166 if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
167 ERR("(%p) : SetPixelShaderConstantI C[%u] invalid\n", This, Register);
168 return D3DERR_INVALIDCALL;
170 if (NULL == pConstantData) {
171 return D3DERR_INVALIDCALL;
173 if (Vector4iCount > 1) {
174 CONST int* f = pConstantData;
176 TRACE("(%p) : SetPixelShaderConstantI 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]);
182 CONST int* f = pConstantData;
183 TRACE("(%p) : SetPixelShaderConstantI, C[%u]={%i, %i, %i, %i}\n", This, Register, f[0], f[1], f[2], f[3]);
185 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
186 memcpy(&This->UpdateStateBlock->pixelShaderConstantI[Register], pConstantData, Vector4iCount * 4 * sizeof(int));
190 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(LPDIRECT3DDEVICE9 iface, UINT Register, int* pConstantData, UINT Vector4iCount) {
191 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
193 TRACE("(%p) : C[%u] count=%u\n", This, Register, Vector4iCount);
194 if (Register + Vector4iCount > D3D_VSHADER_MAX_CONSTANTS) {
195 return D3DERR_INVALIDCALL;
197 if (NULL == pConstantData) {
198 return D3DERR_INVALIDCALL;
200 memcpy(pConstantData, &This->UpdateStateBlock->pixelShaderConstantI[Register], Vector4iCount * 4 * sizeof(FLOAT));
204 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
205 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
208 if (Register + BoolCount > D3D_VSHADER_MAX_CONSTANTS) {
209 ERR("(%p) : SetPixelShaderConstantB C[%u] invalid\n", This, Register);
210 return D3DERR_INVALIDCALL;
212 if (NULL == pConstantData) {
213 return D3DERR_INVALIDCALL;
216 CONST BOOL* f = pConstantData;
217 TRACE("(%p) : SetPixelShaderConstantB C[%u..%u]=\n", This, Register, Register + BoolCount - 1);
218 for (i = 0; i < BoolCount; ++i) {
219 TRACE("{%u}\n", f[i]);
222 CONST BOOL* f = pConstantData;
223 TRACE("(%p) : SetPixelShaderConstantB, C[%u]={%u}\n", This, Register, f[0]);
225 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
226 for (i = 0; i < BoolCount; ++i) {
227 This->UpdateStateBlock->pixelShaderConstantB[Register] = pConstantData[i];
232 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
233 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
234 FIXME("(%p) : stub\n", This);