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
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
34 #include "d3d9_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
38 /* IDirect3DPixelShader9 IUnknown parts follow: */
39 HRESULT WINAPI
IDirect3DPixelShader9Impl_QueryInterface(LPDIRECT3DPIXELSHADER9 iface
, REFIID riid
, LPVOID
* ppobj
) {
40 ICOM_THIS(IDirect3DPixelShader9Impl
,iface
);
42 if (IsEqualGUID(riid
, &IID_IUnknown
)
43 || IsEqualGUID(riid
, &IID_IDirect3DPixelShader9
)) {
44 IDirect3DPixelShader9Impl_AddRef(iface
);
49 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
53 ULONG WINAPI
IDirect3DPixelShader9Impl_AddRef(LPDIRECT3DPIXELSHADER9 iface
) {
54 ICOM_THIS(IDirect3DPixelShader9Impl
,iface
);
55 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
59 ULONG WINAPI
IDirect3DPixelShader9Impl_Release(LPDIRECT3DPIXELSHADER9 iface
) {
60 ICOM_THIS(IDirect3DPixelShader9Impl
,iface
);
61 ULONG ref
= --This
->ref
;
63 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
65 HeapFree(GetProcessHeap(), 0, This
);
70 /* IDirect3DPixelShader9 Interface follow: */
71 HRESULT WINAPI
IDirect3DPixelShader9Impl_GetDevice(LPDIRECT3DPIXELSHADER9 iface
, IDirect3DDevice9
** ppDevice
) {
72 ICOM_THIS(IDirect3DPixelShader9Impl
,iface
);
73 TRACE("(%p) : returning %p\n", This
, This
->Device
);
74 *ppDevice
= (LPDIRECT3DDEVICE9
) This
->Device
;
75 IDirect3DDevice9Impl_AddRef(*ppDevice
);
79 HRESULT WINAPI
IDirect3DPixelShader9Impl_GetFunction(LPDIRECT3DPIXELSHADER9 iface
, VOID
* pData
, UINT
* pSizeOfData
) {
80 ICOM_THIS(IDirect3DPixelShader9Impl
,iface
);
81 FIXME("(%p): stub\n", This
);
86 IDirect3DPixelShader9Vtbl Direct3DPixelShader9_Vtbl
=
88 IDirect3DPixelShader9Impl_QueryInterface
,
89 IDirect3DPixelShader9Impl_AddRef
,
90 IDirect3DPixelShader9Impl_Release
,
91 IDirect3DPixelShader9Impl_GetDevice
,
92 IDirect3DPixelShader9Impl_GetFunction
96 /* IDirect3DDevice9 IDirect3DPixelShader9 Methods follow: */
97 HRESULT WINAPI
IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9 iface
, CONST DWORD
* pFunction
, IDirect3DPixelShader9
** ppShader
) {
98 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
99 FIXME("(%p) : stub\n", This
);
103 HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9 iface
, IDirect3DPixelShader9
* pShader
) {
104 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
106 This
->UpdateStateBlock
->PixelShader
= pShader
;
107 This
->UpdateStateBlock
->Changed
.pixelShader
= TRUE
;
108 This
->UpdateStateBlock
->Set
.pixelShader
= TRUE
;
110 /* Handle recording of state blocks */
111 if (This
->isRecordingState
) {
112 TRACE("Recording... not performing anything\n");
116 * TODO: merge HAL shaders context switching from prototype
121 HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9 iface
, IDirect3DPixelShader9
** ppShader
) {
122 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
123 TRACE("(%p) : GetPixelShader returning %p\n", This
, This
->StateBlock
->PixelShader
);
124 *ppShader
= This
->StateBlock
->PixelShader
;
125 IDirect3DPixelShader9Impl_AddRef(*ppShader
);
129 HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantF(LPDIRECT3DDEVICE9 iface
, UINT Register
, CONST
float* pConstantData
, UINT Vector4fCount
) {
130 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
132 if (Register
+ Vector4fCount
> D3D_VSHADER_MAX_CONSTANTS
) {
133 ERR("(%p) : SetPixelShaderConstant C[%u] invalid\n", This
, Register
);
134 return D3DERR_INVALIDCALL
;
136 if (NULL
== pConstantData
) {
137 return D3DERR_INVALIDCALL
;
139 if (Vector4fCount
> 1) {
140 CONST FLOAT
* f
= pConstantData
;
142 TRACE("(%p) : SetPixelShaderConstant C[%u..%u]=\n", This
, Register
, Register
+ Vector4fCount
- 1);
143 for (i
= 0; i
< Vector4fCount
; ++i
) {
144 TRACE("{%f, %f, %f, %f}\n", f
[0], f
[1], f
[2], f
[3]);
148 FLOAT
* f
= (FLOAT
*) pConstantData
;
149 TRACE("(%p) : SetPixelShaderConstant, C[%u]={%f, %f, %f, %f}\n", This
, Register
, f
[0], f
[1], f
[2], f
[3]);
151 This
->UpdateStateBlock
->Changed
.pixelShaderConstant
= TRUE
;
152 memcpy(&This
->UpdateStateBlock
->pixelShaderConstantF
[Register
], pConstantData
, Vector4fCount
* 4 * sizeof(FLOAT
));
156 HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantF(LPDIRECT3DDEVICE9 iface
, UINT Register
, float* pConstantData
, UINT Vector4fCount
) {
157 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
159 TRACE("(%p) : C[%u] count=%u\n", This
, Register
, Vector4fCount
);
160 if (Register
+ Vector4fCount
> D3D_VSHADER_MAX_CONSTANTS
) {
161 return D3DERR_INVALIDCALL
;
163 if (NULL
== pConstantData
) {
164 return D3DERR_INVALIDCALL
;
166 memcpy(pConstantData
, &This
->UpdateStateBlock
->pixelShaderConstantF
[Register
], Vector4fCount
* 4 * sizeof(FLOAT
));
170 HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantI(LPDIRECT3DDEVICE9 iface
, UINT Register
, CONST
int* pConstantData
, UINT Vector4iCount
) {
171 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
173 if (Register
+ Vector4iCount
> D3D_VSHADER_MAX_CONSTANTS
) {
174 ERR("(%p) : SetPixelShaderConstantI C[%u] invalid\n", This
, Register
);
175 return D3DERR_INVALIDCALL
;
177 if (NULL
== pConstantData
) {
178 return D3DERR_INVALIDCALL
;
180 if (Vector4iCount
> 1) {
181 CONST
int* f
= pConstantData
;
183 TRACE("(%p) : SetPixelShaderConstantI C[%u..%u]=\n", This
, Register
, Register
+ Vector4iCount
- 1);
184 for (i
= 0; i
< Vector4iCount
; ++i
) {
185 TRACE("{%d, %d, %d, %d}\n", f
[0], f
[1], f
[2], f
[3]);
189 CONST
int* f
= pConstantData
;
190 TRACE("(%p) : SetPixelShaderConstantI, C[%u]={%i, %i, %i, %i}\n", This
, Register
, f
[0], f
[1], f
[2], f
[3]);
192 This
->UpdateStateBlock
->Changed
.pixelShaderConstant
= TRUE
;
193 memcpy(&This
->UpdateStateBlock
->pixelShaderConstantI
[Register
], pConstantData
, Vector4iCount
* 4 * sizeof(int));
197 HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantI(LPDIRECT3DDEVICE9 iface
, UINT Register
, int* pConstantData
, UINT Vector4iCount
) {
198 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
200 TRACE("(%p) : C[%u] count=%u\n", This
, Register
, Vector4iCount
);
201 if (Register
+ Vector4iCount
> D3D_VSHADER_MAX_CONSTANTS
) {
202 return D3DERR_INVALIDCALL
;
204 if (NULL
== pConstantData
) {
205 return D3DERR_INVALIDCALL
;
207 memcpy(pConstantData
, &This
->UpdateStateBlock
->pixelShaderConstantI
[Register
], Vector4iCount
* 4 * sizeof(FLOAT
));
211 HRESULT WINAPI
IDirect3DDevice9Impl_SetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface
, UINT Register
, CONST BOOL
* pConstantData
, UINT BoolCount
) {
212 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
215 if (Register
+ BoolCount
> D3D_VSHADER_MAX_CONSTANTS
) {
216 ERR("(%p) : SetPixelShaderConstantB C[%u] invalid\n", This
, Register
);
217 return D3DERR_INVALIDCALL
;
219 if (NULL
== pConstantData
) {
220 return D3DERR_INVALIDCALL
;
223 CONST BOOL
* f
= pConstantData
;
224 TRACE("(%p) : SetPixelShaderConstantB C[%u..%u]=\n", This
, Register
, Register
+ BoolCount
- 1);
225 for (i
= 0; i
< BoolCount
; ++i
) {
226 TRACE("{%u}\n", f
[i
]);
229 CONST BOOL
* f
= pConstantData
;
230 TRACE("(%p) : SetPixelShaderConstantB, C[%u]={%u}\n", This
, Register
, f
[0]);
232 This
->UpdateStateBlock
->Changed
.pixelShaderConstant
= TRUE
;
233 for (i
= 0; i
< BoolCount
; ++i
) {
234 This
->UpdateStateBlock
->pixelShaderConstantB
[Register
] = pConstantData
[i
];
239 HRESULT WINAPI
IDirect3DDevice9Impl_GetPixelShaderConstantB(LPDIRECT3DDEVICE9 iface
, UINT Register
, BOOL
* pConstantData
, UINT BoolCount
) {
240 ICOM_THIS(IDirect3DDevice9Impl
,iface
);
241 FIXME("(%p) : stub\n", This
);