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 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
48 ULONG WINAPI IDirect3DPixelShader9Impl_Release(LPDIRECT3DPIXELSHADER9 iface) {
49 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
50 ULONG ref = --This->ref;
52 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
54 HeapFree(GetProcessHeap(), 0, This);
59 /* IDirect3DPixelShader9 Interface follow: */
60 HRESULT WINAPI IDirect3DPixelShader9Impl_GetDevice(LPDIRECT3DPIXELSHADER9 iface, IDirect3DDevice9** ppDevice) {
61 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
62 TRACE("(%p) : returning %p\n", This, This->Device);
63 *ppDevice = (LPDIRECT3DDEVICE9) This->Device;
64 IDirect3DDevice9Impl_AddRef(*ppDevice);
68 HRESULT WINAPI IDirect3DPixelShader9Impl_GetFunction(LPDIRECT3DPIXELSHADER9 iface, VOID* pData, UINT* pSizeOfData) {
69 IDirect3DPixelShader9Impl *This = (IDirect3DPixelShader9Impl *)iface;
70 FIXME("(%p): stub\n", This);
75 IDirect3DPixelShader9Vtbl Direct3DPixelShader9_Vtbl =
77 IDirect3DPixelShader9Impl_QueryInterface,
78 IDirect3DPixelShader9Impl_AddRef,
79 IDirect3DPixelShader9Impl_Release,
80 IDirect3DPixelShader9Impl_GetDevice,
81 IDirect3DPixelShader9Impl_GetFunction
85 /* IDirect3DDevice9 IDirect3DPixelShader9 Methods follow: */
86 HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9 iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) {
87 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
88 FIXME("(%p) : stub\n", This);
92 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9 iface, IDirect3DPixelShader9* pShader) {
93 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
95 This->UpdateStateBlock->PixelShader = pShader;
96 This->UpdateStateBlock->Changed.pixelShader = TRUE;
97 This->UpdateStateBlock->Set.pixelShader = TRUE;
99 /* Handle recording of state blocks */
100 if (This->isRecordingState) {
101 TRACE("Recording... not performing anything\n");
105 * TODO: merge HAL shaders context switching from prototype
110 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9 iface, IDirect3DPixelShader9** ppShader) {
111 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
112 TRACE("(%p) : GetPixelShader returning %p\n", This, This->StateBlock->PixelShader);
113 *ppShader = This->StateBlock->PixelShader;
114 IDirect3DPixelShader9Impl_AddRef(*ppShader);
118 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(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) : SetPixelShaderConstant 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;
131 TRACE("(%p) : SetPixelShaderConstant 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]);
137 FLOAT* f = (FLOAT*) pConstantData;
138 TRACE("(%p) : SetPixelShaderConstant, C[%u]={%f, %f, %f, %f}\n", This, Register, f[0], f[1], f[2], f[3]);
140 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
141 memcpy(&This->UpdateStateBlock->pixelShaderConstantF[Register], pConstantData, Vector4fCount * 4 * sizeof(FLOAT));
145 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(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->pixelShaderConstantF[Register], Vector4fCount * 4 * sizeof(FLOAT));
159 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(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) : SetPixelShaderConstantI 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;
172 TRACE("(%p) : SetPixelShaderConstantI 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]);
178 CONST int* f = pConstantData;
179 TRACE("(%p) : SetPixelShaderConstantI, C[%u]={%i, %i, %i, %i}\n", This, Register, f[0], f[1], f[2], f[3]);
181 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
182 memcpy(&This->UpdateStateBlock->pixelShaderConstantI[Register], pConstantData, Vector4iCount * 4 * sizeof(int));
186 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(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->pixelShaderConstantI[Register], Vector4iCount * 4 * sizeof(FLOAT));
200 HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, CONST BOOL* pConstantData, UINT BoolCount) {
201 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
204 if (Register + BoolCount > D3D_VSHADER_MAX_CONSTANTS) {
205 ERR("(%p) : SetPixelShaderConstantB C[%u] invalid\n", This, Register);
206 return D3DERR_INVALIDCALL;
208 if (NULL == pConstantData) {
209 return D3DERR_INVALIDCALL;
212 CONST BOOL* f = pConstantData;
213 TRACE("(%p) : SetPixelShaderConstantB C[%u..%u]=\n", This, Register, Register + BoolCount - 1);
214 for (i = 0; i < BoolCount; ++i) {
215 TRACE("{%u}\n", f[i]);
218 CONST BOOL* f = pConstantData;
219 TRACE("(%p) : SetPixelShaderConstantB, C[%u]={%u}\n", This, Register, f[0]);
221 This->UpdateStateBlock->Changed.pixelShaderConstant = TRUE;
222 for (i = 0; i < BoolCount; ++i) {
223 This->UpdateStateBlock->pixelShaderConstantB[Register] = pConstantData[i];
228 HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface, UINT Register, BOOL* pConstantData, UINT BoolCount) {
229 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
230 FIXME("(%p) : stub\n", This);